typedef fltk::Color


fltk::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 fltk::Color in an internal table of 255 colors, called the "fltk colormap", shown here. Thus using any integer in the range 1-255 as an fltk::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 fltk::Color of zero (fltk::NO_COLOR) will draw black but is ambiguous. It is returned as an error value or to indicate portions of a fltk::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 fltk::BLACK (56) to get black.

The entries 1-31 in the colormap are settable by the user program. The advantage of using these over fltk::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 fltk::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 by other code that calls fltk::background() so that the color fltk::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 fltk::rectf() on 8-bit screens. In addition the symbols fltk::BLACK, fltk::RED, fltk::GREEN, fltk::YELLOW, fltk::BLUE, fltk::MAGENTA, fltk::CYAN, fltk::WHITE, and fltk::BLUE_SELECTION_COLOR index the corners of the cube (these have different values than fltk1.0!).

Methods and functions

fltk::Color fltk::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.

fltk::Color fltk::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).

fltk::Color fltk::color_average(fltk::Color A, fltk::Color B, double weight);

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

fltk::Color fltk::inactive(fltk::Color c);

Returns some color between c and fltk::GRAY.

fltk::Color fltk::inactive(fltk::Color c, fltk::Flags f);

This returns fltk::inactive(c) if the bit fltk::INACTIVE is turned on in f, otherwise c is returned unchanged.

fltk::Color fltk::contrast(fltk::Color fg, fltk::Color bg);

Decides if fg can be seen agains bg and returns fg if so. If not this returns either fltk::NO_COLOR or fltk::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.

fltk::Color fltk::get_color(fltk::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 fltk::get_color(fltk::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.

fltk::Color fltk::nearest_color(fltk::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 color cube is returned.

void fltk::set_color(fltk::Color index, fltk::Color v);

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

void fltk::free_color(fltk::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.

void fltk::background(fltk::Color)

Modifies the "gray ramp" in the fltk color map so that the color fltk::GRAY is set the the rgb values of the passed color. This is the best way to change the overall color of your application, because it sets all the shaded borders and works on 8-bit screens.