2021-09-08 22:47:14 +02:00
|
|
|
(*
|
2022-01-12 22:15:22 +01:00
|
|
|
Copyright 2021, 2022 Anton Krotov
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
This file is part of CEdit.
|
|
|
|
|
|
|
|
CEdit is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
CEdit is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE CheckBox;
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
IMPORT G := Graph, K := KolibriOS, U := Utils;
|
|
|
|
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
CONST
|
|
|
|
padding = 4;
|
2021-12-17 07:12:02 +01:00
|
|
|
fontWidth = K.fontWidth;
|
|
|
|
fontHeight = K.fontHeight;
|
|
|
|
bColor = 0FFFFFFH;
|
|
|
|
fColor = 0008000H;
|
2021-09-11 22:57:43 +02:00
|
|
|
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
TYPE
|
2021-09-11 22:57:43 +02:00
|
|
|
tCheckBox* = RECORD
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
left*, top*: INTEGER;
|
2021-09-11 22:57:43 +02:00
|
|
|
value*, mouse: BOOLEAN;
|
2021-09-08 22:47:14 +02:00
|
|
|
text: ARRAY 32 OF WCHAR;
|
|
|
|
canvas: G.tCanvas
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
2022-01-13 16:13:47 +01:00
|
|
|
PROCEDURE draw* (chkbox: tCheckBox);
|
2021-09-08 22:47:14 +02:00
|
|
|
VAR
|
|
|
|
canvas: G.tCanvas;
|
|
|
|
BEGIN
|
|
|
|
canvas := chkbox.canvas;
|
2021-09-11 22:57:43 +02:00
|
|
|
IF canvas # NIL THEN
|
2022-01-12 22:15:22 +01:00
|
|
|
G.SetColor(canvas, K.colors.work);
|
2021-09-11 22:57:43 +02:00
|
|
|
G.clear(canvas);
|
2021-12-17 07:12:02 +01:00
|
|
|
G.SetColor(canvas, bColor);
|
2021-09-11 22:57:43 +02:00
|
|
|
G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
|
2022-01-12 22:15:22 +01:00
|
|
|
G.SetColor(canvas, K.colors.line);
|
2021-09-11 22:57:43 +02:00
|
|
|
G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
|
|
|
|
IF chkbox.value THEN
|
2021-12-17 07:12:02 +01:00
|
|
|
G.SetColor(canvas, fColor);
|
2022-01-20 18:15:39 +01:00
|
|
|
G.DLine(canvas, 2, 6, 6, -1);
|
|
|
|
G.DLine(canvas, 2, 6, 7, -1);
|
|
|
|
G.DLine(canvas, 7, 13, 9, 1);
|
|
|
|
G.DLine(canvas, 7, 13, 10, 1);
|
|
|
|
G.DLine(canvas, 2, 6, 8, -1);
|
|
|
|
G.DLine(canvas, 7, 13, 11, 1);
|
|
|
|
G.DLine(canvas, 2, 6, 5, -1);
|
|
|
|
G.DLine(canvas, 7, 13, 8, 1);
|
2021-09-11 22:57:43 +02:00
|
|
|
END;
|
2022-01-12 22:15:22 +01:00
|
|
|
G.SetTextColor(canvas, K.colors.work_text);
|
|
|
|
G.SetBkColor(canvas, K.colors.work);
|
2021-09-11 22:57:43 +02:00
|
|
|
G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
|
|
|
|
G.DrawCanvas(canvas, chkbox.left, chkbox.top)
|
|
|
|
END
|
2022-01-13 16:13:47 +01:00
|
|
|
END draw;
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
|
2021-09-11 22:57:43 +02:00
|
|
|
PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
|
2021-09-08 22:47:14 +02:00
|
|
|
VAR
|
|
|
|
res: tCheckBox;
|
|
|
|
BEGIN
|
|
|
|
res.left := 0;
|
|
|
|
res.top := 0;
|
|
|
|
res.value := FALSE;
|
|
|
|
res.mouse := FALSE;
|
|
|
|
COPY(text, res.text);
|
2021-09-11 22:57:43 +02:00
|
|
|
res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
|
2022-01-25 22:57:14 +01:00
|
|
|
G.SetFont(res.canvas, G.fonts[1]);
|
2021-09-11 22:57:43 +02:00
|
|
|
chkbox := res
|
2021-09-08 22:47:14 +02:00
|
|
|
END create;
|
|
|
|
|
|
|
|
|
2021-09-28 18:15:37 +02:00
|
|
|
PROCEDURE mouse* (VAR chkbox: tCheckBox);
|
|
|
|
VAR
|
|
|
|
msState: SET;
|
|
|
|
x, y: INTEGER;
|
2021-09-08 22:47:14 +02:00
|
|
|
BEGIN
|
2021-09-28 18:15:37 +02:00
|
|
|
K.mouse(msState, x, y);
|
|
|
|
IF 0 IN msState THEN
|
|
|
|
IF (chkbox.canvas # NIL) & ~chkbox.mouse THEN
|
|
|
|
DEC(x, chkbox.left);
|
|
|
|
DEC(y, chkbox.top);
|
|
|
|
chkbox.mouse := TRUE;
|
2022-01-20 18:15:39 +01:00
|
|
|
IF U.between(0, x, chkbox.canvas.width - 1) & U.between(0, y, chkbox.canvas.height - 1) THEN
|
|
|
|
chkbox.value := ~chkbox.value
|
2021-09-28 18:15:37 +02:00
|
|
|
END;
|
2022-01-13 16:13:47 +01:00
|
|
|
draw(chkbox)
|
2021-09-28 18:15:37 +02:00
|
|
|
END
|
|
|
|
ELSE
|
2021-09-08 22:47:14 +02:00
|
|
|
chkbox.mouse := FALSE
|
|
|
|
END
|
2021-09-28 18:15:37 +02:00
|
|
|
END mouse;
|
2021-09-08 22:47:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
END CheckBox.
|