bctypes.pas 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. { Common types for BGRA Controls package
  3. originally written in 2011 by Krzysztof Dibowski dibowski at interia.pl
  4. }
  5. {******************************* CONTRIBUTOR(S) ******************************
  6. - Edivando S. Santos Brasil | [email protected]
  7. (Compatibility with delphi VCL 11/2018)
  8. ***************************** END CONTRIBUTOR(S) *****************************}
  9. unit BCTypes;
  10. {$I bgracontrols.inc}
  11. interface
  12. uses
  13. Classes, Controls, {$IFNDEF FPC}Types, Windows, BGRAGraphics, GraphType, FPImage, {$ENDIF}
  14. BGRABitmap, BGRABitmapTypes, Graphics, BCBasectrls;
  15. type
  16. {$IFDEF FPC}
  17. {$IFDEF CPU64}
  18. BGRAPtrInt = PtrInt; // Cardinal;//PtrInt;
  19. BGRAPtrUInt = PtrUInt; // Cardinal;//PtrUInt;
  20. {$ELSE}
  21. BGRAPtrInt = PtrInt; // LongInt;//PtrInt;
  22. BGRAPtrUInt = PtrUInt; // Cardinal;//PtrUInt;
  23. BGRAQWord = Int64; // Cardinal;//QWord;
  24. {$ENDIF}
  25. BGRAWord = Word; // Word;
  26. PBGRAWord = PWord; // PWord;
  27. BGRADWord = DWord; // Cardinal; //DWord;
  28. BGRALongWord = LongWord; // Cardinal; //LongWord;
  29. PBGRAQWord = PQWord; // PCardinal; //PQWord;
  30. PBGRADWord = PDWord; // PCardinal; //PDWord;
  31. PBGRALongWord = PLongWord; // PCardinal; //PLongWord;
  32. BGRANativeInt = NativeInt; // NativeInt; //NativeInt;
  33. BGRANativeUInt = NativeUInt; // Cardinal; //NativeUInt;
  34. BGRALongInt = LongInt; // Cardinal; //LongInt;
  35. BGRAInt64 = Int64; // Int64;
  36. BGRAUInt64 = Int64; // UInt64;
  37. BGRACardinal = Cardinal; // Cardinal;
  38. PBGRACardinal = PCardinal; // PCardinal;
  39. HDC = {$IFDEF BGRABITMAP_USE_LCL}LCLType.HDC{$ELSE}BGRAPtrUInt{$ENDIF};
  40. PPTrint = ^PtrInt;
  41. {$ELSE}
  42. ValReal = Extended;
  43. {$IFDEF CPU64}
  44. BGRAPtrInt = Int64;
  45. BGRAPtrUInt = QWord;
  46. {$ELSE}
  47. BGRAPtrInt = LongInt; // LongInt;//LongInt;
  48. BGRAPtrUInt = LongWord; // Cardinal;//LongWord;
  49. BGRAQWord = Int64; // Cardinal;//LongWord;
  50. {$ENDIF}
  51. BGRAWord = Word; // Word;
  52. PBGRAWord = PWord; // PWord;
  53. BGRADWord = DWord; // Cardinal;//DWord;
  54. BGRALongWord = LongWord; // Cardinal;//LongWord;
  55. PBGRAPtrInt = ^BGRAPtrInt; // PCardinal;//^BGRAPtrInt;
  56. PBGRAPtrUInt = ^BGRAPtrUInt; // PCardinal;//^BGRAPtrUInt;
  57. PBGRAQWord = ^BGRAQWord; // PCardinal;//^BGRAQWord;
  58. PBGRADWord = PDWord; // PCardinal;//PDWord;
  59. PBGRALongWord = PLongWord; // PCardinal;//PLongWord;
  60. BGRANativeInt = NativeInt; // NativeInt;//NativeInt;
  61. BGRANativeUInt = NativeUInt; // Cardinal;//NativeUInt;
  62. BGRALongInt = LongInt; // LongInt;
  63. BGRAInt64 = Int64; // Int64;
  64. BGRAUInt64 = Int64; // UInt64;
  65. BGRACardinal = Cardinal; // Cardinal;
  66. PBGRACardinal = PCardinal; // PCardinal;
  67. HDC = Windows.HDC; //
  68. PUnicodeChar = Windows.PWChar; //
  69. UnicodeChar = Windows.WCHAR; //
  70. (* ValReal = FPImage.ValReal;
  71. {$IFDEF CPU64} //WORD = 2 bytes = 4 nybbles = 16 bits for 32bits
  72. BGRAPtrInt = FPImage.BGRAPtrInt;
  73. BGRAPtrUInt = FPImage.BGRAPtrUInt; //QWORD = 2 DWORDs = 4 WORDs = ….. = 64 bits for 32bits
  74. {$ELSE} //BGRADWord = 2 WORDs = 4 bytes = 8 nybbles = 32 bits for 32bits
  75. BGRAPtrInt = FPImage.BGRAPtrInt;
  76. BGRAPtrUInt = FPImage.BGRAPtrUInt;
  77. BGRAQWord = FPImage.BGRAQWord;
  78. {$ENDIF}
  79. BGRADWord = FPImage.BGRADWord;
  80. BGRALongWord = FPImage.BGRALongWord;
  81. PBGRAPtrInt = FPImage.PBGRAPtrInt;
  82. PBGRAPtrUInt = FPImage.PBGRAPtrUInt;
  83. PBGRAQWord = FPImage.PBGRAQWord;
  84. PBGRADWord = FPImage.PBGRADWord;
  85. HDC = FPImage.HDC;
  86. BGRANativeInt = FPImage.BGRANativeInt;
  87. PBGRALongWord = FPImage.PBGRALongWord;
  88. PUnicodeChar = FPImage.PUnicodeChar;
  89. UnicodeChar = FPImage.UnicodeChar; *)
  90. {$ENDIF}
  91. TBCMouseState = (msNone, msHover, msClicked);
  92. TBCAlignment = (bcaLeftTop, bcaLeftCenter, bcaLeftBottom,
  93. bcaCenterTop, bcaCenter, bcaCenterBottom, bcaRightTop, bcaRightCenter,
  94. bcaRightBottom);
  95. TBCBackgroundStyle = (bbsClear, bbsColor, bbsGradient);
  96. TBCBorderStyle = (bboNone, bboSolid);
  97. TBCArrowDirection = (badLeft, badRight, badUp, badDown);
  98. TBCStretchMode = (smNone, smShrink, smStretch, smCover);
  99. TBCCanvasScaleMode = (csmAuto, csmScaleBitmap, csmFullResolution);
  100. TBGRATextAlign = (btaLeft, btaCenter, btaRight); // deprecated
  101. TBGRATextVAlign = (btvaTop, btvaCenter, btvaBottom); // deprecated
  102. TBGRARedrawEvent = procedure(Sender: TObject; Bitmap: TBGRABitmap) of object;
  103. type
  104. { TBCGradient }
  105. TBCGradient = class(TBCProperty)
  106. private
  107. FColorCorrection: boolean;
  108. FDrawMode: TDrawMode;
  109. FGradientType: TGradientType;
  110. FEndColor: TColor;
  111. FEndColorOpacity: byte;
  112. FPoint1XPercent: single;
  113. FPoint1YPercent: single;
  114. FPoint2XPercent: single;
  115. FPoint2YPercent: single;
  116. FSinus: boolean;
  117. FStartColor: TColor;
  118. FStartColorOpacity: byte;
  119. procedure SetColorCorrection(const AValue: boolean);
  120. procedure SetDrawMode(const AValue: TDrawMode);
  121. procedure SetEndColor(const AValue: TColor);
  122. procedure SetEndColorOpacity(const AValue: byte);
  123. procedure SetGradientType(const AValue: TGradientType);
  124. procedure SetPoint1XPercent(const AValue: single);
  125. procedure SetPoint1YPercent(const AValue: single);
  126. procedure SetPoint2XPercent(const AValue: single);
  127. procedure SetPoint2YPercent(const AValue: single);
  128. procedure SetSinus(const AValue: boolean);
  129. procedure SetStartColor(const AValue: TColor);
  130. procedure SetStartColorOpacity(const AValue: byte);
  131. public
  132. constructor Create(AControl: TControl); override;
  133. procedure Assign(Source: TPersistent); override;
  134. procedure Scale(AScale: single);
  135. published
  136. property StartColor: TColor read FStartColor write SetStartColor;
  137. property StartColorOpacity: byte read FStartColorOpacity write SetStartColorOpacity default 255;
  138. property DrawMode: TDrawMode read FDrawMode write SetDrawMode default dmSet;
  139. property EndColor: TColor read FEndColor write SetEndColor;
  140. property EndColorOpacity: byte read FEndColorOpacity write SetEndColorOpacity default 255;
  141. property ColorCorrection: boolean read FColorCorrection write SetColorCorrection default true;
  142. property GradientType: TGradientType read FGradientType write SetGradientType;
  143. property Point1XPercent: single read FPoint1XPercent write SetPoint1XPercent default EmptySingle;
  144. property Point1YPercent: single read FPoint1YPercent write SetPoint1YPercent default EmptySingle;
  145. property Point2XPercent: single read FPoint2XPercent write SetPoint2XPercent default EmptySingle;
  146. property Point2YPercent: single read FPoint2YPercent write SetPoint2YPercent default EmptySingle;
  147. property Sinus: boolean read FSinus write SetSinus default false;
  148. end;
  149. { TBCFont }
  150. TBCFont = class(TBCProperty)
  151. private
  152. FColor, FDisabledColor: TColor;
  153. FEndEllipsis: boolean;
  154. FFontQuality: TBGRAFontQuality;
  155. FHeight: integer;
  156. FName: string;
  157. FPaddingBottom: integer;
  158. FPaddingLeft: integer;
  159. FPaddingRight: integer;
  160. FPaddingTop: integer;
  161. FShadow: boolean;
  162. FShadowColor: TColor;
  163. FShadowColorOpacity: byte;
  164. FShadowOffsetX: shortint;
  165. FShadowOffsetY: shortint;
  166. FShadowRadius: byte;
  167. FSingleLine: boolean;
  168. FStyle: TFontStyles;
  169. FTextAlignment: TBCAlignment;
  170. FWordBreak: boolean;
  171. function IsNameStored: boolean;
  172. procedure SetColor(AValue: TColor);
  173. procedure SetDisabledColor(AValue: TColor);
  174. procedure SetEndEllipsis(AValue: boolean);
  175. procedure SetFontQuality(AValue: TBGRAFontQuality);
  176. procedure SetHeight(AValue: integer);
  177. procedure SetName(AValue: string);
  178. procedure SetPaddingBottom(AValue: integer);
  179. procedure SetPaddingLeft(AValue: integer);
  180. procedure SetPaddingRight(AValue: integer);
  181. procedure SetPaddingTop(AValue: integer);
  182. procedure SetShadow(AValue: boolean);
  183. procedure SetShadowColor(AValue: TColor);
  184. procedure SetShadowColorOpacity(AValue: byte);
  185. procedure SetShadowOffsetX(AValue: shortint);
  186. procedure SetShadowOffsetY(AValue: shortint);
  187. procedure SetShadowRadius(AValue: byte);
  188. procedure SetSingleLine(AValue: boolean);
  189. procedure SetStyle(AValue: TFontStyles);
  190. procedure SetTextAlignment(AValue: TBCAlignment);
  191. procedure SetWordBreak(AValue: boolean);
  192. public
  193. constructor Create(AControl: TControl); override;
  194. procedure Assign(Source: TPersistent); override;
  195. procedure Scale(AScale: single; APreserveDefaultHeight: boolean = true);
  196. published
  197. property Color: TColor read FColor write SetColor;
  198. property DisabledColor: TColor read FDisabledColor write SetDisabledColor default clNone;
  199. property EndEllipsis: boolean read FEndEllipsis write SetEndEllipsis default false;
  200. property FontQuality: TBGRAFontQuality read FFontQuality write SetFontQuality;
  201. property Height: integer read FHeight write SetHeight default 0;
  202. property Name: string read FName write SetName stored IsNameStored;
  203. property SingleLine: boolean read FSingleLine write SetSingleLine default true;
  204. property Shadow: boolean read FShadow write SetShadow;
  205. property ShadowColor: TColor read FShadowColor write SetShadowColor default clBlack;
  206. property ShadowColorOpacity: byte read FShadowColorOpacity
  207. write SetShadowColorOpacity default 255;
  208. property ShadowRadius: byte read FShadowRadius write SetShadowRadius;
  209. property ShadowOffsetX: shortint read FShadowOffsetX write SetShadowOffsetX;
  210. property ShadowOffsetY: shortint read FShadowOffsetY write SetShadowOffsetY;
  211. property Style: TFontStyles read FStyle write SetStyle;
  212. property TextAlignment: TBCAlignment read FTextAlignment write SetTextAlignment default bcaCenter;
  213. property WordBreak: boolean read FWordBreak write SetWordBreak default false;
  214. property PaddingLeft: integer read FPaddingLeft write SetPaddingLeft default 0;
  215. property PaddingRight: integer read FPaddingRight write SetPaddingRight default 0;
  216. property PaddingTop: integer read FPaddingTop write SetPaddingTop default 0;
  217. property PaddingBottom: integer read FPaddingBottom write SetPaddingBottom default 0;
  218. end;
  219. { TBCBackground }
  220. TBCBackground = class(TBCProperty)
  221. private
  222. FColor: TColor;
  223. FColorOpacity: byte;
  224. FGradient1: TBCGradient;
  225. FGradient1EndPercent: single;
  226. FGradient2: TBCGradient;
  227. FStyle: TBCBackgroundStyle;
  228. procedure OnChangeChildProperty({%H-}Sender: TObject; AData: PtrInt);
  229. procedure SetColor(AValue: TColor);
  230. procedure SetColorOpacity(AValue: byte);
  231. procedure SetGradient1(AValue: TBCGradient);
  232. procedure SetGradient1EndPercent(AValue: single);
  233. procedure SetGradient2(AValue: TBCGradient);
  234. procedure SetStyle(AValue: TBCBackgroundStyle);
  235. public
  236. constructor Create(AControl: TControl); override;
  237. destructor Destroy; override;
  238. procedure Assign(Source: TPersistent); override;
  239. procedure Scale(AScale: single);
  240. published
  241. property Color: TColor read FColor write SetColor default clBlack;
  242. property ColorOpacity: byte read FColorOpacity write SetColorOpacity default 255;
  243. property Gradient1: TBCGradient read FGradient1 write SetGradient1;
  244. property Gradient2: TBCGradient read FGradient2 write SetGradient2;
  245. property Gradient1EndPercent: single read FGradient1EndPercent write SetGradient1EndPercent;
  246. property Style: TBCBackgroundStyle read FStyle write SetStyle;
  247. end;
  248. { TBCBorder }
  249. TBCBorder = class(TBCProperty)
  250. private
  251. FColor: TColor;
  252. FColorOpacity: byte;
  253. FLightColor: TColor;
  254. FLightOpacity: byte;
  255. FLightWidth: integer;
  256. FStyle: TBCBorderStyle;
  257. FWidth: integer;
  258. procedure SetColor(AValue: TColor);
  259. procedure SetColorOpacity(AValue: byte);
  260. procedure SetLightColor(AValue: TColor);
  261. procedure SetLightOpacity(AValue: byte);
  262. procedure SetLightWidth(AValue: integer);
  263. procedure SetStyle(AValue: TBCBorderStyle);
  264. procedure SetWidth(AValue: integer);
  265. public
  266. constructor Create(AControl: TControl); override;
  267. procedure Assign(Source: TPersistent); override;
  268. procedure Scale(AScale: single);
  269. published
  270. property Color: TColor read FColor write SetColor default clBlack;
  271. property ColorOpacity: byte read FColorOpacity write SetColorOpacity default 255;
  272. property LightColor: TColor read FLightColor write SetLightColor default clWhite;
  273. property LightOpacity: byte read FLightOpacity write SetLightOpacity default 255;
  274. property LightWidth: integer read FLightWidth write SetLightWidth default 0;
  275. property Style: TBCBorderStyle read FStyle write SetStyle;
  276. property Width: integer read FWidth write SetWidth default 1;
  277. end;
  278. { TBCRounding }
  279. TBCRounding = class(TBCProperty)
  280. private
  281. FRoundOptions: TRoundRectangleOptions;
  282. FRoundX: byte;
  283. FRoundY: byte;
  284. procedure SetRoundOptions(AValue: TRoundRectangleOptions);
  285. procedure SetRoundX(AValue: byte);
  286. procedure SetRoundY(AValue: byte);
  287. public
  288. constructor Create(AControl: TControl); override;
  289. procedure Assign(Source: TPersistent); override;
  290. procedure Scale(AScale: single);
  291. published
  292. property RoundX: byte read FRoundX write SetRoundX;
  293. property RoundY: byte read FRoundY write SetRoundY;
  294. property RoundOptions: TRoundRectangleOptions
  295. read FRoundOptions write SetRoundOptions default [];
  296. end;
  297. { TBCPixel }
  298. TBCPixel = class(TBCProperty)
  299. private
  300. FPixel: TBGRAPixel;
  301. public
  302. { Constructor }
  303. constructor Create(AControl: TControl); overload; override;
  304. constructor Create(AControl: TControl; APixel: TBGRAPixel); overload;
  305. constructor Create(AControl: TControl; AColor: TColor); overload;
  306. { Assign values to Pixel }
  307. procedure Assign(Source: TPersistent); overload; override;
  308. procedure Assign(Source: TBGRAPixel); overload;
  309. procedure Assign(Source: TColor; Opacity: byte = 255);overload;
  310. procedure Assign(Source: string); overload;
  311. { Read values }
  312. property Pixel: TBGRAPixel read FPixel write FPixel;
  313. function Color: TColor;
  314. function Hex: string;
  315. { Color functions }
  316. procedure ApplyLightness(lightness: word);
  317. procedure ApplyIntensity(lightness: longword);
  318. procedure ToGrayscale;
  319. published
  320. { Streaming }
  321. property Red: byte read FPixel.red write FPixel.red;
  322. property Green: byte read FPixel.green write FPixel.green;
  323. property Blue: byte read FPixel.blue write FPixel.blue;
  324. property Alpha: byte read FPixel.alpha write FPixel.alpha;
  325. end;
  326. {const
  327. DEF_START_COL = $00EFE6D2;
  328. DEF_END_COL = $00C87511;
  329. DEF_BORD_COL = $00AB713B;
  330. DEF_BORD_COL_HOVER = $00D7B697;
  331. DEF_FONT_COLOR = $0072412A; }
  332. implementation
  333. uses math;
  334. { TBCPixel }
  335. constructor TBCPixel.Create(AControl: TControl);
  336. begin
  337. inherited Create(AControl);
  338. end;
  339. constructor TBCPixel.Create(AControl: TControl; APixel: TBGRAPixel);
  340. begin
  341. inherited Create(AControl);
  342. Pixel := APixel;
  343. end;
  344. constructor TBCPixel.Create(AControl: TControl; AColor: TColor);
  345. begin
  346. inherited Create(AControl);
  347. Assign(AColor);
  348. end;
  349. procedure TBCPixel.Assign(Source: TPersistent);
  350. begin
  351. if Source is TBCPixel then
  352. Pixel := TBCPixel(Source).Pixel
  353. else
  354. inherited Assign(Source);
  355. end;
  356. procedure TBCPixel.Assign(Source: TBGRAPixel);
  357. begin
  358. Pixel := Source;
  359. end;
  360. procedure TBCPixel.Assign(Source: TColor; Opacity: byte);
  361. begin
  362. Pixel.FromColor(Source, Opacity);
  363. end;
  364. procedure TBCPixel.Assign(Source: string);
  365. begin
  366. Pixel := StrToBGRA(Source);
  367. end;
  368. function TBCPixel.Color: TColor;
  369. begin
  370. Result := Pixel;
  371. end;
  372. function TBCPixel.Hex: string;
  373. begin
  374. Result := Pixel.ToString;
  375. end;
  376. procedure TBCPixel.ApplyLightness(lightness: word);
  377. begin
  378. Pixel := ApplyLightnessFast(Pixel, lightness);
  379. end;
  380. procedure TBCPixel.ApplyIntensity(lightness: longword);
  381. begin
  382. Pixel := ApplyIntensityFast(Pixel, lightness);
  383. end;
  384. procedure TBCPixel.ToGrayscale;
  385. begin
  386. Pixel := BGRAToGrayscale(Pixel);
  387. end;
  388. { TBCRounding }
  389. procedure TBCRounding.SetRoundOptions(AValue: TRoundRectangleOptions);
  390. begin
  391. if FRoundOptions = AValue then
  392. Exit;
  393. FRoundOptions := AValue;
  394. Change;
  395. end;
  396. procedure TBCRounding.SetRoundX(AValue: byte);
  397. begin
  398. if FRoundX = AValue then
  399. Exit;
  400. FRoundX := AValue;
  401. Change;
  402. end;
  403. procedure TBCRounding.SetRoundY(AValue: byte);
  404. begin
  405. if FRoundY = AValue then
  406. Exit;
  407. FRoundY := AValue;
  408. Change;
  409. end;
  410. constructor TBCRounding.Create(AControl: TControl);
  411. begin
  412. inherited Create(AControl);
  413. FRoundX := 1;
  414. FRoundY := 1;
  415. FRoundOptions := [];
  416. end;
  417. procedure TBCRounding.Assign(Source: TPersistent);
  418. begin
  419. if Source is TBCRounding then
  420. begin
  421. FRoundX := TBCRounding(Source).FRoundX;
  422. FRoundY := TBCRounding(Source).FRoundY;
  423. FRoundOptions := TBCRounding(Source).FRoundOptions;
  424. end
  425. else
  426. inherited Assign(Source);
  427. end;
  428. procedure TBCRounding.Scale(AScale: single);
  429. begin
  430. RoundX := min(high(RoundX), round(RoundX * AScale));
  431. RoundY := min(high(RoundY), round(RoundY * AScale));
  432. end;
  433. { TBCGradient }
  434. procedure TBCGradient.SetColorCorrection(const AValue: boolean);
  435. begin
  436. if FColorCorrection = AValue then
  437. exit;
  438. FColorCorrection := AValue;
  439. Change;
  440. end;
  441. procedure TBCGradient.SetDrawMode(const AValue: TDrawMode);
  442. begin
  443. if FDrawMode = AValue then
  444. exit;
  445. FDrawMode := AValue;
  446. Change;
  447. end;
  448. procedure TBCGradient.SetEndColor(const AValue: TColor);
  449. begin
  450. if FEndColor = AValue then
  451. exit;
  452. FEndColor := AValue;
  453. Change;
  454. end;
  455. procedure TBCGradient.SetEndColorOpacity(const AValue: byte);
  456. begin
  457. if FEndColorOpacity = AValue then
  458. exit;
  459. FEndColorOpacity := AValue;
  460. Change;
  461. end;
  462. procedure TBCGradient.SetGradientType(const AValue: TGradientType);
  463. begin
  464. if FGradientType = AValue then
  465. exit;
  466. FGradientType := AValue;
  467. Change;
  468. end;
  469. procedure TBCGradient.SetPoint1XPercent(const AValue: single);
  470. begin
  471. if FPoint1XPercent = AValue then
  472. exit;
  473. FPoint1XPercent := AValue;
  474. Change;
  475. end;
  476. procedure TBCGradient.SetPoint1YPercent(const AValue: single);
  477. begin
  478. if FPoint1YPercent = AValue then
  479. exit;
  480. FPoint1YPercent := AValue;
  481. Change;
  482. end;
  483. procedure TBCGradient.SetPoint2XPercent(const AValue: single);
  484. begin
  485. if FPoint2XPercent = AValue then
  486. exit;
  487. FPoint2XPercent := AValue;
  488. Change;
  489. end;
  490. procedure TBCGradient.SetPoint2YPercent(const AValue: single);
  491. begin
  492. if FPoint2YPercent = AValue then
  493. exit;
  494. FPoint2YPercent := AValue;
  495. Change;
  496. end;
  497. procedure TBCGradient.SetSinus(const AValue: boolean);
  498. begin
  499. if FSinus = AValue then
  500. exit;
  501. FSinus := AValue;
  502. Change;
  503. end;
  504. procedure TBCGradient.SetStartColor(const AValue: TColor);
  505. begin
  506. if FStartColor = AValue then
  507. exit;
  508. FStartColor := AValue;
  509. Change;
  510. end;
  511. procedure TBCGradient.SetStartColorOpacity(const AValue: byte);
  512. begin
  513. if FStartColorOpacity = AValue then
  514. exit;
  515. FStartColorOpacity := AValue;
  516. Change;
  517. end;
  518. constructor TBCGradient.Create(AControl: TControl);
  519. begin
  520. FStartColor := clWhite;
  521. FStartColorOpacity := 255;
  522. FDrawMode := dmSet;
  523. FEndColor := clBlack;
  524. FEndColorOpacity := 255;
  525. FGradientType := gtLinear;
  526. FColorCorrection := True;
  527. FSinus := False;
  528. FPoint1XPercent := 0;
  529. FPoint1YPercent := 0;
  530. FPoint2XPercent := 0;
  531. FPoint2YPercent := 100;
  532. inherited Create(AControl);
  533. end;
  534. procedure TBCGradient.Assign(Source: TPersistent);
  535. begin
  536. if Source is TBCGradient then
  537. begin
  538. FStartColor := TBCGradient(Source).FStartColor;
  539. FStartColorOpacity := TBCGradient(Source).FStartColorOpacity;
  540. FDrawMode := TBCGradient(Source).FDrawMode;
  541. FEndColor := TBCGradient(Source).FEndColor;
  542. FEndColorOpacity := TBCGradient(Source).FEndColorOpacity;
  543. FColorCorrection := TBCGradient(Source).FColorCorrection;
  544. FGradientType := TBCGradient(Source).FGradientType;
  545. FPoint1XPercent := TBCGradient(Source).FPoint1XPercent;
  546. FPoint1YPercent := TBCGradient(Source).FPoint1YPercent;
  547. FPoint2XPercent := TBCGradient(Source).FPoint2XPercent;
  548. FPoint2YPercent := TBCGradient(Source).FPoint2YPercent;
  549. FSinus := TBCGradient(Source).FSinus;
  550. Change;
  551. end
  552. else
  553. inherited Assign(Source);
  554. end;
  555. procedure TBCGradient.Scale(AScale: single);
  556. begin
  557. //nothing
  558. end;
  559. { TBCFont }
  560. function TBCFont.IsNameStored: boolean;
  561. begin
  562. Result := DefFontData.Name <> Name;
  563. end;
  564. procedure TBCFont.SetColor(AValue: TColor);
  565. begin
  566. if FColor = AValue then
  567. Exit;
  568. FColor := AValue;
  569. Change;
  570. end;
  571. procedure TBCFont.SetDisabledColor(AValue: TColor);
  572. begin
  573. if FDisabledColor = AValue then
  574. Exit;
  575. FDisabledColor := AValue;
  576. Change;
  577. end;
  578. procedure TBCFont.SetEndEllipsis(AValue: boolean);
  579. begin
  580. if FEndEllipsis = AValue then
  581. Exit;
  582. FEndEllipsis := AValue;
  583. Change;
  584. end;
  585. procedure TBCFont.SetFontQuality(AValue: TBGRAFontQuality);
  586. begin
  587. if FFontQuality = AValue then
  588. Exit;
  589. FFontQuality := AValue;
  590. Change;
  591. end;
  592. procedure TBCFont.SetHeight(AValue: integer);
  593. begin
  594. if FHeight = AValue then
  595. Exit;
  596. FHeight := AValue;
  597. Change;
  598. end;
  599. procedure TBCFont.SetName(AValue: string);
  600. begin
  601. if FName = AValue then
  602. Exit;
  603. FName := AValue;
  604. if FName = '' then
  605. FName := 'default';
  606. Change;
  607. end;
  608. procedure TBCFont.SetPaddingBottom(AValue: integer);
  609. begin
  610. if FPaddingBottom=AValue then Exit;
  611. FPaddingBottom:=AValue;
  612. Change;
  613. end;
  614. procedure TBCFont.SetPaddingLeft(AValue: integer);
  615. begin
  616. if FPaddingLeft=AValue then Exit;
  617. FPaddingLeft:=AValue;
  618. Change;
  619. end;
  620. procedure TBCFont.SetPaddingRight(AValue: integer);
  621. begin
  622. if FPaddingRight=AValue then Exit;
  623. FPaddingRight:=AValue;
  624. Change;
  625. end;
  626. procedure TBCFont.SetPaddingTop(AValue: integer);
  627. begin
  628. if FPaddingTop=AValue then Exit;
  629. FPaddingTop:=AValue;
  630. Change;
  631. end;
  632. procedure TBCFont.SetShadow(AValue: boolean);
  633. begin
  634. if FShadow = AValue then
  635. Exit;
  636. FShadow := AValue;
  637. Change;
  638. end;
  639. procedure TBCFont.SetShadowColor(AValue: TColor);
  640. begin
  641. if FShadowColor = AValue then
  642. Exit;
  643. FShadowColor := AValue;
  644. Change;
  645. end;
  646. procedure TBCFont.SetShadowColorOpacity(AValue: byte);
  647. begin
  648. if FShadowColorOpacity = AValue then
  649. Exit;
  650. FShadowColorOpacity := AValue;
  651. Change;
  652. end;
  653. procedure TBCFont.SetShadowOffsetX(AValue: shortint);
  654. begin
  655. if FShadowOffsetX = AValue then
  656. Exit;
  657. FShadowOffsetX := AValue;
  658. Change;
  659. end;
  660. procedure TBCFont.SetShadowOffsetY(AValue: shortint);
  661. begin
  662. if FShadowOffsetY = AValue then
  663. Exit;
  664. FShadowOffsetY := AValue;
  665. Change;
  666. end;
  667. procedure TBCFont.SetShadowRadius(AValue: byte);
  668. begin
  669. if FShadowRadius = AValue then
  670. Exit;
  671. FShadowRadius := AValue;
  672. Change;
  673. end;
  674. procedure TBCFont.SetSingleLine(AValue: boolean);
  675. begin
  676. if FSingleLine = AValue then
  677. Exit;
  678. FSingleLine := AValue;
  679. if FSingleLine then
  680. FWordBreak := False;
  681. Change;
  682. end;
  683. procedure TBCFont.SetStyle(AValue: TFontStyles);
  684. begin
  685. if FStyle = AValue then
  686. Exit;
  687. FStyle := AValue;
  688. Change;
  689. end;
  690. procedure TBCFont.SetTextAlignment(AValue: TBCAlignment);
  691. begin
  692. if FTextAlignment = AValue then
  693. Exit;
  694. FTextAlignment := AValue;
  695. Change;
  696. end;
  697. procedure TBCFont.SetWordBreak(AValue: boolean);
  698. begin
  699. if FWordBreak = AValue then
  700. Exit;
  701. FWordBreak := AValue;
  702. if FWordBreak then
  703. FSingleLine := False;
  704. Change;
  705. end;
  706. constructor TBCFont.Create(AControl: TControl);
  707. begin
  708. inherited Create(AControl);
  709. // That is temporary. BGRABitmap draw some yellow background when fqSystemClearType.
  710. // This problem is reported
  711. {$IFDEF LCLGTK2}
  712. FFontQuality := fqFineAntialiasing;
  713. {$ELSE}
  714. FFontQuality := fqSystemClearType;
  715. {$ENDIF}
  716. FShadow := False;
  717. FShadowColor := clBlack;
  718. FShadowColorOpacity := 255;
  719. FShadowRadius := 5;
  720. FShadowOffsetX := 5;
  721. FShadowOffsetY := 5;
  722. FHeight := 0;
  723. FTextAlignment := bcaCenter;
  724. FStyle := [];
  725. FName := DefFontData.Name;
  726. FColor := clDefault;
  727. FDisabledColor := clNone;
  728. FWordBreak := False;
  729. FSingleLine := True;
  730. FEndEllipsis := False;
  731. end;
  732. procedure TBCFont.Assign(Source: TPersistent);
  733. begin
  734. if Source is TBCFont then
  735. begin
  736. FColor := TBCFont(Source).FColor;
  737. FDisabledColor := TBCFont(Source).FDisabledColor;
  738. FEndEllipsis := TBCFont(Source).FEndEllipsis;
  739. FFontQuality := TBCFont(Source).FFontQuality;
  740. FHeight := TBCFont(Source).FHeight;
  741. FName := TBCFont(Source).FName;
  742. FSingleLine := TBCFont(Source).FSingleLine;
  743. FShadow := TBCFont(Source).FShadow;
  744. FShadowColor := TBCFont(Source).FShadowColor;
  745. FShadowColorOpacity := TBCFont(Source).FShadowColorOpacity;
  746. FShadowRadius := TBCFont(Source).FShadowRadius;
  747. FShadowOffsetX := TBCFont(Source).FShadowOffsetX;
  748. FShadowOffsetY := TBCFont(Source).FShadowOffsetY;
  749. FStyle := TBCFont(Source).FStyle;
  750. FTextAlignment := TBCFont(Source).FTextAlignment;
  751. FWordBreak := TBCFont(Source).FWordBreak;
  752. FPaddingLeft:= TBCFont(Source).PaddingLeft;
  753. FPaddingTop:= TBCFont(Source).PaddingTop;
  754. FPaddingRight:= TBCFont(Source).PaddingRight;
  755. FPaddingBottom:= TBCFont(Source).PaddingBottom;
  756. Change;
  757. end else
  758. if Source is TFont then
  759. begin
  760. FColor := TFont(Source).Color;
  761. FHeight := -TFont(Source).Height;
  762. FName := TFont(Source).Name;
  763. FStyle:= TFont(Source).Style;
  764. Change;
  765. end else
  766. inherited Assign(Source);
  767. end;
  768. procedure TBCFont.Scale(AScale: single; APreserveDefaultHeight: boolean);
  769. var
  770. bmp: TBitmap;
  771. begin
  772. // we need to have an actual height and not the default value
  773. if (Height = 0) and not APreserveDefaultHeight then
  774. begin
  775. bmp := TBitmap.Create;
  776. bmp.Canvas.Font.Name:= Name;
  777. bmp.Canvas.Font.Height:= 0;
  778. bmp.Canvas.Font.Style:= Style;
  779. Height := -bmp.Canvas.TextHeight('Bgra');
  780. bmp.Free;
  781. end;
  782. Height := round(Height * AScale);
  783. ShadowRadius:= min(high(ShadowRadius), round(ShadowRadius * AScale));
  784. ShadowOffsetX:= max(low(ShadowOffsetX), min(high(ShadowOffsetX), round(ShadowOffsetX*AScale)));
  785. ShadowOffsetY:= max(low(ShadowOffsetY), min(high(ShadowOffsetY), round(ShadowOffsetY*AScale)));
  786. PaddingLeft:= round(PaddingLeft * AScale);
  787. PaddingTop:= round(PaddingTop * AScale);
  788. PaddingRight:= round(PaddingRight * AScale);
  789. PaddingBottom:= round(PaddingBottom * AScale);
  790. end;
  791. { TBCBackground }
  792. procedure TBCBackground.SetStyle(AValue: TBCBackgroundStyle);
  793. begin
  794. if FStyle = AValue then
  795. Exit;
  796. FStyle := AValue;
  797. Change;
  798. end;
  799. constructor TBCBackground.Create(AControl: TControl);
  800. begin
  801. FStyle := bbsColor;
  802. FColorOpacity := 255;
  803. FGradient1 := TBCGradient.Create(AControl);
  804. FGradient2 := TBCGradient.Create(AControl);
  805. FGradient1EndPercent := 35;
  806. FGradient1.OnChange := OnChangeChildProperty;
  807. FGradient2.OnChange := OnChangeChildProperty;
  808. inherited Create(AControl);
  809. end;
  810. destructor TBCBackground.Destroy;
  811. begin
  812. FGradient1.Free;
  813. FGradient2.Free;
  814. inherited Destroy;
  815. end;
  816. procedure TBCBackground.Assign(Source: TPersistent);
  817. begin
  818. if Source is TBCBackground then
  819. begin
  820. FColor := TBCBackground(Source).FColor;
  821. FColorOpacity := TBCBackground(Source).FColorOpacity;
  822. FGradient1EndPercent := TBCBackground(Source).FGradient1EndPercent;
  823. FStyle := TBCBackground(Source).FStyle;
  824. FGradient1.Assign(TBCBackground(Source).FGradient1);
  825. FGradient2.Assign(TBCBackground(Source).FGradient2);
  826. end
  827. else
  828. inherited Assign(Source);
  829. end;
  830. procedure TBCBackground.Scale(AScale: single);
  831. begin
  832. FGradient1.Scale(AScale);
  833. FGradient2.Scale(AScale);
  834. end;
  835. procedure TBCBackground.SetGradient1(AValue: TBCGradient);
  836. begin
  837. if FGradient1 = AValue then
  838. Exit;
  839. FGradient1 := AValue;
  840. Change;
  841. end;
  842. procedure TBCBackground.OnChangeChildProperty(Sender: TObject; AData: PtrInt);
  843. begin
  844. Change(AData);
  845. end;
  846. procedure TBCBackground.SetColor(AValue: TColor);
  847. begin
  848. if FColor = AValue then
  849. Exit;
  850. FColor := AValue;
  851. Change;
  852. end;
  853. procedure TBCBackground.SetColorOpacity(AValue: byte);
  854. begin
  855. if FColorOpacity = AValue then
  856. Exit;
  857. FColorOpacity := AValue;
  858. Change;
  859. end;
  860. procedure TBCBackground.SetGradient1EndPercent(AValue: single);
  861. begin
  862. if FGradient1EndPercent = AValue then
  863. Exit;
  864. FGradient1EndPercent := AValue;
  865. Change;
  866. end;
  867. procedure TBCBackground.SetGradient2(AValue: TBCGradient);
  868. begin
  869. if FGradient2 = AValue then
  870. Exit;
  871. FGradient2 := AValue;
  872. Change;
  873. end;
  874. { TBCBorder }
  875. procedure TBCBorder.SetLightColor(AValue: TColor);
  876. begin
  877. if FLightColor = AValue then
  878. Exit;
  879. FLightColor := AValue;
  880. Change;
  881. end;
  882. procedure TBCBorder.SetColor(AValue: TColor);
  883. begin
  884. if FColor = AValue then
  885. Exit;
  886. FColor := AValue;
  887. Change;
  888. end;
  889. procedure TBCBorder.SetColorOpacity(AValue: byte);
  890. begin
  891. if FColorOpacity = AValue then
  892. Exit;
  893. FColorOpacity := AValue;
  894. Change;
  895. end;
  896. procedure TBCBorder.SetLightOpacity(AValue: byte);
  897. begin
  898. if FLightOpacity = AValue then
  899. Exit;
  900. FLightOpacity := AValue;
  901. Change;
  902. end;
  903. procedure TBCBorder.SetLightWidth(AValue: integer);
  904. begin
  905. if FLightWidth = AValue then
  906. Exit;
  907. FLightWidth := AValue;
  908. Change;
  909. end;
  910. procedure TBCBorder.SetStyle(AValue: TBCBorderStyle);
  911. begin
  912. if FStyle = AValue then
  913. Exit;
  914. FStyle := AValue;
  915. Change;
  916. end;
  917. procedure TBCBorder.SetWidth(AValue: integer);
  918. begin
  919. if FWidth = AValue then
  920. Exit;
  921. FWidth := AValue;
  922. Change;
  923. end;
  924. constructor TBCBorder.Create(AControl: TControl);
  925. begin
  926. FColor := clBlack;
  927. FColorOpacity := 255;
  928. FLightWidth := 0;
  929. FLightOpacity := 255;
  930. FLightColor := clWhite;
  931. FStyle := bboSolid;
  932. FWidth := 1;
  933. inherited Create(AControl);
  934. end;
  935. procedure TBCBorder.Assign(Source: TPersistent);
  936. begin
  937. if Source is TBCBorder then
  938. begin
  939. FColor := TBCBorder(Source).FColor;
  940. FColorOpacity := TBCBorder(Source).FColorOpacity;
  941. FLightColor := TBCBorder(Source).FLightColor;
  942. FLightOpacity := TBCBorder(Source).FLightOpacity;
  943. FLightWidth := TBCBorder(Source).FLightWidth;
  944. FStyle := TBCBorder(Source).FStyle;
  945. FWidth := TBCBorder(Source).FWidth;
  946. end
  947. else
  948. inherited Assign(Source);
  949. end;
  950. procedure TBCBorder.Scale(AScale: single);
  951. begin
  952. LightWidth:= round(LightWidth * AScale);
  953. Width := round(Width * AScale);
  954. end;
  955. end.