forked from KolibriOS/kolibrios
28e207c0cc
git-svn-id: svn://kolibrios.org@9630 a494cfbc-eb01-0410-851d-a64ba20cac60
115 lines
2.9 KiB
Plaintext
115 lines
2.9 KiB
Plaintext
(*
|
|
Copyright 2021, 2022 Anton Krotov
|
|
|
|
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;
|
|
|
|
IMPORT G := Graph, K := KolibriOS, U := Utils;
|
|
|
|
|
|
CONST
|
|
padding = 4;
|
|
fontWidth = K.fontWidth;
|
|
fontHeight = K.fontHeight;
|
|
bColor = 0FFFFFFH;
|
|
fColor = 0008000H;
|
|
|
|
|
|
TYPE
|
|
tCheckBox* = RECORD
|
|
|
|
left*, top*: INTEGER;
|
|
width, height: INTEGER;
|
|
value*, mouse: BOOLEAN;
|
|
text: ARRAY 32 OF WCHAR;
|
|
canvas: G.tCanvas
|
|
|
|
END;
|
|
|
|
|
|
PROCEDURE draw* (chkbox: tCheckBox);
|
|
VAR
|
|
canvas: G.tCanvas;
|
|
BEGIN
|
|
canvas := chkbox.canvas;
|
|
IF canvas # NIL THEN
|
|
G.SetColor(canvas, K.colors.work);
|
|
G.clear(canvas);
|
|
G.SetColor(canvas, bColor);
|
|
G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
|
|
G.SetColor(canvas, K.colors.line);
|
|
G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
|
|
IF chkbox.value THEN
|
|
G.SetColor(canvas, fColor);
|
|
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);
|
|
END;
|
|
G.SetTextColor(canvas, K.colors.work_text);
|
|
G.SetBkColor(canvas, K.colors.work);
|
|
G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
|
|
G.DrawCanvas(canvas, chkbox.left, chkbox.top)
|
|
END
|
|
END draw;
|
|
|
|
|
|
PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
|
|
VAR
|
|
res: tCheckBox;
|
|
BEGIN
|
|
res.left := 0;
|
|
res.top := 0;
|
|
res.value := FALSE;
|
|
res.mouse := FALSE;
|
|
COPY(text, res.text);
|
|
res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
|
|
G.SetFont(res.canvas, G.CreateFont(1, "", {}));
|
|
res.width := res.canvas.width;
|
|
res.height := res.canvas.height;
|
|
chkbox := res
|
|
END create;
|
|
|
|
|
|
PROCEDURE mouse* (VAR chkbox: tCheckBox);
|
|
VAR
|
|
msState: SET;
|
|
x, y: INTEGER;
|
|
BEGIN
|
|
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;
|
|
IF U.between(0, x, chkbox.width - 1) & U.between(0, y, chkbox.height - 1) THEN
|
|
chkbox.value := ~chkbox.value;
|
|
END;
|
|
draw(chkbox)
|
|
END
|
|
ELSE
|
|
chkbox.mouse := FALSE
|
|
END
|
|
END mouse;
|
|
|
|
|
|
END CheckBox. |