kolibrios-fun/programs/develop/cedit/SRC/CheckBox.ob07
Anton Krotov 9c0be1dd39 CEDIT: Keyboard navigation in menu; internal changes
git-svn-id: svn://kolibrios.org@9187 a494cfbc-eb01-0410-851d-a64ba20cac60
2021-09-11 20:57:43 +00:00

109 lines
2.7 KiB
Plaintext

(*
Copyright 2021 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;
TYPE
tCheckBox* = RECORD
left*, top*: INTEGER;
width, height: INTEGER;
value*, mouse: BOOLEAN;
text: ARRAY 32 OF WCHAR;
canvas: G.tCanvas
END;
PROCEDURE paint* (chkbox: tCheckBox);
VAR
canvas: G.tCanvas;
BEGIN
canvas := chkbox.canvas;
IF canvas # NIL THEN
G.SetColor(canvas, K.winColor);
G.clear(canvas);
G.SetColor(canvas, 0FFFFFFH);
G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
G.SetColor(canvas, K.borderColor);
G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
IF chkbox.value THEN
G.SetColor(canvas, 0008000H);
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)
END;
G.SetTextColor(canvas, K.textColor);
G.SetBkColor(canvas, K.winColor);
G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
G.DrawCanvas(canvas, chkbox.left, chkbox.top)
END
END paint;
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 MouseDown* (VAR chkbox: tCheckBox; x, y: INTEGER);
BEGIN
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) & U.between(0, y, chkbox.height) THEN
chkbox.value := ~chkbox.value;
END;
paint(chkbox)
END
END MouseDown;
PROCEDURE MouseUp* (VAR chkbox: tCheckBox);
BEGIN
IF chkbox.canvas # NIL THEN
chkbox.mouse := FALSE
END
END MouseUp;
END CheckBox.