cdEncodeColor

Definition: include pGUI.e

integer color = cdEncodeColor(atom red, green, blue)
-- or --
integer color = rgb(atom red, green, blue)
Description: Returns a codified triple (r,g,b) in an integer such as 0x00RRGGBB, where RR are the red components, GG are the green ones and BB are the blue ones.
The code is used in the CD library to define colors. It can be used without an active canvas.

Fractional colour values are permitted, and are automatically converted to unsigned integers in the range 0 to 255 (#00 to #FF). The precise mode of that conversion is however officially undefined - you should not overly rely on rounding, trunction, or what happens when you pass values that are negative or above 255.49, but (for instance) one thing you can expect is that 255.01 will always yield 255.

The cdEncodeColor routine invokes the C function of the same name, whereas the rgb function performs the same task in pure phix code. The latter is recommended.

A very similar rgb() routine exists in both arwen and win32lib, note however those libraries encode colours as red+green*#100+blue*#10000, whereas pGUI uses red*#10000+green*#100+blue, a fact you should only ever need to know when debugging or for some reason are directly comparing the results or using hard-coded literals such as #FF0000 (==CD_RED in pGUI) vs #0000FF (==BrightRed in arwen), which you may encounter when porting existing code.