aboutsummaryrefslogtreecommitdiff
path: root/Source/fstextunit.pas
blob: f526d9de74f6c583e07cda38b0240fc599df61b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{ Copyright (C) 2001 Juha Vehviläinen
  This program 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 2
  of the License, or (at your option) any later version.

  This program 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.}

unit fstextunit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  mainunit, fsformunit, fsframeunit;

type
  Tfstext = class(TFsForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    dest: TFsFrame;
    x, y: Integer;
  public
    { Public declarations }
    procedure Parse(const S: String); override;
  end;

var
  fstext: Tfstext;

function ParsePenProperties(const Canvas: TCanvas; const S: String): Boolean;

implementation

{$R *.DFM}

uses
  Strz;

function ParsePenProperties(const Canvas: TCanvas; const S: String): Boolean;
var
  s1: String;
  r, g, b: Integer;
begin
  Result := False;
  s1 := UpperCase(ExtractWord(1, S, [' ']));
  if s1='PEN' then begin
    if WordCount(S, [' '])<4 then
      main.Post('Usage: PEN <r> <g> <b>')
    else begin
      r := MyStrToInt(ExtractWord(2, S, [' ']));
      g := MyStrToInt(ExtractWord(3, S, [' ']));
      b := MyStrToInt(ExtractWord(4, S, [' ']));
      Canvas.Pen.Color := RGB(r, g, b);
    end;
    Result := True;
  end else
  if s1='BRUSH' then begin
    if WordCount(S, [' '])<4 then
      main.Post('Usage: BRUSH <r> <g> <b>')
    else begin
      r := MyStrToInt(ExtractWord(2, S, [' ']));
      g := MyStrToInt(ExtractWord(3, S, [' ']));
      b := MyStrToInt(ExtractWord(4, S, [' ']));
      Canvas.Brush.Color := RGB(r, g, b);
    end;
    Result := True;
  end else
  if s1='COLOR' then begin
    if WordCount(S, [' '])<4 then
      main.Post('Usage: COLOR <r> <g> <b>')
    else begin
      r := MyStrToInt(ExtractWord(2, S, [' ']));
      g := MyStrToInt(ExtractWord(3, S, [' ']));
      b := MyStrToInt(ExtractWord(4, S, [' ']));
      Canvas.Font.Color := RGB(r, g, b);
    end;
    Result := True;
  end else
  if s1='SIZE' then begin
    Canvas.Font.Size := MyStrToInt(ExtractWord(2, S, [' ']));
    Result := True;
  end else
  if s1='FONT' then begin
    Canvas.Font.Name := Copy(S, Length(s1)+2, 255);
    Result := True;
  end else
  if s1='WIDTH' then begin
    Canvas.Pen.Width := MyStrToInt(ExtractWord(2, S, [' ']));
    Result := True;
  end else
end;

{ Tfstext }

procedure Tfstext.Parse(const S: String);
const
  y: Integer = 0;
var
  s1, sa: String;
  b: Boolean;
begin
  if (S='') then Exit;

  s1 := ExtractWord(WordCount(S, [' ']), S, [' ']);
  dest := FindFrame(s1);
  if (dest=nil) or (dest.d1=nil) then Exit;

  sa := Copy(S, 1, Pos(s1, S)-2);

  b := ParsePenProperties(dest.d1.Surface.Canvas, UpperCase(sa));
  dest.d1.Surface.Canvas.Release;
  if b then Exit;

  s1 := UpperCase(ExtractWord(1, sa, [' ']));
  if s1='POS' then begin
    self.x := MyStrToInt(ExtractWord(2, sa, [' ']));
    self.y := MyStrToInt(ExtractWord(3, sa, [' ']));
    Exit;
  end;

  with dest.d1.Surface.Canvas do begin
    Brush.Style := bsClear;

    if (self.x>-1) and (self.y>-1) then
      TextOut(self.x, self.y, sa)
    else begin
      TextOut(0, y, sa);

      Inc(Y, TextHeight(S));
      if y>dest.d1.Surface.Height then
        y := 0;
    end;
  end;
  dest.d1.Surface.Canvas.Release;

  dest.FlipRequest;
end;

procedure Tfstext.FormCreate(Sender: TObject);
begin
  dest := nil;
  x := -1;
  y := -1;
end;

end.