bgraflashprogressbar.pas 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. {
  3. Created by BGRA Controls Team
  4. Dibo, Circular, lainz (007) and contributors.
  5. For detailed information see readme.txt
  6. Site: https://sourceforge.net/p/bgra-controls/
  7. Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
  8. Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
  9. }
  10. {******************************* CONTRIBUTOR(S) ******************************
  11. - Edivando S. Santos Brasil | mailedivando@gmail.com
  12. (Compatibility with delphi VCL 11/2018)
  13. ***************************** END CONTRIBUTOR(S) *****************************}
  14. unit BGRAFlashProgressBar;
  15. {$I bgracontrols.inc}
  16. interface
  17. uses
  18. Classes, SysUtils, {$IFDEF FPC}LResources, LMessages,{$ENDIF} Forms, Controls, Graphics,
  19. {$IFNDEF FPC}Messages, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
  20. BCBaseCtrls, Dialogs, BGRABitmap, BGRADrawerFlashProgressBar;
  21. type
  22. { TBGRAFlashProgressBar }
  23. TBGRAFlashProgressBar = class(TBGRAGraphicCtrl)
  24. private
  25. FBGRA: TBGRABitmap;
  26. FDrawer: TBGRADrawerFlashProgressBar;
  27. FOnRedraw: TBGRAProgressBarRedrawEvent;
  28. function GetBackgroundColor: TColor;
  29. function GetBackgroundRandomize: boolean;
  30. function GetBackgroundRandomizeMaxIntensity: word;
  31. function GetBackgroundRandomizeMinIntensity: word;
  32. function GetBarColor: TColor;
  33. function GetMaxValue: integer;
  34. function GetMinValue: integer;
  35. function GetValue: integer;
  36. procedure OnChangeDrawer(Sender: TObject);
  37. procedure SetBackgroundColor(AValue: TColor);
  38. procedure SetBackgroundRandomize(AValue: boolean);
  39. procedure SetBackgroundRandomizeMaxIntensity(AValue: word);
  40. procedure SetBackgroundRandomizeMinIntensity(AValue: word);
  41. procedure SetBarColor(AValue: TColor);
  42. procedure SetMaxValue(const AValue: integer);
  43. procedure SetMinValue(const AValue: integer);
  44. procedure SetValue(const AValue: integer);
  45. protected
  46. procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
  47. WithThemeSpace: boolean); override;
  48. procedure WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF}); message {$IFDEF FPC}LM_ERASEBKGND{$ELSE}WM_ERASEBKGND{$ENDIF};
  49. procedure Paint; override;
  50. public
  51. constructor Create(AOwner: TComponent); override;
  52. destructor Destroy; override;
  53. public
  54. { Streaming }
  55. {$IFDEF FPC}
  56. procedure SaveToFile(AFileName: string);
  57. procedure LoadFromFile(AFileName: string);
  58. procedure OnFindClass({%H-}Reader: TReader; const AClassName: string;
  59. var ComponentClass: TComponentClass);
  60. {$ENDIF}
  61. published
  62. property Align;
  63. property Anchors;
  64. property OnClick;
  65. property OnMouseDown;
  66. property OnMouseEnter;
  67. property OnMouseLeave;
  68. property OnMouseMove;
  69. property OnMouseUp;
  70. property OnMouseWheel;
  71. property OnMouseWheelUp;
  72. property OnMouseWheelDown;
  73. property MinValue: integer Read GetMinValue Write SetMinValue;
  74. property MaxValue: integer Read GetMaxValue Write SetMaxValue;
  75. property Value: integer Read GetValue Write SetValue;
  76. property Color; deprecated 'User BarColor instead';
  77. property BarColor: TColor read GetBarColor write SetBarColor;
  78. property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor;
  79. property BackgroundRandomizeMinIntensity: word read GetBackgroundRandomizeMinIntensity write SetBackgroundRandomizeMinIntensity;
  80. property BackgroundRandomizeMaxIntensity: word read GetBackgroundRandomizeMaxIntensity write SetBackgroundRandomizeMaxIntensity;
  81. property BackgroundRandomize: boolean read GetBackgroundRandomize write SetBackgroundRandomize;
  82. property OnRedraw: TBGRAProgressBarRedrawEvent read FOnredraw write FOnRedraw;
  83. end;
  84. {$IFDEF FPC}procedure Register;{$ENDIF}
  85. implementation
  86. uses BGRABitmapTypes;
  87. {$IFDEF FPC}
  88. procedure Register;
  89. begin
  90. RegisterComponents('BGRA Controls', [TBGRAFlashProgressBar]);
  91. end;
  92. {$ENDIF}
  93. procedure TBGRAFlashProgressBar.SetMinValue(const AValue: integer);
  94. begin
  95. FDrawer.MinValue := AValue;
  96. end;
  97. procedure TBGRAFlashProgressBar.SetValue(const AValue: integer);
  98. begin
  99. FDrawer.Value := AValue;
  100. end;
  101. {$hints off}
  102. procedure TBGRAFlashProgressBar.CalculatePreferredSize(
  103. var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
  104. begin
  105. PreferredWidth := 379;
  106. PreferredHeight := 33;
  107. end;
  108. {$hints on}
  109. procedure TBGRAFlashProgressBar.Paint;
  110. begin
  111. if (ClientWidth <> FBGRA.Width) or (ClientHeight <> FBGRA.Height) then
  112. FBGRA.SetSize(ClientWidth, ClientHeight);
  113. FDrawer.Draw(FBGRA);
  114. if Assigned(OnRedraw) then
  115. OnRedraw(Self, FBGRA, {%H-}FDrawer.XPosition);
  116. FBGRA.Draw(Canvas, 0, 0, False);
  117. end;
  118. {$hints off}
  119. procedure TBGRAFlashProgressBar.WMEraseBkgnd(var Message: {$IFDEF FPC}TLMEraseBkgnd{$ELSE}TWMEraseBkgnd{$ENDIF});
  120. begin
  121. //do nothing
  122. end;
  123. {$hints on}
  124. constructor TBGRAFlashProgressBar.Create(AOwner: TComponent);
  125. begin
  126. inherited Create(AOwner);
  127. with GetControlClassDefaultSize do
  128. SetInitialBounds(0, 0, CX, 33);
  129. // Bitmap and Drawer
  130. FBGRA := TBGRABitmap.Create(Width, Height);
  131. FDrawer := TBGRADrawerFlashProgressBar.Create;
  132. FDrawer.OnChange := OnChangeDrawer;
  133. // Functionality
  134. MinValue := 0;
  135. MaxValue := 100;
  136. Value := 30;
  137. // Functionality and Style
  138. Randomize;
  139. FDrawer.RandSeed := RandSeed;
  140. // Style
  141. BarColor := BGRA(102, 163, 226);
  142. BackgroundColor := BGRA(47,47,47);
  143. BackgroundRandomize := True;
  144. BackgroundRandomizeMinIntensity := 4000;
  145. BackgroundRandomizeMaxIntensity := 5000;
  146. end;
  147. destructor TBGRAFlashProgressBar.Destroy;
  148. begin
  149. FreeAndNil(FBGRA);
  150. FDrawer.Free;
  151. inherited Destroy;
  152. end;
  153. {$IFDEF FPC}
  154. procedure TBGRAFlashProgressBar.SaveToFile(AFileName: string);
  155. var
  156. AStream: TMemoryStream;
  157. begin
  158. AStream := TMemoryStream.Create;
  159. try
  160. WriteComponentAsTextToStream(AStream, Self);
  161. AStream.SaveToFile(AFileName);
  162. finally
  163. AStream.Free;
  164. end;
  165. end;
  166. procedure TBGRAFlashProgressBar.LoadFromFile(AFileName: string);
  167. var
  168. AStream: TMemoryStream;
  169. begin
  170. AStream := TMemoryStream.Create;
  171. try
  172. AStream.LoadFromFile(AFileName);
  173. ReadComponentFromTextStream(AStream, TComponent(Self), OnFindClass);
  174. finally
  175. AStream.Free;
  176. end;
  177. end;
  178. procedure TBGRAFlashProgressBar.OnFindClass(Reader: TReader;
  179. const AClassName: string; var ComponentClass: TComponentClass);
  180. begin
  181. if CompareText(AClassName, 'TBGRAFlashProgressBar') = 0 then
  182. ComponentClass := TBGRAFlashProgressBar;
  183. end;
  184. {$ENDIF}
  185. procedure TBGRAFlashProgressBar.SetMaxValue(const AValue: integer);
  186. begin
  187. FDrawer.MaxValue := AValue;
  188. end;
  189. procedure TBGRAFlashProgressBar.OnChangeDrawer(Sender: TObject);
  190. begin
  191. Invalidate;
  192. end;
  193. function TBGRAFlashProgressBar.GetBackgroundColor: TColor;
  194. begin
  195. Result := FDrawer.BackgroundColor;
  196. end;
  197. function TBGRAFlashProgressBar.GetBackgroundRandomize: boolean;
  198. begin
  199. Result := FDrawer.BackgroundRandomize;
  200. end;
  201. function TBGRAFlashProgressBar.GetBackgroundRandomizeMaxIntensity: word;
  202. begin
  203. Result := FDrawer.BackgroundRandomizeMaxIntensity;
  204. end;
  205. function TBGRAFlashProgressBar.GetBackgroundRandomizeMinIntensity: word;
  206. begin
  207. Result := FDrawer.BackgroundRandomizeMinIntensity;
  208. end;
  209. function TBGRAFlashProgressBar.GetBarColor: TColor;
  210. begin
  211. Result := FDrawer.BarColor;
  212. end;
  213. function TBGRAFlashProgressBar.GetMaxValue: integer;
  214. begin
  215. Result := FDrawer.MaxValue;
  216. end;
  217. function TBGRAFlashProgressBar.GetMinValue: integer;
  218. begin
  219. Result := FDrawer.MinValue;
  220. end;
  221. function TBGRAFlashProgressBar.GetValue: integer;
  222. begin
  223. Result := FDrawer.Value;
  224. end;
  225. procedure TBGRAFlashProgressBar.SetBackgroundColor(AValue: TColor);
  226. begin
  227. FDrawer.BackgroundColor := AValue;
  228. end;
  229. procedure TBGRAFlashProgressBar.SetBackgroundRandomize(AValue: boolean);
  230. begin
  231. FDrawer.BackgroundRandomize := AValue;
  232. end;
  233. procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMaxIntensity(AValue: word
  234. );
  235. begin
  236. FDrawer.BackgroundRandomizeMaxIntensity := AValue;
  237. end;
  238. procedure TBGRAFlashProgressBar.SetBackgroundRandomizeMinIntensity(AValue: word
  239. );
  240. begin
  241. FDrawer.BackgroundRandomizeMinIntensity := AValue;
  242. end;
  243. procedure TBGRAFlashProgressBar.SetBarColor(AValue: TColor);
  244. begin
  245. FDrawer.BarColor := AValue;
  246. end;
  247. end.