FLTK 1.4.0
|
fl global color, font functions. More...
Functions | |
Fl_Color | fl_color () |
Return the last fl_color() that was set. More... | |
void | fl_color (Fl_Color c) |
Set the color for all subsequent drawing operations. More... | |
void | fl_color (int c) |
for back compatibility - use fl_color(Fl_Color c) instead | |
void | fl_color (uchar r, uchar g, uchar b) |
Set the color for all subsequent drawing operations. More... | |
Fl_Color | fl_color_average (Fl_Color color1, Fl_Color color2, float weight) |
Returns the weighted average color between the two given colors. More... | |
Fl_Color | fl_contrast (Fl_Color fg, Fl_Color bg, int context, int size) |
Returns a color that contrasts with the background color. More... | |
void | fl_contrast_function (Fl_Contrast_Function *f) |
Register a custom contrast function. More... | |
int | fl_contrast_level () |
Get the contrast level (sensitivity) of the fl_contrast() method. More... | |
void | fl_contrast_level (int level) |
Set the contrast level (sensitivity) of the fl_contrast() method. More... | |
int | fl_contrast_mode () |
Return the current contrast algorithm (mode). More... | |
void | fl_contrast_mode (int mode) |
Set the contrast algorithm (mode). More... | |
int | fl_descent () |
Return 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. | |
Fl_Font | fl_font () |
Return the face set by the most recent call to fl_font(). More... | |
void | fl_font (Fl_Font face, Fl_Fontsize fsize) |
Sets the current font, which is then used in various drawing routines. More... | |
int | fl_height () |
Return the recommended minimum line spacing for the current font. More... | |
int | fl_height (int font, int size) |
This function returns the actual height of the specified font and size . More... | |
Fl_Color | fl_inactive (Fl_Color c) |
Returns the inactive, dimmed version of the given color. | |
const char * | fl_latin1_to_local (const char *t, int n=-1) |
Convert text from Windows/X11 latin1 character set to local encoding. More... | |
double | fl_lightness (Fl_Color color) |
Return the perceived lightness of a color. More... | |
const char * | fl_local_to_latin1 (const char *t, int n=-1) |
Convert text from local encoding to Windows/X11 latin1 character set. More... | |
const char * | fl_local_to_mac_roman (const char *t, int n=-1) |
Convert text from local encoding to Mac Roman character set. More... | |
double | fl_luminance (Fl_Color color) |
Return the raw / physical luminance of a color. More... | |
const char * | fl_mac_roman_to_local (const char *t, int n=-1) |
Convert text from Mac Roman character set to local encoding. More... | |
Fl_Color | fl_show_colormap (Fl_Color oldcol) |
Pops up a window to let the user pick a colormap entry. More... | |
Fl_Fontsize | fl_size () |
Return the size set by the most recent call to fl_font(). More... | |
void | fl_text_extents (const char *, int &dx, int &dy, int &w, int &h) |
Determine the minimum pixel dimensions of a nul-terminated string using the current fl_font(). More... | |
void | fl_text_extents (const char *t, int n, int &dx, int &dy, int &w, int &h) |
Determine the minimum pixel dimensions of a sequence of n characters (bytes) using the current fl_font(). More... | |
double | fl_width (const char *txt) |
Return the typographical width of a nul-terminated string using the current font face and size. | |
double | fl_width (const char *txt, int n) |
Return the typographical width of a sequence of n characters using the current font face and size. | |
double | fl_width (unsigned int c) |
Return the typographical width of a single character using the current font face and size. More... | |
static void | Fl::free_color (Fl_Color i, int overlay=0) |
Frees the specified color from the colormap, if applicable. More... | |
static unsigned | Fl::get_color (Fl_Color i) |
Returns the RGB value(s) for the given FLTK color index. More... | |
static void | Fl::get_color (Fl_Color i, uchar &red, uchar &green, uchar &blue) |
Returns the RGB value(s) for the given FLTK color index. More... | |
static void | Fl::get_color (Fl_Color i, uchar &red, uchar &green, uchar &blue, uchar &alpha) |
Returns the RGBA value(s) for the given FLTK color index. More... | |
static const char * | Fl::get_font (Fl_Font) |
Gets the string for this face. More... | |
static const char * | Fl::get_font_name (Fl_Font, int *attributes=0) |
Get a human-readable string describing the family of this face. More... | |
static int | Fl::get_font_sizes (Fl_Font, int *&sizep) |
Return an array of sizes in sizep . More... | |
static void | Fl::set_color (Fl_Color i, unsigned c) |
Sets an entry in the fl_color index table. More... | |
static void | Fl::set_color (Fl_Color, uchar, uchar, uchar) |
Sets an entry in the fl_color index table. More... | |
static void | Fl::set_color (Fl_Color, uchar, uchar, uchar, uchar) |
Sets an entry in the fl_color index table. More... | |
static void | Fl::set_font (Fl_Font, const char *) |
Changes a face. More... | |
static void | Fl::set_font (Fl_Font, Fl_Font) |
Copies one face to another. | |
static Fl_Font | Fl::set_fonts (const char *=0) |
FLTK will open the display, and add every fonts on the server to the face table. More... | |
fl global color, font functions.
These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.
|
inline |
Return the last fl_color() that was set.
This can be used for state save/restore.
|
inline |
Set the color for all subsequent drawing operations.
For color-mapped 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.
[in] | c | color |
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.
[in] | r,g,b | color components |
Returns the weighted average color between the two given colors.
The red, green and blue values are averages using the following formula:
Thus, a weight
value of 1.0 will return the first color, while a value of 0.0 will return the second color.
[in] | color1,color2 | boundary colors |
[in] | weight | weighting factor |
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.
FLTK 1.4.0 uses a different default contrast function than earlier releases (1.3.x) but you can use the old "legacy" contrast function by calling
early in your main program.
You can change the behavior of fl_contrast() in several ways:
Change the "level" (sensitivity) for contrast calculation, see fl_contrast_level(). Valid levels are 0 - 100, the default "medium" value depends on the contrast mode. If you raise the level above the default value the overall contrast will generally be higher, i.e. the required contrast to return the foreground color is raised and therefore the calculated color switches "earlier" to either black or white. In other words, using the following values:
Changing the level
is particularly useful and intended for the "legacy mode" to improve the results partially. Values slightly above 50 (50 - 70) will likely return the best results (50 is the default, as used in FLTK 1.3.x).
The following contrast functions are available:
In the future we may provide even more (and superior) contrast algorithms.
The new parameters context
and size
(since 1.4.0) are defined for future extensions and are currently not used. Default values are 0.
context
is intended to differentiate text and other kinds of objects, e.g. radio buttons, check marks, or icon types.size
parameter is an unspecified (object) size that may be used to calculate the required contrast. In text mode this must be the font size. Rule: the larger the object (font), the lower the required contrast.[in] | fg | foreground (text) color |
[in] | bg | background color |
[in] | context | graphical context (optional, default = 0 == text) |
[in] | size | unspecified size (optional, default = 0 == undefined) |
fg
, FL_BLACK
, or FL_WHITE
void fl_contrast_function | ( | Fl_Contrast_Function * | f | ) |
Register a custom contrast function.
Your custom contrast function will be called when fl_contrast() is called if and only if you previously registered your function and called fl_contrast_mode(FL_CONTRAST_CUSTOM) .
Your custom contrast function must provide the signature
The arguments are the same as for the full fl_contrast() function since FLTK 1.4. You can use the supplied size
to modify the result. Depending on the caller the size
parameter can be 0 (default) or a valid size. In the context of text, i.e. context
== 0, the size
parameter is the fontsize.
The context
parameter is not yet used and will always be 0 unless included in a call to fl_contrast(). The value 0 must be interpreted as text. In the future the context
argument will be used to supply a different context than text (small icons, large icons, etc.). The exact usage is not yet specified.
Your function may also use fl_contrast_level() to modify the result accordingly.
int fl_contrast_level | ( | ) |
Get the contrast level (sensitivity) of the fl_contrast() method.
This returns the level of the currently selected contrast mode.
void fl_contrast_level | ( | int | level | ) |
Set the contrast level (sensitivity) of the fl_contrast() method.
This can be used to tune the legacy fl_contrast() function to achieve slightly better results. The default value is defined per contrast mode (see below). Values between 50 and 70 may be useful for the legacy contrast mode but you can raise it up to 100. Lower values than 50 are probably not useful.
The contrast level
affects not only the legacy (1.3.x) fl_contrast() function but also the new CIELAB contrast mode which is the default since FLTK 1.4.0. See default value below.
Other contrast modes are currently not affected by the contrast level.
You may use the contrast level if you define your own custom contrast function in mode FL_CONTRAST_CUSTOM.
The default contrast level is
See the description of fl_contrast_mode(int mode) for more information about the contrast level per mode.
Example:
A level
greater than 50 (probably best in the range 50 to 70) may achieve better results of the legacy fl_contrast() function in some border cases of low contrast between foreground and background colors but we recommend to use the new default algorithm FL_CONTRAST_CIELAB
unless you need strict backwards compatibility or use a CPU constrained embedded system.
[in] | level | valid range is 0 to 100 |
int fl_contrast_mode | ( | ) |
Return the current contrast algorithm (mode).
void fl_contrast_mode | ( | int | mode | ) |
Set the contrast algorithm (mode).
You can use one of
If you set FL_CONTRAST_CUSTOM you must also register your custom contrast function by calling fl_contrast_function().
You may set the contrast level fl_contrast_level(int) after setting the contrast mode. This affects the contrast algorithm as described below:
[in] | mode | if invalid, FL_CONTRAST_CIELAB will be selected |
|
inline |
Return the face
set by the most recent call to fl_font().
This can be used to save/restore the font.
void fl_font | ( | Fl_Font | face, |
Fl_Fontsize | fsize | ||
) |
Sets the current font, which is then used in various drawing routines.
You may call this outside a draw context if necessary to measure text, for instance by calling fl_width(), fl_measure(), or fl_text_extents(), 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.
|
inline |
Return the recommended minimum line spacing for the current font.
You can also use the value of size
passed to fl_font().
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.
const char * fl_latin1_to_local | ( | const char * | t, |
int | n = -1 |
||
) |
Convert text from Windows/X11 latin1 character set to local encoding.
[in] | t | character string (latin1 encoding) |
[in] | n | optional number of characters (bytes) to convert (default is all) |
double fl_lightness | ( | Fl_Color | color | ) |
Return the perceived lightness of a color.
This function calculates the perceived lightness of Fl_Color color
.
The returned lightness value Lstar
according to the CIELAB (L*a*b*) color model is almost linear with respect to human perception. It is in the range 0 (black) to 100 (white).
The result values of two colors can be compared directly and the difference is their perceived contrast.
[in] | color | Fl_Color value |
const char * fl_local_to_latin1 | ( | const char * | t, |
int | n = -1 |
||
) |
Convert text from local encoding to Windows/X11 latin1 character set.
[in] | t | character string (local encoding) |
[in] | n | optional number of characters (bytes) to convert (default is all) |
const char * fl_local_to_mac_roman | ( | const char * | t, |
int | n = -1 |
||
) |
Convert text from local encoding to Mac Roman character set.
[in] | t | character string (local encoding) |
[in] | n | optional number of characters to convert (default is all) |
double fl_luminance | ( | Fl_Color | color | ) |
Return the raw / physical luminance of a color.
This function calculates the physical luminance of Fl_Color color
.
The returned luminance value (aka Y
) is the physical luminance of the Fl_Color color
.
The result is in the range 0.0 (black) to 1.0 (white).
Y
is not linear with respect to human perception.See fl_lightness(Fl_Color) for a function that returns the perceived lightness of a color which can be used directly for contrast calculation.
[in] | color | Fl_Color value |
const char * fl_mac_roman_to_local | ( | const char * | t, |
int | n = -1 |
||
) |
Convert text from Mac Roman character set to local encoding.
[in] | t | character string (Mac Roman encoding) |
[in] | n | optional number of characters to convert (default is all) |
Pops up a window to let the user pick a colormap entry.
[in] | oldcol | color to be highlighted when grid is shown. |
Fl_Color | value of the chosen colormap entry. |
|
inline |
Return the size
set by the most recent call to fl_font().
This can be used to save/restore the font.
void fl_text_extents | ( | const char * | c, |
int & | dx, | ||
int & | dy, | ||
int & | w, | ||
int & | h | ||
) |
Determine the minimum pixel dimensions of a nul-terminated string using the current fl_font().
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.
Note the desired font and font size must be set with fl_font() before calling this function.
This differs slightly from fl_measure() in that the dx/dy values are also returned.
No FLTK symbol expansion will be performed.
Example use:
|
inline |
Determine the minimum pixel dimensions of a sequence of n
characters (bytes) using the current fl_font().
|
inline |
Return the typographical width of a single character using the current font face and size.
|
static |
Frees the specified color from the colormap, if applicable.
If overlay is non-zero then the color is freed from the overlay colormap.
|
static |
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.
Returns the RGB value(s) for the given FLTK color index.
This form returns the red, green, and blue values separately in referenced variables.
Returns the RGBA value(s) for the given FLTK color index.
This form returns the red, green, blue, and alpha values separately in referenced variables.
|
static |
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.
|
static |
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.
|
static |
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.
|
static |
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.
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.
Sets an entry in the fl_color index table.
You can set it to any 8-bit RGBA color.
|
static |
Changes a face.
fnum | The font number to be assigned a new face |
name | Name of the font to assign. The string pointer is simply stored, the string is not copied, so the string must be in static memory. The exact name to be used depends on the platform : |
' ', 'I', 'B', 'P'
denote plain, italic, bold, and bold-italic variants, respectively. For example, string "IGabriola"
is to be used to denote the "Gabriola italic"
font. The "Oblique"
suffix, in whatever case, is to be treated as "italic"
, that is, prefix the family name with 'I'
.
|
static |
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 only argument to this function is somewhat obsolete since FLTK and most underlying operating systems move to support Unicode. For completeness, following is the original documentation and a few updates:
On X11, 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 the Xft option on Linux, this parameter is ignored.
With Windows, NULL
selects fonts with ANSI_CHARSET encoding and non-NULL selects all fonts.
On macOS, this parameter is ignored.
The return value is how many faces are in the table after this is done.