Subversion Repositories Kolibri OS

Rev

Rev 9182 | Rev 9431 | 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, U := Utils;
  23.  
  24.  
  25. CONST
  26.         padding = 4;
  27.     fontWidth = K.fontWidth;
  28.     fontHeight = K.fontHeight;
  29.  
  30.  
  31. TYPE
  32.         tCheckBox* = RECORD
  33.  
  34.                 left*, top*: INTEGER;
  35.                 width, height: INTEGER;
  36.                 value*, mouse: BOOLEAN;
  37.                 text: ARRAY 32 OF WCHAR;
  38.                 canvas: G.tCanvas
  39.  
  40.         END;
  41.  
  42.  
  43. PROCEDURE paint* (chkbox: tCheckBox);
  44. VAR
  45.         canvas: G.tCanvas;
  46. BEGIN
  47.         canvas := chkbox.canvas;
  48.         IF canvas # NIL THEN
  49.                 G.SetColor(canvas, K.winColor);
  50.                 G.clear(canvas);
  51.                 G.SetColor(canvas, 0FFFFFFH);
  52.                 G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
  53.                 G.SetColor(canvas, K.borderColor);
  54.                 G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
  55.                 IF chkbox.value THEN
  56.                         G.SetColor(canvas, 0008000H);
  57.                     G.DLine(canvas, 2,  6,  6, -1);
  58.                     G.DLine(canvas, 2,  6,  7, -1);
  59.                     G.DLine(canvas, 7, 13,  9,  1);
  60.                     G.DLine(canvas, 7, 13, 10,  1)
  61.                 END;
  62.                 G.SetTextColor(canvas, K.textColor);
  63.                 G.SetBkColor(canvas, K.winColor);
  64.                 G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
  65.                 G.DrawCanvas(canvas, chkbox.left, chkbox.top)
  66.         END
  67. END paint;
  68.  
  69.  
  70. PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
  71. VAR
  72.         res: tCheckBox;
  73. BEGIN
  74.         res.left := 0;
  75.         res.top := 0;
  76.         res.value := FALSE;
  77.         res.mouse := FALSE;
  78.         COPY(text, res.text);
  79.         res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
  80.         G.SetFont(res.canvas, G.CreateFont(1, "", {}));
  81.         res.width := res.canvas.width;
  82.         res.height := res.canvas.height;
  83.         chkbox := res
  84. END create;
  85.  
  86.  
  87. PROCEDURE MouseDown* (VAR chkbox: tCheckBox; x, y: INTEGER);
  88. BEGIN
  89.         IF (chkbox.canvas # NIL) & ~chkbox.mouse THEN
  90.                 DEC(x, chkbox.left);
  91.                 DEC(y, chkbox.top);
  92.                 chkbox.mouse := TRUE;
  93.                 IF U.between(0, x, chkbox.width) & U.between(0, y, chkbox.height) THEN
  94.                         chkbox.value := ~chkbox.value;
  95.                 END;
  96.                 paint(chkbox)
  97.         END
  98. END MouseDown;
  99.  
  100.  
  101. PROCEDURE MouseUp* (VAR chkbox: tCheckBox);
  102. BEGIN
  103.         IF chkbox.canvas # NIL THEN
  104.                 chkbox.mouse := FALSE
  105.         END
  106. END MouseUp;
  107.  
  108.  
  109. END CheckBox.