-
Notifications
You must be signed in to change notification settings - Fork 0
/
urunningcheetah.pas
136 lines (99 loc) · 2.9 KB
/
urunningcheetah.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
unit uRunningCheetah;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Controls, ExtCtrls, Graphics;
Type
{ TRunningCheetah }
TRunningCheetah = class(TCustomControl)
private
fAnimated: Boolean;
fAnimateTimer: TTimer;
fBmpIndex: Integer;
fBMPBckGnd: TBitmap;
fBMPs: array[0..7] of TBitmap;
public
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
protected
Procedure Paint; override;
procedure TimerCall(Sender: TObject);
private
Procedure SetAnimated(AValue: Boolean);
published
Property Anchors;
Property Animated: Boolean read fAnimated write SetAnimated default true;
end;
procedure Register;
IMPLEMENTATION
uses
LResources,Dialogs, LCLIntf;
{ TRunningCheetah }
constructor TRunningCheetah.Create(AOwner: TComponent);
var ii: Integer;
begin
inherited Create(AOwner);
Width:= 144; Height:= 118;
Constraints.MinWidth := 144; Constraints.MaxWidth := 144;
Constraints.MinHeight:= 118; Constraints.MaxHeight:= 118;
fBMPBckGnd:= TBitmap.Create;
fBMPBckGnd.LoadFromLazarusResource('Background');
for ii:= 0 to 7 do fBMPs[ii]:= TBitmap.Create;
fBMPs[0].LoadFromLazarusResource('RunCheetah1');
fBMPs[1].LoadFromLazarusResource('RunCheetah2');
fBMPs[2].LoadFromLazarusResource('RunCheetah3');
fBMPs[3].LoadFromLazarusResource('RunCheetah4');
fBMPs[4].LoadFromLazarusResource('RunCheetah5');
fBMPs[5].LoadFromLazarusResource('RunCheetah6');
fBMPs[6].LoadFromLazarusResource('RunCheetah7');
fBMPs[7].LoadFromLazarusResource('RunCheetah8');
fBmpIndex:= 0;
fAnimated:= true;
Invalidate;
if not (csDesigning in ComponentState) then begin
fAnimateTimer:= TTimer.Create(self);
fAnimateTimer.Interval:= 50;
fAnimateTimer.OnTimer:=@TimerCall;
fAnimateTimer.Enabled:= true;
end;
end;
destructor TRunningCheetah.Destroy;
var ii: Integer;
begin
for ii:= 0 to 7 do fBMPs[ii].Destroy;
inherited Destroy;
end;
procedure TRunningCheetah.Paint;
begin
fBMPBckGnd.Canvas.Draw(6,28,fBMPs[fBmpIndex]);
Canvas.Draw(0,0,fBMPBckGnd);
inherited Paint;
end;
procedure TRunningCheetah.TimerCall(Sender: TObject);
begin
fBmpIndex:= fBmpIndex +1;
if fBmpIndex > 7 then fBmpIndex:= 0;
Invalidate;
end;
procedure TRunningCheetah.SetAnimated(AValue: Boolean);
begin
if fAnimated=AValue then Exit;
fAnimated:=AValue;
if fAnimated then begin
if not (csDesigning in ComponentState) then fAnimateTimer.Enabled:= true;
end else begin
if not (csDesigning in ComponentState) then fAnimateTimer.Enabled:= false;
fBmpIndex:= 0;
end;
Invalidate;
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
procedure Register;
begin
RegisterComponents('Additional',[TRunningCheetah]);
end;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INITIALIZATION
{$I picture/RunningCheetah.lrs}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end.