Recent

Author Topic: Color constants  (Read 1276 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
Color constants
« on: February 06, 2020, 09:32:03 pm »
Hi!

The situation with the color constants in BGRA is not satisfying:

The Css-Color values are variables in BGRA and so they can't be used as constant.

For BGRAPixel it is a lot of typing to define a const:

 
Code: Pascal  [Select][+][-]
  1. colorWood : TBGRAPixel =(red : 180;green:112;blue :64; alpha:255);

Okay, it is anounced that in the unit UITypes the color constant will soon appear.
But those constants do NOT start with 'cl' !! This was default since Delphi 1.

Always the same discussion: Do we have to copy all mistakes from Delphi in fpc???

To get out of all that trouble I made  a mini project  that take all 140 (??) Web colors from BGRA, converts them to TColor values and creates an pascal INC file, that can be put into every project.

The heart of it is just this simple procedure:

Code: Pascal  [Select][+][-]
  1. procedure CreateColorInc(FName: string);
  2. var i: integer;
  3.     s,hex,color : string;
  4.     col : TBGRAPixel;
  5.     list : TStringList;
  6. begin
  7.  list := TStringList.Create;
  8.  
  9. // ... header
  10.  
  11.  for i := 0 to CSSColors.Count-1 do
  12.    begin
  13.     color := CssColors.Name[i];
  14.     col := cssColors.ByIndex[i];
  15.     hex := '$'+IntToHex(col.blue,2)+IntToHex(col.green,2)+IntToHex(col.Red,2);
  16.     s := '  cl'+color+' = '+hex+';';
  17.     List.add(s);
  18.    end; // i
  19.    List.SaveToFile(fname);
  20.   //showMessage (List.text);
  21.    List.free;
  22. end;                
  23.  
  24.  

Hope it helps to save typing

Winni
« Last Edit: February 06, 2020, 09:36:42 pm by winni »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Color constants
« Reply #1 on: February 06, 2020, 09:50:00 pm »
Always the same discussion: Do we have to copy all mistakes from Delphi in fpc???

1. Mistake is a subjective term.  cl* are VCL, UITypes is VCL+FM.
2. Yes. That is what compatibility means. Compatibility is never 100%, but if you start breaking for little things that easily could be compatible, that is the end of it.

But if it is a big deal, we can alias them to cl, I see no problem with that. Please file a bug.

Note that the UITypes ones are nested inside a record, so they already have a prefix (TColorRec.)


 

TinyPortal © 2005-2018