2021-09-03 01:15:33 +02:00
|
|
|
(*
|
2022-01-05 21:32:53 +01:00
|
|
|
Copyright 2021, 2022 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
|
2022-01-20 18:15:39 +01:00
|
|
|
Graph, File, SYSTEM, KOSAPI;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
CONST
|
2022-01-20 18:15:39 +01:00
|
|
|
fileName = "/sys/Icons16.png";
|
|
|
|
SIZE* = 18;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
VAR
|
2022-01-20 18:15:39 +01:00
|
|
|
source: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
2022-01-20 18:15:39 +01:00
|
|
|
(*
|
2021-06-15 19:33:16 +02:00
|
|
|
PROCEDURE copy (src, dst: INTEGER);
|
|
|
|
VAR
|
2022-01-20 18:15:39 +01:00
|
|
|
src_width, src_height,
|
|
|
|
dst_width, dst_height,
|
|
|
|
src_data, dst_data: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
LibImg.GetInf(src, src_width, src_height, src_data);
|
|
|
|
LibImg.GetInf(dst, dst_width, dst_height, dst_data);
|
|
|
|
ASSERT(src_width = dst_width);
|
|
|
|
ASSERT(src_height = dst_height);
|
|
|
|
SYSTEM.MOVE(src_data, dst_data, src_width*src_height*4)
|
2021-06-15 19:33:16 +02:00
|
|
|
END copy;
|
2022-01-20 18:15:39 +01:00
|
|
|
*)
|
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
|
|
|
PROCEDURE GetInf (img: INTEGER; VAR width, height, data: INTEGER);
|
|
|
|
BEGIN
|
|
|
|
SYSTEM.GET(img + 4, width);
|
|
|
|
SYSTEM.GET(img + 8, height);
|
|
|
|
SYSTEM.GET(img + 24, data);
|
|
|
|
END GetInf;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetImg* (ptr, size: INTEGER): INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
VAR
|
2022-01-20 18:15:39 +01:00
|
|
|
image_data, dst, x, type: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +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
|
|
|
|
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
|
2022-01-20 18:15:39 +01:00
|
|
|
size, res, ptr: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
res := 0;
|
|
|
|
ptr := File.Load(fileName, size);
|
|
|
|
IF ptr # 0 THEN
|
|
|
|
res := GetImg(ptr, size);
|
|
|
|
ptr := KOSAPI.free(ptr)
|
|
|
|
END
|
|
|
|
RETURN res
|
|
|
|
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
|
|
|
VAR
|
2022-01-20 18:15:39 +01:00
|
|
|
width, height, data: INTEGER;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
GetInf(icons, width, height, data);
|
|
|
|
KOSAPI.sysfunc7(65, data + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
|
|
|
|
END draw;
|
2021-06-15 19:33:16 +02:00
|
|
|
|
|
|
|
|
2021-12-29 16:38:29 +01:00
|
|
|
PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
|
2021-06-15 19:33:16 +02:00
|
|
|
VAR
|
2022-01-20 18:15:39 +01:00
|
|
|
width, height, data, x, y, pix: INTEGER;
|
|
|
|
b, g, r, gr: BYTE;
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
GetInf(icons, width, height, data);
|
|
|
|
FOR y := 0 TO height - 1 DO
|
|
|
|
FOR x := 0 TO width - 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);
|
2021-06-15 19:33:16 +02:00
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
IF source = 0 THEN
|
|
|
|
source := load();
|
|
|
|
icons := load();
|
|
|
|
grayIcons := load();
|
|
|
|
iconsBackColor(grayIcons, -1);
|
|
|
|
iconsBackColor(grayIcons, BackColor);
|
|
|
|
iconsBackColor(icons, BackColor)
|
|
|
|
(*ELSE
|
|
|
|
copy(source, icons);
|
|
|
|
copy(source, grayIcons)*)
|
|
|
|
END;
|
2021-06-15 19:33:16 +02:00
|
|
|
END get;
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN
|
2022-01-20 18:15:39 +01:00
|
|
|
source := 0
|
2021-06-15 19:33:16 +02:00
|
|
|
END Icons.
|