-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
bgraflashprogressbar.pas
286 lines (247 loc) · 8.29 KB
/
bgraflashprogressbar.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
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{
Created by BGRA Controls Team
Dibo, Circular, lainz (007) and contributors.
For detailed information see readme.txt
Site: https://sourceforge.net/p/bgra-controls/
Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
}
{******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BGRAFlashProgressBar;
{$I bgracontrols.inc}
interface
uses
Classes, SysUtils, {$IFDEF FPC}LResources, LMessages,{$ENDIF} Forms, Controls, Graphics,
{$IFNDEF FPC}Messages, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
BCBaseCtrls, Dialogs, BGRABitmap, BGRADrawerFlashProgressBar;
type
{ TBGRAFlashProgressBar }
TBGRAFlashProgressBar = class(TBGRAGraphicCtrl)
private
FBGRA: TBGRABitmap;
FDrawer: TBGRADrawerFlashProgressBar;
FOnRedraw: TBGRAProgressBarRedrawEvent;
function GetBackgroundColor: TColor;
function GetBackgroundRandomize: boolean;
function GetBackgroundRandomizeMaxIntensity: word;
function GetBackgroundRandomizeMinIntensity: word;
function GetBarColor: TColor;
function GetMaxValue: integer;
function GetMinValue: integer;
function GetValue: integer;
procedure OnChangeDrawer(Sender: TObject);
procedure SetBackgroundColor(AValue: TColor);
procedure SetBackgroundRandomize(AValue: boolean);
procedure SetBackgroundRandomizeMaxIntensity(AValue: word);
procedure SetBackgroundRandomizeMinIntensity(AValue: word);
procedure SetBarColor(AValue: TColor);
procedure SetMaxValue(const AValue: integer);
procedure SetMinValue(const AValue: integer);
procedure SetValue(const AValue: integer);
protected
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: boolean); override;
procedure WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF}); message {$IFDEF FPC}LM_ERASEBKGND{$ELSE}WM_ERASEBKGND{$ENDIF};
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
public
{ Streaming }
{$IFDEF FPC}
procedure SaveToFile(AFileName: string);
procedure LoadFromFile(AFileName: string);
procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
var ComponentClass: TComponentClass);
{$ENDIF}
published
property Align;
property Anchors;
property OnClick;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelUp;
property OnMouseWheelDown;
property MinValue: integer Read GetMinValue Write SetMinValue;
property MaxValue: integer Read GetMaxValue Write SetMaxValue;
property Value: integer Read GetValue Write SetValue;
property Color; deprecated 'User BarColor instead';
property BarColor: TColor read GetBarColor write SetBarColor;
property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor;
property BackgroundRandomizeMinIntensity: word read GetBackgroundRandomizeMinIntensity write SetBackgroundRandomizeMinIntensity;
property BackgroundRandomizeMaxIntensity: word read GetBackgroundRandomizeMaxIntensity write SetBackgroundRandomizeMaxIntensity;
property BackgroundRandomize: boolean read GetBackgroundRandomize write SetBackgroundRandomize;
property OnRedraw: TBGRAProgressBarRedrawEvent read FOnredraw write FOnRedraw;
end;
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
uses BGRABitmapTypes;
{$IFDEF FPC}
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBGRAFlashProgressBar]);
end;
{$ENDIF}
procedure TBGRAFlashProgressBar.SetMinValue(const AValue: integer);
begin
FDrawer.MinValue := AValue;
end;
procedure TBGRAFlashProgressBar.SetValue(const AValue: integer);
begin
FDrawer.Value := AValue;
end;
{$hints off}
procedure TBGRAFlashProgressBar.CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
begin
PreferredWidth := 379;
PreferredHeight := 33;
end;
{$hints on}
procedure TBGRAFlashProgressBar.Paint;
begin
if (ClientWidth <> FBGRA.Width) or (ClientHeight <> FBGRA.Height) then
FBGRA.SetSize(ClientWidth, ClientHeight);
FDrawer.Draw(FBGRA);
if Assigned(OnRedraw) then
OnRedraw(Self, FBGRA, {%H-}FDrawer.XPosition);
FBGRA.Draw(Canvas, 0, 0, False);
end;
{$hints off}
procedure TBGRAFlashProgressBar.WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF});
begin
//do nothing
end;
{$hints on}
constructor TBGRAFlashProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, 33);
// Bitmap and Drawer
FBGRA := TBGRABitmap.Create(Width, Height);
FDrawer := TBGRADrawerFlashProgressBar.Create;
FDrawer.OnChange := OnChangeDrawer;
// Functionality
MinValue := 0;
MaxValue := 100;
Value := 30;
// Functionality and Style
Randomize;
FDrawer.RandSeed := RandSeed;
// Style
BarColor := BGRA(102, 163, 226);
BackgroundColor := BGRA(47,47,47);
BackgroundRandomize := True;
BackgroundRandomizeMinIntensity := 4000;
BackgroundRandomizeMaxIntensity := 5000;
end;
destructor TBGRAFlashProgressBar.Destroy;
begin
FreeAndNil(FBGRA);
FDrawer.Free;
inherited Destroy;
end;
{$IFDEF FPC}
procedure TBGRAFlashProgressBar.SaveToFile(AFileName: string);
var
AStream: TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
WriteComponentAsTextToStream(AStream, Self);
AStream.SaveToFile(AFileName);
finally
AStream.Free;
end;
end;
procedure TBGRAFlashProgressBar.LoadFromFile(AFileName: string);
var
AStream: TMemoryStream;
begin
AStream := TMemoryStream.Create;
try
AStream.LoadFromFile(AFileName);
ReadComponentFromTextStream(AStream, TComponent(Self), OnFindClass);
finally
AStream.Free;
end;
end;
procedure TBGRAFlashProgressBar.OnFindClass(Reader: TReader;
const AClassName: string; var ComponentClass: TComponentClass);
begin
if CompareText(AClassName, 'TBGRAFlashProgressBar') = 0 then
ComponentClass := TBGRAFlashProgressBar;
end;
{$ENDIF}
procedure TBGRAFlashProgressBar.SetMaxValue(const AValue: integer);
begin
FDrawer.MaxValue := AValue;
end;
procedure TBGRAFlashProgressBar.OnChangeDrawer(Sender: TObject);
begin
Invalidate;
end;
function TBGRAFlashProgressBar.GetBackgroundColor: TColor;
begin
Result := FDrawer.BackgroundColor;
end;
function TBGRAFlashProgressBar.GetBackgroundRandomize: boolean;
begin
Result := FDrawer.BackgroundRandomize;
end;
function TBGRAFlashProgressBar.GetBackgroundRandomizeMaxIntensity: word;
begin
Result := FDrawer.BackgroundRandomizeMaxIntensity;
end;
function TBGRAFlashProgressBar.GetBackgroundRandomizeMinIntensity: word;
begin
Result := FDrawer.BackgroundRandomizeMinIntensity;
end;
function TBGRAFlashProgressBar.GetBarColor: TColor;
begin
Result := FDrawer.BarColor;
end;
function TBGRAFlashProgressBar.GetMaxValue: integer;
begin
Result := FDrawer.MaxValue;
end;
function TBGRAFlashProgressBar.GetMinValue: integer;
begin
Result := FDrawer.MinValue;
end;
function TBGRAFlashProgressBar.GetValue: integer;
begin
Result := FDrawer.Value;
end;
procedure TBGRAFlashProgressBar.SetBackgroundColor(AValue: TColor);
begin
FDrawer.BackgroundColor := AValue;
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomize(AValue: boolean);
begin
FDrawer.BackgroundRandomize := AValue;
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMaxIntensity(AValue: word
);
begin
FDrawer.BackgroundRandomizeMaxIntensity := AValue;
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMinIntensity(AValue: word
);
begin
FDrawer.BackgroundRandomizeMinIntensity := AValue;
end;
procedure TBGRAFlashProgressBar.SetBarColor(AValue: TColor);
begin
FDrawer.BarColor := AValue;
end;
end.