typedef Fl_Color

Fl_Color is an unsigned integer.

The (low) 4 bytes of the color are rgbN. (r is the byte with the highest value, not the first in memory. On an Intel or other little-endian machine the first byte in memory is N, while on a big-endian machine such as a MIPS it is r)

If the rgb is zero, the N is the color "index". This index is used to look up an Fl_Color in an internal table of 256 colors, called the "fltk colormap", shown here. Thus using any integer in the range 0-255 as an Fl_Color will index the colormap. If rgb is not zero the index value is ignored (future code may treat the last byte as an "alpha" value).

An Fl_Color of zero (FL_NO_COLOR) will draw black but is ambiguous. It is returned as an error value or to indicate portions of a Fl_Style that should be inherited, and it is also used as the default label color for everything so that changing color zero can be used by the -fg switch. You should use FL_BLACK (56) to get black.

The entries 1-31 in the colormap are settable by the user program. The advantage of using these over fl_rgb(r,g,b) is that they are reproduced exactly on 8-bit screens (normal rgb colors are selected on 8-bit screens by using fl_nearest_color()). Colors 1-15 are preset for back compatability but fltk no longer uses these so you can change them.

Entries 32-55 of the colormap are a 24-entry "gray" ramp. This ramp is modified by the -bg switch or other user preferences so that the entry FL_GRAY (49) is the background color, and the others are a nice range from black to white. These are used to draw box edges.

The remiander of the colormap is a 5x8x5 color cube. This cube is used to dither images or fl_rectf() on 8-bit screens. In addition the symbols FL_BLACK, FL_RED, FL_GREEN, FL_YELLOW, FL_BLUE, FL_MAGENTA, FL_CYAN, FL_WHITE, and FL_BLUE_SELECTION_COLOR index the corners of the cube (these have different values than fltk1.0!).

Methods and functions

Fl_Color fl_rgb(unsigned char r, unsigned char g, unsigned char b)

Inline function to build a color out of individual bytes. The index is set to zero.

Fl_Color fl_rgb(const char*);

Return a named color, returns 0 if the name is not found (on X this does Xlookupcolor, on Windows it can only do colors of the form #123456).

Fl_Color fl_color_average(Fl_Color A, Fl_Color B, double weight);

Returns a color that is weight*A+(1-weight)*B.

Fl_Color fl_inactive(Fl_Color c);

Returns some color between c and FL_GRAY.

Fl_Color fl_inactive(Fl_Color c, Fl_Flags f);

This returns fl_inactive(c) if the bit FL_INACTIVE is turned on in f, otherwise c is returned unchanged.

Fl_Color fl_contrast(Fl_Color fg, Fl_Color bg);

Decides if fg can be seen agains bg and returns fg if so. If not this returns either FL_NO_COLOR or FL_WHITE, whichever one is more different than bg. This function is often used by fltk for labels and text when no color is specified in the style.

Fl_Color fl_get_color(Fl_Color c);

Turns an indexed color into an rgb color by looking it up in the colormap. If c is not an indexed color it is returned unchanged.

void fl_get_color(Fl_Color c, uchar& r, uchar& g, uchar& b);

Turns an indexed color into an rgb color if necessary, and then the rgb portions of the color are extracted and put in the passed variables.

Fl_Color fl_nearest_color(Fl_Color c);

Turns an rgb color into an indexed color. If c is already an indexed color it is returned unchanged. Otherwise, the closest color from the gray ramp or color cube is returned.

void fl_set_color(Fl_Color index, Fl_Color v);

Set entry index in the fltk colormap to the rgb values of v. index must be in the range 1-31.

void fl_free_color(Fl_Color index);

Tell a colormapped-display that we don't need this indexed color anymore. Fltk will free any hardware colormap it allocated so that it can be reused by this or another program.

Fl_Color fl_gray_ramp(int index)

Return indexed color index from the gray ramp (this is a simple inline function). There are FL_NUM_GRAY (24) shades in the gray ramp, with zero being black and 23 being white.

Fl_Color fl_color_cube(int r, int g, int b)

Return a indexed color from the color cube. Unless you really need exact colors on an 8-bit screen you are better off using fl_rgb(r,g,b), which takes 8-bit numbers. The three arguments are indexes into the cube (not 8 bit numbers!), the number of values in each index is FL_NUM_RED(5), FL_NUM_GREEN(8) and FL_NUM_BLUE(5).