2021-12-20 20:09:01 +01:00
|
|
|
(*
|
2023-02-22 16:56:05 +01:00
|
|
|
Copyright 2021-2023 Anton Krotov
|
2021-12-20 20:09:01 +01:00
|
|
|
|
|
|
|
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 Toolbar;
|
|
|
|
|
|
|
|
IMPORT
|
|
|
|
Icons, K := KolibriOS;
|
|
|
|
|
|
|
|
CONST
|
|
|
|
max = 14;
|
|
|
|
|
2021-12-29 16:38:29 +01:00
|
|
|
BtnSize* = 26;
|
2021-12-20 20:09:01 +01:00
|
|
|
BtnInter = 5;
|
|
|
|
DelimSize = 7;
|
|
|
|
IconPad = (BtnSize - Icons.SIZE) DIV 2;
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
tButtonText = ARRAY 4 OF CHAR;
|
|
|
|
|
|
|
|
tButton = RECORD
|
|
|
|
btn, icon, x: INTEGER;
|
|
|
|
text: tButtonText;
|
|
|
|
enabled: BOOLEAN
|
|
|
|
END;
|
|
|
|
|
|
|
|
tToolbar* = RECORD
|
|
|
|
buttons: ARRAY max OF tButton;
|
|
|
|
x, y, cnt, width: INTEGER;
|
2021-12-29 16:38:29 +01:00
|
|
|
icons, grayIcons: INTEGER;
|
|
|
|
colors: RECORD back, text, disText, light, shadow, window: INTEGER END
|
2021-12-20 20:09:01 +01:00
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE drawIcons* (toolbar: tToolbar);
|
|
|
|
VAR
|
|
|
|
i, icons, color: INTEGER;
|
|
|
|
button: tButton;
|
|
|
|
BEGIN
|
|
|
|
i := 0;
|
|
|
|
WHILE i < toolbar.cnt DO
|
|
|
|
button := toolbar.buttons[i];
|
|
|
|
IF button.btn # 0 THEN
|
|
|
|
IF button.enabled THEN
|
|
|
|
icons := toolbar.icons;
|
2021-12-29 16:38:29 +01:00
|
|
|
color := toolbar.colors.text
|
2021-12-20 20:09:01 +01:00
|
|
|
ELSE
|
|
|
|
icons := toolbar.grayIcons;
|
2021-12-29 16:38:29 +01:00
|
|
|
color := toolbar.colors.disText
|
2021-12-20 20:09:01 +01:00
|
|
|
END;
|
|
|
|
IF button.icon # -1 THEN
|
|
|
|
Icons.draw(icons, button.icon, button.x + IconPad, toolbar.y + IconPad)
|
|
|
|
ELSE
|
2021-12-29 16:38:29 +01:00
|
|
|
K.DrawRect(button.x + 1, toolbar.y + 1, BtnSize - 1, BtnSize - 1, toolbar.colors.back);
|
2021-12-20 20:09:01 +01:00
|
|
|
K.DrawText69(button.x + (BtnSize - LENGTH(button.text)*6) DIV 2, toolbar.y + (BtnSize - 9) DIV 2 + 2, color, button.text)
|
|
|
|
END
|
|
|
|
END;
|
|
|
|
INC(i)
|
|
|
|
END
|
|
|
|
END drawIcons;
|
|
|
|
|
|
|
|
|
2021-12-29 16:38:29 +01:00
|
|
|
PROCEDURE setColors (VAR toolbar: tToolbar);
|
|
|
|
BEGIN
|
2022-01-12 22:15:22 +01:00
|
|
|
toolbar.colors.back := 0F2EFECH;
|
2021-12-29 16:38:29 +01:00
|
|
|
toolbar.colors.text := 00000FFH;
|
2022-01-12 22:15:22 +01:00
|
|
|
toolbar.colors.disText := 0808080H;
|
2021-12-29 16:38:29 +01:00
|
|
|
toolbar.colors.light := 0FEFEFEH;
|
2022-01-12 22:15:22 +01:00
|
|
|
toolbar.colors.shadow := 09F9C9AH;
|
|
|
|
toolbar.colors.window := K.colors.work
|
2021-12-29 16:38:29 +01:00
|
|
|
END setColors;
|
|
|
|
|
|
|
|
|
2021-12-20 20:09:01 +01:00
|
|
|
PROCEDURE draw* (VAR toolbar: tToolbar);
|
|
|
|
VAR
|
|
|
|
i, x, y, btn: INTEGER;
|
|
|
|
button: tButton;
|
|
|
|
BEGIN
|
2021-12-29 16:38:29 +01:00
|
|
|
setColors(toolbar);
|
2023-02-22 16:56:05 +01:00
|
|
|
IF (toolbar.icons = 0) OR (toolbar.grayIcons = 0) THEN
|
|
|
|
Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back)
|
|
|
|
END;
|
2021-12-20 20:09:01 +01:00
|
|
|
i := 0;
|
|
|
|
WHILE i < toolbar.cnt DO
|
|
|
|
button := toolbar.buttons[i];
|
|
|
|
btn := button.btn;
|
|
|
|
IF btn # 0 THEN
|
|
|
|
x := button.x;
|
|
|
|
y := toolbar.y;
|
2021-12-29 16:38:29 +01:00
|
|
|
K.DrawRect(x + 1, y + 1, BtnSize, BtnSize - 1, toolbar.colors.back);
|
|
|
|
K.DrawLine(x + 1, y + BtnSize, x + BtnSize - 1, y + BtnSize, toolbar.colors.shadow);
|
|
|
|
K.DrawLine(x + 1, y, x + BtnSize - 1, y, toolbar.colors.light);
|
|
|
|
K.DrawLine(x, y + 1, x, y + BtnSize - 1, toolbar.colors.light);
|
|
|
|
K.PutPixel(x + BtnSize, y + 1, toolbar.colors.light);
|
|
|
|
K.PutPixel(x, y + BtnSize - 1, toolbar.colors.shadow);
|
|
|
|
K.PutPixel(x + BtnSize, y + BtnSize - 1, toolbar.colors.shadow);
|
|
|
|
K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, 0, "")
|
2021-12-20 20:09:01 +01:00
|
|
|
END;
|
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
drawIcons(toolbar)
|
|
|
|
END draw;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE enable* (VAR toolbar: tToolbar; btn: INTEGER; value: BOOLEAN);
|
|
|
|
VAR
|
|
|
|
i: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
i := 0;
|
|
|
|
WHILE (i < toolbar.cnt) & (toolbar.buttons[i].btn # btn) DO
|
|
|
|
INC(i)
|
|
|
|
END;
|
|
|
|
IF i < toolbar.cnt THEN
|
|
|
|
toolbar.buttons[i].enabled := value
|
|
|
|
END
|
|
|
|
END enable;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE add* (VAR toolbar: tToolbar; btn, icon: INTEGER; text: tButtonText);
|
|
|
|
VAR
|
|
|
|
button: tButton;
|
|
|
|
BEGIN
|
|
|
|
ASSERT(toolbar.cnt < max);
|
|
|
|
button.btn := btn;
|
|
|
|
button.icon := icon;
|
2021-12-29 16:38:29 +01:00
|
|
|
button.x := toolbar.width + toolbar.x;
|
2021-12-20 20:09:01 +01:00
|
|
|
button.text := text;
|
|
|
|
button.enabled := TRUE;
|
|
|
|
toolbar.buttons[toolbar.cnt] := button;
|
|
|
|
INC(toolbar.cnt);
|
|
|
|
IF btn # 0 THEN
|
|
|
|
INC(toolbar.width, BtnSize + BtnInter)
|
|
|
|
ELSE
|
|
|
|
INC(toolbar.width, DelimSize)
|
|
|
|
END
|
|
|
|
END add;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE delimiter* (VAR toolbar: tToolbar);
|
|
|
|
BEGIN
|
|
|
|
add(toolbar, 0, 0, "")
|
|
|
|
END delimiter;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE create* (VAR toolbar: tToolbar; x, y: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
toolbar.x := x;
|
|
|
|
toolbar.y := y;
|
|
|
|
toolbar.cnt := 0;
|
2023-02-22 16:56:05 +01:00
|
|
|
toolbar.width := 0;
|
|
|
|
toolbar.icons := 0;
|
|
|
|
toolbar.grayIcons := 0;
|
2021-12-20 20:09:01 +01:00
|
|
|
END create;
|
|
|
|
|
|
|
|
|
|
|
|
END Toolbar.
|