bgraflashprogressbar.pas 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. {
  2. Created by BGRA Controls Team
  3. Dibo, Circular, lainz (007) and contributors.
  4. For detailed information see readme.txt
  5. Site: https://sourceforge.net/p/bgra-controls/
  6. Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
  7. Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
  8. }
  9. {******************************* CONTRIBUTOR(S) ******************************
  10. - Edivando S. Santos Brasil | [email protected]
  11. (Compatibility with delphi VCL 11/2018)
  12. - Massimo Magnano
  13. 2024-12 Added Marquee and MultiProgress Style
  14. Added Caption, CaptionShowPercent, CaptionShowPercentAlign, CaptionShowPercentDigits;
  15. Changed Values to Double Type;
  16. Deleted Unit BGRADrawerFlashProgressBar;
  17. New Test with all Features
  18. Added Timer Style
  19. 2025-01 Added Marquee Bounce and Stepit Method,
  20. TimerPlayPause works also for Marquee (useful for debugging)
  21. Added Graph Style and ShowDividers, Renamed MultiProgress properties
  22. Added ShowBarAnimation
  23. 2025-02 Added use of Font.Color
  24. 2025-03 Added MarqueeWidthType
  25. ***************************** END CONTRIBUTOR(S) *****************************}
  26. unit BGRAFlashProgressBar;
  27. {$I bgracontrols.inc}
  28. interface
  29. uses
  30. Classes, {$IFDEF BGRABITMAP_USE_MSEGUI} mclasses, {$ENDIF}
  31. SysUtils, Types, Forms, Controls, Graphics,
  32. {$IFDEF FPC} LResources, LMessages,
  33. {$ELSE} Messages, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
  34. BCBaseCtrls, BGRABitmap, BGRABitmapTypes, BGRAGraphics, BGRAGradients,
  35. Math, fptimer;
  36. type
  37. TBGRAPBarStyle = (pbstNormal, pbstMultiProgress, pbstMarquee, pbstTimer, pbstGraph);
  38. TBGRAPBarMarqueeWidthType = (pbmwAuto, pbmwFixed, pbmwValue, pbmwValueSub); //, pbmwInc MaxM: maybe tomorrow when I have free time
  39. TBGRAPBarMarqueeDirection = (pbmdToRight, pbmdToLeft);
  40. TBGRAPBarMarqueeSpeed = (pbmsSlow, pbmsMedium, pbmsFast);
  41. TBGRAProgressBarRedrawEvent = procedure(Sender: TObject; Bitmap: TBGRABitmap; xpos: integer) of object;
  42. { TBGRAFlashProgressBar }
  43. TGraphValue = record
  44. XValue, YValue: Double;
  45. end;
  46. TGraphValues = array of TGraphValue;
  47. TBGRAFlashProgressBar = class(TBGRAGraphicCtrl)
  48. private
  49. function GetMax: Integer;
  50. function GetMin: Integer;
  51. function GetPosition: Integer;
  52. procedure SetBackgroundRandomize(AValue: boolean);
  53. procedure SetBackgroundRandomizeMaxIntensity(AValue: word);
  54. procedure SetBackgroundRandomizeMinIntensity(AValue: word);
  55. procedure SetBarColor(AValue: TColor);
  56. procedure SetBackgroundColor(AValue: TColor);
  57. procedure SetBarColorSub(AValue: TColor);
  58. procedure SetCaptionPercentDigits(AValue: Integer);
  59. procedure SetCaptionPercentTimerFormat(AValue: String);
  60. procedure SetCaptionShowPercent(AValue: Boolean);
  61. procedure SetCaptionPercentAlign(AValue: TAlignment);
  62. procedure SetCaptionPercentSubAlign(AValue: TAlignment);
  63. procedure SetCaptionShowPercentSub(AValue: Boolean);
  64. procedure SetGraphShowYLine(AValue: Boolean);
  65. procedure SetGraphYLineAfter(AValue: String);
  66. procedure SetGraphYLineCaption(AValue: String);
  67. procedure SetGraphYLineDigits(AValue: Integer);
  68. procedure SetMarqueeWidthType(AValue: TBGRAPBarMarqueeWidthType);
  69. procedure SetMax(AValue: Integer);
  70. procedure SetMin(AValue: Integer);
  71. procedure SetPosition(AValue: Integer);
  72. procedure SetShowBarAnimation(AValue: Boolean);
  73. procedure SetShowDividers(AValue: Boolean);
  74. procedure SetMarqueeBounce(AValue: Word);
  75. procedure SetMarqueeDirection(AValue: TBGRAPBarMarqueeDirection);
  76. procedure SetMarqueeSpeed(AValue: TBGRAPBarMarqueeSpeed);
  77. procedure SetMarqueeWidth(AValue: Word);
  78. procedure SetMaxValue(AValue: Double);
  79. procedure SetMaxYValue(AValue: Double);
  80. procedure SetMinValue(AValue: Double);
  81. procedure SetMinYValue(AValue: Double);
  82. procedure SetRandSeed(AValue: integer);
  83. procedure SetGraphShowYDividers(AValue: Boolean);
  84. procedure SetStyle(AValue: TBGRAPBarStyle);
  85. procedure SetTimerInterval(AValue: Cardinal);
  86. procedure SetValueSub(AValue: Double);
  87. protected
  88. FBGRA: TBGRABitmap;
  89. FCaptionPercentDigits: Integer;
  90. FCaptionPercentTimerFormat: String;
  91. FCaptionShowPercent: Boolean;
  92. FCaptionPercentAlign: TAlignment;
  93. FCaptionPercentSubAlign: TAlignment;
  94. FCaptionShowPercentSub: Boolean;
  95. FMarqueeBounce: Word;
  96. FOnRedraw: TBGRAProgressBarRedrawEvent;
  97. FBackgroundColor: TColor;
  98. FBackgroundRandomize: boolean;
  99. FBackgroundRandomizeMaxIntensity: word;
  100. FBackgroundRandomizeMinIntensity: word;
  101. FShowDividers,
  102. FGraphShowYDividers: Boolean;
  103. FBarColor,
  104. FBarColorSub: TColor;
  105. FMarqueeWidthType: TBGRAPBarMarqueeWidthType;
  106. FMarqueeDirection: TBGRAPBarMarqueeDirection;
  107. FMarqueeSpeed: TBGRAPBarMarqueeSpeed;
  108. FMarqueeWidth,
  109. rMarqueeWidth: Word;
  110. FOnTimerTimer: TNotifyEvent;
  111. FTimerAutoRestart: Boolean;
  112. FOnTimerEnd: TNotifyEvent;
  113. FOnTimerStart: TNotifyEvent;
  114. FTimerInterval: Cardinal;
  115. FMaxValue,
  116. FMinValue,
  117. FMinYValue,
  118. FMaxYValue,
  119. FValue,
  120. FValueSub: Double;
  121. FOnChange: TNotifyEvent;
  122. FRandSeed: integer;
  123. FStyle: TBGRAPBarStyle;
  124. FGraphShowYLine: Boolean;
  125. FGraphYLineAfter: String;
  126. FGraphYLineCaption: String;
  127. FGraphYLineDigits: Integer;
  128. FShowBarAnimation: Boolean;
  129. xpos,
  130. xposSub,
  131. marqueeLeft,
  132. marqueeRight,
  133. marqueeCount,
  134. marqueeBCount,
  135. barAnimLeft: Integer;
  136. marqueeWall,
  137. marqueeBouncing: Boolean;
  138. marqueeCurMode: TBGRAPBarMarqueeDirection;
  139. internalTimer: TFPTimer;
  140. closing: Boolean;
  141. GraphValues: TGraphValues; //array of Real Graph Values
  142. GraphPoints: array of TPointF; //array of Calculated xpos and ypos
  143. class function GetControlClassDefaultSize: TSize; override;
  144. procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean); override;
  145. procedure DoOnResize; override;
  146. procedure WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF}); message {$IFDEF FPC}LM_ERASEBKGND{$ELSE}WM_ERASEBKGND{$ENDIF};
  147. procedure Paint; override;
  148. procedure Loaded; override;
  149. procedure TextChanged; override;
  150. procedure TimerOnTimer(Sender: TObject);
  151. procedure CalcMarqueeWidth;
  152. public
  153. constructor Create(AOwner: TComponent); override;
  154. destructor Destroy; override;
  155. { Streaming }
  156. {$IFDEF FPC}
  157. procedure SaveToFile(AFileName: string);
  158. procedure LoadFromFile(AFileName: string);
  159. procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
  160. var ComponentClass: TComponentClass);
  161. {$ENDIF}
  162. procedure Draw(ABitmap: TBGRABitmap);
  163. procedure SetValue(AValue: Double); overload;
  164. //Set Current Value and it's Y Value in Graph Style
  165. procedure SetValue(AValue, AYValue: Double); overload;
  166. //Step It, if Style is pbstNormal then Inc/Dec Value,
  167. // if pbstMarquee then do next Animation Step (AIncrement is ignored)
  168. // if pbstTimer then Value is decremented of 100ms (AIncrement is ignored)
  169. procedure StepIt(AIncrement: Double);
  170. //Timer Restart applies only if Style is pbstTimer
  171. procedure TimerReStart;
  172. //Timer Play/Pause applies only if Style is pbstMarquee or pbstTimer
  173. procedure TimerPlayPause;
  174. //For Compatibility with TProgressBar code
  175. property Position: Integer read GetPosition write SetPosition;
  176. property Min: Integer read GetMin write SetMin;
  177. property Max: Integer read GetMax write SetMax;
  178. property XPosition: integer read xpos;
  179. property XPositionSub: integer read xposSub;
  180. published
  181. property Align;
  182. property BorderSpacing;
  183. property Anchors;
  184. property Caption;
  185. property CaptionShowPercent: Boolean read FCaptionShowPercent write SetCaptionShowPercent default False;
  186. property CaptionPercentAlign: TAlignment read FCaptionPercentAlign write SetCaptionPercentAlign default taCenter;
  187. property CaptionShowPercentSub: Boolean read FCaptionShowPercentSub write SetCaptionShowPercentSub default False;
  188. property CaptionPercentSubAlign: TAlignment read FCaptionPercentSubAlign write SetCaptionPercentSubAlign default taLeftJustify;
  189. property CaptionPercentDigits: Integer read FCaptionPercentDigits write SetCaptionPercentDigits default 0;
  190. property CaptionPercentTimerFormat: String read FCaptionPercentTimerFormat write SetCaptionPercentTimerFormat;
  191. property Font;
  192. property ParentFont;
  193. property MinValue: Double read FMinValue write SetMinValue;
  194. property MaxValue: Double read FMaxValue write SetMaxValue;
  195. property MinYValue: Double read FMinYValue write SetMinYValue;
  196. property MaxYValue: Double read FMaxYValue write SetMaxYValue;
  197. property Value: Double read FValue write SetValue;
  198. property ValueSub: Double read FValueSub write SetValueSub;
  199. property Color; deprecated 'User BarColor instead';
  200. property RandSeed: integer read FRandSeed write SetRandSeed;
  201. property BarColor: TColor read FBarColor write SetBarColor;
  202. property BarColorSub: TColor read FBarColorSub write SetBarColorSub;
  203. property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor;
  204. property BackgroundRandomizeMinIntensity: Word read FBackgroundRandomizeMinIntensity write SetBackgroundRandomizeMinIntensity;
  205. property BackgroundRandomizeMaxIntensity: Word read FBackgroundRandomizeMaxIntensity write SetBackgroundRandomizeMaxIntensity;
  206. property BackgroundRandomize: Boolean read FBackgroundRandomize write SetBackgroundRandomize;
  207. property ShowDividers: Boolean read FShowDividers write SetShowDividers default False;
  208. property ShowBarAnimation: Boolean read FShowBarAnimation write SetShowBarAnimation default False;
  209. property Style: TBGRAPBarStyle read FStyle write SetStyle default pbstNormal;
  210. property MarqueeWidthType: TBGRAPBarMarqueeWidthType read FMarqueeWidthType write SetMarqueeWidthType default pbmwAuto;
  211. property MarqueeWidth: Word read FMarqueeWidth write SetMarqueeWidth default 95;
  212. property MarqueeSpeed: TBGRAPBarMarqueeSpeed read FMarqueeSpeed write SetMarqueeSpeed default pbmsMedium;
  213. property MarqueeDirection: TBGRAPBarMarqueeDirection read FMarqueeDirection write SetMarqueeDirection default pbmdToRight;
  214. property MarqueeBounce: Word read FMarqueeBounce write SetMarqueeBounce default 0;
  215. property TimerInterval: Cardinal read FTimerInterval write SetTimerInterval default 100;
  216. property TimerAutoRestart: Boolean read FTimerAutoRestart write FTimerAutoRestart default True;
  217. property GraphShowYDividers: Boolean read FGraphShowYDividers write SetGraphShowYDividers default False;
  218. property GraphShowYLine: Boolean read FGraphShowYLine write SetGraphShowYLine default False;
  219. property GraphYLineCaption: String read FGraphYLineCaption write SetGraphYLineCaption;
  220. property GraphYLineAfter: String read FGraphYLineAfter write SetGraphYLineAfter;
  221. property GraphYLineDigits: Integer read FGraphYLineDigits write SetGraphYLineDigits default 0;
  222. property OnClick;
  223. property OnMouseDown;
  224. property OnMouseEnter;
  225. property OnMouseLeave;
  226. property OnMouseMove;
  227. property OnMouseUp;
  228. property OnMouseWheel;
  229. property OnMouseWheelUp;
  230. property OnMouseWheelDown;
  231. property OnChange: TNotifyEvent read FOnChange write FOnChange;
  232. property OnRedraw: TBGRAProgressBarRedrawEvent read FOnRedraw write FOnRedraw;
  233. property OnTimerStart: TNotifyEvent read FOnTimerStart write FOnTimerStart;
  234. property OnTimerEnd: TNotifyEvent read FOnTimerEnd write FOnTimerEnd;
  235. property OnTimerTimer: TNotifyEvent read FOnTimerTimer write FOnTimerTimer;
  236. end;
  237. {$IFDEF FPC}procedure Register;{$ENDIF}
  238. implementation
  239. uses DateUtils, BGRATextFX;
  240. const
  241. BAR_ANIM_TIMER = 20;
  242. BAR_ANIM_INC = 4;
  243. MARQUEE_TIMER_SLOW = 50;
  244. MARQUEE_TIMER_MED = 20;
  245. MARQUEE_TIMER_FAST = 10;
  246. MARQUEE_INC = 2;
  247. MARQUEE_WIDTH_MIN = 10;
  248. {$IFDEF FPC}
  249. procedure Register;
  250. begin
  251. RegisterComponents('BGRA Controls', [TBGRAFlashProgressBar]);
  252. end;
  253. {$ENDIF}
  254. { TBGRAFlashProgressBar }
  255. procedure TBGRAFlashProgressBar.SetBarColor(AValue: TColor);
  256. begin
  257. if FBarColor = AValue then exit;
  258. FBarColor := AValue;
  259. if Assigned(FOnChange) then FOnChange(Self);
  260. Invalidate;
  261. end;
  262. function TBGRAFlashProgressBar.GetMax: Integer;
  263. begin
  264. Result:= Trunc(FMaxValue);
  265. end;
  266. function TBGRAFlashProgressBar.GetMin: Integer;
  267. begin
  268. Result:= Trunc(FMinValue);
  269. end;
  270. function TBGRAFlashProgressBar.GetPosition: Integer;
  271. begin
  272. Result:= Trunc(FValue);
  273. end;
  274. procedure TBGRAFlashProgressBar.SetBackgroundRandomize(AValue: boolean);
  275. begin
  276. if FBackgroundRandomize = AValue then exit;
  277. FBackgroundRandomize := AValue;
  278. if Assigned(FOnChange) then FOnChange(Self);
  279. Invalidate;
  280. end;
  281. procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMaxIntensity(AValue: word);
  282. begin
  283. if FBackgroundRandomizeMaxIntensity = AValue then exit;
  284. FBackgroundRandomizeMaxIntensity := AValue;
  285. if Assigned(FOnChange) then FOnChange(Self);
  286. Invalidate;
  287. end;
  288. procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMinIntensity(AValue: word);
  289. begin
  290. if FBackgroundRandomizeMinIntensity = AValue then exit;
  291. FBackgroundRandomizeMinIntensity := AValue;
  292. if Assigned(FOnChange) then FOnChange(Self);
  293. Invalidate;
  294. end;
  295. procedure TBGRAFlashProgressBar.SetBackgroundColor(AValue: TColor);
  296. begin
  297. if FBackgroundColor = AValue then exit;
  298. FBackgroundColor := AValue;
  299. if Assigned(FOnChange) then FOnChange(Self);
  300. Invalidate;
  301. end;
  302. procedure TBGRAFlashProgressBar.SetBarColorSub(AValue: TColor);
  303. begin
  304. if FBarColorSub = AValue then exit;
  305. FBarColorSub := AValue;
  306. if Assigned(FOnChange) then FOnChange(Self);
  307. Invalidate;
  308. end;
  309. procedure TBGRAFlashProgressBar.SetCaptionPercentDigits(AValue: Integer);
  310. begin
  311. if FCaptionPercentDigits=AValue then Exit;
  312. FCaptionPercentDigits:=AValue;
  313. if Assigned(FOnChange) then FOnChange(Self);
  314. Invalidate;
  315. end;
  316. procedure TBGRAFlashProgressBar.SetCaptionPercentTimerFormat(AValue: String);
  317. begin
  318. if FCaptionPercentTimerFormat=AValue then Exit;
  319. FCaptionPercentTimerFormat:=AValue;
  320. if Assigned(FOnChange) then FOnChange(Self);
  321. Invalidate;
  322. end;
  323. procedure TBGRAFlashProgressBar.SetCaptionShowPercent(AValue: Boolean);
  324. begin
  325. if FCaptionShowPercent=AValue then Exit;
  326. FCaptionShowPercent:=AValue;
  327. if Assigned(FOnChange) then FOnChange(Self);
  328. Invalidate;
  329. end;
  330. procedure TBGRAFlashProgressBar.SetCaptionPercentAlign(AValue: TAlignment);
  331. begin
  332. if FCaptionPercentAlign=AValue then Exit;
  333. FCaptionPercentAlign:=AValue;
  334. if Assigned(FOnChange) then FOnChange(Self);
  335. Invalidate;
  336. end;
  337. procedure TBGRAFlashProgressBar.SetCaptionPercentSubAlign(AValue: TAlignment);
  338. begin
  339. if FCaptionPercentSubAlign=AValue then Exit;
  340. FCaptionPercentSubAlign:=AValue;
  341. if Assigned(FOnChange) then FOnChange(Self);
  342. Invalidate;
  343. end;
  344. procedure TBGRAFlashProgressBar.SetCaptionShowPercentSub(AValue: Boolean);
  345. begin
  346. if FCaptionShowPercentSub=AValue then Exit;
  347. FCaptionShowPercentSub:=AValue;
  348. if Assigned(FOnChange) then FOnChange(Self);
  349. Invalidate;
  350. end;
  351. procedure TBGRAFlashProgressBar.SetGraphShowYLine(AValue: Boolean);
  352. begin
  353. if FGraphShowYLine=AValue then Exit;
  354. FGraphShowYLine:=AValue;
  355. if Assigned(FOnChange) then FOnChange(Self);
  356. Invalidate;
  357. end;
  358. procedure TBGRAFlashProgressBar.SetGraphYLineAfter(AValue: String);
  359. begin
  360. if FGraphYLineAfter=AValue then Exit;
  361. FGraphYLineAfter:=AValue;
  362. if Assigned(FOnChange) then FOnChange(Self);
  363. Invalidate;
  364. end;
  365. procedure TBGRAFlashProgressBar.SetGraphYLineCaption(AValue: String);
  366. begin
  367. if FGraphYLineCaption=AValue then Exit;
  368. FGraphYLineCaption:=AValue;
  369. if Assigned(FOnChange) then FOnChange(Self);
  370. Invalidate;
  371. end;
  372. procedure TBGRAFlashProgressBar.SetGraphYLineDigits(AValue: Integer);
  373. begin
  374. if FGraphYLineDigits=AValue then Exit;
  375. FGraphYLineDigits:=AValue;
  376. if Assigned(FOnChange) then FOnChange(Self);
  377. Invalidate;
  378. end;
  379. procedure TBGRAFlashProgressBar.SetMarqueeWidthType(AValue: TBGRAPBarMarqueeWidthType);
  380. begin
  381. if FMarqueeWidthType=AValue then Exit;
  382. FMarqueeWidthType:=AValue;
  383. CalcMarqueeWidth;
  384. if Assigned(FOnChange) then FOnChange(Self);
  385. Invalidate;
  386. end;
  387. procedure TBGRAFlashProgressBar.SetMax(AValue: Integer);
  388. begin
  389. SetMaxValue(AValue);
  390. end;
  391. procedure TBGRAFlashProgressBar.SetMin(AValue: Integer);
  392. begin
  393. SetMinValue(AValue);
  394. end;
  395. procedure TBGRAFlashProgressBar.SetPosition(AValue: Integer);
  396. begin
  397. SetValue(AValue);
  398. end;
  399. procedure TBGRAFlashProgressBar.SetShowBarAnimation(AValue: Boolean);
  400. begin
  401. if FShowBarAnimation=AValue then Exit;
  402. FShowBarAnimation:=AValue;
  403. if (FStyle in [pbstNormal, pbstMultiProgress, pbstGraph]) and
  404. not(csLoading in ComponentState) and
  405. not(csDesigning in ComponentState) then
  406. begin
  407. barAnimLeft:= 0;
  408. if FShowBarAnimation then internalTimer.Interval:= BAR_ANIM_TIMER;
  409. internalTimer.Enabled:= FShowBarAnimation;
  410. end;
  411. if Assigned(FOnChange) then FOnChange(Self);
  412. Invalidate;
  413. end;
  414. procedure TBGRAFlashProgressBar.SetShowDividers(AValue: Boolean);
  415. begin
  416. if FShowDividers=AValue then Exit;
  417. FShowDividers:=AValue;
  418. if Assigned(FOnChange) then FOnChange(Self);
  419. Invalidate;
  420. end;
  421. procedure TBGRAFlashProgressBar.SetMarqueeBounce(AValue: Word);
  422. begin
  423. marqueeBCount:= AValue;
  424. if FMarqueeBounce=AValue then Exit;
  425. FMarqueeBounce:=AValue;
  426. if Assigned(FOnChange) then FOnChange(Self);
  427. Invalidate;
  428. end;
  429. procedure TBGRAFlashProgressBar.SetMarqueeDirection(AValue: TBGRAPBarMarqueeDirection);
  430. begin
  431. if (FMarqueeDirection <> AValue) then
  432. begin
  433. FMarqueeDirection:= AValue;
  434. marqueeCurMode:= AValue;
  435. if Assigned(FOnChange) then FOnChange(Self);
  436. Invalidate;
  437. end;
  438. end;
  439. procedure TBGRAFlashProgressBar.SetMarqueeSpeed(AValue: TBGRAPBarMarqueeSpeed);
  440. begin
  441. FMarqueeSpeed:=AValue;
  442. case FMarqueeSpeed of
  443. pbmsSlow: internalTimer.Interval:= MARQUEE_TIMER_SLOW;
  444. pbmsMedium: internalTimer.Interval:= MARQUEE_TIMER_MED;
  445. pbmsFast: internalTimer.Interval:= MARQUEE_TIMER_FAST;
  446. end;
  447. end;
  448. procedure TBGRAFlashProgressBar.SetMarqueeWidth(AValue: Word);
  449. begin
  450. if FMarqueeWidth=AValue then Exit;
  451. if (AValue > Width) then AValue:= Width;
  452. if (AValue < MARQUEE_WIDTH_MIN) then AValue:= MARQUEE_WIDTH_MIN;
  453. FMarqueeWidth:= AValue;
  454. if (FMarqueeWidthType = pbmwFixed) then
  455. begin
  456. rMarqueeWidth:= FMarqueeWidth;
  457. if Assigned(FOnChange) then FOnChange(Self);
  458. Invalidate;
  459. end;
  460. end;
  461. procedure TBGRAFlashProgressBar.SetMaxValue(AValue: Double);
  462. begin
  463. if FMaxValue = AValue then exit;
  464. FMaxValue := AValue;
  465. if (FValue > FMaxValue) then FValue := FMaxValue;
  466. if (FMinValue > FMaxValue) then FMinValue := FMaxValue;
  467. if Assigned(FOnChange) then FOnChange(Self);
  468. Invalidate;
  469. end;
  470. procedure TBGRAFlashProgressBar.SetMaxYValue(AValue: Double);
  471. begin
  472. if FMaxYValue=AValue then Exit;
  473. FMaxYValue:=AValue;
  474. end;
  475. procedure TBGRAFlashProgressBar.SetMinValue(AValue: Double);
  476. begin
  477. if FMinValue = AValue then exit;
  478. FMinValue := AValue;
  479. if (FValue < FMinValue) then FValue := FMinValue;
  480. if (FMaxValue < FMinValue) then FMaxValue := FMinValue;
  481. if Assigned(FOnChange) then FOnChange(Self);
  482. Invalidate;
  483. end;
  484. procedure TBGRAFlashProgressBar.SetMinYValue(AValue: Double);
  485. begin
  486. if FMinYValue=AValue then Exit;
  487. FMinYValue:=AValue;
  488. end;
  489. procedure TBGRAFlashProgressBar.SetRandSeed(AValue: integer);
  490. begin
  491. if FRandSeed = AValue then exit;
  492. FRandSeed := AValue;
  493. if Assigned(FOnChange) then FOnChange(Self);
  494. Invalidate;
  495. end;
  496. procedure TBGRAFlashProgressBar.SetGraphShowYDividers(AValue: Boolean);
  497. begin
  498. if FGraphShowYDividers=AValue then Exit;
  499. FGraphShowYDividers:=AValue;
  500. if Assigned(FOnChange) then FOnChange(Self);
  501. Invalidate;
  502. end;
  503. procedure TBGRAFlashProgressBar.SetStyle(AValue: TBGRAPBarStyle);
  504. begin
  505. if (FStyle <> AValue) then
  506. begin
  507. FStyle:= AValue;
  508. Case FStyle of
  509. pbstNormal,
  510. pbstMultiProgress: begin
  511. if FShowBarAnimation and
  512. not(csLoading in ComponentState) and
  513. not(csDesigning in ComponentState)
  514. then begin
  515. barAnimLeft:= 0;
  516. internalTimer.Interval:= BAR_ANIM_TIMER;
  517. internalTimer.Enabled:= True;
  518. end
  519. else internalTimer.Enabled:= False;
  520. end;
  521. pbstMarquee: begin
  522. SetMarqueeSpeed(FMarqueeSpeed);
  523. if (FMarqueeDirection = pbmdToRight)
  524. then marqueeLeft:= 2
  525. else marqueeLeft:= -rMarqueeWidth;
  526. if FTimerAutoRestart and
  527. not(csLoading in ComponentState) and
  528. not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
  529. end;
  530. pbstTimer: begin
  531. FValue:= FMaxValue;
  532. internalTimer.Interval:= FTimerInterval;
  533. if FTimerAutoRestart and
  534. not(csLoading in ComponentState) and
  535. not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
  536. end;
  537. pbstGraph: begin
  538. //Save space for the 2 points to close the polygon
  539. if (Length(GraphPoints) < 2) then SetLength(GraphPoints, 2);
  540. if FShowBarAnimation and
  541. not(csLoading in ComponentState) and
  542. not(csDesigning in ComponentState)
  543. then begin
  544. internalTimer.Interval:= BAR_ANIM_TIMER;
  545. internalTimer.Enabled:= True;
  546. end
  547. else internalTimer.Enabled:= False;
  548. end;
  549. end;
  550. if Assigned(FOnChange) then FOnChange(Self);
  551. Invalidate;
  552. end;
  553. end;
  554. procedure TBGRAFlashProgressBar.SetTimerInterval(AValue: Cardinal);
  555. begin
  556. if FTimerInterval=AValue then Exit;
  557. FTimerInterval:=AValue;
  558. if (FStyle = pbstTimer) then internalTimer.Interval:= AValue;
  559. if Assigned(FOnChange) then FOnChange(Self);
  560. Invalidate;
  561. end;
  562. procedure TBGRAFlashProgressBar.SetValueSub(AValue: Double);
  563. begin
  564. if FValueSub = AValue then exit;
  565. FValueSub := AValue;
  566. if (FValueSub < FMinValue) then FValueSub := FMinValue;
  567. if (FValueSub > FValue) then FValueSub := FValue;
  568. if Assigned(FOnChange) then FOnChange(Self);
  569. Invalidate;
  570. end;
  571. procedure TBGRAFlashProgressBar.TimerOnTimer(Sender: TObject);
  572. begin
  573. try
  574. if closing then exit;
  575. Case FStyle of
  576. pbstNormal,
  577. pbstMultiProgress,
  578. pbstGraph: if FShowBarAnimation then begin
  579. inc(barAnimLeft, BAR_ANIM_INC);
  580. //Wait 16 times after reached the end
  581. if (barAnimLeft+18 > xpos) then barAnimLeft:= -16*BAR_ANIM_INC;
  582. end;
  583. pbstMarquee: begin
  584. if (FMarqueeBounce > 0) then
  585. begin
  586. if marqueeBouncing then
  587. begin
  588. if (marqueeCount = 0) //we've reached the rebound wall
  589. then begin
  590. marqueeCount:= 3; //Set the bounce length (3*2pixels)
  591. if (marqueeCurMode = pbmdToRight)
  592. then marqueeCurMode:= pbmdToLeft
  593. else marqueeCurMode:= pbmdToRight;
  594. //decreases the rebound counter only if we are in the real wall
  595. if marqueeWall then dec(marqueeBCount);
  596. if (marqueeBCount > 0)
  597. then marqueeBouncing:= True
  598. else begin
  599. //Stop Bouncing
  600. if marqueeWall then marqueeBCount:= FMarqueeBounce;
  601. marqueeBouncing:= False;
  602. end;
  603. end
  604. else dec(marqueeCount);
  605. end;
  606. end;
  607. //Move the bar 2 pixels
  608. if (marqueeCurMode = pbmdToRight)
  609. then inc(marqueeLeft, MARQUEE_INC)
  610. else dec(marqueeLeft, MARQUEE_INC);
  611. end;
  612. pbstTimer: begin
  613. { #note -oMaxM : If we had to be more precise we should keep the Start time and subtract the current time }
  614. FValue:= IncMilliSecond(FValue, -internalTimer.Interval);
  615. if (FValue <= 0)
  616. then begin
  617. if Assigned(FOnTimerEnd) then FOnTimerEnd(Self);
  618. if FTimerAutoRestart then FValue:= FMaxValue;
  619. internalTimer.Enabled:= FTimerAutoRestart;
  620. end
  621. else if Assigned(FOnTimerTimer) then FOnTimerTimer(Self);
  622. end;
  623. end;
  624. Invalidate;
  625. except
  626. //MaxM: Ignore Exception sometimes it happens when we are closing
  627. end;
  628. end;
  629. procedure TBGRAFlashProgressBar.CalcMarqueeWidth;
  630. begin
  631. Case FMarqueeWidthType of
  632. pbmwAuto: rMarqueeWidth:= Width div 4;
  633. pbmwFixed: rMarqueeWidth:= FMarqueeWidth;
  634. pbmwValue: begin
  635. rMarqueeWidth:= round((FValue - FMinValue) / (FMaxValue - FMinValue) * (Width-2));
  636. if (rMarqueeWidth < MARQUEE_WIDTH_MIN) then rMarqueeWidth:= MARQUEE_WIDTH_MIN;
  637. end;
  638. pbmwValueSub: begin
  639. rMarqueeWidth:= round((FValueSub - FMinValue) / (FMaxValue - FMinValue) * (Width-2));
  640. if (rMarqueeWidth < MARQUEE_WIDTH_MIN) then rMarqueeWidth:= MARQUEE_WIDTH_MIN;
  641. end;
  642. end;
  643. end;
  644. {$hints off}
  645. class function TBGRAFlashProgressBar.GetControlClassDefaultSize: TSize;
  646. begin
  647. Result.CX := 380;
  648. Result.CY := 34;
  649. end;
  650. procedure TBGRAFlashProgressBar.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
  651. begin
  652. PreferredWidth := 380;
  653. PreferredHeight := 34;
  654. end;
  655. procedure TBGRAFlashProgressBar.DoOnResize;
  656. begin
  657. inherited DoOnResize;
  658. if (FMarqueeWidthType = pbmwAuto) then rMarqueeWidth:= Width div 4;
  659. end;
  660. {$hints on}
  661. procedure TBGRAFlashProgressBar.Paint;
  662. begin
  663. if (ClientWidth <> FBGRA.Width) or (ClientHeight <> FBGRA.Height)
  664. then FBGRA.SetSize(ClientWidth, ClientHeight);
  665. Draw(FBGRA);
  666. if Assigned(OnRedraw) then OnRedraw(Self, FBGRA, {%H-}XPosition);
  667. FBGRA.Draw(Canvas, 0, 0, False);
  668. end;
  669. procedure TBGRAFlashProgressBar.Loaded;
  670. begin
  671. inherited Loaded;
  672. Case FStyle of
  673. pbstNormal,
  674. pbstMultiProgress,
  675. pbstGraph: begin
  676. if FShowBarAnimation then internalTimer.Interval:= BAR_ANIM_TIMER;
  677. internalTimer.Enabled:= FShowBarAnimation;
  678. end;
  679. pbstMarquee: begin
  680. CalcMarqueeWidth;
  681. if (FMarqueeDirection = pbmdToRight)
  682. then marqueeLeft:= 2
  683. else marqueeLeft:= -rMarqueeWidth;
  684. if FTimerAutoRestart and not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
  685. end;
  686. pbstTimer: begin
  687. FValue:= FMaxValue;
  688. internalTimer.Interval:= FTimerInterval;
  689. if FTimerAutoRestart and not(csDesigning in ComponentState) then internalTimer.Enabled:= True;
  690. end;
  691. end;
  692. end;
  693. procedure TBGRAFlashProgressBar.TextChanged;
  694. begin
  695. Invalidate;
  696. end;
  697. {$hints off}
  698. procedure TBGRAFlashProgressBar.WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF});
  699. begin
  700. //do nothing
  701. end;
  702. {$hints on}
  703. constructor TBGRAFlashProgressBar.Create(AOwner: TComponent);
  704. begin
  705. inherited Create(AOwner);
  706. with GetControlClassDefaultSize do
  707. SetInitialBounds(0, 0, CX, CY);
  708. // Bitmap
  709. FBGRA := TBGRABitmap.Create(Width, Height);
  710. // Functionality
  711. FMinValue := 0;
  712. FMaxValue := 100;
  713. FValue := 30;
  714. FValueSub := 10;
  715. xpos:= 0;
  716. xposSub:= 0;
  717. // Functionality and Style
  718. Randomize;
  719. FRandSeed := RandSeed;
  720. FCaptionShowPercent:= False;
  721. FCaptionPercentAlign:= taCenter;
  722. FCaptionPercentSubAlign:= taLeftJustify;
  723. FCaptionPercentDigits:= 0;
  724. Caption:= '';
  725. // Style
  726. FStyle:=pbstNormal;
  727. FBarColor := BGRA(102, 163, 226);
  728. FBarColorSub := BGRA(240, 240, 15);
  729. FBackgroundColor := BGRA(47,47,47);
  730. FBackgroundRandomize := True;
  731. FBackgroundRandomizeMinIntensity := 4000;
  732. FBackgroundRandomizeMaxIntensity := 5000;
  733. FShowDividers:= False;
  734. FGraphShowYDividers:= False;
  735. FShowBarAnimation:= False;
  736. barAnimLeft:= 0;
  737. //Marquee
  738. FMarqueeWidthType:= pbmwAuto; //AutoWidth
  739. rMarqueeWidth:= 95; //PreferredWidth div 4
  740. FMarqueeWidth:= 95;
  741. FMarqueeSpeed:= pbmsMedium;
  742. FMarqueeDirection:= pbmdToRight;
  743. marqueeCurMode:= pbmdToRight;
  744. marqueeLeft:= 0;
  745. marqueeRight:= 0;
  746. FMarqueeBounce:= 0;
  747. marqueeBouncing:= False;
  748. //Timer
  749. FTimerInterval:= 100;
  750. FTimerAutoRestart:= True;
  751. FCaptionPercentTimerFormat:= 'nn:ss.zzz';
  752. //Graph
  753. FMinYValue := 0;
  754. FMaxYValue := 100;
  755. GraphValues:= nil;
  756. GraphPoints:= nil;
  757. FGraphShowYDividers:= False;
  758. FGraphShowYLine:= False;
  759. FGraphYLineCaption:= '';
  760. FGraphYLineAfter:= '';
  761. FGraphYLineDigits:= 0;
  762. internalTimer:= TFPTimer.Create(Self);
  763. internalTimer.UseTimerThread:= True;
  764. internalTimer.Enabled:= False;
  765. internalTimer.Interval:= MARQUEE_TIMER_MED;
  766. internalTimer.OnTimer:= TimerOnTimer;
  767. closing:= False;
  768. end;
  769. destructor TBGRAFlashProgressBar.Destroy;
  770. begin
  771. //Avoid Exception when internalTimer is Enabled
  772. closing:= True;
  773. internalTimer.Enabled:=False;
  774. CheckSynchronize(40);
  775. internalTimer.Free;
  776. GraphValues:= nil;
  777. GraphPoints:= nil;
  778. FBGRA.Free;
  779. inherited Destroy;
  780. end;
  781. {$IFDEF FPC}
  782. procedure TBGRAFlashProgressBar.SaveToFile(AFileName: string);
  783. var
  784. AStream: TMemoryStream;
  785. begin
  786. AStream := TMemoryStream.Create;
  787. try
  788. WriteComponentAsTextToStream(AStream, Self);
  789. AStream.SaveToFile(AFileName);
  790. finally
  791. AStream.Free;
  792. end;
  793. end;
  794. procedure TBGRAFlashProgressBar.LoadFromFile(AFileName: string);
  795. var
  796. AStream: TMemoryStream;
  797. begin
  798. AStream := TMemoryStream.Create;
  799. try
  800. AStream.LoadFromFile(AFileName);
  801. ReadComponentFromTextStream(AStream, TComponent(Self), OnFindClass);
  802. finally
  803. AStream.Free;
  804. end;
  805. end;
  806. procedure TBGRAFlashProgressBar.OnFindClass(Reader: TReader;
  807. const AClassName: string; var ComponentClass: TComponentClass);
  808. begin
  809. if CompareText(AClassName, 'TBGRAFlashProgressBar') = 0 then
  810. ComponentClass := TBGRAFlashProgressBar;
  811. end;
  812. {$ENDIF}
  813. procedure TBGRAFlashProgressBar.Draw(ABitmap: TBGRABitmap);
  814. var
  815. content: TRect;
  816. y, tx, ty,
  817. marqueeOver: integer;
  818. bgColor: TBGRAPixel;
  819. pStr: String;
  820. pValue: Double;
  821. function ApplyLightness(c: TBGRAPixel; lightness: word): TBGRAPixel;
  822. begin
  823. Result := GammaCompression(SetLightness(GammaExpansion(c), lightness));
  824. end;
  825. procedure DrawBar(bounds: TRect; AColor: TColor);
  826. var
  827. lCol: TBGRAPixel;
  828. begin
  829. lCol := AColor;
  830. DoubleGradientAlphaFill(ABitmap, bounds,
  831. ApplyLightness(lCol, 37000), ApplyLightness(lCol, 29000),
  832. ApplyLightness(lCol, 26000), ApplyLightness(lCol, 18000),
  833. gdVertical, gdVertical, gdVertical, 0.53);
  834. InflateRect(bounds, -1, -1);
  835. DoubleGradientAlphaFill(ABitmap, bounds,
  836. ApplyLightness(lCol, 28000), ApplyLightness(lCol, 22000),
  837. ApplyLightness(lCol, 19000), ApplyLightness(lCol, 11000),
  838. gdVertical, gdVertical, gdVertical, 0.53);
  839. end;
  840. procedure DrawBarAnimation;
  841. begin
  842. if FShowBarAnimation and (barAnimLeft >= 0)
  843. then ABitmap.GradientFill(barAnimLeft, content.Top, barAnimLeft+36, content.Bottom,
  844. BGRA(255, 255, 255, 64), BGRA(255, 255, 255, 2), gtReflected,
  845. PointF(barAnimLeft+18, content.Bottom-content.Top/2), PointF(barAnimLeft+36, content.Bottom-content.Top/2),
  846. dmLinearBlend);
  847. end;
  848. procedure DrawText(ACaption: String; AAlign: TAlignment);
  849. var
  850. fx: TBGRATextEffect;
  851. lColB: TBGRAPixel;
  852. begin
  853. try
  854. if (Font.Size=0)
  855. then fx:= TBGRATextEffect.Create(ACaption, Font.Name, ABitmap.Height div 2, True)
  856. else fx:= TBGRATextEffect.Create(ACaption, Font, True);
  857. if (Font.Color = clDefault) or (Font.Color = clNone)
  858. then lColB:= ApplyLightness(FBarColor, 59000)
  859. else lColB:= ColorToBGRA(Font.Color);
  860. y:= (ABitmap.Height-fx.TextHeight) div 2;
  861. Case AAlign of
  862. taLeftJustify: begin
  863. fx.DrawOutline(ABitmap, 4, y, BGRABlack, taLeftJustify);
  864. fx.Draw(ABitmap, 4, y, lColB, taLeftJustify);
  865. end;
  866. taRightJustify: begin
  867. fx.DrawOutline(ABitmap, tx-4, y, BGRABlack, taRightJustify);
  868. fx.Draw(ABitmap, tx-4, y, lColB, taRightJustify);
  869. end;
  870. taCenter: begin
  871. fx.DrawOutline(ABitmap, ABitmap.Width div 2, y, BGRABlack, taCenter);
  872. fx.Draw(ABitmap, ABitmap.Width div 2, y, lColB, taCenter);
  873. end;
  874. end;
  875. finally
  876. fx.Free;
  877. end;
  878. end;
  879. procedure DrawDividers(DrawYDiv: Boolean);
  880. var
  881. lColD: TBGRAPixel;
  882. posS: Single;
  883. i: Integer;
  884. begin
  885. lColD:= BGRA(128, 128, 128, 128);
  886. for i:= 1 to 9 do
  887. begin
  888. posS:= content.left+(i*10*(content.right-content.left)/100);
  889. ABitmap.DrawLineAntialias(posS, 2, posS, content.Bottom-1, lColD, 1, True);
  890. end;
  891. if DrawYDiv then
  892. for i:= 1 to 9 do
  893. begin
  894. posS:= content.Bottom-1-(i*10*(content.Bottom-content.Top)/100);
  895. ABitmap.DrawLineAntialias(2, posS, content.Right-1, posS, lColD, 1, True);
  896. end;
  897. end;
  898. procedure DrawG;
  899. var
  900. lCol,
  901. lColB: TBGRAPixel;
  902. posS: Single;
  903. curIndex: Integer;
  904. fx: TBGRATextEffect;
  905. begin
  906. lCol := FBarColor;
  907. if (Font.Color = clDefault) or (Font.Color = clNone)
  908. then lColB:= ApplyLightness(FBarColor, 37000)
  909. else lColB:= ColorToBGRA(Font.Color);
  910. posS:= content.left+((FValue-FMinValue)/(FMaxValue-FMinValue)*(content.right-content.left));
  911. if (posS > content.Right-1) then posS:= content.Right-1;
  912. //Fixed Points to Close the Path
  913. GraphPoints[0].x:= posS;
  914. GraphPoints[0].y:= content.Bottom-1;
  915. GraphPoints[1].x:= content.Left;
  916. GraphPoints[1].y:= content.Bottom-1;
  917. //Draw Value Position
  918. xpos:= Round(posS);
  919. ABitmap.RectangleAntialias(content.left, content.Top, xpos, content.Bottom-1, lColB, 1, lColB);
  920. if FShowDividers then DrawDividers(FGraphShowYDividers);
  921. //Draw the Graph
  922. if (Length(GraphPoints) > 2) then
  923. begin
  924. ABitmap.DrawPolygonAntialias(GraphPoints, lCol, 1, lCol);
  925. if FGraphShowYLine then
  926. begin
  927. curIndex:= Length(GraphValues)-1;
  928. //Check if we have at least one Value
  929. if (curIndex >= 0) then
  930. begin
  931. lColB:= BGRA(0, 0, 0, 192);
  932. pStr:= FGraphYLineCaption+FloatToStrF(GraphValues[curIndex].YValue, ffFixed, 15, FGraphYLineDigits)+FGraphYLineAfter;
  933. //Get last Value Y Point and draw a horizontal line
  934. curIndex:= Length(GraphPoints)-1;
  935. posS:= GraphPoints[curIndex].y;
  936. ABitmap.DrawLineAntialias(2, posS, tx-4, posS, lColB, 1, True);
  937. try
  938. fx:= TBGRATextEffect.Create(pStr, Font.Name, 12, True);
  939. //Write the text above the line if possible else write below
  940. if (Round(posS-fx.TextHeight) >= 2) then posS:= posS-fx.TextHeight;
  941. fx.Draw(ABitmap, tx-6, Round(posS), lColB, taRightJustify);
  942. finally
  943. fx.Free;
  944. end;
  945. end;
  946. end;
  947. end;
  948. DrawBarAnimation; { #note -oMaxM : Evaluate how it seems }
  949. //Draw Value Text
  950. pStr:= '';
  951. if FCaptionShowPercent then
  952. begin
  953. pValue:= 100*(FValue - FMinValue)/FMaxValue;
  954. if (pValue <> 0) then pStr:= FloatToStrF(pValue, ffFixed, 15, FCaptionPercentDigits)+'%'
  955. end;
  956. DrawText(Caption+pStr, FCaptionPercentAlign);
  957. end;
  958. begin
  959. try
  960. ABitmap.FillTransparent;
  961. tx := ABitmap.Width;
  962. ty := ABitmap.Height;
  963. ABitmap.Rectangle(0, 0, tx, ty, BGRA(255, 255, 255, 6), FBackgroundColor, dmSet);
  964. if (tx > 2) and (ty > 2) then
  965. ABitmap.Rectangle(1, 1, tx - 1, ty - 1, BGRA(29, 29, 29), dmSet);
  966. if (tx > 4) and (ty > 4) then
  967. begin
  968. content := Rect(2, 2, tx - 2, ty - 2);
  969. randseed := FRandSeed;
  970. if FBackgroundRandomize then
  971. for y := content.Top to content.Bottom - 1 do
  972. begin
  973. bgColor := FBackgroundColor;
  974. bgColor.Intensity := RandomRange(FBackgroundRandomizeMinIntensity, FBackgroundRandomizeMaxIntensity);
  975. ABitmap.HorizLine(content.Left, y, content.Right - 1, bgColor, dmSet);
  976. end;
  977. if tx >= 6 then
  978. ABitmap.DrawVertLine(content.Right - 1, content.Top, content.Bottom - 1,
  979. BGRA(0, 0, 0, 32));
  980. Case FStyle of
  981. pbstNormal: begin
  982. if FMaxValue > FMinValue then
  983. begin
  984. //Draw Value Bar
  985. xpos := round((FValue - FMinValue) / (FMaxValue - FMinValue) *
  986. (content.right - content.left)) + content.left;
  987. if xpos > content.left then
  988. begin
  989. DrawBar(rect(content.left, content.top, xpos, content.bottom), FBarColor);
  990. if xpos < content.right then
  991. begin
  992. ABitmap.SetPixel(xpos, content.top, BGRA(62, 62, 62));
  993. ABitmap.SetVertLine(xpos, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  994. end;
  995. if FShowDividers then DrawDividers(False);
  996. DrawBarAnimation;
  997. //Draw Value Text
  998. pStr:= '';
  999. if FCaptionShowPercent then
  1000. begin
  1001. pValue:= 100*(FValue - FMinValue)/FMaxValue;
  1002. if (pValue <> 0) then pStr:= FloatToStrF(pValue, ffFixed, 15, FCaptionPercentDigits)+'%'
  1003. end;
  1004. DrawText(Caption+pStr, FCaptionPercentAlign);
  1005. end;
  1006. end
  1007. else if FShowDividers then DrawDividers(False);
  1008. end;
  1009. pbstMultiProgress: begin
  1010. if FMaxValue > FMinValue then
  1011. begin
  1012. //Draw Value Bar
  1013. xpos := round((FValue - FMinValue) / (FMaxValue - FMinValue) *
  1014. (content.right - content.left)) + content.left;
  1015. if xpos > content.left then
  1016. begin
  1017. DrawBar(rect(content.left, content.top, xpos, content.bottom), FBarColor);
  1018. if xpos < content.right then
  1019. begin
  1020. ABitmap.SetPixel(xpos, content.top, BGRA(62, 62, 62));
  1021. ABitmap.SetVertLine(xpos, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1022. end;
  1023. end;
  1024. //Draw ValueSub Bar
  1025. xposSub := round((FValueSub - FMinValue) / (FMaxValue - FMinValue) *
  1026. (content.right - content.left)) + content.left;
  1027. if xposSub > content.left then
  1028. begin
  1029. DrawBar(rect(content.left, content.top, xposSub, content.bottom), FBarColorSub);
  1030. if xposSub < content.right then
  1031. begin
  1032. ABitmap.SetPixel(xposSub, content.top, BGRA(62, 62, 62));
  1033. ABitmap.SetVertLine(xposSub, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1034. end;
  1035. end;
  1036. if FShowDividers then DrawDividers(False);
  1037. DrawBarAnimation;
  1038. //Draw Value Text
  1039. pStr:= '';
  1040. if FCaptionShowPercent then
  1041. begin
  1042. pValue:= 100*(FValue - FMinValue)/FMaxValue;
  1043. if (pValue <> 0) then pStr:= FloatToStrF(pValue, ffFixed, 15, FCaptionPercentDigits)+'%'
  1044. end;
  1045. DrawText(Caption+pStr, FCaptionPercentAlign);
  1046. //Draw ValueSub Text
  1047. pStr:= '';
  1048. if FCaptionShowPercentSub then
  1049. begin
  1050. pValue:= 100*(FValueSub - FMinValue)/FMaxValue;
  1051. if (pValue <> 0) then pStr:= FloatToStrF(pValue, ffFixed, 15, FCaptionPercentDigits)+'%'
  1052. end;
  1053. DrawText(pStr, FCaptionPercentSubAlign);
  1054. end
  1055. else if FShowDividers then DrawDividers(False);
  1056. end;
  1057. pbstMarquee: begin
  1058. //Calculate new MarqueeWidth based on Values (only if type is Value related)
  1059. Case FMarqueeWidthType of
  1060. pbmwValue: begin
  1061. rMarqueeWidth:= round((FValue - FMinValue) / (FMaxValue - FMinValue) * (content.right - content.left));
  1062. if (rMarqueeWidth < MARQUEE_WIDTH_MIN) then rMarqueeWidth:= MARQUEE_WIDTH_MIN;
  1063. end;
  1064. pbmwValueSub: begin
  1065. rMarqueeWidth:= round((FValueSub - FMinValue) / (FMaxValue - FMinValue) * (content.right - content.left));
  1066. if (rMarqueeWidth < MARQUEE_WIDTH_MIN) then rMarqueeWidth:= MARQUEE_WIDTH_MIN;
  1067. end;
  1068. end;
  1069. if (marqueeCurMode = pbmdToRight)
  1070. then begin
  1071. //check if the whole bar is out put it back to the beginning
  1072. if (marqueeLeft >= content.Right)
  1073. then marqueeLeft:= content.Left;
  1074. //Calculate the Right
  1075. marqueeRight:= marqueeLeft+(rMarqueeWidth-1);
  1076. //Check if part of the bar is out calculate the visible piece on the left
  1077. marqueeOver:= 0;
  1078. marqueeWall:= (marqueeRight >= content.Right-1);
  1079. if marqueeWall then
  1080. begin
  1081. if (FMarqueeBounce > 0)
  1082. then begin
  1083. //Put perfectly on the Right edge
  1084. marqueeRight:= content.Right-1;
  1085. marqueeLeft:= marqueeRight-(rMarqueeWidth-1);
  1086. marqueeBouncing:= True;
  1087. end
  1088. else marqueeOver:= marqueeRight-(content.Right-1);
  1089. end;
  1090. end
  1091. else begin
  1092. //check if the whole bar is out put it back to the end
  1093. if (marqueeLeft <= -rMarqueeWidth)
  1094. then marqueeLeft:= content.Right-rMarqueeWidth;
  1095. //Calculate the Right
  1096. marqueeRight:= marqueeLeft+(rMarqueeWidth-1);
  1097. //check if part of the bar is out then the visible piece on the left is equal to marqueeRight
  1098. marqueeOver:= 0;
  1099. marqueeWall:= (marqueeRight-1 <= rMarqueeWidth);
  1100. if marqueeWall then
  1101. begin
  1102. if (FMarqueeBounce > 0)
  1103. then begin
  1104. //Put perfectly on the Left edge
  1105. marqueeLeft:= content.Left;
  1106. marqueeRight:= marqueeLeft+(rMarqueeWidth-1);
  1107. marqueeBouncing:= True;
  1108. end
  1109. else marqueeOver:= marqueeRight;
  1110. end;
  1111. end;
  1112. if (marqueeOver = 0)
  1113. then begin
  1114. //Draw Normal Bar Left-Right
  1115. DrawBar(rect(marqueeLeft, content.top, marqueeRight, content.bottom), FBarColor);
  1116. ABitmap.SetPixel(marqueeLeft, content.top, BGRA(62, 62, 62));
  1117. ABitmap.SetVertLine(marqueeLeft, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1118. ABitmap.SetPixel(marqueeRight, content.top, BGRA(62, 62, 62));
  1119. ABitmap.SetVertLine(marqueeRight, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1120. end
  1121. else begin
  1122. //Draw visible piece on the Left
  1123. DrawBar(rect(content.Left, content.top, marqueeOver, content.bottom), FBarColor);
  1124. ABitmap.SetPixel(marqueeOver, content.top, BGRA(62, 62, 62));
  1125. ABitmap.SetVertLine(marqueeOver, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1126. //Draw visible piece on the Right
  1127. DrawBar(rect(content.Right-(rMarqueeWidth+1-marqueeOver), content.top, tx-2, content.bottom), FBarColor);
  1128. ABitmap.SetPixel(content.Right-(rMarqueeWidth+1-marqueeOver), content.top, BGRA(62, 62, 62));
  1129. ABitmap.SetVertLine(content.Right-(rMarqueeWidth+1-marqueeOver), content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1130. end;
  1131. //Draw Value Text
  1132. pStr:= '';
  1133. if FCaptionShowPercent then
  1134. begin
  1135. pValue:= 100*(FValue - FMinValue)/FMaxValue;
  1136. if (pValue <> 0) then pStr:= FloatToStrF(pValue, ffFixed, 15, FCaptionPercentDigits)+'%'
  1137. end;
  1138. DrawText(Caption+pStr, FCaptionPercentAlign);
  1139. end;
  1140. pbstTimer: begin
  1141. if FMaxValue > FMinValue then
  1142. begin
  1143. //Draw Timer Bar
  1144. xpos := round((FValue - FMinValue) / (FMaxValue - FMinValue) *
  1145. (content.right - content.left)) + content.left;
  1146. if xpos > content.left then
  1147. begin
  1148. DrawBar(rect(content.left, content.top, xpos, content.bottom), FBarColor);
  1149. if xpos < content.right then
  1150. begin
  1151. ABitmap.SetPixel(xpos, content.top, BGRA(62, 62, 62));
  1152. ABitmap.SetVertLine(xpos, content.top + 1, content.bottom - 1, BGRA(40, 40, 40));
  1153. end;
  1154. if FShowDividers then DrawDividers(False);
  1155. //Draw Timer Text
  1156. pStr:= '';
  1157. if FCaptionShowPercent then
  1158. begin
  1159. if (FValue <> 0) then pStr:= FormatDateTime(FCaptionPercentTimerFormat, FValue)
  1160. end;
  1161. DrawText(Caption+pStr, FCaptionPercentAlign);
  1162. end;
  1163. end
  1164. else if FShowDividers then DrawDividers(False);
  1165. end;
  1166. pbstGraph: DrawG;
  1167. end;
  1168. end;
  1169. except
  1170. //MaxM: Ignore Exception sometimes it happens when the timer is active and we are closing
  1171. end;
  1172. end;
  1173. procedure TBGRAFlashProgressBar.SetValue(AValue: Double);
  1174. begin
  1175. SetValue(AValue, 0);
  1176. end;
  1177. procedure TBGRAFlashProgressBar.SetValue(AValue, AYValue: Double);
  1178. var
  1179. curIndex: Integer;
  1180. begin
  1181. if (FStyle = pbstGraph)
  1182. then begin
  1183. if (AValue >= FMinValue) and (AValue <= FMaxValue) then
  1184. begin
  1185. //Check if Y Value is on the Range
  1186. FValue := AValue;
  1187. if (AYValue < FMinYValue) then AYValue := FMinYValue;
  1188. if (AYValue > FMaxYValue) then AYValue := FMaxYValue;
  1189. if (AValue > FValue)
  1190. then begin
  1191. //Add a new Value in the array
  1192. curIndex:= Length(GraphValues);
  1193. SetLength(GraphValues, curIndex+1);
  1194. GraphValues[curIndex].XValue:= AValue;
  1195. GraphValues[curIndex].YValue:= AYValue;
  1196. //Calculate new Value x/y Position and add in the array
  1197. curIndex:= Length(GraphPoints);
  1198. SetLength(GraphPoints, curIndex+1);
  1199. GraphPoints[curIndex].x:= 2+((AValue-FMinValue) / (FMaxValue-FMinValue))*(Width-4);
  1200. GraphPoints[curIndex].y:= Height-3-((AYValue-FMinYValue) / (FMaxYValue-FMinYValue))*(Height-4);
  1201. if (GraphPoints[curIndex].x > Width-4) then GraphPoints[curIndex].x:= Width-4;
  1202. if (GraphPoints[curIndex].y < 2) then GraphPoints[curIndex].y:= 2;
  1203. end
  1204. else begin
  1205. //Deletes all values from the array that are no longer visible
  1206. curIndex:= Length(GraphValues)-1;
  1207. while (curIndex>=0) and (GraphValues[curIndex].XValue > AValue) do
  1208. begin
  1209. SetLength(GraphValues, curIndex);
  1210. SetLength(GraphPoints, curIndex+2); //there are 2 fixed points at the beginning
  1211. dec(curIndex);
  1212. end;
  1213. //If the last XValue is the same then assign the YValue else add a new Value
  1214. if (curIndex>=0) and (GraphValues[curIndex].XValue = AValue)
  1215. then GraphValues[curIndex].YValue:= AYValue
  1216. else begin
  1217. curIndex:= Length(GraphValues);
  1218. SetLength(GraphValues, curIndex+1);
  1219. GraphValues[curIndex].XValue:= AValue;
  1220. GraphValues[curIndex].YValue:= AYValue;
  1221. SetLength(GraphPoints, Length(GraphPoints)+1);
  1222. end;
  1223. curIndex:= Length(GraphPoints)-1;
  1224. GraphPoints[curIndex].x:= 2+((AValue-FMinValue) / (FMaxValue-FMinValue))*(Width-4);
  1225. GraphPoints[curIndex].y:= Height-3-((AYValue-FMinYValue) / (FMaxYValue-FMinYValue))*(Height-4);
  1226. if (GraphPoints[curIndex].x > Width-4) then GraphPoints[curIndex].x:= Width-4;
  1227. if (GraphPoints[curIndex].y < 2) then GraphPoints[curIndex].y:= 2;
  1228. end;
  1229. FValue:= AValue;
  1230. if Assigned(FOnChange) then FOnChange(Self);
  1231. Invalidate;
  1232. end;
  1233. end
  1234. else if (FValue <> AValue) then
  1235. begin
  1236. FValue := AValue;
  1237. if (FValue < FMinValue) then FValue := FMinValue;
  1238. if (FValue > FMaxValue) then FValue := FMaxValue;
  1239. if Assigned(FOnChange) then FOnChange(Self);
  1240. Invalidate;
  1241. end;
  1242. end;
  1243. procedure TBGRAFlashProgressBar.StepIt(AIncrement: Double);
  1244. begin
  1245. Case FStyle of
  1246. pbstMarquee,
  1247. pbstTimer: begin
  1248. internalTimer.Enabled:= False;
  1249. TimerOnTimer(nil);
  1250. end
  1251. else Value:= Value+AIncrement;
  1252. end;
  1253. end;
  1254. procedure TBGRAFlashProgressBar.TimerReStart;
  1255. begin
  1256. if (FStyle = pbstTimer) then
  1257. begin
  1258. FValue:= FMaxValue;
  1259. internalTimer.Interval:= FTimerInterval;
  1260. internalTimer.Enabled:= True;
  1261. Invalidate;
  1262. if Assigned(FOnTimerStart) then FOnTimerStart(Self);
  1263. end;
  1264. end;
  1265. procedure TBGRAFlashProgressBar.TimerPlayPause;
  1266. begin
  1267. if (FStyle in [pbstMarquee, pbstTimer]) then
  1268. begin
  1269. internalTimer.Enabled:= not(internalTimer.Enabled);
  1270. Invalidate;
  1271. end;
  1272. end;
  1273. end.