system.uiconsts.pp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. unit System.UIConsts;
  2. {
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2023 the Free Pascal development team
  5. FPC/Lazarus Replacement for UIConsts from Delphi 10.x
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. {$MODE OBJFPC}
  13. {$H+}
  14. interface
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. uses System.UITypes, System.Classes;
  17. {$ELSE}
  18. uses System.UITypes, Classes;
  19. {$ENDIF}
  20. const
  21. MaxColorChannel = $FF;
  22. const
  23. claAliceblue = TAlphaColors.AliceBlue;
  24. claAntiquewhite = TAlphaColors.Antiquewhite;
  25. claAqua = TAlphaColors.Aqua;
  26. claAquamarine = TAlphaColors.Aquamarine;
  27. claAzure = TAlphaColors.Azure;
  28. claBeige = TAlphaColors.Beige;
  29. claBisque = TAlphaColors.Bisque;
  30. claBlack = TAlphaColors.Black;
  31. claBlanchedalmond = TAlphaColors.Blanchedalmond;
  32. claBlue = TAlphaColors.Blue;
  33. claBlueviolet = TAlphaColors.Blueviolet;
  34. claBrown = TAlphaColors.Brown;
  35. claBurlywood = TAlphaColors.Burlywood;
  36. claCadetblue = TAlphaColors.Cadetblue;
  37. claChartreuse = TAlphaColors.Chartreuse;
  38. claChocolate = TAlphaColors.Chocolate;
  39. claCoral = TAlphaColors.Coral;
  40. claCornflowerblue = TAlphaColors.Cornflowerblue;
  41. claCornsilk = TAlphaColors.Cornsilk;
  42. claCrimson = TAlphaColors.Crimson;
  43. claCyan = TAlphaColors.Cyan;
  44. claDarkblue = TAlphaColors.Darkblue;
  45. claDarkcyan = TAlphaColors.Darkcyan;
  46. claDarkgoldenrod = TAlphaColors.Darkgoldenrod;
  47. claDarkgray = TAlphaColors.Darkgray;
  48. claDarkgreen = TAlphaColors.Darkgreen;
  49. claDarkgrey = TAlphaColors.Darkgrey;
  50. claDarkkhaki = TAlphaColors.Darkkhaki;
  51. claDarkmagenta = TAlphaColors.Darkmagenta;
  52. claDarkolivegreen = TAlphaColors.Darkolivegreen;
  53. claDarkorange = TAlphaColors.Darkorange;
  54. claDarkorchid = TAlphaColors.Darkorchid;
  55. claDarkred = TAlphaColors.Darkred;
  56. claDarksalmon = TAlphaColors.Darksalmon;
  57. claDarkseagreen = TAlphaColors.Darkseagreen;
  58. claDarkslateblue = TAlphaColors.Darkslateblue;
  59. claDarkslategray = TAlphaColors.Darkslategray;
  60. claDarkslategrey = TAlphaColors.Darkslategrey;
  61. claDarkturquoise = TAlphaColors.Darkturquoise;
  62. claDarkviolet = TAlphaColors.Darkviolet;
  63. claDeeppink = TAlphaColors.Deeppink;
  64. claDeepskyblue = TAlphaColors.Deepskyblue;
  65. claDimgray = TAlphaColors.Dimgray;
  66. claDimgrey = TAlphaColors.Dimgrey;
  67. claDodgerblue = TAlphaColors.Dodgerblue;
  68. claFirebrick = TAlphaColors.Firebrick;
  69. claFloralwhite = TAlphaColors.Floralwhite;
  70. claForestgreen = TAlphaColors.Forestgreen;
  71. claFuchsia = TAlphaColors.Fuchsia;
  72. claGainsboro = TAlphaColors.Gainsboro;
  73. claGhostwhite = TAlphaColors.Ghostwhite;
  74. claGold = TAlphaColors.Gold;
  75. claGoldenrod = TAlphaColors.Goldenrod;
  76. claGray = TAlphaColors.Gray;
  77. claGreen = TAlphaColors.Green;
  78. claGreenyellow = TAlphaColors.Greenyellow;
  79. claGrey = TAlphaColors.Grey;
  80. claHoneydew = TAlphaColors.Honeydew;
  81. claHotpink = TAlphaColors.Hotpink;
  82. claIndianred = TAlphaColors.Indianred;
  83. claIndigo = TAlphaColors.Indigo;
  84. claIvory = TAlphaColors.Ivory;
  85. claKhaki = TAlphaColors.Khaki;
  86. claLavender = TAlphaColors.Lavender;
  87. claLavenderblush = TAlphaColors.Lavenderblush;
  88. claLawngreen = TAlphaColors.Lawngreen;
  89. claLemonchiffon = TAlphaColors.Lemonchiffon;
  90. claLightblue = TAlphaColors.Lightblue;
  91. claLightcoral = TAlphaColors.Lightcoral;
  92. claLightcyan = TAlphaColors.Lightcyan;
  93. claLightgoldenrodyellow = TAlphaColors.Lightgoldenrodyellow;
  94. claLightgray = TAlphaColors.Lightgray;
  95. claLightgreen = TAlphaColors.Lightgreen;
  96. claLightgrey = TAlphaColors.Lightgrey;
  97. claLightpink = TAlphaColors.Lightpink;
  98. claLightsalmon = TAlphaColors.Lightsalmon;
  99. claLightseagreen = TAlphaColors.Lightseagreen;
  100. claLightskyblue = TAlphaColors.Lightskyblue;
  101. claLightslategray = TAlphaColors.Lightslategray;
  102. claLightslategrey = TAlphaColors.Lightslategrey;
  103. claLightsteelblue = TAlphaColors.Lightsteelblue;
  104. claLightyellow = TAlphaColors.Lightyellow;
  105. claLime = TAlphaColors.Lime;
  106. claLimegreen = TAlphaColors.Limegreen;
  107. claLinen = TAlphaColors.Linen;
  108. claMagenta = TAlphaColors.Magenta;
  109. claMaroon = TAlphaColors.Maroon;
  110. claMediumaquamarine = TAlphaColors.Mediumaquamarine;
  111. claMediumblue = TAlphaColors.Mediumblue;
  112. claMediumorchid = TAlphaColors.Mediumorchid;
  113. claMediumpurple = TAlphaColors.Mediumpurple;
  114. claMediumseagreen = TAlphaColors.Mediumseagreen;
  115. claMediumslateblue = TAlphaColors.Mediumslateblue;
  116. claMediumspringgreen = TAlphaColors.Mediumspringgreen;
  117. claMediumturquoise = TAlphaColors.Mediumturquoise;
  118. claMediumvioletred = TAlphaColors.Mediumvioletred;
  119. claMidnightblue = TAlphaColors.Midnightblue;
  120. claMintcream = TAlphaColors.Mintcream;
  121. claMistyrose = TAlphaColors.Mistyrose;
  122. claMoccasin = TAlphaColors.Moccasin;
  123. claNavajowhite = TAlphaColors.Navajowhite;
  124. claNavy = TAlphaColors.Navy;
  125. claOldlace = TAlphaColors.Oldlace;
  126. claOlive = TAlphaColors.Olive;
  127. claOlivedrab = TAlphaColors.Olivedrab;
  128. claOrange = TAlphaColors.Orange;
  129. claOrangered = TAlphaColors.Orangered;
  130. claOrchid = TAlphaColors.Orchid;
  131. claPalegoldenrod = TAlphaColors.Palegoldenrod;
  132. claPalegreen = TAlphaColors.Palegreen;
  133. claPaleturquoise = TAlphaColors.Paleturquoise;
  134. claPalevioletred = TAlphaColors.Palevioletred;
  135. claPapayawhip = TAlphaColors.Papayawhip;
  136. claPeachpuff = TAlphaColors.Peachpuff;
  137. claPeru = TAlphaColors.Peru;
  138. claPink = TAlphaColors.Pink;
  139. claPlum = TAlphaColors.Plum;
  140. claPowderblue = TAlphaColors.Powderblue;
  141. claPurple = TAlphaColors.Purple;
  142. claRed = TAlphaColors.Red;
  143. claRosybrown = TAlphaColors.Rosybrown;
  144. claRoyalblue = TAlphaColors.Royalblue;
  145. claSaddlebrown = TAlphaColors.Saddlebrown;
  146. claSalmon = TAlphaColors.Salmon;
  147. claSandybrown = TAlphaColors.Sandybrown;
  148. claSeagreen = TAlphaColors.Seagreen;
  149. claSeashell = TAlphaColors.Seashell;
  150. claSienna = TAlphaColors.Sienna;
  151. claSilver = TAlphaColors.Silver;
  152. claSkyblue = TAlphaColors.Skyblue;
  153. claSlateblue = TAlphaColors.Slateblue;
  154. claSlategray = TAlphaColors.Slategray;
  155. claSlategrey = TAlphaColors.Slategrey;
  156. claSnow = TAlphaColors.Snow;
  157. claSpringgreen = TAlphaColors.Springgreen;
  158. claSteelblue = TAlphaColors.Steelblue;
  159. claTan = TAlphaColors.Tan;
  160. claTeal = TAlphaColors.Teal;
  161. claThistle = TAlphaColors.Thistle;
  162. claTomato = TAlphaColors.Tomato;
  163. claTurquoise = TAlphaColors.Turquoise;
  164. claViolet = TAlphaColors.Violet;
  165. claWheat = TAlphaColors.Wheat;
  166. claWhite = TAlphaColors.White;
  167. claWhitesmoke = TAlphaColors.Whitesmoke;
  168. claYellow = TAlphaColors.Yellow;
  169. claYellowgreen = TAlphaColors.Yellowgreen;
  170. claNull = TAlphaColors.Null;
  171. { Cursor string functions }
  172. function CursorToString(Cursor: TCursor): string;
  173. function StringToCursor(const S: string): TCursor;
  174. procedure GetCursorValues(const Proc: TGetStrProc);
  175. function CursorToIdent(Cursor: LongInt; var Ident: string): Boolean; inline;
  176. function IdentToCursor(const Ident: string; var Cursor: LongInt): Boolean; inline;
  177. procedure RegisterCursorIntegerConsts;
  178. { TColor string functions }
  179. function ColorToString(Color: TColor): string;
  180. function StringToColor(const S: string): TColor;
  181. procedure GetColorValues(Proc: TGetStrProc);
  182. function ColorToIdent(Color: Longint; var Ident: string): Boolean; inline;
  183. function IdentToColor(const Ident: string; var Color: LongInt): Boolean; inline;
  184. procedure RegisterColorIntegerConsts;
  185. { TAlphaColor string functions }
  186. procedure GetAlphaColorValues(Proc: TGetStrProc);
  187. function AlphaColorToString(Value: TAlphaColor): string;
  188. function StringToAlphaColor(const Value: string): TAlphaColor;
  189. function AlphaColorToIdent(Color: LongInt; var Ident: string): Boolean;
  190. function IdentToAlphaColor(const Ident: string; var Color: Longint): Boolean;
  191. procedure RegisterAlphaColorIntegerConsts;
  192. { TAlphaColor function's }
  193. /// <summary>Converts TAlphaColor into TColor structure, exchanging red and blue channels while losing alpha channel. </summary>
  194. function AlphaColorToColor(const Color: TAlphaColor): TColor;
  195. function AppendColor(Start, Stop: TAlphaColor): TAlphaColor;
  196. function SubtractColor(Start, Stop: TAlphaColor): TAlphaColor;
  197. function RGBtoBGR(const C: TAlphaColor): TAlphaColor;
  198. function CorrectColor(const C: TAlphaColor): TAlphaColor;
  199. function PremultiplyAlpha(const C: TAlphaColor): TAlphaColor;
  200. function UnpremultiplyAlpha(const C: TAlphaColor): TAlphaColor;
  201. function MakeColor(R, G, B: Byte; A: Byte = MaxColorChannel): TAlphaColor; overload;
  202. function MakeColor(const C: TAlphaColor; const AOpacity: Single): TAlphaColor; overload;
  203. function HSLtoRGB(H, S, L: Single): TAlphaColor;
  204. procedure RGBtoHSL(RGB: TAlphaColor; out H, S, L: Single);
  205. function ChangeHSL(const C: TAlphaColor; dH, dS, dL: Single): TAlphaColor;
  206. const
  207. // Please keep these sorted.
  208. CursorNames: array[0..30] of TIdentMapEntry = (
  209. (Value: crAppStart; Name: 'crAppStart'),
  210. (Value: crArrow; Name: 'crArrow'),
  211. (Value: crCross; Name: 'crCross'),
  212. (Value: crDefault; Name: 'crDefault'),
  213. (Value: crDrag; Name: 'crDrag'),
  214. (Value: crHandPoint; Name: 'crHandPoint'),
  215. (Value: crHelp; Name: 'crHelp'),
  216. (Value: crHourGlass; Name: 'crHourGlass'),
  217. (Value: crHSplit; Name: 'crHSplit'),
  218. (Value: crIBeam; Name: 'crIBeam'),
  219. (Value: crMultiDrag; Name: 'crMultiDrag'),
  220. (Value: crNoDrop; Name: 'crNoDrop'),
  221. (Value: crNo; Name: 'crNo'),
  222. (Value: crSizeAll; Name: 'crSizeAll'),
  223. (Value: crSizeE; Name: 'crSizeE'),
  224. (Value: crSizeNE; Name: 'crSizeNE'),
  225. (Value: crSizeNESW; Name: 'crSizeNESW'),
  226. (Value: crSizeN; Name: 'crSizeN'),
  227. (Value: crSizeNS; Name: 'crSizeNS'),
  228. (Value: crSizeNW; Name: 'crSizeNW'),
  229. (Value: crSizeNWSE; Name: 'crSizeNWSE'),
  230. (Value: crSizeSE; Name: 'crSizeSE'),
  231. (Value: crSizeS; Name: 'crSizeS'),
  232. (Value: crSizeSW; Name: 'crSizeSW'),
  233. (Value: crSizeWE; Name: 'crSizeWE'),
  234. (Value: crSizeW; Name: 'crSizeW'),
  235. (Value: crSQLWait; Name: 'crSQLWait'),
  236. (Value: crUpArrow; Name: 'crUpArrow'),
  237. (Value: crVSplit; Name: 'crVSplit'),
  238. // These must be last, duplicates!
  239. (Value: crSize; Name: 'crSize'),
  240. (Value: crLow; Name: 'crLow')
  241. );
  242. // Please keep these sorted.
  243. ColorNames: array[0..51] of TIdentMapEntry = (
  244. (Value: TColors.Aqua; Name: 'clAqua'),
  245. (Value: TColors.Black; Name: 'clBlack'),
  246. (Value: TColors.Blue; Name: 'clBlue'),
  247. (Value: TColors.Cream; Name: 'clCream'),
  248. (Value: TColors.Fuchsia; Name: 'clFuchsia'),
  249. (Value: TColors.Gray; Name: 'clGray'),
  250. (Value: TColors.Green; Name: 'clGreen'),
  251. (Value: TColors.Lime; Name: 'clLime'),
  252. (Value: TColors.Maroon; Name: 'clMaroon'),
  253. (Value: TColors.MedGray; Name: 'clMedGray'),
  254. (Value: TColors.MoneyGreen; Name: 'clMoneyGreen'),
  255. (Value: TColors.Navy; Name: 'clNavy'),
  256. (Value: TColors.Olive; Name: 'clOlive'),
  257. (Value: TColors.Purple; Name: 'clPurple'),
  258. (Value: TColors.Red; Name: 'clRed'),
  259. (Value: TColors.Silver; Name: 'clSilver'),
  260. (Value: TColors.SkyBlue; Name: 'clSkyBlue'),
  261. (Value: TColors.Sys3DDkShadow; Name: 'cl3DDkShadow'),
  262. (Value: TColors.Sys3DLight; Name: 'cl3DLight'),
  263. (Value: TColors.SysActiveBorder; Name: 'clActiveBorder'),
  264. (Value: TColors.SysActiveCaption; Name: 'clActiveCaption'),
  265. (Value: TColors.SysAppWorkSpace; Name: 'clAppWorkSpace'),
  266. (Value: TColors.SysBackground; Name: 'clBackground'),
  267. (Value: TColors.SysBtnFace; Name: 'clBtnFace'),
  268. (Value: TColors.SysBtnHighlight; Name: 'clBtnHighlight'),
  269. (Value: TColors.SysBtnShadow; Name: 'clBtnShadow'),
  270. (Value: TColors.SysBtnText; Name: 'clBtnText'),
  271. (Value: TColors.SysCaptionText; Name: 'clCaptionText'),
  272. (Value: TColors.SysDefault; Name: 'clDefault'),
  273. (Value: TColors.SysGradientActiveCaption; Name: 'clGradientActiveCaption'),
  274. (Value: TColors.SysGradientInactiveCaption; Name: 'clGradientInactiveCaption'),
  275. (Value: TColors.SysGrayText; Name: 'clGrayText'),
  276. (Value: TColors.SysHighlight; Name: 'clHighlight'),
  277. (Value: TColors.SysHighlightText; Name: 'clHighlightText'),
  278. (Value: TColors.SysHotLight; Name: 'clHotLight'),
  279. (Value: TColors.SysInactiveBorder; Name: 'clInactiveBorder'),
  280. (Value: TColors.SysInactiveCaption; Name: 'clInactiveCaption'),
  281. (Value: TColors.SysInactiveCaptionText; Name: 'clInactiveCaptionText'),
  282. (Value: TColors.SysInfoBk; Name: 'clInfoBk'),
  283. (Value: TColors.SysInfoText; Name: 'clInfoText'),
  284. (Value: TColors.SysMenuBar; Name: 'clMenuBar'),
  285. (Value: TColors.SysMenuHighlight; Name: 'clMenuHighlight'),
  286. (Value: TColors.SysMenu; Name: 'clMenu'),
  287. (Value: TColors.SysMenuText; Name: 'clMenuText'),
  288. (Value: TColors.SysNone; Name: 'clNone'),
  289. (Value: TColors.SysScrollBar; Name: 'clScrollBar'),
  290. (Value: TColors.SysWindowFrame; Name: 'clWindowFrame'),
  291. (Value: TColors.SysWindow; Name: 'clWindow'),
  292. (Value: TColors.SysWindowText; Name: 'clWindowText'),
  293. (Value: TColors.Teal; Name: 'clTeal'),
  294. (Value: TColors.White; Name: 'clWhite'),
  295. (Value: TColors.Yellow; Name: 'clYellow')
  296. );
  297. AlphaColorNames: array [0..154] of TIdentMapEntry = (
  298. (Value: TAlphaColors.AliceBlue; Name: 'claAliceBlue'),
  299. (Value: TAlphaColors.Alpha; Name: 'claAlpha'),
  300. (Value: TAlphaColors.AntiqueWhite; Name: 'claAntiqueWhite'),
  301. (Value: TAlphaColors.AquaMarine; Name: 'claAquaMarine'),
  302. (Value: TAlphaColors.Aqua; Name: 'claAqua'),
  303. (Value: TAlphaColors.Azure; Name: 'claAzure'),
  304. (Value: TAlphaColors.Beige; Name: 'claBeige'),
  305. (Value: TAlphaColors.Bisque; Name: 'claBisque'),
  306. (Value: TAlphaColors.Black; Name: 'claBlack'),
  307. (Value: TAlphaColors.BlanchedAlmond; Name: 'claBlanchedAlmond'),
  308. (Value: TAlphaColors.Blue; Name: 'claBlue'),
  309. (Value: TAlphaColors.BlueViolet; Name: 'claBlueViolet'),
  310. (Value: TAlphaColors.Brown; Name: 'claBrown'),
  311. (Value: TAlphaColors.BurlyWood; Name: 'claBurlyWood'),
  312. (Value: TAlphaColors.CadetBlue; Name: 'claCadetBlue'),
  313. (Value: TAlphaColors.Chartreuse; Name: 'claChartreuse'),
  314. (Value: TAlphaColors.Chocolate; Name: 'claChocolate'),
  315. (Value: TAlphaColors.Coral; Name: 'claCoral'),
  316. (Value: TAlphaColors.CornflowerBlue; Name: 'claCornflowerBlue'),
  317. (Value: TAlphaColors.CornSilk; Name: 'claCornSilk'),
  318. (Value: TAlphaColors.Cream; Name: 'claCream'),
  319. (Value: TAlphaColors.Crimson; Name: 'claCrimson'),
  320. (Value: TAlphaColors.Cyan; Name: 'claCyan'),
  321. (Value: TAlphaColors.DarkBlue; Name: 'claDarkBlue'),
  322. (Value: TAlphaColors.DarkCyan; Name: 'claDarkCyan'),
  323. (Value: TAlphaColors.DarkGoldenRod; Name: 'claDarkGoldenRod'),
  324. (Value: TAlphaColors.DarkGray; Name: 'claDarkGray'),
  325. (Value: TAlphaColors.DarkGreen; Name: 'claDarkGreen'),
  326. (Value: TAlphaColors.DarkGrey; Name: 'claDarkGrey'),
  327. (Value: TAlphaColors.DarkKhaki; Name: 'claDarkKhaki'),
  328. (Value: TAlphaColors.DarkMagenta; Name: 'claDarkMagenta'),
  329. (Value: TAlphaColors.DarkOliveGreen; Name: 'claDarkOliveGreen'),
  330. (Value: TAlphaColors.DarkOrange; Name: 'claDarkOrange'),
  331. (Value: TAlphaColors.DarkOrchid; Name: 'claDarkOrchid'),
  332. (Value: TAlphaColors.DarkRed; Name: 'claDarkRed'),
  333. (Value: TAlphaColors.DarkSalmon; Name: 'claDarkSalmon'),
  334. (Value: TAlphaColors.DarkSeaGreen; Name: 'claDarkSeaGreen'),
  335. (Value: TAlphaColors.DarkSlateBlue; Name: 'claDarkSlateBlue'),
  336. (Value: TAlphaColors.DarkSlateGray; Name: 'claDarkSlateGray'),
  337. (Value: TAlphaColors.DarkSlateGrey; Name: 'claDarkSlateGrey'),
  338. (Value: TAlphaColors.DarkTurquoise; Name: 'claDarkTurquoise'),
  339. (Value: TAlphaColors.DarkViolet; Name: 'claDarkViolet'),
  340. (Value: TAlphaColors.DeepPink; Name: 'claDeepPink'),
  341. (Value: TAlphaColors.DeepSkyBlue; Name: 'claDeepSkyBlue'),
  342. (Value: TAlphaColors.DimGray; Name: 'claDimGray'),
  343. (Value: TAlphaColors.DimGrey; Name: 'claDimGrey'),
  344. (Value: TAlphaColors.DkGray; Name: 'claDkGray'),
  345. (Value: TAlphaColors.DodgerBlue; Name: 'claDodgerBlue'),
  346. (Value: TAlphaColors.Firebrick; Name: 'claFirebrick'),
  347. (Value: TAlphaColors.FloralWhite; Name: 'claFloralWhite'),
  348. (Value: TAlphaColors.ForestGreen; Name: 'claForestGreen'),
  349. (Value: TAlphaColors.Fuchsia; Name: 'claFuchsia'),
  350. (Value: TAlphaColors.Gainsboro; Name: 'claGainsboro'),
  351. (Value: TAlphaColors.GhostWhite; Name: 'claGhostWhite'),
  352. (Value: TAlphaColors.GoldenRod; Name: 'claGoldenRod'),
  353. (Value: TAlphaColors.Gold; Name: 'claGold'),
  354. (Value: TAlphaColors.Gray; Name: 'claGray'),
  355. (Value: TAlphaColors.Green; Name: 'claGreen'),
  356. (Value: TAlphaColors.GreenYellow; Name: 'claGreenYellow'),
  357. (Value: TAlphaColors.Grey; Name: 'claGrey'),
  358. (Value: TAlphaColors.HoneyDew; Name: 'claHoneyDew'),
  359. (Value: TAlphaColors.HotPink; Name: 'claHotPink'),
  360. (Value: TAlphaColors.IndianRed; Name: 'claIndianRed'),
  361. (Value: TAlphaColors.Indigo; Name: 'claIndigo'),
  362. (Value: TAlphaColors.Ivory; Name: 'claIvory'),
  363. (Value: TAlphaColors.Khaki; Name: 'claKhaki'),
  364. (Value: TAlphaColors.LavenderBlush; Name: 'claLavenderBlush'),
  365. (Value: TAlphaColors.Lavender; Name: 'claLavender'),
  366. (Value: TAlphaColors.LawnGreen; Name: 'claLawnGreen'),
  367. (Value: TAlphaColors.LegacySkyBlue; Name: 'claLegacySkyBlue'),
  368. (Value: TAlphaColors.LemonChiffon; Name: 'claLemonChiffon'),
  369. (Value: TAlphaColors.LightBlue; Name: 'claLightBlue'),
  370. (Value: TAlphaColors.LightCoral; Name: 'claLightCoral'),
  371. (Value: TAlphaColors.LightCyan; Name: 'claLightCyan'),
  372. (Value: TAlphaColors.LightGoldenRodYellow; Name: 'claLightGoldenRodYellow'),
  373. (Value: TAlphaColors.LightGray; Name: 'claLightGray'),
  374. (Value: TAlphaColors.LightGreen; Name: 'claLightGreen'),
  375. (Value: TAlphaColors.LightGrey; Name: 'claLightGrey'),
  376. (Value: TAlphaColors.LightPink; Name: 'claLightPink'),
  377. (Value: TAlphaColors.LightSalmon; Name: 'claLightSalmon'),
  378. (Value: TAlphaColors.LightSeaGreen; Name: 'claLightSeaGreen'),
  379. (Value: TAlphaColors.LightSkyBlue; Name: 'claLightSkyBlue'),
  380. (Value: TAlphaColors.LightSlateGray; Name: 'claLightSlateGray'),
  381. (Value: TAlphaColors.LightSlateGrey; Name: 'claLightSlateGrey'),
  382. (Value: TAlphaColors.LightSteelBlue; Name: 'claLightSteelBlue'),
  383. (Value: TAlphaColors.LightYellow; Name: 'claLightYellow'),
  384. (Value: TAlphaColors.LimeGreen; Name: 'claLimeGreen'),
  385. (Value: TAlphaColors.Lime; Name: 'claLime'),
  386. (Value: TAlphaColors.Linen; Name: 'claLinen'),
  387. (Value: TAlphaColors.LtGray; Name: 'claLtGray'),
  388. (Value: TAlphaColors.Magenta; Name: 'claMagenta'),
  389. (Value: TAlphaColors.Maroon; Name: 'claMaroon'),
  390. (Value: TAlphaColors.MedGray; Name: 'claMedGray'),
  391. (Value: TAlphaColors.MediumAquaMarine; Name: 'claMediumAquaMarine'),
  392. (Value: TAlphaColors.MediumBlue; Name: 'claMediumBlue'),
  393. (Value: TAlphaColors.MediumOrchid; Name: 'claMediumOrchid'),
  394. (Value: TAlphaColors.MediumPurple; Name: 'claMediumPurple'),
  395. (Value: TAlphaColors.MediumSeaGreen; Name: 'claMediumSeaGreen'),
  396. (Value: TAlphaColors.MediumSlateBlue; Name: 'claMediumSlateBlue'),
  397. (Value: TAlphaColors.MediumSpringGreen; Name: 'claMediumSpringGreen'),
  398. (Value: TAlphaColors.MediumTurquoise; Name: 'claMediumTurquoise'),
  399. (Value: TAlphaColors.MediumVioletRed; Name: 'claMediumVioletRed'),
  400. (Value: TAlphaColors.MidnightBlue; Name: 'claMidnightBlue'),
  401. (Value: TAlphaColors.MintCream; Name: 'claMintCream'),
  402. (Value: TAlphaColors.MistyRose; Name: 'claMistyRose'),
  403. (Value: TAlphaColors.Moccasin; Name: 'claMoccasin'),
  404. (Value: TAlphaColors.MoneyGreen; Name: 'claMoneyGreen'),
  405. (Value: TAlphaColors.NavajoWhite; Name: 'claNavajoWhite'),
  406. (Value: TAlphaColors.Navy; Name: 'claNavy'),
  407. (Value: TAlphaColors.Null; Name: 'claNull'),
  408. (Value: TAlphaColors.OldLace; Name: 'claOldLace'),
  409. (Value: TAlphaColors.OliveDrab; Name: 'claOliveDrab'),
  410. (Value: TAlphaColors.Olive; Name: 'claOlive'),
  411. (Value: TAlphaColors.Orange; Name: 'claOrange'),
  412. (Value: TAlphaColors.OrangeRed; Name: 'claOrangeRed'),
  413. (Value: TAlphaColors.Orchid; Name: 'claOrchid'),
  414. (Value: TAlphaColors.PaleGoldenRod; Name: 'claPaleGoldenRod'),
  415. (Value: TAlphaColors.PaleGreen; Name: 'claPaleGreen'),
  416. (Value: TAlphaColors.PaleTurquoise; Name: 'claPaleTurquoise'),
  417. (Value: TAlphaColors.PaleVioletRed; Name: 'claPaleVioletRed'),
  418. (Value: TAlphaColors.PapayaWhip; Name: 'claPapayaWhip'),
  419. (Value: TAlphaColors.PeachPuff; Name: 'claPeachPuff'),
  420. (Value: TAlphaColors.Peru; Name: 'claPeru'),
  421. (Value: TAlphaColors.Pink; Name: 'claPink'),
  422. (Value: TAlphaColors.Plum; Name: 'claPlum'),
  423. (Value: TAlphaColors.PowderBlue; Name: 'claPowderBlue'),
  424. (Value: TAlphaColors.Purple; Name: 'claPurple'),
  425. (Value: TAlphaColors.Red; Name: 'claRed'),
  426. (Value: TAlphaColors.RosyBrown; Name: 'claRosyBrown'),
  427. (Value: TAlphaColors.RoyalBlue; Name: 'claRoyalBlue'),
  428. (Value: TAlphaColors.SaddleBrown; Name: 'claSaddleBrown'),
  429. (Value: TAlphaColors.Salmon; Name: 'claSalmon'),
  430. (Value: TAlphaColors.SandyBrown; Name: 'claSandyBrown'),
  431. (Value: TAlphaColors.SeaGreen; Name: 'claSeaGreen'),
  432. (Value: TAlphaColors.SeaShell; Name: 'claSeaShell'),
  433. (Value: TAlphaColors.Sienna; Name: 'claSienna'),
  434. (Value: TAlphaColors.Silver; Name: 'claSilver'),
  435. (Value: TAlphaColors.SkyBlue; Name: 'claSkyBlue'),
  436. (Value: TAlphaColors.SlateBlue; Name: 'claSlateBlue'),
  437. (Value: TAlphaColors.SlateGray; Name: 'claSlateGray'),
  438. (Value: TAlphaColors.SlateGrey; Name: 'claSlateGrey'),
  439. (Value: TAlphaColors.Snow; Name: 'claSnow'),
  440. (Value: TAlphaColors.SpringGreen; Name: 'claSpringGreen'),
  441. (Value: TAlphaColors.SteelBlue; Name: 'claSteelBlue'),
  442. (Value: TAlphaColors.Tan; Name: 'claTan'),
  443. (Value: TAlphaColors.Teal; Name: 'claTeal'),
  444. (Value: TAlphaColors.Thistle; Name: 'claThistle'),
  445. (Value: TAlphaColors.Tomato; Name: 'claTomato'),
  446. (Value: TAlphaColors.Turquoise; Name: 'claTurquoise'),
  447. (Value: TAlphaColors.Violet; Name: 'claViolet'),
  448. (Value: TAlphaColors.Wheat; Name: 'claWheat'),
  449. (Value: TAlphaColors.White; Name: 'claWhite'),
  450. (Value: TAlphaColors.WhiteSmoke; Name: 'claWhiteSmoke'),
  451. (Value: TAlphaColors.YellowGreen; Name: 'claYellowGreen'),
  452. (Value: TAlphaColors.Yellow; Name: 'claYellow')
  453. );
  454. implementation
  455. {$IFDEF FPC_DOTTEDUNITS}
  456. uses System.SysUtils;
  457. {$ELSE}
  458. uses SysUtils;
  459. {$ENDIF}
  460. { ****************************************************************************
  461. Colors
  462. ****************************************************************************}
  463. function ColorToIdent(Color: LongInt;var Ident: string): Boolean;
  464. begin
  465. Result:=IntToIdent(Color,Ident,ColorNames);
  466. end;
  467. function IdentToColor(const Ident: string;var Color: LongInt): Boolean;
  468. begin
  469. Result:=IdentToInt(Ident,Color,ColorNames);
  470. end;
  471. function ColorToString(Color: TColor): string;
  472. begin
  473. if ColorToIdent(Color,Result) then
  474. exit;
  475. Result:=Format('$%0.8x',[Integer(Color)]);
  476. end;
  477. function StringToColor(const S: string): TColor;
  478. begin
  479. if IdentToColor(S,LongInt(Result)) then
  480. exit;
  481. Result:=TColor(StrToIntDef(S,Integer(TColorRec.Black)));
  482. end;
  483. procedure GetColorValues(Proc: TGetStrProc);
  484. var
  485. C: Integer;
  486. begin
  487. for C:=Low(ColorNames) to High(ColorNames) do
  488. Proc(ColorNames[C].Name);
  489. end;
  490. procedure RegisterColorIntegerConsts;
  491. begin
  492. if Assigned(FindIntToIdent(TypeInfo(TColor))) then
  493. exit;
  494. RegisterIntegerConsts(TypeInfo(TColor),@IdentToColor,@ColorToIdent);
  495. end;
  496. { ****************************************************************************
  497. AlphaColors
  498. ****************************************************************************}
  499. function AlphaColorToIdent(Color: LongInt; var Ident: string): Boolean;
  500. begin
  501. Result:=IntToIdent(Color,Ident,AlphaColorNames);
  502. if not Result then
  503. begin
  504. Ident:='x'+IntToHex(Color,8);
  505. Result:=True;
  506. end;
  507. end;
  508. function IdentToAlphaColor(const Ident: string; var Color: LongInt): Boolean;
  509. var
  510. S: string;
  511. begin
  512. S:=Ident;
  513. Result:=(Length(S)>1) and (S[1]='x');
  514. if Result then
  515. Color:=Integer(StringToAlphaColor(S))
  516. else
  517. begin
  518. Result:=IdentToInt(S,Color,AlphaColorNames);
  519. if not Result and (Length(S)>2) and (S[1]='c') and (S[2]='l') then
  520. begin
  521. Insert('a',S,3);
  522. Result:=IdentToInt(S,Color,AlphaColorNames);
  523. end;
  524. end;
  525. end;
  526. procedure GetAlphaColorValues(Proc: TGetStrProc);
  527. var
  528. AC: Integer;
  529. begin
  530. for AC:=Low(AlphaColorNames) to High(AlphaColorNames) do
  531. Proc(Copy(AlphaColorNames[AC].Name,4));
  532. end;
  533. function AlphaColorToString(Value: TAlphaColor): string;
  534. begin
  535. Result:='';
  536. if AlphaColorToIdent(Integer(Value),Result) then
  537. begin
  538. if Result[1]='x' then
  539. Result[1]:='#'
  540. else
  541. Delete(Result,1,3); // Strip cla...
  542. end;
  543. end;
  544. function StringToAlphaColor(const Value: string): TAlphaColor;
  545. var
  546. S: string;
  547. begin
  548. S:=Value;
  549. if (S=#0) or (S='') then
  550. Result:=TAlphaColors.Black
  551. else if (Length(S)>0) and (S[1] in ['#','x']) then
  552. begin
  553. S:='$'+Copy(S,2);
  554. Result:=TAlphaColor(StrToIntDef(S,TAlphaColors.Black));
  555. end
  556. else
  557. if not IdentToAlphaColor(S,LongInt(Result)) then
  558. if not IdentToAlphaColor('cla'+S,LongInt(Result)) then
  559. Result:=TAlphaColor(StrToIntDef(S,TAlphaColors.Black));
  560. end;
  561. procedure RegisterAlphaColorIntegerConsts;
  562. begin
  563. if not Assigned(FindIntToIdent(TypeInfo(TAlphaColor))) then
  564. RegisterIntegerConsts(TypeInfo(TAlphaColor),@IdentToAlphaColor,@AlphaColorToIdent);
  565. end;
  566. function AlphaColorToColor(const Color: TAlphaColor): TColor;
  567. Var
  568. R : TColorRec;
  569. begin
  570. R.A:=0;
  571. R.R:=TAlphaColorRec(Color).R;
  572. R.G:=TAlphaColorRec(Color).G;
  573. R.B:=TAlphaColorRec(Color).B;
  574. Result:=TColor(R);
  575. end;
  576. function AppendColor(Start, Stop: TAlphaColor): TAlphaColor;
  577. function Channel(aStart,aStop : Byte) : byte;
  578. var
  579. R : Integer;
  580. begin
  581. Result:=MaxColorChannel;
  582. R:=aStart+aStop;
  583. if R<Result then
  584. Result:=R;
  585. end;
  586. var
  587. RSA : TAlphaColorRec absolute start;
  588. RSS : TAlphaColorRec absolute stop;
  589. R : TAlphaColorRec;
  590. begin
  591. R.A:=Channel(RSA.A,RSS.A);
  592. R.R:=Channel(RSA.R,RSS.R);
  593. R.G:=Channel(RSA.G,RSS.G);
  594. R.B:=Channel(RSA.B,RSS.B);
  595. Result:=TAlphaColor(R);
  596. end;
  597. function SubtractColor(Start, Stop: TAlphaColor): TAlphaColor;
  598. function Channel(aStart,aStop : Byte) : byte;
  599. var
  600. R : Integer;
  601. begin
  602. Result:=MaxColorChannel;
  603. R:=aStart-aStop;
  604. if R>=0 then
  605. Result:=R;
  606. end;
  607. var
  608. RSA : TAlphaColorRec absolute start;
  609. RSS : TAlphaColorRec absolute stop;
  610. R : TAlphaColorRec absolute Result;
  611. begin
  612. R.A:=Channel(RSA.A,RSS.A);
  613. R.R:=Channel(RSA.R,RSS.R);
  614. R.G:=Channel(RSA.G,RSS.G);
  615. R.B:=Channel(RSA.B,RSS.B);
  616. end;
  617. function RGBtoBGR(const C: TAlphaColor): TAlphaColor;
  618. Var
  619. R : TAlphaColorRec absolute result;
  620. CR : TAlphaColorRec absolute c;
  621. begin
  622. Result:=C;
  623. R.R:=CR.B;
  624. R.B:=CR.R;
  625. end;
  626. function CorrectColor(const C: TAlphaColor): TAlphaColor;
  627. begin
  628. {$IFNDEF WINDOWS}
  629. Result:=RGBtoBGR(C);
  630. {$ELSE}
  631. Result:=C;
  632. {$ENDIF}
  633. end;
  634. function PremultiplyAlpha(const C: TAlphaColor): TAlphaColor;
  635. Function Mul(C,A : Byte) : Byte; inline;
  636. begin
  637. Result:=Trunc(C*A/MaxColorChannel);
  638. end;
  639. var
  640. CR : TAlphaColorRec absolute C;
  641. R : TAlphaColorRec absolute Result;
  642. begin
  643. if CR.A=0 then
  644. Result:=0
  645. else if CR.A=MaxColorChannel then
  646. Result:=C
  647. else
  648. begin
  649. R.A:=CR.A;
  650. R.R:=Mul(CR.R,CR.A);
  651. R.G:=Mul(CR.G,CR.A);
  652. R.B:=Mul(CR.B,CR.A);
  653. end;
  654. end;
  655. function UnpremultiplyAlpha(const C: TAlphaColor): TAlphaColor;
  656. Function CDiv(C,A : Byte) : Byte; inline;
  657. begin
  658. Result:=Trunc(C/A/MaxColorChannel);
  659. end;
  660. var
  661. CR : TAlphaColorRec absolute C;
  662. R : TAlphaColorRec absolute Result;
  663. begin
  664. if CR.A=0 then
  665. Result:=0
  666. else if CR.A=MaxColorChannel then
  667. Result:=C
  668. else
  669. begin
  670. R.A:=CR.A;
  671. R.R:=CDiv(CR.R,CR.A);
  672. R.G:=CDiv(CR.G,CR.A);
  673. R.B:=CDiv(CR.B,CR.A);
  674. end;
  675. end;
  676. function MakeColor(const C: TAlphaColor; const AOpacity: Single): TAlphaColor;
  677. var
  678. CR : TAlphaColorRec absolute C;
  679. R : TAlphaColorRec absolute Result;
  680. begin
  681. Result:=C;
  682. if AOpacity<1 then
  683. R.A:=trunc(CR.A*AOpacity);
  684. end;
  685. function MakeColor(R, G, B: Byte; A: Byte = MaxColorChannel): TAlphaColor;
  686. var
  687. RC : TAlphaColorRec absolute Result;
  688. begin
  689. RC.A:=A;
  690. RC.R:=R;
  691. RC.G:=G;
  692. RC.B:=B;
  693. end;
  694. function LimitRange01(v : single):single;inline;
  695. begin
  696. if V<0 then
  697. V:=0
  698. else if V>1 then
  699. V:=1;
  700. Result:=V;
  701. end;
  702. // Only valid for -1<=V<=2
  703. function ToRange01(v : single):single;inline;
  704. begin
  705. if V<0 then
  706. V:=V+1
  707. else if V>1 then
  708. V:=V-1;
  709. Result:=V;
  710. end;
  711. function Max(A,B: Single):Single;inline;
  712. begin
  713. if (A>B) then Result:=A else Result:=B;
  714. end;
  715. function Min(A,B: Single):Single;inline;
  716. begin
  717. if (A<B) then Result:=A else Result:=B;
  718. end;
  719. function ChangeHSL(const C: TAlphaColor; dH, dS, dL: Single): TAlphaColor;
  720. var
  721. H,S,L: Single;
  722. CR : TAlphaColorRec absolute C;
  723. R : TAlphaColorRec absolute Result;
  724. begin
  725. RGBtoHSL(C,H,S,L);
  726. H:=ToRange01(H+dH);
  727. S:=LimitRange01(S+dS);
  728. L:=LimitRange01(S+dL);
  729. Result:=HSLtoRGB(H,S,L);
  730. R.A:=CR.A;
  731. end;
  732. function Hue2RGBChannel(P,Q,T: Single): Single;
  733. begin
  734. T:=ToRange01(T);
  735. if (t<1/6) then
  736. Exit(P+(Q-P)*6*t);
  737. if (t<1/2) then
  738. Exit(Q);
  739. if (t<2/3) then
  740. Exit(P+(Q-P)*(2/3-t)*6);
  741. Result:=LimitRange01(P);
  742. end;
  743. // Adapted from https://www.delphipraxis.net/157099-fast-integer-rgb-hsl.html
  744. function HSLtoRGB(H, S, L: Single): TAlphaColor;
  745. const
  746. Fact = 1/3;
  747. Function UpScale(S : Single) : Byte; inline;
  748. begin
  749. Result:=round(S*MaxColorChannel);
  750. end;
  751. var
  752. R, G, B: Single;
  753. Q, P: Single;
  754. begin
  755. if (S = 0) then
  756. begin
  757. L:=LimitRange01(L);
  758. R:=L;
  759. G:=L;
  760. B:=L;
  761. end
  762. else
  763. begin
  764. if (L < 0.5) then
  765. Q:=L*(1+S)
  766. else
  767. Q:=L+S*(1-L);
  768. P:=2*L-q;
  769. G:=Hue2RGBChannel(P,Q,H);
  770. B:=Hue2RGBChannel(P,Q,H-Fact);
  771. R:=Hue2RGBChannel(P,Q,H+Fact);
  772. end;
  773. Result:=MakeColor(UpScale(R),UpScale(G),UpScale(B));
  774. end;
  775. procedure RGBtoHSL(RGB: TAlphaColor; out H, S, L: Single);
  776. var
  777. R,G,B,MA,MI,Su,Diff: Single;
  778. RGBR : TAlphaColorRec absolute RGB;
  779. begin
  780. R:=RGBR.R/$FF;
  781. G:=RGBR.G/$FF;
  782. B:=RGBR.B/$FF;
  783. MA:=Max(Max(R,G),B);
  784. MI:=Min(Min(R,G),B);
  785. Su:=(MI+MA);
  786. H:=Su/2;
  787. L:=H;
  788. if (MI=MA) then
  789. begin
  790. S:=0;
  791. H:=0;
  792. end
  793. else
  794. begin
  795. S:=H;
  796. Diff:=MA-MI;
  797. if L<=0.5 then
  798. S:=Diff/Su
  799. else
  800. S:=Diff/(2-Su);
  801. if (MA=R) then
  802. H:=(G-B)/Diff
  803. else if (MA=G) then
  804. H:=((B-R)/Diff)+2
  805. else
  806. H:=((R-G)/Diff)+4;
  807. H:=H/6;
  808. if H<0 then
  809. H:=H+1;
  810. end;
  811. end;
  812. function AlphaColorToIntColor(Color: TAlphaColor): Longint;
  813. begin
  814. Result:=AlphaColorToColor(Color);
  815. end;
  816. { ****************************************************************************
  817. Cursors
  818. ****************************************************************************}
  819. procedure RegisterCursorIntegerConsts;
  820. begin
  821. if Assigned(FindIntToIdent(TypeInfo(TCursor))) then
  822. exit;
  823. RegisterIntegerConsts(TypeInfo(TCursor),@IdentToCursor,@CursorToIdent);
  824. end;
  825. function CursorToIdent(Cursor: LongInt;var Ident: string): Boolean;
  826. begin
  827. Result:=IntToIdent(Cursor,Ident,CursorNames);
  828. end;
  829. function IdentToCursor(const Ident: string;var Cursor: LongInt): Boolean;
  830. begin
  831. Result:=IdentToInt(Ident, Cursor, CursorNames);
  832. end;
  833. function CursorToString(Cursor: TCursor): string;
  834. begin
  835. if CursorToIdent(Cursor,Result) then
  836. exit;
  837. Result:=Format('%d',[Cursor]);
  838. end;
  839. function StringToCursor(const S: string): TCursor;
  840. var
  841. C : Longint;
  842. begin
  843. if IdentToCursor(S,C) then
  844. Exit(TCursor(C));
  845. Result:=StrToIntDef(S, Integer(crDefault));
  846. end;
  847. procedure GetCursorValues(const Proc: TGetStrProc);
  848. var
  849. C: Integer;
  850. begin
  851. // Last 2 are duplicates
  852. for C:=Low(CursorNames) to High(CursorNames)-2 do
  853. Proc(CursorNames[C].Name);
  854. end;
  855. initialization
  856. System.UITypes.TAlphaColorRec.ColorToRGB:=@AlphaColorToIntColor;
  857. end.