Subversion Repositories Kolibri OS

Rev

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