Subversion Repositories Kolibri OS

Rev

Rev 9628 | 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 Toolbar;
  21.  
  22. IMPORT
  23.         Icons, K := KolibriOS;
  24.  
  25. CONST
  26.         max = 14;
  27.  
  28.     BtnSize* = 26;
  29.     BtnInter = 5;
  30.     DelimSize = 7;
  31.     IconPad = (BtnSize - Icons.SIZE) DIV 2;
  32.  
  33. TYPE
  34.         tButtonText = ARRAY 4 OF CHAR;
  35.  
  36.         tButton = RECORD
  37.                 btn, icon, x: INTEGER;
  38.                 text: tButtonText;
  39.                 enabled: BOOLEAN
  40.         END;
  41.  
  42.         tToolbar* = RECORD
  43.                 buttons: ARRAY max OF tButton;
  44.                 x, y, cnt, width: INTEGER;
  45.                 icons, grayIcons: INTEGER;
  46.                 colors: RECORD back, text, disText, light, shadow, window: INTEGER      END
  47.         END;
  48.  
  49.  
  50. PROCEDURE drawIcons* (toolbar: tToolbar);
  51. VAR
  52.         i, icons, color: INTEGER;
  53.         button: tButton;
  54. BEGIN
  55.         i := 0;
  56.         WHILE i < toolbar.cnt DO
  57.                 button := toolbar.buttons[i];
  58.                 IF button.btn # 0 THEN
  59.                         IF button.enabled THEN
  60.                                 icons := toolbar.icons;
  61.                                 color := toolbar.colors.text
  62.                         ELSE
  63.                                 icons := toolbar.grayIcons;
  64.                                 color := toolbar.colors.disText
  65.                         END;
  66.                         IF button.icon # -1 THEN
  67.                                 Icons.draw(icons, button.icon, button.x + IconPad, toolbar.y + IconPad)
  68.                         ELSE
  69.                             K.DrawRect(button.x + 1, toolbar.y + 1, BtnSize - 1, BtnSize - 1, toolbar.colors.back);
  70.                         K.DrawText69(button.x + (BtnSize - LENGTH(button.text)*6) DIV 2, toolbar.y + (BtnSize - 9) DIV 2 + 2, color, button.text)
  71.                         END
  72.                 END;
  73.                 INC(i)
  74.         END
  75. END drawIcons;
  76.  
  77.  
  78. PROCEDURE setColors (VAR toolbar: tToolbar);
  79. BEGIN
  80.         toolbar.colors.back    := 0F2EFECH;
  81.         toolbar.colors.text    := 00000FFH;
  82.         toolbar.colors.disText := 0808080H;
  83.         toolbar.colors.light   := 0FEFEFEH;
  84.         toolbar.colors.shadow  := 09F9C9AH;
  85.         toolbar.colors.window  := K.colors.work
  86. END setColors;
  87.  
  88.  
  89. PROCEDURE draw* (VAR toolbar: tToolbar);
  90. VAR
  91.         i, x, y, btn: INTEGER;
  92.         button: tButton;
  93. BEGIN
  94.         setColors(toolbar);
  95.         IF (toolbar.icons = 0) OR (toolbar.grayIcons = 0) THEN
  96.                 Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back)
  97.         END;
  98.         i := 0;
  99.         WHILE i < toolbar.cnt DO
  100.                 button := toolbar.buttons[i];
  101.                 btn := button.btn;
  102.                 IF btn # 0 THEN
  103.                         x := button.x;
  104.                         y := toolbar.y;
  105.                         K.DrawRect(x + 1, y + 1, BtnSize, BtnSize - 1, toolbar.colors.back);
  106.                         K.DrawLine(x + 1, y + BtnSize, x + BtnSize - 1, y + BtnSize, toolbar.colors.shadow);
  107.                         K.DrawLine(x + 1, y, x + BtnSize  - 1, y, toolbar.colors.light);
  108.                         K.DrawLine(x, y + 1, x, y + BtnSize - 1, toolbar.colors.light);
  109.                         K.PutPixel(x + BtnSize, y + 1, toolbar.colors.light);
  110.                         K.PutPixel(x, y + BtnSize - 1, toolbar.colors.shadow);
  111.                         K.PutPixel(x + BtnSize, y + BtnSize - 1, toolbar.colors.shadow);
  112.                         K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, 0, "")
  113.                 END;
  114.                 INC(i)
  115.         END;
  116.         drawIcons(toolbar)
  117. END draw;
  118.  
  119.  
  120. PROCEDURE enable* (VAR toolbar: tToolbar; btn: INTEGER; value: BOOLEAN);
  121. VAR
  122.         i: INTEGER;
  123. BEGIN
  124.         i := 0;
  125.         WHILE (i < toolbar.cnt) & (toolbar.buttons[i].btn # btn) DO
  126.                 INC(i)
  127.         END;
  128.         IF i < toolbar.cnt THEN
  129.                 toolbar.buttons[i].enabled := value
  130.         END
  131. END enable;
  132.  
  133.  
  134. PROCEDURE add* (VAR toolbar: tToolbar; btn, icon: INTEGER; text: tButtonText);
  135. VAR
  136.         button: tButton;
  137. BEGIN
  138.         ASSERT(toolbar.cnt < max);
  139.         button.btn := btn;
  140.         button.icon := icon;
  141.         button.x := toolbar.width + toolbar.x;
  142.         button.text := text;
  143.         button.enabled := TRUE;
  144.         toolbar.buttons[toolbar.cnt] := button;
  145.         INC(toolbar.cnt);
  146.         IF btn # 0 THEN
  147.                 INC(toolbar.width, BtnSize + BtnInter)
  148.         ELSE
  149.                 INC(toolbar.width, DelimSize)
  150.         END
  151. END add;
  152.  
  153.  
  154. PROCEDURE delimiter* (VAR toolbar: tToolbar);
  155. BEGIN
  156.         add(toolbar, 0, 0, "")
  157. END delimiter;
  158.  
  159.  
  160. PROCEDURE create* (VAR toolbar: tToolbar; x, y: INTEGER);
  161. BEGIN
  162.         toolbar.x := x;
  163.         toolbar.y := y;
  164.         toolbar.cnt := 0;
  165.         toolbar.width := 0;
  166.         toolbar.icons := 0;
  167.         toolbar.grayIcons := 0;
  168. END create;
  169.  
  170.  
  171. END Toolbar.