Color.h File Reference


Typedefs

typedef unsigned  Color

Enumerations

enum   {
  NO_COLOR, FREE_COLOR, NUM_FREE_COLOR, GRAY00,
  GRAY05, GRAY10, GRAY15, GRAY20,
  GRAY25, GRAY30, GRAY33, GRAY35,
  GRAY40, GRAY45, GRAY50, GRAY55,
  GRAY60, GRAY65, GRAY66, GRAY70,
  GRAY75, GRAY80, GRAY85, GRAY90,
  GRAY95, GRAY99, BLACK, RED,
  GREEN, YELLOW, BLUE, MAGENTA,
  CYAN, WHITE, DARK_RED, DARK_GREEN,
  DARK_YELLOW, DARK_BLUE, DARK_MAGENTA, DARK_CYAN,
  WINDOWS_BLUE
}

Functions

Color  color (unsigned char r, unsigned char g, unsigned char b)
Color  color (unsigned char g)
Color  color (const char *)
Color  parsecolor (const char *, unsigned length)
Color  lerp (Color c0, Color c1, float f)
Color  inactive (Color)
Color  inactive (Color, Flags f)
Color  contrast (Color fg, Color bg)
void  split_color (Color c, unsigned char &r, unsigned char &g, unsigned char &b)
void  set_color_index (Color index, Color)
Color  get_color_index (Color index)
void  set_background (Color)
Color  nearest_index (Color)

Detailed Description


Typedef Documentation

Color
 

Color is a typedef for a 32-bit integer containing r,g,b bytes and an "index" in the lowest byte (the first byte on a little-endian machine such as an x86). For instance 0xFF008000 is 255 red, zero green, and 128 blue. If rgb are not zero then the low byte is ignored, or may be treated as "alpha" by some code.

If the rgb is zero, the N is the color "index". This index is used to look up an Color in an internal table of 255 colors shown here. All the indexed colors may be changed by using set_color_index(). However fltk uses the ones between 32 and 255 and assummes they are not changed from their default values.

fl_show_colormap.gif
(this is not the X colormap used by fltk)

A Color of zero (NO_COLOR) will draw black but is ambiguous. It is returned as an error value or to indicate portions of a 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 BLACK (56) to get black.


Enumeration Type Documentation

anonymous enum
 

Symbolic names for some of the indexed colors.

The 24-entry "gray ramp" is modified by set_background() so that the color GRAY75 is the background color, and the others are a nice range from black to white. These are used to draw box edges. The gray levels are chosen to be evenly spaced, listed here is the actual 8-bit and decimal gray level assigned by default. Also listed here is the letter used for FrameBox and the old fltk1.1 names used for these levels.

The remiander of the colormap is a 5x8x5 color cube. This cube is used to dither images on 8-bit screens X colormaps to reduce the number of colors used.

Enumeration values:
NO_COLOR  Black, empty place holder in Style
FREE_COLOR  Starting from index 16 is the FREE_COLOR area
NUM_FREE_COLOR  Number of free color slots starting from index FREE_COLOR
GRAY00  00 .00 A fltk1: GRAY0 GRAY_RAMP
GRAY05  0d .05 B
GRAY10  1a .10 C
GRAY15  26 .15 D
GRAY20  31 .19 E
GRAY25  3d .24 F
GRAY30  48 .28 G
GRAY33  55 .33 H fltk1: DARK3
GRAY35  5f .37 I
GRAY40  6a .42 J (18% gray card)
GRAY45  75 .46 K
GRAY50  80 .50 L
GRAY55  8a .54 M
GRAY60  95 .58 N fltk1: DARK2
GRAY65  a0 .63 O
GRAY66  aa .67 P fltk1: DARK1 INACTIVE_COLOR
GRAY70  b5 .71 Q
GRAY75  c0 .75 R fltk1: GRAY SELECTION_COLOR
GRAY80  cb .80 S
GRAY85  d5 .84 T fltk1: LIGHT1
GRAY90  ea .92 V fltk1: LIGHT2
GRAY95  f5 .96 W
GRAY99  ff 1.00 X fltk1: LIGHT3
BLACK  Corner of color cube
RED  Corner of color cube
GREEN  Corner of color cube
YELLOW  Corner of color cube
BLUE  Corner of color cube
MAGENTA  Corner of color cube
CYAN  Corner of color cube
WHITE  Corner of color cube
WINDOWS_BLUE  default selection_color


Function Documentation

Color color const char *  name  ) 
 

Turn a string into a color. If name is null this returns NO_COLOR. Otherwise it returns parsecolor(name, strlen(name)).

Color contrast Color  fg,
Color  bg
 

Returns fg if fltk decides it can be seen well when drawn against bg. Otherwise it returns either BLACK or WHITE.

Color get_color_index Color  color  ) 
 

Return the rgb form of color. If it is an indexed color that entry is returned. If it is an rgb color it is returned unchanged.

Color inactive Color  c,
Flags  f
 

Same as (f&INACTIVE_R) ? inactive(c) : c

Color inactive Color  c  ) 
 

Same as lerp(c, GRAY75, .7), it grays out the color.

Color lerp Color  color0,
Color  color1,
float  weight
 

Return (1-weight)*color0 + weight*color1. weight is clamped to the 0-1 range before use.

Color nearest_index Color  i  ) 
 

Find an indexed color in the range 56-127 that is closest to this color. If this is an indexed color it is returned unchanged.

Color parsecolor const char *  name,
unsigned  length
 

Turn the first n bytes of name into an fltk color. This allows you to parse a color out of the middle of a string.

Recognized values are:

  • "" turns into NO_COLOR
  • "0"-"99" decimal fltk color number, only works for indexed color range
  • "0xnnn" hex value of any fltk color number
  • "rgb" or "#rgb" three hex digits for rgb
  • "rrggbb" or "#rrggbb" 2 hex digits for each of rgb
  • "rrggbbaa" or "#rrggbbaa" fltk color number in hex
  • "rrrgggbbb" or "#rrrgggbbb" 3 hex digits for each of rgb
  • "rrrrggggbbbb" or "#rrrrggggbbbb" 4 hex digits for each of rgb
  • 17 "web safe colors" as defined by CSS 2.1
  • If FLTK is compiled to use X11, then XParseColor() is tried
  • all other strings return NO_COLOR.

void set_background Color  c  ) 
 

GRAY75 is replaced with the passed color, and all the other GRAY* colors are replaced with a color ramp (or sometimes a straight line) so that using them for highlighted edges of raised buttons looks correct.

void set_color_index Color  i,
Color  color
 

Set one of the indexed colors to the given rgb color. i must be in the range 0-255, and c must be a non-indexed rgb color.

void split_color Color  i,
unsigned char &  r,
unsigned char &  g,
unsigned char &  b
 

Set r,g,b to the 8-bit components of this color. If it is an indexed color they are looked up in the table, otherwise they are simply copied out of the color number.


Sun Jan 7 00:55:16 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.