Subversion Repositories Kolibri OS

Rev

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

  1. (*
  2.     Copyright 2021, 2022 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 StatusBar;
  21.  
  22. IMPORT G := Graph, U := Utils, K := KolibriOS;
  23.  
  24. TYPE
  25.  
  26.         tString = ARRAY 32 OF WCHAR;
  27.  
  28.         tStatusBar* = RECORD
  29.  
  30.                 pos, sel, enc: tString;
  31.                 canvas: G.tCanvas
  32.  
  33.         END;
  34.  
  35. VAR
  36.  
  37.         SB: tStatusBar;
  38.         font: G.tFont;
  39.  
  40.  
  41. PROCEDURE setPos* (line, col: INTEGER);
  42. VAR
  43.         s1, s2: tString;
  44. BEGIN
  45.         U.int2str(line, s1);
  46.         U.append(s1, ": ");
  47.         U.int2str(col, s2);
  48.         U.append(s1, s2);
  49.         SB.pos := s1
  50. END setPos;
  51.  
  52.  
  53. PROCEDURE setSel* (chars, lines: INTEGER);
  54. VAR
  55.         s1, s2: tString;
  56. BEGIN
  57.         IF chars # 0 THEN
  58.                 s1 := "sel: ";
  59.                 U.int2str(chars, s2);
  60.                 U.append(s1, s2);
  61.                 U.append(s1, " | ");
  62.                 U.int2str(lines, s2);
  63.                 U.append(s1, s2);
  64.                 SB.sel := s1
  65.         ELSE
  66.                 SB.sel := ""
  67.         END
  68. END setSel;
  69.  
  70.  
  71. PROCEDURE setEnc* (eol, enc: ARRAY OF WCHAR);
  72. BEGIN
  73.         SB.enc := eol;
  74.         U.append(SB.enc, 20X + 20X);
  75.         U.append(SB.enc, enc)
  76. END setEnc;
  77.  
  78.  
  79. PROCEDURE height* (): INTEGER;
  80.         RETURN font.height + 3
  81. END height;
  82.  
  83.  
  84. PROCEDURE setWidth* (width: INTEGER);
  85. BEGIN
  86.         ASSERT(width > 0);
  87.         IF (SB.canvas = NIL) OR (SB.canvas.width # width) OR (SB.canvas.height # height()) THEN
  88.                 G.destroy(SB.canvas);
  89.                 SB.canvas := G.CreateCanvas(width, height());
  90.                 G.SetFont(SB.canvas, font)
  91.         END
  92. END setWidth;
  93.  
  94.  
  95. PROCEDURE TextOut (x: INTEGER; s: ARRAY OF WCHAR);
  96. BEGIN
  97.         G.TextOut2(SB.canvas, x, 2, s, LENGTH(s))
  98. END TextOut;
  99.  
  100.  
  101. PROCEDURE draw* (left, top: INTEGER);
  102. BEGIN
  103.         G.SetColor(SB.canvas, K.colors.work);
  104.         G.SetBkColor(SB.canvas, K.colors.work);
  105.         G.SetTextColor(SB.canvas, K.colors.work_text);
  106.         G.clear(SB.canvas);
  107.         TextOut(1, SB.pos);
  108.         TextOut(16*font.width, SB.sel);
  109.         TextOut(SB.canvas.width - LENGTH(SB.enc)*font.width - 1, SB.enc);
  110.         G.DrawCanvas(SB.canvas, left, top)
  111. END draw;
  112.  
  113.  
  114. PROCEDURE SetFont* (_font: G.tFont);
  115. BEGIN
  116.         font := _font;
  117.         IF SB.canvas # NIL THEN
  118.                 setWidth(SB.canvas.width)
  119.         END
  120. END SetFont;
  121.  
  122.  
  123. BEGIN
  124.         SB.canvas := NIL;
  125.         font := G.font1
  126. END StatusBar.