-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbgraflashprogressbar.pas
1448 lines (1228 loc) · 46.9 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
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
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)
- Massimo Magnano
2024-12 Added Marquee and MultiProgress Style
Added Caption, CaptionShowPercent, CaptionShowPercentAlign, CaptionShowPercentDigits;
Changed Values to Double Type;
Deleted Unit BGRADrawerFlashProgressBar;
New Test with all Features
Added Timer Style
2025-01 Added Marquee Bounce and Stepit Method,
TimerPlayPause works also for Marquee (useful for debugging)
Added Graph Style and ShowDividers, Renamed MultiProgress properties
Added ShowBarAnimation
2025-02 Added use of Font.Color
***************************** END CONTRIBUTOR(S) *****************************}
unit BGRAFlashProgressBar;
{$I bgracontrols.inc}
interface
uses
Classes, {$IFDEF BGRABITMAP_USE_MSEGUI} mclasses, {$ENDIF}
SysUtils, Types, Forms, Controls, Graphics,
{$IFDEF FPC} LResources, LMessages,
{$ELSE} Messages, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
BCBaseCtrls, BGRABitmap, BGRABitmapTypes, BGRAGraphics, BGRAGradients,
Math, fptimer;
type
TBGRAPBarStyle = (pbstNormal, pbstMultiProgress, pbstMarquee, pbstTimer, pbstGraph);
TBGRAPBarMarqueeDirection = (pbmdToRight, pbmdToLeft);
TBGRAPBarMarqueeSpeed = (pbmsSlow, pbmsMedium, pbmsFast);
TBGRAProgressBarRedrawEvent = procedure(Sender: TObject; Bitmap: TBGRABitmap; xpos: integer) of object;
{ TBGRAFlashProgressBar }
TGraphValue = record
XValue, YValue: Double;
end;
TGraphValues = array of TGraphValue;
TBGRAFlashProgressBar = class(TBGRAGraphicCtrl)
private
function GetMax: Integer;
function GetMin: Integer;
function GetPosition: Integer;
procedure SetBackgroundRandomize(AValue: boolean);
procedure SetBackgroundRandomizeMaxIntensity(AValue: word);
procedure SetBackgroundRandomizeMinIntensity(AValue: word);
procedure SetBarColor(AValue: TColor);
procedure SetBackgroundColor(AValue: TColor);
procedure SetBarColorSub(AValue: TColor);
procedure SetCaptionPercentDigits(AValue: Integer);
procedure SetCaptionPercentTimerFormat(AValue: String);
procedure SetCaptionShowPercent(AValue: Boolean);
procedure SetCaptionPercentAlign(AValue: TAlignment);
procedure SetCaptionPercentSubAlign(AValue: TAlignment);
procedure SetCaptionShowPercentSub(AValue: Boolean);
procedure SetGraphShowYLine(AValue: Boolean);
procedure SetGraphYLineAfter(AValue: String);
procedure SetGraphYLineCaption(AValue: String);
procedure SetGraphYLineDigits(AValue: Integer);
procedure SetMax(AValue: Integer);
procedure SetMin(AValue: Integer);
procedure SetPosition(AValue: Integer);
procedure SetShowBarAnimation(AValue: Boolean);
procedure SetShowDividers(AValue: Boolean);
procedure SetMarqueeBounce(AValue: Word);
procedure SetMarqueeDirection(AValue: TBGRAPBarMarqueeDirection);
procedure SetMarqueeSpeed(AValue: TBGRAPBarMarqueeSpeed);
procedure SetMarqueeWidth(AValue: Word);
procedure SetMaxValue(AValue: Double);
procedure SetMaxYValue(AValue: Double);
procedure SetMinValue(AValue: Double);
procedure SetMinYValue(AValue: Double);
procedure SetRandSeed(AValue: integer);
procedure SetGraphShowYDividers(AValue: Boolean);
procedure SetStyle(AValue: TBGRAPBarStyle);
procedure SetTimerInterval(AValue: Cardinal);
procedure SetValueSub(AValue: Double);
protected
FBGRA: TBGRABitmap;
FCaptionPercentDigits: Integer;
FCaptionPercentTimerFormat: String;
FCaptionShowPercent: Boolean;
FCaptionPercentAlign: TAlignment;
FCaptionPercentSubAlign: TAlignment;
FCaptionShowPercentSub: Boolean;
FMarqueeBounce: Word;
FOnRedraw: TBGRAProgressBarRedrawEvent;
FBackgroundColor: TColor;
FBackgroundRandomize: boolean;
FBackgroundRandomizeMaxIntensity: word;
FBackgroundRandomizeMinIntensity: word;
FShowDividers,
FGraphShowYDividers: Boolean;
FBarColor,
FBarColorSub: TColor;
FMarqueeDirection: TBGRAPBarMarqueeDirection;
FMarqueeSpeed: TBGRAPBarMarqueeSpeed;
FMarqueeWidth,
rMarqueeWidth: Word;
FOnTimerTimer: TNotifyEvent;
FTimerAutoRestart: Boolean;
FOnTimerEnd: TNotifyEvent;
FOnTimerStart: TNotifyEvent;
FTimerInterval: Cardinal;
FMaxValue,
FMinValue,
FMinYValue,
FMaxYValue,
FValue,
FValueSub: Double;
FOnChange: TNotifyEvent;
FRandSeed: integer;
FStyle: TBGRAPBarStyle;
FGraphShowYLine: Boolean;
FGraphYLineAfter: String;
FGraphYLineCaption: String;
FGraphYLineDigits: Integer;
FShowBarAnimation: Boolean;
xpos,
xposSub,
marqueeLeft,
marqueeRight,
marqueeCount,
marqueeBCount,
barAnimLeft: Integer;
marqueeWall,
marqueeBouncing: Boolean;
marqueeCurMode: TBGRAPBarMarqueeDirection;
internalTimer: TFPTimer;
closing: Boolean;
GraphValues: TGraphValues; //array of Real Graph Values
GraphPoints: array of TPointF; //array of Calculated xpos and ypos
class function GetControlClassDefaultSize: TSize; override;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean); override;
procedure DoOnResize; override;
procedure WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF}); message {$IFDEF FPC}LM_ERASEBKGND{$ELSE}WM_ERASEBKGND{$ENDIF};
procedure Paint; override;
procedure Loaded; override;
procedure TextChanged; override;
procedure TimerOnTimer(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Streaming }
{$IFDEF FPC}
procedure SaveToFile(AFileName: string);
procedure LoadFromFile(AFileName: string);
procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
var ComponentClass: TComponentClass);
{$ENDIF}
procedure Draw(ABitmap: TBGRABitmap);
procedure SetValue(AValue: Double); overload;
//Set Current Value and it's Y Value in Graph Style
procedure SetValue(AValue, AYValue: Double); overload;
//Step It, if Style is pbstNormal then Inc/Dec Value,
// if pbstMarquee then do next Animation Step (AIncrement is ignored)
// if pbstTimer then Value is decremented of 100ms (AIncrement is ignored)
procedure StepIt(AIncrement: Double);
//Timer Restart applies only if Style is pbstTimer
procedure TimerReStart;
//Timer Play/Pause applies only if Style is pbstMarquee or pbstTimer
procedure TimerPlayPause;
//For Compatibility with TProgressBar code
property Position: Integer read GetPosition write SetPosition;
property Min: Integer read GetMin write SetMin;
property Max: Integer read GetMax write SetMax;
property XPosition: integer read xpos;
property XPositionSub: integer read xposSub;
published
property Align;
property BorderSpacing;
property Anchors;
property Caption;
property CaptionShowPercent: Boolean read FCaptionShowPercent write SetCaptionShowPercent default False;
property CaptionPercentAlign: TAlignment read FCaptionPercentAlign write SetCaptionPercentAlign default taCenter;
property CaptionShowPercentSub: Boolean read FCaptionShowPercentSub write SetCaptionShowPercentSub default False;
property CaptionPercentSubAlign: TAlignment read FCaptionPercentSubAlign write SetCaptionPercentSubAlign default taLeftJustify;
property CaptionPercentDigits: Integer read FCaptionPercentDigits write SetCaptionPercentDigits default 0;
property CaptionPercentTimerFormat: String read FCaptionPercentTimerFormat write SetCaptionPercentTimerFormat;
property Font;
property ParentFont;
property MinValue: Double read FMinValue write SetMinValue;
property MaxValue: Double read FMaxValue write SetMaxValue;
property MinYValue: Double read FMinYValue write SetMinYValue;
property MaxYValue: Double read FMaxYValue write SetMaxYValue;
property Value: Double read FValue write SetValue;
property ValueSub: Double read FValueSub write SetValueSub;
property Color; deprecated 'User BarColor instead';
property RandSeed: integer read FRandSeed write SetRandSeed;
property BarColor: TColor read FBarColor write SetBarColor;
property BarColorSub: TColor read FBarColorSub write SetBarColorSub;
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor;
property BackgroundRandomizeMinIntensity: Word read FBackgroundRandomizeMinIntensity write SetBackgroundRandomizeMinIntensity;
property BackgroundRandomizeMaxIntensity: Word read FBackgroundRandomizeMaxIntensity write SetBackgroundRandomizeMaxIntensity;
property BackgroundRandomize: Boolean read FBackgroundRandomize write SetBackgroundRandomize;
property ShowDividers: Boolean read FShowDividers write SetShowDividers default False;
property ShowBarAnimation: Boolean read FShowBarAnimation write SetShowBarAnimation default False;
property Style: TBGRAPBarStyle read FStyle write SetStyle default pbstNormal;
property MarqueeWidth: Word read FMarqueeWidth write SetMarqueeWidth default 0;
property MarqueeSpeed: TBGRAPBarMarqueeSpeed read FMarqueeSpeed write SetMarqueeSpeed default pbmsMedium;
property MarqueeDirection: TBGRAPBarMarqueeDirection read FMarqueeDirection write SetMarqueeDirection default pbmdToRight;
property MarqueeBounce: Word read FMarqueeBounce write SetMarqueeBounce;
property TimerInterval: Cardinal read FTimerInterval write SetTimerInterval default 100;
property TimerAutoRestart: Boolean read FTimerAutoRestart write FTimerAutoRestart default True;
property GraphShowYDividers: Boolean read FGraphShowYDividers write SetGraphShowYDividers default False;
property GraphShowYLine: Boolean read FGraphShowYLine write SetGraphShowYLine default False;
property GraphYLineCaption: String read FGraphYLineCaption write SetGraphYLineCaption;
property GraphYLineAfter: String read FGraphYLineAfter write SetGraphYLineAfter;
property GraphYLineDigits: Integer read FGraphYLineDigits write SetGraphYLineDigits default 0;
property OnClick;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelUp;
property OnMouseWheelDown;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnRedraw: TBGRAProgressBarRedrawEvent read FOnRedraw write FOnRedraw;
property OnTimerStart: TNotifyEvent read FOnTimerStart write FOnTimerStart;
property OnTimerEnd: TNotifyEvent read FOnTimerEnd write FOnTimerEnd;
property OnTimerTimer: TNotifyEvent read FOnTimerTimer write FOnTimerTimer;
end;
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
uses DateUtils, BGRATextFX;
const
BAR_ANIM_TIMER = 20;
BAR_ANIM_INC = 4;
MARQUEE_TIMER_SLOW = 50;
MARQUEE_TIMER_MED = 20;
MARQUEE_TIMER_FAST = 10;
MARQUEE_INC = 2;
{$IFDEF FPC}
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBGRAFlashProgressBar]);
end;
{$ENDIF}
{ TBGRAFlashProgressBar }
procedure TBGRAFlashProgressBar.SetBarColor(AValue: TColor);
begin
if FBarColor = AValue then exit;
FBarColor := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
function TBGRAFlashProgressBar.GetMax: Integer;
begin
Result:= Trunc(FMaxValue);
end;
function TBGRAFlashProgressBar.GetMin: Integer;
begin
Result:= Trunc(FMinValue);
end;
function TBGRAFlashProgressBar.GetPosition: Integer;
begin
Result:= Trunc(FValue);
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomize(AValue: boolean);
begin
if FBackgroundRandomize = AValue then exit;
FBackgroundRandomize := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMaxIntensity(AValue: word);
begin
if FBackgroundRandomizeMaxIntensity = AValue then exit;
FBackgroundRandomizeMaxIntensity := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMinIntensity(AValue: word);
begin
if FBackgroundRandomizeMinIntensity = AValue then exit;
FBackgroundRandomizeMinIntensity := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetBackgroundColor(AValue: TColor);
begin
if FBackgroundColor = AValue then exit;
FBackgroundColor := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetBarColorSub(AValue: TColor);
begin
if FBarColorSub = AValue then exit;
FBarColorSub := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionPercentDigits(AValue: Integer);
begin
if FCaptionPercentDigits=AValue then Exit;
FCaptionPercentDigits:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionPercentTimerFormat(AValue: String);
begin
if FCaptionPercentTimerFormat=AValue then Exit;
FCaptionPercentTimerFormat:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionShowPercent(AValue: Boolean);
begin
if FCaptionShowPercent=AValue then Exit;
FCaptionShowPercent:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionPercentAlign(AValue: TAlignment);
begin
if FCaptionPercentAlign=AValue then Exit;
FCaptionPercentAlign:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionPercentSubAlign(AValue: TAlignment);
begin
if FCaptionPercentSubAlign=AValue then Exit;
FCaptionPercentSubAlign:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetCaptionShowPercentSub(AValue: Boolean);
begin
if FCaptionShowPercentSub=AValue then Exit;
FCaptionShowPercentSub:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetGraphShowYLine(AValue: Boolean);
begin
if FGraphShowYLine=AValue then Exit;
FGraphShowYLine:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetGraphYLineAfter(AValue: String);
begin
if FGraphYLineAfter=AValue then Exit;
FGraphYLineAfter:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetGraphYLineCaption(AValue: String);
begin
if FGraphYLineCaption=AValue then Exit;
FGraphYLineCaption:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetGraphYLineDigits(AValue: Integer);
begin
if FGraphYLineDigits=AValue then Exit;
FGraphYLineDigits:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMax(AValue: Integer);
begin
SetMaxValue(AValue);
end;
procedure TBGRAFlashProgressBar.SetMin(AValue: Integer);
begin
SetMinValue(AValue);
end;
procedure TBGRAFlashProgressBar.SetPosition(AValue: Integer);
begin
SetValue(AValue);
end;
procedure TBGRAFlashProgressBar.SetShowBarAnimation(AValue: Boolean);
begin
if FShowBarAnimation=AValue then Exit;
FShowBarAnimation:=AValue;
if (FStyle in [pbstNormal, pbstMultiProgress, pbstGraph]) and
not(csLoading in ComponentState) and
not(csDesigning in ComponentState) then
begin
barAnimLeft:= 0;
if FShowBarAnimation then internalTimer.Interval:= BAR_ANIM_TIMER;
internalTimer.Enabled:= FShowBarAnimation;
end;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetShowDividers(AValue: Boolean);
begin
if FShowDividers=AValue then Exit;
FShowDividers:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMarqueeBounce(AValue: Word);
begin
marqueeBCount:= AValue;
if FMarqueeBounce=AValue then Exit;
FMarqueeBounce:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMarqueeDirection(AValue: TBGRAPBarMarqueeDirection);
begin
if (FMarqueeDirection <> AValue) then
begin
FMarqueeDirection:= AValue;
marqueeCurMode:= AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
end;
procedure TBGRAFlashProgressBar.SetMarqueeSpeed(AValue: TBGRAPBarMarqueeSpeed);
begin
FMarqueeSpeed:=AValue;
case FMarqueeSpeed of
pbmsSlow: internalTimer.Interval:= MARQUEE_TIMER_SLOW;
pbmsMedium: internalTimer.Interval:= MARQUEE_TIMER_MED;
pbmsFast: internalTimer.Interval:= MARQUEE_TIMER_FAST;
end;
end;
procedure TBGRAFlashProgressBar.SetMarqueeWidth(AValue: Word);
begin
if FMarqueeWidth=AValue then Exit;
FMarqueeWidth:= AValue;
if (FMarqueeWidth = 0)
then rMarqueeWidth:= Width div 4
else rMarqueeWidth:= FMarqueeWidth;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMaxValue(AValue: Double);
begin
if FMaxValue = AValue then exit;
FMaxValue := AValue;
if (FValue > FMaxValue) then FValue := FMaxValue;
if (FMinValue > FMaxValue) then FMinValue := FMaxValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMaxYValue(AValue: Double);
begin
if FMaxYValue=AValue then Exit;
FMaxYValue:=AValue;
end;
procedure TBGRAFlashProgressBar.SetMinValue(AValue: Double);
begin
if FMinValue = AValue then exit;
FMinValue := AValue;
if (FValue < FMinValue) then FValue := FMinValue;
if (FMaxValue < FMinValue) then FMaxValue := FMinValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetMinYValue(AValue: Double);
begin
if FMinYValue=AValue then Exit;
FMinYValue:=AValue;
end;
procedure TBGRAFlashProgressBar.SetRandSeed(AValue: integer);
begin
if FRandSeed = AValue then exit;
FRandSeed := AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetGraphShowYDividers(AValue: Boolean);
begin
if FGraphShowYDividers=AValue then Exit;
FGraphShowYDividers:=AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetStyle(AValue: TBGRAPBarStyle);
begin
if (FStyle <> AValue) then
begin
FStyle:= AValue;
Case FStyle of
pbstNormal,
pbstMultiProgress: begin
if FShowBarAnimation and
not(csLoading in ComponentState) and
not(csDesigning in ComponentState)
then begin
barAnimLeft:= 0;
internalTimer.Interval:= BAR_ANIM_TIMER;
internalTimer.Enabled:= True;
end
else internalTimer.Enabled:= False;
end;
pbstMarquee: begin
SetMarqueeSpeed(FMarqueeSpeed);
if (FMarqueeDirection = pbmdToRight)
then marqueeLeft:= 2
else marqueeLeft:= -FMarqueeWidth;
if FTimerAutoRestart and
not(csLoading in ComponentState) and
not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
end;
pbstTimer: begin
FValue:= FMaxValue;
internalTimer.Interval:= FTimerInterval;
if FTimerAutoRestart and
not(csLoading in ComponentState) and
not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
end;
pbstGraph: begin
//Save space for the 2 points to close the polygon
if (Length(GraphPoints) < 2) then SetLength(GraphPoints, 2);
if FShowBarAnimation and
not(csLoading in ComponentState) and
not(csDesigning in ComponentState)
then begin
internalTimer.Interval:= BAR_ANIM_TIMER;
internalTimer.Enabled:= True;
end
else internalTimer.Enabled:= False;
end;
end;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
end;
procedure TBGRAFlashProgressBar.SetTimerInterval(AValue: Cardinal);
begin
if FTimerInterval=AValue then Exit;
FTimerInterval:=AValue;
if (FStyle = pbstTimer) then internalTimer.Interval:= AValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.SetValueSub(AValue: Double);
begin
if FValueSub = AValue then exit;
FValueSub := AValue;
if (FValueSub < FMinValue) then FValueSub := FMinValue;
if (FValueSub > FValue) then FValueSub := FValue;
if Assigned(FOnChange) then FOnChange(Self);
Invalidate;
end;
procedure TBGRAFlashProgressBar.TimerOnTimer(Sender: TObject);
begin
try
if closing then exit;
Case FStyle of
pbstNormal,
pbstMultiProgress,
pbstGraph: if FShowBarAnimation then begin
inc(barAnimLeft, BAR_ANIM_INC);
//Wait 16 times after reached the end
if (barAnimLeft+18 > xpos) then barAnimLeft:= -16*BAR_ANIM_INC;
end;
pbstMarquee: begin
if (FMarqueeBounce > 0) then
begin
if marqueeBouncing then
begin
if (marqueeCount = 0) //we've reached the rebound wall
then begin
marqueeCount:= 3; //Set the bounce length (3*2pixels)
if (marqueeCurMode = pbmdToRight)
then marqueeCurMode:= pbmdToLeft
else marqueeCurMode:= pbmdToRight;
//decreases the rebound counter only if we are in the real wall
if marqueeWall then dec(marqueeBCount);
if (marqueeBCount > 0)
then marqueeBouncing:= True
else begin
//Stop Bouncing
if marqueeWall then marqueeBCount:= FMarqueeBounce;
marqueeBouncing:= False;
end;
end
else dec(marqueeCount);
end;
end;
//Move the bar 2 pixels
if (marqueeCurMode = pbmdToRight)
then inc(marqueeLeft, MARQUEE_INC)
else dec(marqueeLeft, MARQUEE_INC);
end;
pbstTimer: begin
{ #note -oMaxM : If we had to be more precise we should keep the Start time and subtract the current time }
FValue:= IncMilliSecond(FValue, -internalTimer.Interval);
if (FValue <= 0)
then begin
if Assigned(FOnTimerEnd) then FOnTimerEnd(Self);
if FTimerAutoRestart then FValue:= FMaxValue;
internalTimer.Enabled:= FTimerAutoRestart;
end
else if Assigned(FOnTimerTimer) then FOnTimerTimer(Self);
end;
end;
Invalidate;
except
//MaxM: Ignore Exception sometimes it happens when we are closing
end;
end;
{$hints off}
class function TBGRAFlashProgressBar.GetControlClassDefaultSize: TSize;
begin
Result.CX := 380;
Result.CY := 34;
end;
procedure TBGRAFlashProgressBar.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
begin
PreferredWidth := 380;
PreferredHeight := 34;
end;
procedure TBGRAFlashProgressBar.DoOnResize;
begin
inherited DoOnResize;
if (FMarqueeWidth = 0)
then rMarqueeWidth:= Width div 4
else rMarqueeWidth:= FMarqueeWidth;
end;
{$hints on}
procedure TBGRAFlashProgressBar.Paint;
begin
if (ClientWidth <> FBGRA.Width) or (ClientHeight <> FBGRA.Height)
then FBGRA.SetSize(ClientWidth, ClientHeight);
Draw(FBGRA);
if Assigned(OnRedraw) then OnRedraw(Self, FBGRA, {%H-}XPosition);
FBGRA.Draw(Canvas, 0, 0, False);
end;
procedure TBGRAFlashProgressBar.Loaded;
begin
inherited Loaded;
Case FStyle of
pbstNormal,
pbstMultiProgress,
pbstGraph: begin
if FShowBarAnimation then internalTimer.Interval:= BAR_ANIM_TIMER;
internalTimer.Enabled:= FShowBarAnimation;
end;
pbstMarquee: begin
if (FMarqueeDirection = pbmdToRight)
then marqueeLeft:= 2
else marqueeLeft:= -FMarqueeWidth;
if FTimerAutoRestart and not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
end;
pbstTimer: begin
FValue:= FMaxValue;
internalTimer.Interval:= FTimerInterval;
if FTimerAutoRestart and not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
end;
end;
end;
procedure TBGRAFlashProgressBar.TextChanged;
begin
Invalidate;
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, CY);
// Bitmap
FBGRA := TBGRABitmap.Create(Width, Height);
// Functionality
FMinValue := 0;
FMaxValue := 100;
FValue := 30;
FValueSub := 10;
xpos:= 0;
xposSub:= 0;
// Functionality and Style
Randomize;
FRandSeed := RandSeed;
FCaptionShowPercent:= False;
FCaptionPercentAlign:= taCenter;
FCaptionPercentSubAlign:= taLeftJustify;
FCaptionPercentDigits:= 0;
Caption:= '';
// Style
FStyle:=pbstNormal;
FBarColor := BGRA(102, 163, 226);
FBarColorSub := BGRA(240, 240, 15);
FBackgroundColor := BGRA(47,47,47);
FBackgroundRandomize := True;
FBackgroundRandomizeMinIntensity := 4000;
FBackgroundRandomizeMaxIntensity := 5000;
FShowDividers:= False;
FGraphShowYDividers:= False;
FShowBarAnimation:= False;
barAnimLeft:= 0;
//Marquee
FMarqueeWidth:= 0; //AutoWidth
rMarqueeWidth:= 95; //PreferredWidth div 4
FMarqueeSpeed:= pbmsMedium;
FMarqueeDirection:= pbmdToRight;
marqueeCurMode:= pbmdToRight;
marqueeLeft:= 0;
marqueeRight:= 0;
marqueeBouncing:= False;
//Timer
FTimerInterval:= 100;
FTimerAutoRestart:= True;
FCaptionPercentTimerFormat:= 'nn:ss.zzz';
//Graph
FMinYValue := 0;
FMaxYValue := 100;
GraphValues:= nil;
GraphPoints:= nil;
FGraphShowYDividers:= False;
FGraphShowYLine:= False;
FGraphYLineCaption:= '';
FGraphYLineAfter:= '';
FGraphYLineDigits:= 0;
internalTimer:= TFPTimer.Create(Self);
internalTimer.UseTimerThread:= True;
internalTimer.Enabled:= False;
internalTimer.Interval:= MARQUEE_TIMER_MED;
internalTimer.OnTimer:= TimerOnTimer;
closing:= False;
end;
destructor TBGRAFlashProgressBar.Destroy;
begin
//Avoid Exception when internalTimer is Enabled
closing:= True;
internalTimer.Enabled:=False;
CheckSynchronize(40);
internalTimer.Free;
GraphValues:= nil;
GraphPoints:= nil;
FBGRA.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.Draw(ABitmap: TBGRABitmap);
var
content: TRect;
y, tx, ty,
marqueeOver: integer;
bgColor: TBGRAPixel;
pStr: String;
pValue: Double;
function ApplyLightness(c: TBGRAPixel; lightness: word): TBGRAPixel;
begin
Result := GammaCompression(SetLightness(GammaExpansion(c), lightness));
end;
procedure DrawBar(bounds: TRect; AColor: TColor);
var
lCol: TBGRAPixel;
begin
lCol := AColor;
DoubleGradientAlphaFill(ABitmap, bounds,
ApplyLightness(lCol, 37000), ApplyLightness(lCol, 29000),
ApplyLightness(lCol, 26000), ApplyLightness(lCol, 18000),
gdVertical, gdVertical, gdVertical, 0.53);
InflateRect(bounds, -1, -1);
DoubleGradientAlphaFill(ABitmap, bounds,
ApplyLightness(lCol, 28000), ApplyLightness(lCol, 22000),
ApplyLightness(lCol, 19000), ApplyLightness(lCol, 11000),
gdVertical, gdVertical, gdVertical, 0.53);
end;
procedure DrawBarAnimation;
begin
if FShowBarAnimation and (barAnimLeft >= 0)
then ABitmap.GradientFill(barAnimLeft, content.Top, barAnimLeft+36, content.Bottom,
BGRA(255, 255, 255, 64), BGRA(255, 255, 255, 2), gtReflected,
PointF(barAnimLeft+18, content.Bottom-content.Top/2), PointF(barAnimLeft+36, content.Bottom-content.Top/2),
dmLinearBlend);
end;
procedure DrawText(ACaption: String; AAlign: TAlignment);
var
fx: TBGRATextEffect;
lColB: TBGRAPixel;
begin
try
if (Font.Size=0)
then fx:= TBGRATextEffect.Create(ACaption, Font.Name, ABitmap.Height div 2, True)
else fx:= TBGRATextEffect.Create(ACaption, Font, True);
if (Font.Color = clDefault) or (Font.Color = clNone)
then lColB:= ApplyLightness(FBarColor, 59000)
else lColB:= ColorToBGRA(Font.Color);
y:= (ABitmap.Height-fx.TextHeight) div 2;
Case AAlign of
taLeftJustify: begin
fx.DrawOutline(ABitmap, 4, y, BGRABlack, taLeftJustify);
fx.Draw(ABitmap, 4, y, lColB, taLeftJustify);
end;
taRightJustify: begin
fx.DrawOutline(ABitmap, tx-4, y, BGRABlack, taRightJustify);
fx.Draw(ABitmap, tx-4, y, lColB, taRightJustify);
end;
taCenter: begin
fx.DrawOutline(ABitmap, ABitmap.Width div 2, y, BGRABlack, taCenter);
fx.Draw(ABitmap, ABitmap.Width div 2, y, lColB, taCenter);
end;