(* Copyright 2021-2023 Anton Krotov 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 . *) MODULE Icons; IMPORT Graph, File, SYSTEM, KOSAPI; CONST fileName = "/sys/Icons16.png"; SIZE* = 18; icoNew *= 0; icoOpen *= 1; icoSave *= 2; icoSearch *= 3; icoUndo *= 4; icoRedo *= 5; icoBuild *= 6; icoRun *= 7; NumberOfIcons = 8; 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; PROCEDURE GetImg (ptr, size: INTEGER): INTEGER; VAR image_data, dst, x, Type: INTEGER; BEGIN 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; PROCEDURE load (): INTEGER; VAR size, res, ptr: INTEGER; BEGIN res := 0; ptr := File.Load(fileName, size); IF ptr # 0 THEN res := GetImg(ptr, size); ptr := KOSAPI.free(ptr) END RETURN res END load; PROCEDURE draw* (icons, n, x, y: INTEGER); BEGIN KOSAPI.sysfunc7(65, icons + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0) END draw; 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; PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER); VAR data, x, y, pix: INTEGER; b, g, r, gr: BYTE; BEGIN 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 END iconsBackColor; PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER); VAR source: INTEGER; BEGIN 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 END get; END Icons.