-
Notifications
You must be signed in to change notification settings - Fork 1
/
aboutformu.pas
325 lines (269 loc) · 8.01 KB
/
aboutformu.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
unit AboutFormU;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Buttons, ComCtrls, StdCtrls, LCLIntf;
type
{ TScrollingText }
TScrollingText = class(TGraphicControl)
private
FActive: boolean;
FActiveLine: integer; //the line over which the mouse hovers
FBuffer: TBitmap;
FEndLine: integer;
FLineHeight: integer;
FLines: TStrings;
FNumLines: integer;
FOffset: integer;
FStartLine: integer;
FStepSize: integer;
FTimer: TTimer;
function ActiveLineIsURL: boolean;
procedure DoTimer(Sender: TObject);
procedure SetActive(const AValue: boolean);
procedure Init;
procedure DrawScrollingText(Sender: TObject);
protected
procedure DoOnChangeBounds; override;
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Active: boolean read FActive write SetActive;
property Lines: TStrings read FLines write FLines;
end;
{ TAboutForm }
TAboutForm = class(TForm)
BitBtn1: TBitBtn;
Image1: TImage;
L_Version: TLabel;
PageControl1: TPageControl;
About: TTabSheet;
AcknowledgementsPage: TTabSheet;
ContributorsPage: TTabSheet;
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
private
{ private declarations }
Acknowledgements: TScrollingText;
Contributors: TScrollingText;
procedure LoadContributors;
procedure LoadAcknowledgements;
public
{ public declarations }
end;
var
AboutForm: TAboutForm;
implementation
{$R *.lfm}
uses ConfigFormU, DebugU, VersionSupportU;
const
cContributors = '#Programming'+LineEnding+
LineEnding+
'Miguel Risco-Castillo'+LineEnding+
LineEnding+
'#Reviews'+LineEnding+
LineEnding+
'Juan Vega Martinez';
cAcknowledgements = '#SBACreator uses the following'+LineEnding+
'#libraries and tools:'+LineEnding+
LineEnding+
'SBA Simple Bus Architecture'+LineEnding+
'http://sba.accesus.com/'+LineEnding+
LineEnding+
'Lazarus IDE'+LineEnding+
'http://www.lazarus-ide.org/'+LineEnding+
LineEnding+
'Silk Icons'+LineEnding+
'http://www.famfamfam.com/lab/icons/silk/'+LineEnding+
LineEnding+
'IPCodeDraw PlugIn'+LineEnding+
'https://github.com/jvegam/IpCoreDraw';
{ TAboutForm }
procedure TAboutForm.FormDestroy(Sender: TObject);
begin
Info('TAboutForm','FormDestroy');
end;
procedure TAboutForm.PageControl1Change(Sender: TObject);
begin
if Assigned(Contributors) then
Contributors.Active:=PageControl1.ActivePage = ContributorsPage;
if Assigned(Acknowledgements) then
Acknowledgements.Active:=PageControl1.ActivePage = AcknowledgementsPage;
end;
procedure TAboutForm.FormCreate(Sender: TObject);
begin
L_Version.Caption:='Version: '+GetFileVersion+' - BuildDate: '+{$I %date%};
LoadContributors;
LoadAcknowledgements;
end;
procedure TAboutForm.FormActivate(Sender: TObject);
begin
PageControl1.ActivePageIndex:=0;
end;
procedure TAboutForm.LoadContributors;
var
ContributorsFileName: string;
begin
ContributorsPage.ControlStyle := ContributorsPage.ControlStyle - [csOpaque];
Contributors:= TScrollingText.Create(ContributorsPage);
Contributors.Name:='Contributors';
Contributors.Parent := ContributorsPage;
Contributors.Align:=alClient;
ContributorsFileName:=AppDir+'contributors.txt';
if FileExists(ContributorsFileName) then
Contributors.Lines.LoadFromFile(ContributorsFileName)
else
Contributors.Lines.Text:=cContributors;
end;
procedure TAboutForm.LoadAcknowledgements;
var
AcknowledgementsFileName: string;
begin
Acknowledgements := TScrollingText.Create(AcknowledgementsPage);
Acknowledgements.Name:='Acknowledgements';
Acknowledgements.Parent := AcknowledgementsPage;
Acknowledgements.Align:=alClient;
AcknowledgementsFileName:=AppDir+'acknowledgements.txt';
if FileExists(AcknowledgementsFileName) then
Acknowledgements.Lines.LoadFromFile(AcknowledgementsFileName)
else
Acknowledgements.Lines.Text:=cAcknowledgements;
end;
{ TScrollingText }
procedure TScrollingText.SetActive(const AValue: boolean);
begin
FActive := AValue;
if FActive then
Init;
FTimer.Enabled:=Active;
end;
procedure TScrollingText.Init;
begin
FBuffer.Width := Width;
FBuffer.Height := Height;
FLineHeight := FBuffer.Canvas.TextHeight('X');
FNumLines := FBuffer.Height div FLineHeight;
if FOffset = -1 then
FOffset := FBuffer.Height;
with FBuffer.Canvas do
begin
Brush.Color := clWhite;
Brush.Style := bsSolid;
FillRect(0, 0, Width, Height);
end;
end;
procedure TScrollingText.DrawScrollingText(Sender: TObject);
begin
if Active then
Canvas.Draw(0,0,FBuffer);
end;
procedure TScrollingText.DoTimer(Sender: TObject);
var
w: integer;
s: string;
i: integer;
begin
if not Active then
Exit;
Dec(FOffset, FStepSize);
if FOffSet < 0 then
FStartLine := -FOffset div FLineHeight
else
FStartLine := 0;
FEndLine := FStartLine + FNumLines + 1;
if FEndLine > FLines.Count - 1 then
FEndLine := FLines.Count - 1;
FBuffer.Canvas.FillRect(Rect(0, 0, FBuffer.Width, FBuffer.Height));
for i := FEndLine downto FStartLine do
begin
s := Trim(FLines[i]);
//reset buffer font
FBuffer.Canvas.Font.Style := [];
FBuffer.Canvas.Font.Color := clBlack;
//skip empty lines
if Length(s) > 0 then
begin
//check for bold format token
if s[1] = '#' then
begin
s := copy(s, 2, Length(s) - 1);
FBuffer.Canvas.Font.Style := [fsBold];
end
else
begin
//check for url
if (Pos('http://', s) = 1) or (Pos('https://', s) = 1) then
begin
if i = FActiveLine then
begin
FBuffer.Canvas.Font.Style := [fsUnderline];
FBuffer.Canvas.Font.Color := clRed;
end
else
FBuffer.Canvas.Font.Color := clBlue;
end;
end;
w := FBuffer.Canvas.TextWidth(s);
FBuffer.Canvas.TextOut((FBuffer.Width - w) div 2, FOffset + i * FLineHeight, s);
end;
end;
//start showing the list from the start
if FStartLine > FLines.Count - 1 then
FOffset := FBuffer.Height;
Invalidate;
end;
function TScrollingText.ActiveLineIsURL: boolean;
begin
if (FActiveLine > 0) and (FActiveLine < FLines.Count) then
Result := Pos('http://', FLines[FActiveLine]) = 1
else
Result := False;
end;
procedure TScrollingText.DoOnChangeBounds;
begin
inherited DoOnChangeBounds;
Init;
end;
procedure TScrollingText.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if ActiveLineIsURL then
OpenURL(FLines[FActiveLine]);
end;
procedure TScrollingText.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
//calculate what line is clicked from the mouse position
FActiveLine := (Y - FOffset) div FLineHeight;
Cursor := crDefault;
if (FActiveLine >= 0) and (FActiveLine < FLines.Count) and ActiveLineIsURL then
Cursor := crHandPoint;
end;
constructor TScrollingText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque];
OnPaint := @DrawScrollingText;
FLines := TStringList.Create;
FTimer := TTimer.Create(nil);
FTimer.OnTimer:=@DoTimer;
FTimer.Interval:=30;
FBuffer := TBitmap.Create;
FStepSize := 1;
FStartLine := 0;
FOffset := -1;
end;
destructor TScrollingText.Destroy;
begin
FLines.Free;
FTimer.Free;
FBuffer.Free;
inherited Destroy;
end;
end.