Subversion Repositories Kolibri OS

Rev

Rev 9668 | Rev 9902 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2021-2023 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 <http://www.gnu.org/licenses/>.
  18. *)
  19.  
  20. MODULE Icons;
  21.  
  22. IMPORT
  23.         Graph, File, SYSTEM, KOSAPI;
  24.  
  25. CONST
  26.         fileName = "/sys/Icons16.png";
  27.         SIZE* = 18;
  28.  
  29. VAR
  30.         source: INTEGER;
  31.  
  32. (*
  33. PROCEDURE copy (src, dst: INTEGER);
  34. VAR
  35.         src_width, src_height,
  36.         dst_width, dst_height,
  37.         src_data, dst_data: INTEGER;
  38. BEGIN
  39.         LibImg.GetInf(src, src_width, src_height, src_data);
  40.         LibImg.GetInf(dst, dst_width, dst_height, dst_data);
  41.         ASSERT(src_width = dst_width);
  42.         ASSERT(src_height = dst_height);
  43.         SYSTEM.MOVE(src_data, dst_data, src_width*src_height*4)
  44. END copy;
  45. *)
  46.  
  47. PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
  48. PROCEDURE [stdcall, "Libimg.obj", ""] img_convert (src, dst, dst_type, flags, param: INTEGER): INTEGER; END;
  49. PROCEDURE [stdcall, "Libimg.obj", ""] img_destroy (img: INTEGER); END;
  50.  
  51. PROCEDURE GetInf (img: INTEGER; VAR width, height, data: INTEGER);
  52. BEGIN
  53.         SYSTEM.GET(img +  4, width);
  54.         SYSTEM.GET(img +  8, height);
  55.         SYSTEM.GET(img + 24, data);
  56. END GetInf;
  57.  
  58.  
  59. PROCEDURE GetImg (ptr, size: INTEGER): INTEGER;
  60. VAR
  61.         image_data, dst, x, Type: INTEGER;
  62. BEGIN
  63.         image_data := img_decode(ptr, size, 0);
  64.         IF image_data # 0 THEN
  65.                 SYSTEM.GET(image_data + 4, x);
  66.                 ASSERT(x = SIZE);
  67.                 SYSTEM.GET(image_data + 20, Type);
  68.                 IF Type # 3 THEN
  69.                         dst := img_convert(image_data, 0, 3, 0, 0);
  70.                         img_destroy(image_data);
  71.                         image_data := dst
  72.                 END
  73.         END
  74.         RETURN image_data
  75. END GetImg;
  76.  
  77.  
  78. PROCEDURE load (): INTEGER;
  79. VAR
  80.         size, res, ptr: INTEGER;
  81. BEGIN
  82.         res := 0;
  83.         ptr := File.Load(fileName, size);
  84.         IF ptr # 0 THEN
  85.                 res := GetImg(ptr, size);
  86.                 ptr := KOSAPI.free(ptr)
  87.         END
  88.         RETURN res
  89. END load;
  90.  
  91.  
  92. PROCEDURE draw* (icons, n, x, y: INTEGER);
  93. VAR
  94.         width, height, data: INTEGER;
  95. BEGIN
  96.         GetInf(icons, width, height, data);
  97.         KOSAPI.sysfunc7(65, data + SIZE*SIZE*4*n, SIZE*65536 + SIZE, x*65536 + y, 32, 0, 0)
  98. END draw;
  99.  
  100.  
  101. PROCEDURE iconsBackColor (icons: INTEGER; BackColor: INTEGER);
  102. VAR
  103.         width, height, data, x, y, pix: INTEGER;
  104.         b, g, r, gr: BYTE;
  105. BEGIN
  106.         GetInf(icons, width, height, data);
  107.         FOR y := 0 TO height - 1 DO
  108.                 FOR x := 0 TO width - 1 DO
  109.                         SYSTEM.GET32(data, pix);
  110.                         Graph.getRGB(pix, r, g, b);
  111.                         gr := (r + g + b) DIV 3;
  112.                         IF BackColor = -1 THEN
  113.                                 pix := gr + 256*gr + 65536*gr
  114.                         ELSIF gr = 255 THEN
  115.                                 pix := BackColor
  116.                         END;
  117.                         SYSTEM.PUT32(data, pix);
  118.                         INC(data, 4)
  119.                 END
  120.         END
  121. END iconsBackColor;
  122.  
  123.  
  124. PROCEDURE get* (VAR icons, grayIcons: INTEGER; BackColor: INTEGER);
  125. BEGIN
  126.         IF source = 0 THEN
  127.                 source := load();
  128.                 icons := load();
  129.                 grayIcons := load();
  130.                 iconsBackColor(grayIcons, -1);
  131.                 iconsBackColor(grayIcons, BackColor);
  132.                 iconsBackColor(icons, BackColor)
  133.         (*ELSE
  134.                 copy(source, icons);
  135.                 copy(source, grayIcons)*)
  136.         END
  137. END get;
  138.  
  139.  
  140. BEGIN
  141.         source := 0
  142. END Icons.