2021-09-03 01:15:33 +02:00
|
|
|
(*
|
2023-01-21 15:34:25 +01:00
|
|
|
Copyright 2021-2023 Anton Krotov
|
2021-06-15 19:33:16 +02: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 Icons;
|
|
|
|
|
|
|
|
IMPORT
|
2023-02-22 16:56:05 +01:00
|
|
|
Graph, File, SYSTEM, KOSAPI;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
CONST
|
2023-02-22 16:56:05 +01:00
|
|
|
fileName = "/sys/Icons16.png";
|
|
|
|
SIZE* = 18;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
2023-02-22 16:56:05 +01:00
|
|
|
icoNew *= 0;
|
|
|
|
icoOpen *= 1;
|
|
|
|
icoSave *= 2;
|
|
|
|
icoSearch *= 3;
|
|
|
|
icoUndo *= 4;
|
|
|
|
icoRedo *= 5;
|
|
|
|
icoBuild *= 6;
|
|
|
|
icoRun *= 7;
|
|
|
|
|
|
|
|
NumberOfIcons = 8;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
|
2022-01-20 18:15:39 +01:00
|
|
|
PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
|
|
|
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
|
|
|
|
PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy (img: INTEGER); END;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
2022-01-20 18:15:39 +01:00
|
|
|
|
2022-01-24 23:03:13 +01:00
|
|
|
PROCEDURE GetImg (ptr, size: INTEGER): INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
image_data, dst, x, Type: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
image_data := img_decode(ptr, size, 0);
|
|
|
|
IF image_data # 0 THEN
|
|
|
|
SYSTEM.GET(image_data + 4, x);
|
|
|
|
ASSERT(x = SIZE);
|
|
|
|
SYSTEM.GET(image_data + 20, Type);
|
|
|
|
IF Type # 3 THEN
|
|
|
|
dst := img_convert(image_data, 0, 3, 0, 0);
|
|
|
|
img_destroy(image_data);
|
|
|
|
image_data := dst
|
|
|
|
END
|
|
|
|
END
|
|
|
|
RETURN image_data
|
2022-01-20 18:15:39 +01:00
|
|
|
END GetImg;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
|
2022-01-20 18:15:39 +01:00
|
|
|
PROCEDURE load (): INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
size, res, ptr: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
res := 0;
|
|
|
|
ptr := File.Load(fileName, size);
|
|
|
|
IF ptr # 0 THEN
|
|
|
|
res := GetImg(ptr, size);
|
|
|
|
ptr := KOSAPI.free(ptr)
|
|
|
|
END
|
|
|
|
RETURN res
|
2022-01-20 18:15:39 +01:00
|
|
|
END load;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
|
2022-01-20 18:15:39 +01:00
|
|
|
PROCEDURE draw* (icons, n, x, y: INTEGER);
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
KOSAPI.sysfunc7(65, icons + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
|
2022-01-20 18:15:39 +01:00
|
|
|
END draw;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
|
2023-02-22 16:56:05 +01:00
|
|
|
PROCEDURE copy (img: INTEGER; n: INTEGER; dst: INTEGER; m: INTEGER);
|
|
|
|
VAR
|
|
|
|
data: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
SYSTEM.GET(img + 24, data);
|
|
|
|
SYSTEM.MOVE(data + SIZE*SIZE*4*n, dst + SIZE*SIZE*4*m, SIZE*SIZE*4)
|
|
|
|
END copy;
|
|
|
|
|
|
|
|
|
2021-12-29 16:38:29 +01:00
|
|
|
PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
|
2021-06-15 19:33:16 +02:00
|
|
|
VAR
|
2023-02-22 16:56:05 +01:00
|
|
|
data, x, y, pix: INTEGER;
|
|
|
|
b, g, r, gr: BYTE;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
data := icons;
|
|
|
|
FOR y := 0 TO SIZE*NumberOfIcons - 1 DO
|
|
|
|
FOR x := 0 TO SIZE - 1 DO
|
|
|
|
SYSTEM.GET32(data, pix);
|
|
|
|
Graph.getRGB(pix, r, g, b);
|
|
|
|
gr := (r + g + b) DIV 3;
|
|
|
|
IF BackColor = -1 THEN
|
|
|
|
pix := gr + 256*gr + 65536*gr
|
|
|
|
ELSIF gr = 255 THEN
|
|
|
|
pix := BackColor
|
|
|
|
END;
|
|
|
|
SYSTEM.PUT32(data, pix);
|
|
|
|
INC(data, 4)
|
|
|
|
END
|
|
|
|
END
|
2021-06-15 19:33:16 +02:00
|
|
|
END iconsBackColor;
|
|
|
|
|
|
|
|
|
2021-12-29 16:38:29 +01:00
|
|
|
PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
|
2023-02-22 16:56:05 +01:00
|
|
|
VAR
|
|
|
|
source: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2023-02-22 16:56:05 +01:00
|
|
|
source := load();
|
|
|
|
IF source # 0 THEN
|
|
|
|
icons := KOSAPI.malloc(SIZE*SIZE*4*NumberOfIcons*2);
|
|
|
|
grayIcons := icons + SIZE*SIZE*4*NumberOfIcons;
|
|
|
|
|
|
|
|
copy(source, 2, icons, icoNew);
|
|
|
|
copy(source, 0, icons, icoOpen);
|
|
|
|
copy(source, 5, icons, icoSave);
|
|
|
|
copy(source, 49, icons, icoSearch);
|
|
|
|
copy(source, 37, icons, icoUndo);
|
|
|
|
copy(source, 36, icons, icoRedo);
|
|
|
|
copy(source, 54, icons, icoBuild);
|
|
|
|
copy(source, 53, icons, icoRun);
|
|
|
|
img_destroy(source);
|
|
|
|
source := 0;
|
|
|
|
SYSTEM.MOVE(icons, grayIcons, SIZE*SIZE*4*NumberOfIcons);
|
|
|
|
|
|
|
|
iconsBackColor(grayIcons, -1);
|
|
|
|
iconsBackColor(grayIcons, BackColor);
|
|
|
|
iconsBackColor(icons, BackColor)
|
|
|
|
END
|
2021-06-15 19:33:16 +02:00
|
|
|
END get;
|
|
|
|
|
|
|
|
END Icons.
|