Color and Line Style
[Drawing Functions]


Typedefs

typedef unsigned fltk::Color

Enumerations

enum  {
  fltk::NO_COLOR, fltk::GRAY00, fltk::GRAY05, fltk::GRAY10,
  fltk::GRAY15, fltk::GRAY20, fltk::GRAY25, fltk::GRAY30,
  fltk::GRAY33, fltk::GRAY35, fltk::GRAY40, fltk::GRAY45,
  fltk::GRAY50, fltk::GRAY55, fltk::GRAY60, fltk::GRAY65,
  fltk::GRAY66, fltk::GRAY70, fltk::GRAY75, fltk::GRAY80,
  fltk::GRAY85, fltk::GRAY90, fltk::GRAY95, fltk::GRAY99,
  fltk::BLACK, fltk::RED, fltk::GREEN, fltk::YELLOW,
  fltk::BLUE, fltk::MAGENTA, fltk::CYAN, fltk::WHITE,
  fltk::WINDOWS_BLUE
}
enum  {
  SOLID, DASH, DOT, DASHDOT,
  DASHDOTDOT, CAP_FLAT, CAP_ROUND, CAP_SQUARE,
  JOIN_MITER, JOIN_ROUND, JOIN_BEVEL
}

Functions

Color fltk::color (const char *)
Color fltk::color (unsigned char g)
Color fltk::color (unsigned char r, unsigned char g, unsigned char b)
Color fltk::contrast (Color fg, Color bg)
Flags fltk::drawflags (Flags f)
Flags fltk::drawflags ()
const Style * fltk::drawstyle ()
void fltk::drawstyle (const Style *s, Flags)
Color fltk::get_color_index (Color index)
Color fltk::getbgcolor ()
Color fltk::getcolor ()
Color fltk::inactive (Color, Flags f)
Color fltk::inactive (Color)
Color fltk::lerp (Color c0, Color c1, float f)
void fltk::line_style (int, int width=0, char *dashes=0)
Color fltk::nearest_index (Color)
void fltk::set_background (Color)
void fltk::set_color_index (Color index, Color)
void fltk::setbgcolor (Color c)
void fltk::setcolor (Color)
void fltk::setdrawflags (Flags f)
void fltk::split_color (Color c, unsigned char &r, unsigned char &g, unsigned char &b)

Variables

Color current_bgcolor_
Color current_color_
Flags drawflags_
const Styledrawstyle_

Typedef Documentation

Color
 

fltk::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 fltk::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 (fltk::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 fltk::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 fltk::set_background() so that the color fltk::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 fltk::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
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 unsigned char  red,
unsigned char  green,
unsigned char  blue
[inline]
 

Uses shift and add to make an rgb color out of the 8-bit components.

Color color unsigned char  gray  )  [inline]
 

Makes a gray-scale color using an 8-bit gray level. This is done by multiplying gray by 0x1010100.

fltk::Color color const char *  name  ) 
 

Turn a string into a color. On X this uses XParseColor to lookup named colors like "red".

On other platforms it only understands colors of the form "n,n,n" or hex strings of 3, 6, 9, or 12 digits. Maybe we should add the standard web color names, there are only 16 of them.

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 inactive Color  c  ) 
 

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

Color inactive Color  c,
Flags  f
 

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

Color contrast Color  fg,
Color  bg
 

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

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.

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.

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.

void set_background Color  c  ) 
 

fltk::GRAY75 is replaced with the passed color, and all the other fltk::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.

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.

void setcolor Color   ) 
 

Set the color for all subsequent drawing operations.

Color getcolor  )  [inline]
 

Returns the last Color passed to setcolor().

void setbgcolor Color  c  )  [inline]
 

Set the "background" color. This is not used by the drawing functions, but many box and image types will refer to it by calling getbgcolor().

Color getbgcolor  )  [inline]
 

Returns the last Color passed to setbgcolor(). To actually draw in the bg color, do this:

  Color saved = getcolor();
  setcolor(getbgcolor());
  draw_stuff();
  setcolor(saved)

void drawstyle const Style style,
Flags  flags
 

Draw using this style. Set drawstyle() to this, drawflags() to flags, calls setcolor() and setbgcolor() with appropriate colors for this style and the given flags, and calls setfont(). This is called by the draw() methods on most fltk widgets. The calling Widget picks what flags to pass to the Symbols so that when they call this they get the correct colors for each part of the widget.

Flags that are understood:

  • HIGHLIGHT: if highlight_color() is non-zero, set bg to highlight_color() and fg to highlight_textcolor().
  • SELECTED: if selection_color() is non-zero, set bg to selection_color() and fg to selection_textcolor().
  • OUTPUT: Normally color(), textcolor(), textfont(), and textsize() are used. If this flag is set buttoncolor(), labelcolor(), labelfont(), and labelsize() are used. Widgets will set this true for any internal buttons, but false for the main area.
  • INACTIVE: Change the fg to a gray color.

It then further modifies fg so that it contrasts with the bg.

const Style * drawstyle  )  [inline]
 

Return the last style sent to drawstyle(s,f). Some drawing functions (such as glyphs) look in this for box types. If this has not been called it is Widget::default_style.

void setdrawflags Flags  f  )  [inline]
 

Store a set of bit flags that may influence the drawing of some fltk::Symbol subclasses, such as boxes. Generally you must also use setcolor() and setbgcolor() to set the color you expect as not all symbols draw differently depending on the flags.

The flags are usually copied from the flags() on a Widget.

Some commonly-used flags:

  • INACTIVE : Draw inactive, fill images with solid fg color
  • VALUE: Draw turned on or checked
  • SELECTED: Draw as though selected in a browser or menu.
  • HIGHLIGHT: Draw as though highlighted with the mouse pointing at it
  • PUSHED: The mouse is pushing this button. This also inverts VALUE.
  • FOCUSED: Indicates that the current object has keyboard focus.
  • INVISIBLE: Some boxes don't draw their interior if this is set

See also:
fltk::drawstyle()

Flags drawflags  )  [inline]
 

Return the last flags passed to setdrawflags().

Flags drawflags Flags  f  )  [inline]
 

Same as (drawflags() & f), returns true if any of the flags in f are set.

void line_style int  style,
int  width = 0,
char *  dashes = 0
 

Set how to draw lines (the "pen"). If you change this it is your responsibility to set it back to the default with fltk::line_style(0).

style is a bitmask in which you 'or' the following values. If you don't specify a dash type you will get a solid line. If you don't specify a cap or join type you will get a system-defined default of whatever value is fastest.

  • fltk::SOLID -------
  • fltk::DASH - - - -
  • fltk::DOT ·········
  • fltk::DASHDOT - · - ·
  • fltk::DASHDOTDOT - ·· - ··
  • fltk::CAP_FLAT
  • fltk::CAP_ROUND
  • fltk::CAP_SQUARE (extends past end point 1/2 line width)
  • fltk::JOIN_MITER (pointed)
  • fltk::JOIN_ROUND
  • fltk::JOIN_BEVEL (flat)

width is the number of pixels thick to draw the lines. Zero results in the system-defined default, which on both X and Windows is somewhat different and nicer than 1.

dashes is a pointer to an array of dash lengths, measured in pixels. The first location is how long to draw a solid portion, the next is how long to draw the gap, then the solid, etc. It is terminated with a zero-length entry. A null pointer or a zero-length array results in a solid line. Odd array sizes are not supported and result in undefined behavior. The dashes array is ignored on Windows 95/98.


Sun May 8 21:48:57 2005. FLTK ©2004 Bill Spitzak and others. See Main Page for details.