2689ca976d
git-svn-id: svn://kolibrios.org@9431 a494cfbc-eb01-0410-851d-a64ba20cac60
120 lines
3.1 KiB
Plaintext
120 lines
3.1 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;
|
|
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 paint* (chkbox: tCheckBox);
|
|
VAR
|
|
canvas: G.tCanvas;
|
|
(*r1, r2, g1, g2, b1, b2: BYTE;*)
|
|
BEGIN
|
|
canvas := chkbox.canvas;
|
|
IF canvas # NIL THEN
|
|
G.SetColor(canvas, K.winColor);
|
|
G.clear(canvas);
|
|
G.SetColor(canvas, bColor);
|
|
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, 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.getRGB(bColor, r1, g1, b1);
|
|
G.getRGB(fColor, r2, g2, b2);
|
|
G.SetColor(canvas, (b1 + b2) DIV 2 + ((g1 + g2) DIV 2)*256 + ((r1 + r2) DIV 2)*65536);
|
|
*)
|
|
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.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 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;
|
|
paint(chkbox)
|
|
END
|
|
ELSE
|
|
chkbox.mouse := FALSE
|
|
END
|
|
END mouse;
|
|
|
|
|
|
END CheckBox. |