Subversion Repositories Kolibri OS

Rev

Rev 9182 | Rev 9208 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9182 akron1 1
(*
2
    Copyright 2021 Anton Krotov
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;
9187 akron1 27
    fontWidth = K.fontWidth;
28
    fontHeight = K.fontHeight;
9182 akron1 29
 
9187 akron1 30
 
9182 akron1 31
TYPE
9187 akron1 32
	tCheckBox* = RECORD
9182 akron1 33
 
34
		left*, top*: INTEGER;
35
		width, height: INTEGER;
9187 akron1 36
		value*, mouse: BOOLEAN;
9182 akron1 37
		text: ARRAY 32 OF WCHAR;
38
		canvas: G.tCanvas
39
 
40
	END;
41
 
42
 
43
PROCEDURE paint* (chkbox: tCheckBox);
44
VAR
45
	canvas: G.tCanvas;
46
BEGIN
47
	canvas := chkbox.canvas;
9187 akron1 48
	IF canvas # NIL THEN
49
		G.SetColor(canvas, K.winColor);
50
		G.clear(canvas);
51
		G.SetColor(canvas, 0FFFFFFH);
52
		G.FillRect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
53
		G.SetColor(canvas, K.borderColor);
54
		G.Rect(canvas, 0, 0, fontHeight - 1, fontHeight - 1);
55
		IF chkbox.value THEN
56
			G.SetColor(canvas, 0008000H);
57
		    G.DLine(canvas, 2,  6,  6, -1);
58
		    G.DLine(canvas, 2,  6,  7, -1);
59
		    G.DLine(canvas, 7, 13,  9,  1);
60
		    G.DLine(canvas, 7, 13, 10,  1)
61
		END;
62
		G.SetTextColor(canvas, K.textColor);
63
		G.SetBkColor(canvas, K.winColor);
64
		G.TextOut2(canvas, fontHeight + padding, 0, chkbox.text, LENGTH(chkbox.text));
65
		G.DrawCanvas(canvas, chkbox.left, chkbox.top)
66
	END
9182 akron1 67
END paint;
68
 
69
 
9187 akron1 70
PROCEDURE create* (text: ARRAY OF WCHAR; VAR chkbox: tCheckBox);
9182 akron1 71
VAR
72
	res: tCheckBox;
73
BEGIN
74
	res.left := 0;
75
	res.top := 0;
76
	res.value := FALSE;
77
	res.mouse := FALSE;
78
	COPY(text, res.text);
9187 akron1 79
	res.canvas := G.CreateCanvas(fontHeight + padding + LENGTH(res.text)*fontWidth, fontHeight + 1);
80
	G.SetFont(res.canvas, G.CreateFont(1, "", {}));
9182 akron1 81
	res.width := res.canvas.width;
82
	res.height := res.canvas.height;
9187 akron1 83
	chkbox := res
9182 akron1 84
END create;
85
 
86
 
9187 akron1 87
PROCEDURE MouseDown* (VAR chkbox: tCheckBox; x, y: INTEGER);
9182 akron1 88
BEGIN
9187 akron1 89
	IF (chkbox.canvas # NIL) & ~chkbox.mouse THEN
9182 akron1 90
		DEC(x, chkbox.left);
91
		DEC(y, chkbox.top);
92
		chkbox.mouse := TRUE;
9187 akron1 93
		IF U.between(0, x, chkbox.width) & U.between(0, y, chkbox.height) THEN
9182 akron1 94
			chkbox.value := ~chkbox.value;
95
		END;
96
		paint(chkbox)
97
	END
98
END MouseDown;
99
 
100
 
9187 akron1 101
PROCEDURE MouseUp* (VAR chkbox: tCheckBox);
9182 akron1 102
BEGIN
9187 akron1 103
	IF chkbox.canvas # NIL THEN
9182 akron1 104
		chkbox.mouse := FALSE
105
	END
106
END MouseUp;
107
 
108
 
109
END CheckBox.