bclearingslider.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. {
  2. *****************************************************************************
  3. See the file COPYING.modifiedLGPL.txt, included in this distribution,
  4. for details about the license.
  5. *****************************************************************************
  6. Author: Boban Spasic
  7. Credits to: hedgehog, circular and lainz from Lazarus forum
  8. Based on TFluentProgressRing from hedgehog
  9. }
  10. unit BCLeaRingSlider;
  11. {$mode ObjFPC}{$H+}
  12. interface
  13. uses
  14. Classes, SysUtils, Controls, Graphics, ExtCtrls, LResources,
  15. BGRABitmapTypes, BGRABitmap, BGRATextFX, BGRAGradients, BCLeaTheme, BCLeaTypes;
  16. type
  17. { TBCLeaRingSlider }
  18. TBCLeaRingSlider = class(TCustomControl)
  19. private
  20. FBitmap: TBGRABitmap;
  21. FTheme: TBCLeaTheme;
  22. FOnChangeValue: TNotifyEvent;
  23. FMaxValue: integer;
  24. FMinValue: integer;
  25. FOffset: integer;
  26. FValue: integer;
  27. FLineColor: TColor;
  28. FLineBkgColor: TColor;
  29. FLineWidth: integer;
  30. FVerticalPos: single;
  31. FDeltaPos: single;
  32. FDirection: integer;
  33. FPrevCurrPosition: single;
  34. FSettingVerticalPos: boolean;
  35. FSensitivity: integer;
  36. FMinAngle: integer;
  37. FMaxAngle: integer;
  38. FFontShadowColor: TColor;
  39. FFontShadowOffsetX: integer;
  40. FFontShadowOffsetY: integer;
  41. FFontShadowRadius: integer;
  42. FDrawText: boolean;
  43. FDrawPointer: boolean;
  44. FBkgColor: TColor;
  45. FStyle: TZStyle;
  46. FDrawTextPhong: boolean;
  47. FPointerColor: TColor;
  48. FPointerSize: integer;
  49. FAltitude: integer;
  50. //global intensity of the light
  51. FLightSourceIntensity: single;
  52. //minimum distance always added (positive value)
  53. FLightSourceDistanceTerm: single;
  54. //how much actual distance is taken into account (usually 0 or 1)
  55. FLightSourceDistanceFactor: single;
  56. //how much the location of the lightened pixel is taken into account (usually 0 or 1)
  57. FLightDestFactor: single;
  58. //color of the light reflection
  59. FLightColor: TColor;
  60. //how much light is reflected (0..1)
  61. FSpecularFactor: single;
  62. //how concentrated reflected light is (positive value)
  63. FSpecularIndex: single;
  64. //ambiant lighting whereever the point is (0..1)
  65. FAmbientFactor: single;
  66. //diffusion, i.e. how much pixels are lightened by light source (0..1)
  67. FDiffusionFactor: single;
  68. //how much hidden surface are darkened (0..1)
  69. FNegativeDiffusionFactor: single;
  70. //when diffusion saturates, use light color to show it
  71. FDiffuseSaturation: boolean;
  72. FLightPositionX: integer;
  73. FLightPositionY: integer;
  74. FLightPositionZ: integer;
  75. procedure SetLineBkgColor(AValue: TColor);
  76. procedure SetLineColor(AValue: TColor);
  77. procedure SetMaxValue(AValue: integer);
  78. procedure SetMinValue(AValue: integer);
  79. procedure SetValue(AValue: integer);
  80. procedure SetLineWidth(AValue: integer);
  81. procedure UpdateVerticalPos(X, Y: integer);
  82. procedure SetSensitivity(AValue: integer);
  83. procedure SetMinAngle(AValue: integer);
  84. procedure SetMaxAngle(AValue: integer);
  85. procedure SetDrawText(AValue: boolean);
  86. procedure SetDrawPointer(AValue: boolean);
  87. procedure SetBkgColor(AValue: TColor);
  88. procedure SetFFontShadowColor(AValue: TColor);
  89. procedure SetFFontShadowOffsetX(AValue: integer);
  90. procedure SetFFontShadowOffsetY(AValue: integer);
  91. procedure SetFFontShadowRadius(AValue: integer);
  92. procedure SetStyle(AValue: TZStyle);
  93. procedure SetDrawTextPhong(AValue: boolean);
  94. procedure SetPointerColor(AValue: TColor);
  95. procedure SetPointerSize(AValue: integer);
  96. procedure SetAltitude(AValue: integer);
  97. procedure SetTheme(AValue: TBCLeaTheme);
  98. protected
  99. procedure SetEnabled(Value: boolean); override;
  100. procedure SetVisible(Value: boolean); override;
  101. procedure Paint; override;
  102. procedure Redraw;
  103. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
  104. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
  105. procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
  106. public
  107. constructor Create(AOwner: TComponent); override;
  108. destructor Destroy; override;
  109. procedure UpdateTheme;
  110. procedure ApplyTheme;
  111. procedure SaveThemeToFile(AFileName: string);
  112. procedure LoadThemeFromFile(AFileName: string);
  113. procedure ApplyDefaultTheme;
  114. published
  115. property Align;
  116. property Caption;
  117. property Color;
  118. property Cursor;
  119. property Enabled;
  120. property Font;
  121. property ParentColor;
  122. property ParentFont;
  123. property ParentShowHint;
  124. property PopupMenu;
  125. property ShowHint;
  126. property TabOrder;
  127. property TabStop default True;
  128. property Anchors;
  129. property Constraints;
  130. property Visible;
  131. property OnClick;
  132. property OnDblClick;
  133. property OnEnter;
  134. property OnExit;
  135. property OnMouseMove;
  136. property OnMouseDown;
  137. property OnMouseUp;
  138. property OnMouseWheel;
  139. property OnMouseWheelDown;
  140. property OnMouseWheelUp;
  141. property OnKeyDown;
  142. property OnKeyUp;
  143. property OnKeyPress;
  144. property OnConTextPopup;
  145. property MinValue: integer read FMinValue write SetMinValue default 0;
  146. property MaxValue: integer read FMaxValue write SetMaxValue default 100;
  147. property Value: integer read FValue write SetValue default 0;
  148. property LineColor: TColor read FLineColor write SetLineColor default TColor($009E5A00);
  149. property LineBkgColor: TColor read FLineBkgColor write SetLineBkgColor default TColor($00D3D3D3);
  150. property LineWidth: integer read FLineWidth write SetLineWidth default 8;
  151. property OnChangeValue: TNotifyEvent read FOnChangeValue write FOnChangeValue;
  152. //Greater value is less sensitive
  153. property Sensitivity: integer read FSensitivity write SetSensitivity default 10;
  154. property MinAngle: integer read FMinAngle write SetMinAngle default 20;
  155. property MaxAngle: integer read FMaxAngle write SetMaxAngle default 340;
  156. property FontShadowColor: TColor read FFontShadowColor write SetFFontShadowColor default clBlack;
  157. property FontShadowOffsetX: integer read FFontShadowOffsetX write SetFFontShadowOffsetX default 2;
  158. property FontShadowOffsetY: integer read FFontShadowOffsetY write SetFFontShadowOffsetY default 2;
  159. property FontShadowRadius: integer read FFontSHadowRadius write SetFFontShadowRadius default 4;
  160. property DrawText: boolean read FDrawText write SetDrawText default True;
  161. property DrawPointer: boolean read FDrawPointer write SetDrawPointer default False;
  162. property BackgroundColor: TColor read FBkgColor write SetBkgColor default clBtnFace;
  163. property Style: TZStyle read FStyle write SetStyle default zsRaised;
  164. property DrawTextPhong: boolean read FDrawTextPhong write SetDrawTextPhong default False;
  165. property PointerColor: TColor read FPointerColor write SetPointerColor default TColor($00FF9C15);
  166. property PointerSize: integer read FPointerSize write SetPointerSize default 2;
  167. property Altitude: integer read FAltitude write SetAltitude default 2;
  168. property Theme: TBCLeaTheme read FTheme write SetTheme;
  169. end;
  170. procedure Register;
  171. implementation
  172. procedure Register;
  173. begin
  174. RegisterComponents('BGRA Controls', [TBCLeaRingSlider]);
  175. end;
  176. { TBCLeaRingSlider }
  177. procedure TBCLeaRingSlider.SetMaxAngle(AValue: integer);
  178. begin
  179. if FMaxAngle = AValue then
  180. exit;
  181. FMaxAngle := AValue;
  182. if FMaxAngle > 350 then
  183. FMaxAngle := 350;
  184. if FMinAngle > FMaxAngle then
  185. FMaxAngle := FMinAngle;
  186. Invalidate;
  187. end;
  188. procedure TBCLeaRingSlider.SetMinAngle(AValue: integer);
  189. begin
  190. if FMinAngle = AValue then
  191. exit;
  192. FMinAngle := AValue;
  193. if FMinAngle < 10 then
  194. FMinAngle := 10;
  195. if FMinAngle > FMaxAngle then
  196. FMinAngle := FMaxAngle;
  197. Invalidate;
  198. end;
  199. procedure TBCLeaRingSlider.SetSensitivity(AValue: integer);
  200. begin
  201. if FSensitivity = AValue then
  202. exit;
  203. if AValue <> 0 then
  204. FSensitivity := AValue
  205. else
  206. FSensitivity := 10;
  207. end;
  208. procedure TBCLeaRingSlider.SetMaxValue(AValue: integer);
  209. begin
  210. if FMaxValue = AValue then
  211. exit;
  212. FMaxValue := AValue;
  213. if FValue > FMaxValue then
  214. FValue := FMaxValue;
  215. if FMinValue > FMaxValue then
  216. FMinValue := FMaxValue;
  217. Invalidate;
  218. end;
  219. procedure TBCLeaRingSlider.SetLineBkgColor(AValue: TColor);
  220. begin
  221. if FLineBkgColor = AValue then
  222. Exit;
  223. FLineBkgColor := AValue;
  224. Invalidate;
  225. end;
  226. procedure TBCLeaRingSlider.SetLineColor(AValue: TColor);
  227. begin
  228. if FLineColor = AValue then
  229. Exit;
  230. FLineColor := AValue;
  231. Invalidate;
  232. end;
  233. procedure TBCLeaRingSlider.SetMinValue(AValue: integer);
  234. begin
  235. if FMinValue = AValue then
  236. exit;
  237. FMinValue := AValue;
  238. if FMinValue <> 0 then FOffset := -FMinValue;
  239. if FValue < FMinValue then
  240. FValue := FMinValue;
  241. if FMaxValue < FMinValue then
  242. FMaxValue := FMinValue;
  243. Invalidate;
  244. end;
  245. procedure TBCLeaRingSlider.SetValue(AValue: integer);
  246. begin
  247. if FValue = AValue then
  248. exit;
  249. FValue := AValue;
  250. if FValue < FMinValue then
  251. FValue := FMinValue;
  252. if FValue > FMaxValue then
  253. FValue := FMaxValue;
  254. Invalidate;
  255. end;
  256. procedure TBCLeaRingSlider.SetLineWidth(AValue: integer);
  257. begin
  258. if FLineWidth = AValue then exit;
  259. FLineWidth := AValue;
  260. if Visible then Redraw;
  261. end;
  262. procedure TBCLeaRingSlider.SetEnabled(Value: boolean);
  263. begin
  264. inherited SetEnabled(Value);
  265. Invalidate;
  266. end;
  267. procedure TBCLeaRingSlider.SetVisible(Value: boolean);
  268. begin
  269. inherited SetVisible(Value);
  270. Invalidate;
  271. end;
  272. procedure TBCLeaRingSlider.Paint;
  273. begin
  274. inherited Paint;
  275. Redraw;
  276. end;
  277. procedure TBCLeaRingSlider.Redraw;
  278. const
  279. pi15 = pi * 1.5;
  280. var
  281. TextBmp: TBGRABitmap;
  282. TextStr: string;
  283. EffectiveSize, ScaledPhongSize: integer;
  284. EffectiveLineWidth: single;
  285. r: single;
  286. RMinAngle, RMaxAngle: single;
  287. RValue: single;
  288. Blur: TBGRABitmap;
  289. Mask, Mask2: TBGRABitmap;
  290. Phong: TPhongShading;
  291. procedure DoDrawArc(a, b: single; c: TColor);
  292. begin
  293. FBitmap.Canvas2D.strokeStyle(c);
  294. FBitmap.Canvas2D.beginPath;
  295. FBitmap.Canvas2D.arc(0, 0, r, a, b, False);
  296. FBitmap.Canvas2D.stroke;
  297. end;
  298. procedure DoDrawPointer(a: single; c: TColor);
  299. begin
  300. FBitmap.Canvas2D.strokeStyle(c);
  301. FBitmap.Canvas2D.beginPath;
  302. FBitmap.Canvas2D.arc(0, 0, r, a - (FPointerSize / 100), a + (FPointerSize / 100), False);
  303. FBitmap.Canvas2D.stroke;
  304. end;
  305. procedure DoDrawTick(a, b: single; c: TColor);
  306. begin
  307. FBitmap.Canvas2D.strokeStyle(c);
  308. FBitmap.Canvas2D.lineWidth := 5;
  309. FBitmap.Canvas2D.beginPath;
  310. FBitmap.Canvas2D.lineTo(0 - a, 0 - b);
  311. FBitmap.Canvas2D.lineTo(5 - a, -2 - b);
  312. FBitmap.Canvas2D.lineTo(5 - a, 2 - b);
  313. FBitmap.Canvas2D.lineTo(0 - a, 0 - b);
  314. FBitmap.Canvas2D.stroke;
  315. end;
  316. begin
  317. FBitmap.SetSize(Width, Height);
  318. FBitmap.Fill(FBkgColor);
  319. if Width < Height then
  320. EffectiveSize := Width
  321. else
  322. EffectiveSize := Height;
  323. if EffectiveSize < 2 then exit;
  324. FBitmap.Canvas2D.resetTransform;
  325. FBitmap.Canvas2D.translate(FBitmap.Width / 2, FBitmap.Height / 2);
  326. FBitmap.Canvas2D.rotate(pi15);
  327. if FLineWidth = 0 then
  328. EffectiveLineWidth := EffectiveSize / 12
  329. else
  330. EffectiveLineWidth := FLineWidth;
  331. r := (EffectiveSize - EffectiveLineWidth) / 2;
  332. FBitmap.Canvas2D.lineWidth := EffectiveLineWidth;
  333. RMinAngle := (180 + FMinAngle) * pi / 180;
  334. RMaxAngle := ((180 + FMaxAngle) * pi / 180);
  335. RValue := ((180 + FMinAngle + ((FMaxAngle - FMinAngle) / FMaxValue * FValue)) * pi / 180);
  336. FBitmap.Canvas2D.lineCapLCL := pecRound;
  337. // background line
  338. if FLineBkgColor <> clNone then
  339. DoDrawArc(RMinAngle, RMaxAngle, FLineBkgColor);
  340. if Enabled then
  341. begin
  342. if FValue > FMinValue then
  343. begin
  344. DoDrawArc(RMinAngle, RValue, FLineColor);
  345. if FDrawPointer then
  346. DoDrawPointer(RValue, FPointerColor);
  347. end;
  348. end
  349. else
  350. DoDrawArc(RMinAngle, RMaxAngle, clGray);
  351. if FDrawText and FDrawTextPhong then
  352. begin
  353. TextStr := IntToStr(FValue);
  354. TextBmp := TextShadow(EffectiveSize, EffectiveSize, TextStr, Font.Height,
  355. Font.Color, FontShadowColor, FontShadowOFfsetX,
  356. FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
  357. FBitmap.PutImage(0, 0, TextBmp, dmDrawWithTransparency);
  358. TextBmp.Free;
  359. end;
  360. if (FStyle = zsRaised) or (FStyle = zsLowered) then
  361. begin
  362. ScaledPhongSize := round(EffectiveLineWidth / 2);
  363. Mask := FBitmap.FilterGrayscale as TBGRABitmap;
  364. if FStyle = zsRaised then
  365. Mask.Negative;
  366. Blur := Mask.FilterBlurRadial(ScaledPhongSize, ScaledPhongSize, rbFast) as TBGRABitmap;
  367. Blur.FillMask(0, 0, Mask, BGRAPixelTransparent, dmSet);
  368. Mask.Free;
  369. Phong := TPhongShading.Create;
  370. if Assigned(FTheme) then
  371. begin
  372. Phong.AmbientFactor := FAmbientFactor;
  373. Phong.SpecularIndex := FSpecularIndex;
  374. Phong.LightDestFactor := FLightDestFactor;
  375. Phong.LightPosition := Point(FLightPositionX, FLightPositionY);
  376. Phong.LightPositionZ := FLightPositionZ;
  377. Phong.LightSourceIntensity := FLightSourceIntensity;
  378. Phong.LightSourceDistanceTerm := FLightSourceDistanceTerm;
  379. Phong.LightSourceDistanceFactor := FLightSourceDistanceFactor;
  380. Phong.NegativeDiffusionFactor := FNegativeDiffusionFactor;
  381. Phong.SpecularFactor := FSpecularFactor;
  382. Phong.DiffusionFactor := FDiffusionFactor;
  383. Phong.DiffuseSaturation := FDiffuseSaturation;
  384. Phong.LightColor := FLightColor;
  385. end;
  386. Phong.Draw(FBitmap, Blur, FAltitude, 0, 0, FBitmap);
  387. Phong.Free;
  388. Blur.Free;
  389. Mask := TBGRABitmap.Create(EffectiveSize, EffectiveSize, BGRABlack);
  390. Mask.FillEllipseAntialias(EffectiveSize div 2, EffectiveSize div 2, EffectiveSize div 2, EffectiveSize div 2, BGRAWhite);
  391. Mask2 := TBGRABitmap.Create(EffectiveSize, EffectiveSize, ColorToBGRA(ColorToRGB(FBkgColor)));
  392. Mask2.PutImage(0, 0, FBitmap, dmSet);
  393. Mask2.ApplyMask(Mask);
  394. Mask.Free;
  395. FBitmap.Fill(FBkgColor);
  396. FBitmap.PutImage(0, 0, Mask2, dmDrawWithTransparency);
  397. Mask2.Free;
  398. end;
  399. if FDrawText and not FDrawTextPhong then
  400. begin
  401. TextStr := IntToStr(FValue);
  402. TextBmp := TextShadow(EffectiveSize, EffectiveSize, TextStr, Font.Height,
  403. Font.Color, FontShadowColor, FontShadowOFfsetX,
  404. FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
  405. FBitmap.PutImage(0, 0, TextBmp, dmDrawWithTransparency);
  406. TextBmp.Free;
  407. end;
  408. FBitmap.Draw(Canvas, 0, 0, True);
  409. end;
  410. constructor TBCLeaRingSlider.Create(AOwner: TComponent);
  411. begin
  412. inherited Create(AOwner);
  413. with GetControlClassDefaultSize do
  414. SetInitialBounds(0, 0, 100, 100);
  415. TabStop := True;
  416. FMaxValue := 100;
  417. FMinValue := 0;
  418. FOffset := 0;
  419. FMinAngle := 20;
  420. FMaxAngle := 340;
  421. FValue := 0;
  422. FDeltaPos := 0;
  423. FDirection := 0;
  424. FSensitivity := 10;
  425. Font.Color := clBlack;
  426. Font.Height := 20;
  427. FDrawText := True;
  428. FDrawPointer := False;
  429. ApplyDefaultTheme;
  430. FBitmap := TBGRABitmap.Create(Width, Height, FBkgColor);
  431. end;
  432. destructor TBCLeaRingSlider.Destroy;
  433. begin
  434. FreeAndNil(FBitmap);
  435. inherited Destroy;
  436. end;
  437. procedure TBCLeaRingSlider.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
  438. begin
  439. inherited MouseDown(Button, Shift, X, Y);
  440. if Button = mbLeft then
  441. begin
  442. FDeltaPos := ((ClientHeight / FSensitivity) - (Y / FSensitivity)) * (FMaxValue / ClientHeight);
  443. FDirection := 0;
  444. FPrevCurrPosition := 0;
  445. FVerticalPos := FValue;
  446. FSettingVerticalPos := True;
  447. end;
  448. end;
  449. procedure TBCLeaRingSlider.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
  450. begin
  451. inherited MouseUp(Button, Shift, X, Y);
  452. if Button = mbLeft then
  453. FSettingVerticalPos := False;
  454. end;
  455. procedure TBCLeaRingSlider.MouseMove(Shift: TShiftState; X, Y: integer);
  456. begin
  457. inherited MouseMove(Shift, X, Y);
  458. if FSettingVerticalPos then
  459. UpdateVerticalPos(X, Y);
  460. end;
  461. procedure TBCLeaRingSlider.UpdateVerticalPos(X, Y: integer);
  462. var
  463. FPreviousPos: single;
  464. FCurrPos: single;
  465. FNewDirection: integer;
  466. begin
  467. {The whole code here is for beter control of the slider with the mouse movements}
  468. FPreviousPos := FVerticalPos;
  469. FCurrPos := ((ClientHeight / FSensitivity) - (Y / FSensitivity)) * (FMaxValue / ClientHeight);
  470. if FPrevCurrPosition <> 0 then
  471. begin
  472. if FCurrPos < FPrevCurrPosition then FNewDirection := -1;
  473. if FCurrPos > FPrevCurrPosition then FNewDirection := 1;
  474. if FNewDirection <> FDirection then
  475. begin
  476. FDirection := FNewDirection;
  477. FDeltaPos := ((ClientHeight / FSensitivity) - (Y / FSensitivity)) * (FMaxValue / ClientHeight);
  478. end;
  479. end;
  480. FPrevCurrPosition := FCurrPos;
  481. FVerticalPos := FVerticalPos - FDeltaPos + FCurrPos;
  482. if FVerticalPos < FMinValue then FVerticalPos := FMinValue;
  483. if FVerticalPos > FMaxValue then FVerticalPos := FMaxValue;
  484. FValue := round(FVerticalPos);
  485. if FValue < FMinValue then
  486. FValue := FMinValue;
  487. if FValue > FMaxValue then
  488. FValue := FMaxValue;
  489. Redraw;
  490. if (FPreviousPos <> FVerticalPos) and Assigned(FOnChangeValue) then
  491. FOnChangeValue(Self);
  492. end;
  493. procedure TBCLeaRingSlider.SetFFontShadowColor(AValue: TColor);
  494. begin
  495. if FFontShadowColor = AValue then
  496. Exit;
  497. FFontShadowColor := AValue;
  498. Invalidate;
  499. end;
  500. procedure TBCLeaRingSlider.SetDrawText(AValue: boolean);
  501. begin
  502. if FDrawText = AValue then Exit;
  503. FDrawText := AValue;
  504. Invalidate;
  505. end;
  506. procedure TBCLeaRingSlider.SetFFontShadowOffsetX(AValue: integer);
  507. begin
  508. if FFontShadowOffsetX = AValue then
  509. Exit;
  510. FFontShadowOffsetX := AValue;
  511. Invalidate;
  512. end;
  513. procedure TBCLeaRingSlider.SetFFontShadowOffsetY(AValue: integer);
  514. begin
  515. if FFontShadowOffsetY = AValue then
  516. Exit;
  517. FFontShadowOffsetY := AValue;
  518. Invalidate;
  519. end;
  520. procedure TBCLeaRingSlider.SetFFontShadowRadius(AValue: integer);
  521. begin
  522. if FFontSHadowRadius = AValue then
  523. Exit;
  524. FFontSHadowRadius := AValue;
  525. Invalidate;
  526. end;
  527. procedure TBCLeaRingSlider.SetBkgColor(AValue: TColor);
  528. begin
  529. if FBkgColor = AValue then
  530. Exit;
  531. FBkgColor := AValue;
  532. Invalidate;
  533. end;
  534. procedure TBCLeaRingSlider.SetDrawPointer(AValue: boolean);
  535. begin
  536. if FDrawPointer = AValue then
  537. Exit;
  538. FDrawPointer := AValue;
  539. Invalidate;
  540. end;
  541. procedure TBCLeaRingSlider.SetStyle(AValue: TZStyle);
  542. begin
  543. if FStyle = AValue then
  544. Exit;
  545. FStyle := AValue;
  546. Invalidate;
  547. end;
  548. procedure TBCLeaRingSlider.SetDrawTextPhong(AValue: boolean);
  549. begin
  550. if FDrawTextPhong = AValue then
  551. Exit;
  552. FDrawTextPhong := AValue;
  553. Invalidate;
  554. end;
  555. procedure TBCLeaRingSlider.SetPointerColor(AValue: TColor);
  556. begin
  557. if FPointerColor = AValue then
  558. Exit;
  559. FPointerColor := AValue;
  560. Invalidate;
  561. end;
  562. procedure TBCLeaRingSlider.SetPointerSize(AValue: integer);
  563. begin
  564. if FPointerSize = AValue then
  565. Exit;
  566. FPointerSize := AValue;
  567. Invalidate;
  568. end;
  569. procedure TBCLeaRingSlider.SetAltitude(AValue: integer);
  570. begin
  571. if FAltitude = AValue then
  572. Exit;
  573. FAltitude := AValue;
  574. Invalidate;
  575. end;
  576. procedure TBCLeaRingSlider.SetTheme(AValue: TBCLeaTheme);
  577. begin
  578. if FTheme = AValue then
  579. Exit;
  580. if Assigned(FTheme) then
  581. FTheme := nil;
  582. FTheme := AValue;
  583. ApplyTheme;
  584. end;
  585. procedure TBCLeaRingSlider.UpdateTheme;
  586. begin
  587. if Assigned(FTheme) then
  588. begin
  589. FTheme.RS_LineWidth := FLineWidth;
  590. FTheme.RS_LineColor := FLineColor;
  591. FTheme.RS_LineBkgColor := FLineBkgColor;
  592. FTheme.RS_BkgColor := FBkgColor;
  593. FTheme.RS_FontShadowColor := FFontShadowColor;
  594. FTheme.RS_FontShadowOffsetX := FFontShadowOffsetX;
  595. FTheme.RS_FontShadowOffsetY := FFontShadowOffsetY;
  596. FTheme.RS_FontShadowRadius := FFontShadowRadius;
  597. FTheme.RS_PointerSize := FPointerSize;
  598. FTheme.RS_PointerColor := FPointerColor;
  599. FTheme.RS_Style := FStyle;
  600. FTheme.RS_DrawTextPhong := FDrawTextPhong;
  601. FTheme.RS_Altitude := FAltitude;
  602. end;
  603. end;
  604. procedure TBCLeaRingSlider.ApplyTheme;
  605. begin
  606. if Assigned(FTheme) then
  607. begin
  608. FLineWidth := FTheme.RS_LineWidth;
  609. FLineColor := FTheme.RS_LineColor;
  610. FLineBkgColor := FTheme.RS_LineBkgColor;
  611. FBkgColor := FTheme.RS_BkgColor;
  612. FFontShadowColor := FTheme.RS_FontShadowColor;
  613. FFontShadowOffsetX := FTheme.RS_FontShadowOffsetX;
  614. FFontShadowOffsetY := FTheme.RS_FontShadowOffsetY;
  615. FFontShadowRadius := FTheme.RS_FontShadowRadius;
  616. FPointerSize := FTheme.RS_PointerSize;
  617. FPointerColor := Ftheme.RS_PointerColor;
  618. FStyle := FTheme.RS_Style;
  619. FDrawTextPhong := FTheme.RS_DrawTextPhong;
  620. FAltitude := FTheme.RS_Altitude;
  621. FLightSourceIntensity := FTheme.COM_LightSourceIntensity;
  622. FLightSourceDistanceTerm := FTheme.COM_LightSourceDistanceTerm;
  623. FLightSourceDistanceFactor := FTheme.COM_LightSourceDistanceFactor;
  624. FLightDestFactor := FTheme.COM_LightDestFactor;
  625. FLightColor := FTheme.COM_LightColor;
  626. FSpecularFactor := FTheme.COM_SpecularFactor;
  627. FSpecularIndex := FTheme.COM_SpecularIndex;
  628. FAmbientFactor := FTheme.COM_AmbientFactor;
  629. FDiffusionFactor := FTheme.COM_DiffusionFactor;
  630. FNegativeDiffusionFactor := FTheme.COM_NegativeDiffusionFactor;
  631. FDiffuseSaturation := FTheme.COM_DiffuseSaturation;
  632. FLightPositionX := FTheme.COM_LightPositionX;
  633. FLightPositionY := FTheme.COM_LightPositionY;
  634. FLightPositionZ := FTheme.COM_LightPositionZ;
  635. Invalidate;
  636. end
  637. else
  638. begin
  639. ApplyDefaultTheme;
  640. end;
  641. end;
  642. procedure TBCLeaRingSlider.SaveThemeToFile(AFileName: string);
  643. begin
  644. if Assigned(FTheme) then
  645. FTheme.SaveThemeToFile(AFileName);
  646. end;
  647. procedure TBCLeaRingSlider.LoadThemeFromFile(AFileName: string);
  648. begin
  649. if Assigned(FTheme) then
  650. FTheme.LoadThemeFromFile(AFileName);
  651. end;
  652. procedure TBCLeaRingSlider.ApplyDefaultTheme;
  653. begin
  654. FLineWidth := 8;
  655. FLineColor := TColor($009E5A00);
  656. FLineBkgColor := TColor($00D3D3D3);
  657. FBkgColor := clBtnFace;
  658. FFontShadowColor := clBlack;
  659. FFontShadowOffsetX := 2;
  660. FFontShadowOffsetY := 2;
  661. FFontShadowRadius := 4;
  662. FPointerSize := 3;
  663. FPointerColor := TColor($00FF9C15);
  664. FStyle := zsRaised;
  665. FDrawTextPhong := False;
  666. FAltitude := 2;
  667. FAmbientFactor := 0.3;
  668. FSpecularIndex := 10;
  669. FSpecularFactor := 0.6;
  670. FLightDestFactor := 1;
  671. FLightPositionX := -100;
  672. FLightPositionY := -100;
  673. FLightPositionZ := 100;
  674. FLightSourceIntensity := 500;
  675. FLightSourceDistanceTerm := 150;
  676. FLightSourceDistanceFactor := 1;
  677. FNegativeDiffusionFactor := 0.1;
  678. FLightColor := clWhite;
  679. FDiffuseSaturation := False;
  680. FDiffusionFactor := 0.9;
  681. end;
  682. end.