Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2021, 2022 Anton Krotov
  3.  
  4.     This file is part of fb2read.
  5.  
  6.     fb2read 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.     fb2read 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 fb2read. If not, see <http://www.gnu.org/licenses/>.
  18. *)
  19.  
  20. MODULE Toolbar;
  21.  
  22. IMPORT
  23.         Icons, K := SysUtils;
  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.winColor
  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.         Icons.get(toolbar.icons, toolbar.grayIcons, toolbar.colors.back);
  96.         i := 0;
  97.         WHILE i < toolbar.cnt DO
  98.                 button := toolbar.buttons[i];
  99.                 btn := button.btn;
  100.                 IF btn # 0 THEN
  101.                         x := button.x;
  102.                         y := toolbar.y;
  103.                         K.DrawRect(x + 1, y + 1, BtnSize, BtnSize - 1, toolbar.colors.back);
  104.                         K.DrawLine(x + 1, y + BtnSize, x + BtnSize - 1, y + BtnSize, toolbar.colors.shadow);
  105.                         K.DrawLine(x + 1, y, x + BtnSize  - 1, y, toolbar.colors.light);
  106.                         K.DrawLine(x, y + 1, x, y + BtnSize - 1, toolbar.colors.light);
  107.                         K.PutPixel(x + BtnSize, y + 1, toolbar.colors.light);
  108.                         K.PutPixel(x, y + BtnSize - 1, toolbar.colors.shadow);
  109.                         K.PutPixel(x + BtnSize, y + BtnSize - 1, toolbar.colors.shadow);
  110.                         K.CreateButton(btn + ORD({30}), x, y, BtnSize, BtnSize, 0, "")
  111.                 END;
  112.                 INC(i)
  113.         END;
  114.         drawIcons(toolbar)
  115. END draw;
  116.  
  117.  
  118. PROCEDURE enable* (VAR toolbar: tToolbar; btn: INTEGER; value: BOOLEAN);
  119. VAR
  120.         i: INTEGER;
  121. BEGIN
  122.         i := 0;
  123.         WHILE (i < toolbar.cnt) & (toolbar.buttons[i].btn # btn) DO
  124.                 INC(i)
  125.         END;
  126.         IF i < toolbar.cnt THEN
  127.                 toolbar.buttons[i].enabled := value
  128.         END
  129. END enable;
  130.  
  131.  
  132. PROCEDURE add* (VAR toolbar: tToolbar; btn, icon: INTEGER; text: tButtonText);
  133. VAR
  134.         button: tButton;
  135. BEGIN
  136.         ASSERT(toolbar.cnt < max);
  137.         button.btn := btn;
  138.         button.icon := icon;
  139.         button.x := toolbar.width + toolbar.x;
  140.         button.text := text;
  141.         button.enabled := TRUE;
  142.         toolbar.buttons[toolbar.cnt] := button;
  143.         INC(toolbar.cnt);
  144.         IF btn # 0 THEN
  145.                 INC(toolbar.width, BtnSize + BtnInter)
  146.         ELSE
  147.                 INC(toolbar.width, DelimSize)
  148.         END
  149. END add;
  150.  
  151.  
  152. PROCEDURE delimiter* (VAR toolbar: tToolbar);
  153. BEGIN
  154.         add(toolbar, 0, 0, "")
  155. END delimiter;
  156.  
  157.  
  158. PROCEDURE create* (VAR toolbar: tToolbar; x, y: INTEGER);
  159. BEGIN
  160.         toolbar.x := x;
  161.         toolbar.y := y;
  162.         toolbar.cnt := 0;
  163.         toolbar.width := 0
  164. END create;
  165.  
  166.  
  167. END Toolbar.