fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Color & Font functions

Functions

static void Fl::set_color (Fl_Color, uchar, uchar, uchar)
static void Fl::set_color (Fl_Color i, unsigned c)
static unsigned Fl::get_color (Fl_Color i)
static void Fl::get_color (Fl_Color i, uchar &red, uchar &green, uchar &blue)
static void Fl::free_color (Fl_Color i, int overlay=0)
static const char * Fl::get_font (Fl_Font)
static const char * Fl::get_font_name (Fl_Font, int *attributes=0)
static int Fl::get_font_sizes (Fl_Font, int *&sizep)
static void Fl::set_font (Fl_Font, const char *)
static void Fl::set_font (Fl_Font, Fl_Font)
static Fl_Font Fl::set_fonts (const char *=0)
void fl_color (Fl_Color c)
void fl_color (int c)
void fl_color (uchar r, uchar g, uchar b)
Fl_Color fl_color ()
void fl_font (Fl_Font face, Fl_Fontsize size)
Fl_Font fl_font ()
Fl_Fontsize fl_size ()
FL_EXPORT int fl_height ()
FL_EXPORT int fl_height (int font, int size)
FL_EXPORT int fl_descent ()
FL_EXPORT double fl_width (const char *txt)
FL_EXPORT double fl_width (const char *txt, int n)
FL_EXPORT double fl_width (unsigned int)
FL_EXPORT void fl_text_extents (const char *, int &dx, int &dy, int &w, int &h)
FL_EXPORT void fl_text_extents (const char *, int n, int &dx, int &dy, int &w, int &h)
FL_EXPORT const char * fl_latin1_to_local (const char *t, int n=-1)
FL_EXPORT const char * fl_local_to_latin1 (const char *t, int n=-1)
FL_EXPORT const char * fl_mac_roman_to_local (const char *t, int n=-1)
FL_EXPORT const char * fl_local_to_mac_roman (const char *t, int n=-1)
FL_EXPORT Fl_Color fl_show_colormap (Fl_Color oldcol)
 Pops up a window to let the user pick an colormap entry.
ulong fl_xpixel (uchar r, uchar g, uchar b)
ulong fl_xpixel (Fl_Color i)
Fl_Color fl_color_average (Fl_Color color1, Fl_Color color2, float weight)
Fl_Color fl_inactive (Fl_Color c)
Fl_Color fl_contrast (Fl_Color fg, Fl_Color bg)

Variables

FL_EXPORT Fl_Color fl_color_
 The current color.
FL_EXPORT Fl_Font fl_font_
 current font index
FL_EXPORT Fl_Fontsize fl_size_
 current font size

Detailed Description

fl global color, font functions. These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.


Function Documentation

void fl_color ( Fl_Color  c) [inline]

Sets the color for all subsequent drawing operations. For colormapped displays, a color cell will be allocated out of fl_colormap the first time you use a color. If the colormap fills up then a least-squares algorithm is used to find the closest color. If no valid graphical context (fl_gc) is available, the foreground is not set for the current window.

Parameters:
[in]ccolor

Definition at line 61 of file fl_draw.H.

References Fl_Graphics_Driver::color(), and fl_graphics_driver.

Referenced by Fl_Text_Display::clear_rect(), Fl_Timer::draw(), Fl_FormsPixmap::draw(), Fl_FormsBitmap::draw(), Fl_Window::draw(), Fl_Value_Slider::draw(), Fl_Value_Output::draw(), Fl_Tree_Item::draw(), Fl_TooltipBox::draw(), Fl_Slider::draw(), Fl_Scrollbar::draw(), Fl_Scroll::draw(), Fl_Roller::draw(), Fl_Positioner::draw(), Fl_Pack::draw(), Fl_Menu_Button::draw(), Fl_Menu_Bar::draw(), Fl_Menu_Item::draw(), Fl_Light_Button::draw(), Fl_File_Icon::draw(), Fl_Dial::draw(), Fl_Counter::draw(), Fl_Clock_Output::draw(), Fl_Choice::draw(), Fl_Browser_::draw(), Fl_Adjuster::draw(), Shortcut_Button::draw(), Fl_Text_Display::draw_cursor(), Fl_Image::draw_empty(), Fl_Widget::draw_focus(), Fl_Tree_Item::draw_horizontal_connector(), Fl_Window_Type::draw_overlay(), Fl_Text_Display::draw_string(), Fl_Tree_Item::draw_vertical_connector(), Fl_Input_::drawtext(), fl_color(), fl_down_box(), fl_draw(), fl_drw_text(), fl_drw_text_beside(), fl_embossed_box(), fl_engraved_box(), fl_frame(), fl_frame2(), fl_normal_label(), fl_rect(), fl_rectbound(), fl_rectf(), fl_return_arrow(), fl_thin_down_box(), fl_thin_up_box(), fl_up_box(), gtk_round_down_box(), gtk_round_up_box(), Fl_Help_Font_Stack::init(), Fl_Browser::item_draw(), Fl_Image::labeltype(), Fl_Help_Font_Stack::pop(), and Fl_Help_Font_Stack::push().

void fl_color ( int  c) [inline]

for back compatibility - use fl_color(Fl_Color c) instead

Definition at line 63 of file fl_draw.H.

References fl_color().

void fl_color ( uchar  r,
uchar  g,
uchar  b 
) [inline]

Set the color for all subsequent drawing operations. The closest possible match to the RGB color is used. The RGB color is used directly on TrueColor displays. For colormap visuals the nearest index in the gray ramp or color cube is used. If no valid graphical context (fl_gc) is available, the foreground is not set for the current window.

Parameters:
[in]r,g,bcolor components

Definition at line 74 of file fl_draw.H.

References Fl_Graphics_Driver::color(), and fl_graphics_driver.

Fl_Color fl_color ( ) [inline]

Returns the last fl_color() that was set. This can be used for state save/restore.

Definition at line 81 of file fl_draw.H.

References fl_color_.

Fl_Color fl_color_average ( Fl_Color  color1,
Fl_Color  color2,
float  weight 
)

Returns the weighted average color between the two given colors. The red, green and blue values are averages using the following formula:

  color = color1 * weight  + color2 * (1 - weight)

Thus, a weight value of 1.0 will return the first color, while a value of 0.0 will return the second color.

Parameters:
[in]color1,color2boundary colors
[in]weightweighting factor

Definition at line 414 of file fl_color.cxx.

References b, and fl_rgb_color().

Referenced by Fl_Text_Display::clear_rect(), Fl_Window::draw(), Fl_Menu_Item::draw(), Fl_Light_Button::draw(), Fl_Clock_Output::draw(), Fl_Text_Display::draw_string(), fl_darker(), fl_inactive(), fl_lighter(), gtk_round_down_box(), gtk_round_up_box(), Fl_File_Icon::load_fti(), and shade_color().

Fl_Color fl_contrast ( Fl_Color  fg,
Fl_Color  bg 
)

Returns a color that contrasts with the background color. This will be the foreground color if it contrasts sufficiently with the background color. Otherwise, returns FL_WHITE or FL_BLACK depending on which color provides the best contrast.

Parameters:
[in]fg,bgforeground and background colors
Returns:
contrasting color

Definition at line 447 of file fl_color.cxx.

References FL_BLACK, and FL_WHITE.

Referenced by Fl::background2(), color2_cb(), color_cb(), Fl_Progress::draw(), Fl_Menu_Item::draw(), Fl_Choice::draw(), Fl_Button::draw(), Fl_Widget::draw_focus(), Fl_Text_Display::draw_string(), Fl_Input_::drawtext(), Fl_Choice::handle(), Fl_Browser::item_draw(), labelcolor_cb(), and textcolor_cb().

FL_EXPORT int fl_descent ( )

Returns the recommended distance above the bottom of a fl_height() tall box to draw the text at so it looks centered vertically in that box.

Definition at line 257 of file fl_font_mac.cxx.

References check_default_font, and current_font.

Referenced by Fl_Tree_Item::draw(), Fl_Text_Display::draw_string(), Fl_Input_::drawtext(), fl_draw(), and fl_text_extents().

Fl_Font fl_font ( ) [inline]

Returns the face set by the most recent call to fl_font(). This can be used to save/restore the font.

Definition at line 459 of file fl_draw.H.

References fl_font_.

void fl_font ( Fl_Font  face,
Fl_Fontsize  size 
) [inline]

Sets the current font, which is then used in various drawing routines. You may call this outside a draw context if necessary to call fl_width(), but on X this will open the display.

The font is identified by a face and a size. The size of the font is measured in pixels and not "points". Lines should be spaced size pixels apart or more.

Definition at line 452 of file fl_draw.H.

References fl_graphics_driver, and Fl_Graphics_Driver::font().

Referenced by Fl_Timer::draw(), Fl_Value_Slider::draw(), Fl_Value_Output::draw(), Fl_Tree_Item::draw(), Fl_Tree::draw(), Fl_TooltipBox::draw(), Fl_Counter::draw(), Fl_Chart::draw(), Shortcut_Button::draw(), Fl_Text_Display::draw_string(), fl_drw_text(), fl_drw_text_beside(), fl_height(), fl_normal_label(), fl_normal_measure(), Fl_Input_Choice_Type::ideal_size(), Fl_Value_Output_Type::ideal_size(), Fl_Value_Input_Type::ideal_size(), Fl_Output_Type::ideal_size(), Fl_Help_View_Type::ideal_size(), Fl_Text_Editor_Type::ideal_size(), Fl_Text_Display_Type::ideal_size(), Fl_File_Input_Type::ideal_size(), Fl_Input_Type::ideal_size(), Fl_Spinner_Type::ideal_size(), Fl_File_Browser_Type::ideal_size(), Fl_Check_Browser_Type::ideal_size(), Fl_Browser_Type::ideal_size(), Fl_Tabs_Type::ideal_spacing(), Fl_Help_Font_Stack::init(), Fl_Browser::item_draw(), Fl_Browser::item_height(), Fl_Browser::item_width(), Fl_TooltipBox::layout(), Fl_Input_::linesPerPage(), Fl_Help_Font_Stack::pop(), Fl_Help_Font_Stack::push(), resizeform(), Fl::set_font(), and Fl_Text_Display::string_width().

FL_EXPORT int fl_height ( int  font,
int  size 
)

This function returns the actual height of the specified font and size. Normally the font height should always be 'size', but with the advent of XFT, there are (currently) complexities that seem to only be solved by asking the font what its actual font height is. (See STR#2115)

This function was originally undocumented in 1.1.x, and was used only by Fl_Text_Display. We're now documenting it in 1.3.x so that apps that need precise height info can get it with this function.

Returns:
the height of the font in pixels.
Todo:
In the future, when the XFT issues are resolved, this function should simply return the 'size' value.

Definition at line 476 of file fl_draw.cxx.

References fl_font(), fl_height(), fl_size(), and height.

FL_EXPORT const char* fl_latin1_to_local ( const char *  t,
int  n = -1 
)

convert text from Windows/X11 latin1 charcter set to local encoding.

Parameters:
[in]tcharacter string (latin1 encoding)
[in]noptional number of characters to convert (default is all)
Returns:
pointer to internal buffer containing converted characters

Definition at line 123 of file fl_encoding_latin1.cxx.

FL_EXPORT const char* fl_local_to_latin1 ( const char *  t,
int  n = -1 
)

convert text from local encoding to Windowx/X11 latin1 character set.

Parameters:
[in]tcharacter string (local encoding)
[in]noptional number of characters to convert (default is all)
Returns:
pointer to internal buffer containing converted characters

Definition at line 128 of file fl_encoding_latin1.cxx.

FL_EXPORT const char* fl_local_to_mac_roman ( const char *  t,
int  n = -1 
)

convert text from local encoding to Mac Roman character set.

Parameters:
[in]tcharacter string (local encoding)
[in]noptional number of characters to convert (default is all)
Returns:
pointer to internal buffer containing converted characters

Definition at line 88 of file fl_encoding_mac_roman.cxx.

References buf.

FL_EXPORT const char* fl_mac_roman_to_local ( const char *  t,
int  n = -1 
)

convert text from Mac Roman charcter set to local encoding.

Parameters:
[in]tcharacter string (Mac Roman encoding)
[in]noptional number of characters to convert (default is all)
Returns:
pointer to internal buffer containing converted characters

Definition at line 109 of file fl_encoding_mac_roman.cxx.

References buf.

FL_EXPORT Fl_Color fl_show_colormap ( Fl_Color  oldcol)

Pops up a window to let the user pick an colormap entry.

fl_show_colormap.png
Parameters:
[in]oldcolcolor to be highlighted when grid is shown.
Return values:
Fl_Colorvalue of the chosen colormap entry.
See also:
Fl_Color_Chooser

Definition at line 155 of file fl_show_colormap.cxx.

References m, and ColorMenu::run().

Referenced by color2_cb(), color_cb(), labelcolor_cb(), and textcolor_cb().

Fl_Fontsize fl_size ( ) [inline]

Returns the size set by the most recent call to fl_font(). This can be used to save/restore the font.

Definition at line 466 of file fl_draw.H.

References fl_size_.

Referenced by fl_height().

FL_EXPORT void fl_text_extents ( const char *  ,
int  n,
int &  dx,
int &  dy,
int &  w,
int &  h 
)

Determine the minimum pixel dimensions of a sequence of n characters.

See also:
fl_text_extents(const char*, int& dx, int& dy, int& w, int& h)

Definition at line 394 of file fl_font_mac.cxx.

References current_font, dh, EXTENTS_UPDATE, Fl::first_window(), fl_descent(), fl_gc, fl_height(), fl_measure(), fl_text_extents(), fl_utf8toUtf16(), fl_width(), fl_xid(), gi, H, h, int, and NULL.

FL_EXPORT void fl_text_extents ( const char *  ,
int &  dx,
int &  dy,
int &  w,
int &  h 
)

Determine the minimum pixel dimensions of a nul-terminated string.

Usage: given a string "txt" drawn using fl_draw(txt, x, y) you would determine its pixel extents on the display using fl_text_extents(txt, dx, dy, wo, ho) such that a bounding box that exactly fits around the text could be drawn with fl_rect(x+dx, y+dy, wo, ho). Note the dx, dy values hold the offset of the first "colored in" pixel of the string, from the draw origin.

Definition at line 75 of file fl_font.cxx.

References fl_text_extents().

Referenced by fl_text_extents().

FL_EXPORT double fl_width ( const char *  txt,
int  n 
)

Return the typographical width of a sequence of n characters

Definition at line 317 of file fl_font_mac.cxx.

References current_font, fl_nonspacing(), fl_utf8decode(), fl_width(), i, w, and XUtf8TextWidth().

FL_EXPORT double fl_width ( unsigned  int)

Return the typographical width of a single character :

Note:
if a valid fl_gc is NOT found then it uses the first window gc, or the screen gc if no fltk window is available when called.

Definition at line 327 of file fl_font_mac.cxx.

References current_font, Fl::fatal, Fl::first_window(), fl_gc, fl_width(), fl_xid(), gc, i, NULL, and XUtf8UcsWidth().

ulong fl_xpixel ( uchar  r,
uchar  g,
uchar  b 
)

Returns the X pixel number used to draw the given rgb color. This is the X pixel that fl_color() would use.

Parameters:
[in]r,g,bcolor components
Returns:
X pixel number

Definition at line 162 of file fl_color.cxx.

References fl_bluemask, fl_blueshift, FL_COLOR_CUBE, fl_color_cube(), fl_extrashift, fl_greenmask, fl_greenshift, FL_NUM_BLUE, FL_NUM_GREEN, FL_NUM_RED, fl_overlay, fl_redmask, fl_redshift, fl_xpixel(), i, Fl_XColor::mapped, and Fl_XColor::pixel.

ulong fl_xpixel ( Fl_Color  i)

Returns the X pixel number used to draw the given FLTK color index. This is the X pixel that fl_color() would use.

Parameters:
[in]icolor index
Returns:
X pixel number

Definition at line 215 of file fl_color.cxx.

References Fl_XColor::b, b, fl_bluemask, fl_blueshift, fl_colormap, fl_display, fl_extrashift, fl_greenmask, fl_greenshift, fl_overlay, fl_redmask, fl_redshift, fl_visual, fl_xpixel(), Fl_XColor::g, i, int, Fl_XColor::mapped, Fl_XColor::pixel, and Fl_XColor::r.

Referenced by Fl_Xlib_Graphics_Driver::color(), and fl_xpixel().

void Fl::free_color ( Fl_Color  i,
int  overlay = 0 
) [static, inherited]

Frees the specified color from the colormap, if applicable. If overlay is non-zero then the color is freed from the overlay colormap.

Free color i if used, and clear mapping table entry.

Parameters:
[in]icolor index
[in]overlay0 for normal, 1 for overlay color

Definition at line 328 of file fl_color.cxx.

References fl_colormap, fl_display, i, and Fl_XColor::mapped.

Referenced by Fl::set_color().

unsigned Fl::get_color ( Fl_Color  i) [static, inherited]

Returns the RGB value(s) for the given FLTK color index.

This form returns the RGB values packed in a 32-bit unsigned integer with the red value in the upper 8 bits, the green value in the next 8 bits, and the blue value in bits 8-15. The lower 8 bits will always be 0.

Definition at line 371 of file fl_color.cxx.

References i.

Referenced by Fl::background2(), Fl_PostScript_Graphics_Driver::color(), Fl_Pixmap::color_average(), Fl_RGB_Image::color_average(), Fl_Window::cursor(), fl_draw_pixmap(), Fl::reload_scheme(), and shade_color().

void Fl::get_color ( Fl_Color  i,
uchar red,
uchar green,
uchar blue 
) [static, inherited]

Returns the RGB value(s) for the given FLTK color index.

This form returns the red, green, and blue values separately in referenced variables.

See also unsigned get_color(Fl_Color c)

Definition at line 392 of file fl_color.cxx.

References i.

const char * Fl::get_font ( Fl_Font  fnum) [static, inherited]

Gets the string for this face. This string is different for each face. Under X this value is passed to XListFonts to get all the sizes of this face.

Definition at line 93 of file fl_set_font.cxx.

References fl_fonts, and Fl_Fontdesc::name.

Referenced by Fl::set_font().

const char * Fl::get_font_name ( Fl_Font  fnum,
int *  attributes = 0 
) [static, inherited]

Get a human-readable string describing the family of this face. This is useful if you are presenting a choice to the user. There is no guarantee that each face has a different name. The return value points to a static buffer that is overwritten each call.

The integer pointed to by attributes (if the pointer is not zero) is set to zero, FL_BOLD or FL_ITALIC or FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search forward and back for a set with non-zero attributes, these faces along with the face with a zero attribute before them constitute a family.

Definition at line 44 of file fl_set_fonts_mac.cxx.

References ENDOFBUFFER, f, FL_BOLD, fl_fonts, FL_ITALIC, Fl_Fontdesc::fontname, Fl_Fontdesc::name, strlcpy, and type.

int Fl::get_font_sizes ( Fl_Font  fnum,
int *&  sizep 
) [static, inherited]

Return an array of sizes in sizep. The return value is the length of this array. The sizes are sorted from smallest to largest and indicate what sizes can be given to fl_font() that will be matched exactly (fl_font() will pick the closest size for other sizes). A zero in the first location of the array indicates a scalable font, where any size works, although the array may list sizes that work "better" than others. Warning: the returned array points at a static buffer that is overwritten each call. Under X this will open the display.

Definition at line 137 of file fl_set_fonts_mac.cxx.

References fl_fonts, and Fl_Fontdesc::name.

void Fl::set_color ( Fl_Color  i,
unsigned  c 
) [static, inherited]

Sets an entry in the fl_color index table. You can set it to any 8-bit RGB color. The color is not allocated until fl_color(i) is used.

Set color mapping table entry i to color c

Parameters:
[in]icolor index
[in]ccolor

Definition at line 352 of file fl_color.cxx.

References Fl::free_color(), and i.

void Fl::set_color ( Fl_Color  i,
uchar  red,
uchar  green,
uchar  blue 
) [static, inherited]

Sets an entry in the fl_color index table. You can set it to any 8-bit RGB color. The color is not allocated until fl_color(i) is used.

Definition at line 380 of file fl_color.cxx.

Referenced by Fl::background(), Fl::background2(), fl_mapcolor(), and Fl::foreground().

void Fl::set_font ( Fl_Font  fnum,
const char *  name 
) [static, inherited]

Changes a face. The string pointer is simply stored, the string is not copied, so the string must be in static memory.

Definition at line 43 of file fl_set_font.cxx.

References f, Fl_Fontdesc::first, fl_font(), fl_fonts, FL_FREE_FONT, Fl_Fontdesc::fontname, i, Fl_Fontdesc::n, name, Fl_Fontdesc::name, and Fl_Fontdesc::xlist.

Referenced by fl_set_font_name(), Fl::set_font(), and Fl::set_fonts().

void Fl::set_font ( Fl_Font  fnum,
Fl_Font  from 
) [static, inherited]

Copies one face to another.

Definition at line 85 of file fl_set_font.cxx.

References Fl::get_font(), and Fl::set_font().

Fl_Font Fl::set_fonts ( const char *  xstarname = 0) [static, inherited]

FLTK will open the display, and add every fonts on the server to the face table. It will attempt to put "families" of faces together, so that the normal one is first, followed by bold, italic, and bold italic.

The optional argument is a string to describe the set of fonts to add. Passing NULL will select only fonts that have the ISO8859-1 character set (and are thus usable by normal text). Passing "-*" will select all fonts with any encoding as long as they have normal X font names with dashes in them. Passing "*" will list every font that exists (on X this may produce some strange output). Other values may be useful but are system dependent. With WIN32 NULL selects fonts with ISO8859-1 encoding and non-NULL selects all fonts.

The return value is how many faces are in the table after this is done.

Definition at line 61 of file fl_set_fonts_mac.cxx.

References FL_FREE_FONT, fl_mac_os_version, fl_open_display(), i, NULL, Fl::set_font(), and value.


Variable Documentation

FL_EXPORT Fl_Color fl_color_

The current color.

Current color for drawing operations

Definition at line 128 of file fl_color.cxx.

Referenced by Fl_PostScript_Graphics_Driver::color(), Fl_Xlib_Graphics_Driver::color(), and fl_color().

FL_EXPORT Fl_Font fl_font_

current font index

Definition at line 236 of file fl_font_mac.cxx.

Referenced by fl_font(), and fl_xxfont().

FL_EXPORT Fl_Fontsize fl_size_

current font size

Definition at line 237 of file fl_font_mac.cxx.

Referenced by fl_font(), fl_size(), and fl_xxfont().