-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preview.pas
227 lines (202 loc) · 5.28 KB
/
Preview.pas
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//******************************************************************************
// LBA Font Editor - editing lfn (font) files from Little Big Adventure 1 & 2
//
// Preview unit.
// Contains preview routines.
//
// Copyright (C) Zink
// e-mail: [email protected]
// See the GNU General Public License (License.txt) for details.
//******************************************************************************
unit Preview;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, StdCtrls;
type
TPrevForm = class(TForm)
btLockTop: TSpeedButton;
btLockBtm: TSpeedButton;
btClose: TSpeedButton;
btOptions: TSpeedButton;
Timer1: TTimer;
PanelMain: TPanel;
Panel2: TPanel;
Label2: TLabel;
Label3: TLabel;
cFont: TColorBox;
cBack: TColorBox;
cbRemSet: TCheckBox;
cbLbaStyle: TCheckBox;
cbOnTop: TCheckBox;
Panel1: TPanel;
pbPrev: TPaintBox;
Buffer1: TImage;
Buffer2: TImage;
sbHoriz: TScrollBar;
eText: TEdit;
procedure btCloseClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure pbPrevPaint(Sender: TObject);
procedure btOptionsClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure btLockBtmClick(Sender: TObject);
procedure cbOnTopClick(Sender: TObject);
procedure eTextChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const CharCount: Integer = 256;
var
PrevForm: TPrevForm;
ImgBuffer: TImage;
procedure PaintPreview;
implementation
{$R *.dfm}
uses FControl, LBAFont1;
procedure Wait(Time: Integer);
begin
PrevForm.Timer1.Interval:=Time;
PrevForm.Timer1.Enabled:=True;
repeat
Application.ProcessMessages;
until not PrevForm.Timer1.Enabled;
end;
Procedure PaintChar(Code: Byte; x, y: Integer; Colour: TColor);
var a, b, c, e: Integer;
begin
ImgBuffer.Canvas.Pen.Color:=Colour;
With LFont.LChar[Code] do
For a:=0 to Height-1 do begin
c:=0;
e:=x+OffsetX;
For b:=0 to Data[a].LCount-1 do begin
If c=1 then begin
ImgBuffer.Canvas.MoveTo(e,a+y+OffsetY);
ImgBuffer.Canvas.LineTo(e+Data[a].Lines[b],a+y+OffsetY);
c:=0;
end
else c:=1;
Inc(e,Data[a].Lines[b]);
end;
end;
end;
procedure UpdateImage;
begin
With PrevForm do begin
pbPrev.Canvas.CopyRect(Rect(0,0,pbPrev.Width,pbPrev.Height),
ImgBuffer.Canvas,Rect(0,0,ImgBuffer.Width,ImgBuffer.Height));
If ImgBuffer.Name='Buffer1' then ImgBuffer:=Buffer2
else ImgBuffer:=Buffer1;
end;
end;
procedure PaintPreview;
var a, b: Integer;
c: byte;
begin
If (CurrentFile='') or not PrevForm.Visible then Exit;
With PrevForm do begin
ImgBuffer.Canvas.Brush.Color:=cBack.Selected;
ImgBuffer.Canvas.FillRect(Rect(0,0,ImgBuffer.Width,ImgBuffer.Height));
b:=2-sbHoriz.Position;
for a:=1 to Length(PrevForm.eText.Text) do begin
c:=Ord(PrevForm.eText.Text[a]);
If ((b+LFont.LChar[c].Width>=-2) and (b<=pbPrev.Width))
and (c<>32) and (c<>13) and (c<>10) then begin
if cbLbaStyle.Checked then
PaintChar(c,b+2,6,clBlack);
PaintChar(c,b,2,cFont.Selected);
end;
If (c=32) or (c=13) or (c=10) then Inc(b,15) else Inc(b,LFont.LChar[c].Width+2);
end;
If b+2+sbHoriz.Position>pbPrev.Width then begin
sbHoriz.Max:=b+2+sbHoriz.Position;
sbHoriz.PageSize:=pbPrev.Width;
sbHoriz.Enabled:=True;
end
else begin
sbHoriz.Enabled:=False;
sbHoriz.Position:=0;
end;
end;
UpdateImage;
end;
procedure TPrevForm.btCloseClick(Sender: TObject);
begin
Close;
end;
procedure TPrevForm.FormResize(Sender: TObject);
begin
Buffer1.Width:=pbPrev.Width;
Buffer1.Height:=pbPrev.Height;
Buffer1.Picture.Bitmap.Width:=pbPrev.Width;
Buffer1.Picture.Bitmap.Height:=pbPrev.Height;
Buffer2.Width:=pbPrev.Width;
Buffer2.Height:=pbPrev.Height;
Buffer2.Picture.Bitmap.Width:=pbPrev.Width;
Buffer2.Picture.Bitmap.Height:=pbPrev.Height;
PaintPreview;
end;
procedure TPrevForm.FormCreate(Sender: TObject);
begin
ImgBuffer:=Buffer1;
//PrevForm.DoubleBuffered:=True;
Panel1.DoubleBuffered:=True;
end;
procedure TPrevForm.pbPrevPaint(Sender: TObject);
begin
PaintPreview;
end;
procedure TPrevForm.btOptionsClick(Sender: TObject);
var a: Integer;
begin
btOptions.Enabled:=False;
If btOptions.Down then begin
for a:=0 to 8 do begin
Panel2.Top:=PanelMain.Height-a*8;
Panel1.Top:=-a*8;
Panel1.Refresh;
Panel2.Refresh;
end;
end
else begin
for a:=8 downto 0 do begin
Panel2.Top:=PanelMain.Height-a*8;
Panel1.Top:=-a*8;
Panel1.Refresh;
Panel2.Refresh;
end;
end;
btOptions.Enabled:=True;
end;
procedure TPrevForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:=False;
end;
procedure TPrevForm.btLockBtmClick(Sender: TObject);
begin
If btLockTop.Down or btLockBtm.Down then begin
PrevForm.Width:=PrevForm.ClientWidth;
PrevForm.Height:=PrevForm.ClientHeight;
PrevForm.BorderStyle:=bsNone;
Form1.Realign;
end
else begin
PrevForm.BorderStyle:=bsSizeable;
PrevForm.ClientWidth:=PrevForm.Width;
PrevForm.ClientHeight:=PrevForm.Height;
end;
end;
procedure TPrevForm.cbOnTopClick(Sender: TObject);
begin
If cbOnTop.Checked then PrevForm.FormStyle:=fsStayOnTop
else PrevForm.FormStyle:=fsNormal;
end;
procedure TPrevForm.eTextChange(Sender: TObject);
begin
PaintPreview;
end;
end.