Subversion Repositories Kolibri OS

Rev

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

  1. (*
  2.     Copyright 2021, 2022 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.         bColor = 0FFFFFFH;
  30.         fColor = 0008000H;
  31.  
  32.  
  33. TYPE
  34.         tCheckBox* = RECORD
  35.  
  36.                 left*, top*: INTEGER;
  37.                 width, height: INTEGER;
  38.                 value*, mouse: BOOLEAN;
  39.                 text: ARRAY 32 OF WCHAR;
  40.                 canvas: G.tCanvas
  41.  
  42.         END;
  43.  
  44.  
  45. PROCEDURE draw* (chkbox: tCheckBox);
  46. VAR
  47.         canvas: G.tCanvas;
  48. BEGIN
  49.         canvas := chkbox.canvas;
  50.         IF canvas # NIL THEN
  51.                 G.SetColor(canvas, K.colors.work);
  52.                 G.clear(canvas);
  53.                 G.SetColor(canvas, bColor);
  54.                 G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
  55.                 G.SetColor(canvas, K.colors.line);
  56.                 G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
  57.                 IF chkbox.value THEN
  58.                         G.SetColor(canvas, fColor);
  59.                     G.DLine(canvas, 2,  6,  6, -1);
  60.                     G.DLine(canvas, 2,  6,  7, -1);
  61.                     G.DLine(canvas, 7, 13,  9,  1);
  62.                     G.DLine(canvas, 7, 13, 10,  1);
  63.                     G.DLine(canvas, 2,  6,  8, -1);
  64.                     G.DLine(canvas, 7, 13, 11,  1);
  65.                     G.DLine(canvas, 2,  6,  5, -1);
  66.                     G.DLine(canvas, 7, 13,  8,  1);
  67.                 END;
  68.                 G.SetTextColor(canvas, K.colors.work_text);
  69.                 G.SetBkColor(canvas, K.colors.work);
  70.                 G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
  71.                 G.DrawCanvas(canvas, chkbox.left, chkbox.top)
  72.         END
  73. END draw;
  74.  
  75.  
  76. PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
  77. VAR
  78.         res: tCheckBox;
  79. BEGIN
  80.         res.left := 0;
  81.         res.top := 0;
  82.         res.value := FALSE;
  83.         res.mouse := FALSE;
  84.         COPY(text, res.text);
  85.         res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
  86.         G.SetFont(res.canvas, G.CreateFont(1, "", {}));
  87.         res.width := res.canvas.width;
  88.         res.height := res.canvas.height;
  89.         chkbox := res
  90. END create;
  91.  
  92.  
  93. PROCEDURE mouse* (VAR chkbox: tCheckBox);
  94. VAR
  95.         msState: SET;
  96.         x, y: INTEGER;
  97. BEGIN
  98.         K.mouse(msState, x, y);
  99.         IF 0 IN msState THEN
  100.                 IF (chkbox.canvas # NIL) & ~chkbox.mouse THEN
  101.                         DEC(x, chkbox.left);
  102.                         DEC(y, chkbox.top);
  103.                         chkbox.mouse := TRUE;
  104.                         IF U.between(0, x, chkbox.width - 1) & U.between(0, y, chkbox.height - 1) THEN
  105.                                 chkbox.value := ~chkbox.value;
  106.                         END;
  107.                         draw(chkbox)
  108.                 END
  109.         ELSE
  110.                 chkbox.mouse := FALSE
  111.         END
  112. END mouse;
  113.  
  114.  
  115. END CheckBox.