Subversion Repositories Kolibri OS

Rev

Rev 9187 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2021 Anton Krotov
  3.  
  4.     This file is part of CEdit.
  5.  
  6.     CEdit is free software: you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation, either version 3 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     CEdit is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with CEdit. If not, see <http://www.gnu.org/licenses/>.
  18. *)
  19.  
  20. MODULE CheckBox;
  21.  
  22. IMPORT G := Graph, K := KolibriOS;
  23.  
  24. CONST
  25.         padding = 4;
  26.  
  27. TYPE
  28.         tCheckBox* = POINTER TO RECORD
  29.  
  30.                 left*, top*: INTEGER;
  31.                 width, height: INTEGER;
  32.                 value*, mouse*: BOOLEAN;
  33.                 text: ARRAY 32 OF WCHAR;
  34.                 canvas: G.tCanvas
  35.  
  36.         END;
  37.  
  38.  
  39. PROCEDURE mark (canvas: G.tCanvas);
  40. BEGIN
  41.     G.DLine(canvas, 2,  6,  6, -1);
  42.     G.DLine(canvas, 2,  6,  7, -1);
  43.     G.DLine(canvas, 7, 13,  9,  1);
  44.     G.DLine(canvas, 7, 13, 10,  1);
  45. END mark;
  46.  
  47.  
  48. PROCEDURE paint* (chkbox: tCheckBox);
  49. VAR
  50.         canvas: G.tCanvas;
  51.         fontHeight: INTEGER;
  52. BEGIN
  53.         canvas := chkbox.canvas;
  54.         fontHeight := canvas.font.height - 1;
  55.         G.SetColor(canvas, K.winColor);
  56.         G.clear(canvas);
  57.         G.SetColor(canvas, 0FFFFFFH);
  58.         G.FillRect(canvas, 0, 0, fontHeight, fontHeight);
  59.         G.SetColor(canvas, K.borderColor);
  60.         G.Rect(canvas, 0, 0, fontHeight, fontHeight);
  61.         IF chkbox.value THEN
  62.                 G.SetColor(canvas, 0008000H);
  63.                 mark(canvas)
  64.         END;
  65.         G.SetTextColor(canvas, K.textColor);
  66.         G.SetBkColor(canvas, K.winColor);
  67.         G.TextOut2(canvas, canvas.font.height + padding, 0, chkbox.text, LENGTH(chkbox.text));
  68.         G.DrawCanvas(canvas, chkbox.left, chkbox.top)
  69. END paint;
  70.  
  71.  
  72. PROCEDURE create* (text: ARRAY OF WCHAR): tCheckBox;
  73. VAR
  74.         res: tCheckBox;
  75.         font: G.tFont;
  76. BEGIN
  77.         font := G.CreateFont(1, "", {});
  78.         NEW(res);
  79.         res.left := 0;
  80.         res.top := 0;
  81.         res.value := FALSE;
  82.         res.mouse := FALSE;
  83.         COPY(text, res.text);
  84.         res.canvas := G.CreateCanvas(font.height + padding + LENGTH(res.text)*font.width, font.height + 1);
  85.         G.SetFont(res.canvas, font);
  86.         res.width := res.canvas.width;
  87.         res.height := res.canvas.height;
  88.         RETURN res
  89. END create;
  90.  
  91.  
  92. PROCEDURE between (a, b, c: INTEGER): BOOLEAN;
  93.         RETURN (a <= b) & (b <= c)
  94. END between;
  95.  
  96.  
  97. PROCEDURE MouseDown* (chkbox: tCheckBox; x, y: INTEGER);
  98. BEGIN
  99.         IF (chkbox # NIL) & ~chkbox.mouse THEN
  100.                 DEC(x, chkbox.left);
  101.                 DEC(y, chkbox.top);
  102.                 chkbox.mouse := TRUE;
  103.                 IF between(0, x, chkbox.width) & between(0, y, chkbox.height) THEN
  104.                         chkbox.value := ~chkbox.value;
  105.                 END;
  106.                 paint(chkbox)
  107.         END
  108. END MouseDown;
  109.  
  110.  
  111. PROCEDURE MouseUp* (chkbox: tCheckBox);
  112. BEGIN
  113.         IF chkbox # NIL THEN
  114.                 chkbox.mouse := FALSE
  115.         END
  116. END MouseUp;
  117.  
  118.  
  119. END CheckBox.