[fpc-pascal] TFPColor vs TColor

Igor Stojkovic stojkovic.igor at gmail.com
Fri Aug 28 17:25:23 CEST 2009


I am working on something similar so I found this mail. Here is my
solution, maybe someone can use it:

TDNAColor = packed record
    case Integer of
    0: (
         b : Byte; //blue
         g : Byte; //green
         r : Byte; //red
         a : Byte; //alpha
       );
    1: (
         l : Byte; //lightness
         s : Byte; //saturation
         h : Byte; //hue
       );
    2: (
         Value: LongWord;
       );
  end;

Now you can have col: TColor and set it like col.Value := $FF80FF60
and after that col.r will be $80, col.g will be $FF and col.b will be
$60. If you set col.r := $20 then col.Value will be $FF20FF60.

>Incidentally, while working with the TfpgColor type, I've come up with a
>rather sloppy, but (for the time being) usable solution. I keep
>a "fixme" comment in the code, because it may very well blow up in my
>face sometime.
>
>type
>  TfpgIntColor = TfpgColor;
>  TfpgRecordColor = record
>    blue, green, red, alpha : byte;  // order is important
>    end;
>
>operator := (c_in : TfpgRecordColor) : TfpgIntColor;
>  var
>    p : pointer;
>  begin
>    p := @c_in;
>    result := TfpgIntColor (p^);
>  end;
>
>operator := (c_in : TfpgIntColor) : TfpgRecordColor
>  var
>    p : pointer;
>  begin
>    p := @c_in;
>    result := TfpgRecordColor (p^);
>  end;


-- 
Regards,
Igor Stojkovic mailto: stojkovic.igor at gmail.com



More information about the fpc-pascal mailing list