Subversion Repositories Kolibri OS

Rev

Rev 9668 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9182 akron1 1
(*
9628 akron1 2
    Copyright 2021, 2022 Anton Krotov
9182 akron1 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 .
18
*)
19
 
20
MODULE CheckBox;
21
 
9187 akron1 22
IMPORT G := Graph, K := KolibriOS, U := Utils;
9182 akron1 23
 
9187 akron1 24
 
9182 akron1 25
CONST
26
	padding = 4;
9431 akron1 27
	fontWidth = K.fontWidth;
28
	fontHeight = K.fontHeight;
29
	bColor = 0FFFFFFH;
30
	fColor = 0008000H;
9182 akron1 31
 
9187 akron1 32
 
9182 akron1 33
TYPE
9187 akron1 34
	tCheckBox* = RECORD
9182 akron1 35
 
36
		left*, top*: INTEGER;
9187 akron1 37
		value*, mouse: BOOLEAN;
9182 akron1 38
		text: ARRAY 32 OF WCHAR;
39
		canvas: G.tCanvas
40
 
41
	END;
42
 
43
 
9630 akron1 44
PROCEDURE draw* (chkbox: tCheckBox);
9182 akron1 45
VAR
46
	canvas: G.tCanvas;
47
BEGIN
48
	canvas := chkbox.canvas;
9187 akron1 49
	IF canvas # NIL THEN
9628 akron1 50
		G.SetColor(canvas, K.colors.work);
9187 akron1 51
		G.clear(canvas);
9431 akron1 52
		G.SetColor(canvas, bColor);
9187 akron1 53
		G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
9628 akron1 54
		G.SetColor(canvas, K.colors.line);
9187 akron1 55
		G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
56
		IF chkbox.value THEN
9431 akron1 57
			G.SetColor(canvas, fColor);
9659 akron1 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);
9187 akron1 66
		END;
9628 akron1 67
		G.SetTextColor(canvas, K.colors.work_text);
68
		G.SetBkColor(canvas, K.colors.work);
9187 akron1 69
		G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
70
		G.DrawCanvas(canvas, chkbox.left, chkbox.top)
71
	END
9630 akron1 72
END draw;
9182 akron1 73
 
74
 
9187 akron1 75
PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
9182 akron1 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);
9187 akron1 84
	res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
9671 akron1 85
	G.SetFont(res.canvas, G.fonts[1]);
9187 akron1 86
	chkbox := res
9182 akron1 87
END create;
88
 
89
 
9208 akron1 90
PROCEDURE mouse* (VAR chkbox: tCheckBox);
91
VAR
92
	msState: SET;
93
	x, y: INTEGER;
9182 akron1 94
BEGIN
9208 akron1 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;
9659 akron1 101
			IF U.between(0, x, chkbox.canvas.width - 1) & U.between(0, y, chkbox.canvas.height - 1) THEN
102
				chkbox.value := ~chkbox.value
9208 akron1 103
			END;
9630 akron1 104
			draw(chkbox)
9208 akron1 105
		END
106
	ELSE
9182 akron1 107
		chkbox.mouse := FALSE
108
	END
9208 akron1 109
END mouse;
9182 akron1 110
 
111
 
112
END CheckBox.