Next: Bounding Boxes, Up: Changing Attributes [Contents][Index]
To change the color of a particular object use the routine
void fl_set_object_color(FL_OBJECT *obj, FL_COLOR col1, FL_COLOR col2);
col1
and col2
are indices into a colormap. Which colors
are actually changed depends on the type of the object. For box and
text only col1
is important. It indicates the color of the box
or of the box in which the text is placed. For buttons, col1
is
the color of the button when released and col2
is the color of
the button when pushed. (Note that when changing the color of a button
the nice property that the color of a button changes when the mouse
moves over it disappears.) For light buttons the two colors indicate
the color of the light when off and when on. For bitmap buttons,
col1
is the color of the box and col2
is the color of
the bitmap. For sliders col1
is the color of the background of
the slider and col2
is the color of the slider itself. Finally,
for input objects col1
is the color of the input field when it
is not selected and col2
is the color when it has input focus,
i.e., the user can enter text. For all types of objects, the default
colors can be found in the file forms.h. For example, for input
fields the default colors are FL_INPUT_COL1
and
FL_INPUT_COL2
. Form Designer comes in very handy in
familiarizing you with various attributes since you can change all
attributes of an object and immediately see the difference by
"test"ing the object.
To find out the colors of an object use
void fl_get_object_color(FL_OBJECT *obj, FL_COLOR *col1, FL_COLOR *col2);
The following pre-defined color symbols can be used in all color change requests. If the workstation does not support this many colors, substitution by the closest color will happen.
Of all the colors listed in the table above FL_FREE_COL1
has
the largest numerical value, and all color with indices smaller than
that are used (or can potentially be used) by the Forms Library
although, if you wish, they can also be changed using the following
routine prior to fl_initialize()
:
void fl_set_icm_color(FL_COLOR index, int r, int g, int b);
Note that although the color of an object is indicated by a single index, it is not necessarily true that the Forms Library is operating in PseudoColor. Forms Library is capable of operating in all visuals and as a matter of fact the Forms Library will always select TrueColor or DirectColor if the hardware is capable of it.
The actual color is handled by an internal colormap of
FL_MAX_COLORS
entries (default is 1024). To change or query the
values of this internal colormap use the call
void fl_set_icm_color(FL_COLOR index, int r, int g, int b); void fl_get_icm_color(FL_COLOR index, int *r, int *g, int *b);
Call fl_set_icm_color()
before
fl_initialize()
to change XForms’s default colormap. Note
that these two routines do not communicate with the X server, they
only populate/return information about the internal colormap, which is
made known to the X server by the initialization routine
fl_initialize()
.
To change the colormap and make a color index active so that it can be
used in various drawing routines after fl_initialize()
initialization, use the following function
unsigned long fl_mapcolor(FL_COLOR i, int red, int green, int blue);
This function frees the previous allocated pixel corresponding to color
index i
and re-allocates a pixel with the RGB value specified.
The pixel value is returned by the function. It is recommended that you
use an index larger than FL_FREE_COL1
for your remap request to
avoid accidentally freeing the colors you have not explicitly allocated.
Indices larger than 224 are reserved and should not be used.
Sometimes it may be more convenient to associate an index with a colorname, e.g., "red" etc., which may have been obtained via resources. To this end, the following routine exists
long fl_mapcolorname(FL_COLOR i, const char *name);
where name
is the color name2. The function returns -1 if the colorname name is
not resolved. You can obtain the RGB values of an index by using the
following routine
unsigned long fl_getmcolor(FL_COLOR i, int *red, int *green, int *blue);
The function returns the pixel value as known by the Xserver. If the
requested index, i
, is never mapped or is freed, the RGB values
as well as the pixel value are random. Since this function communicates
with the Xserver to obtain the pixel information, it has a two-way
traffic overhead. If you’re only interested in the internal colormap of
XForms, fl_get_icm_color()
is more efficient.
Note that the current version only uses the lower byte of the primary color. Thus all primary colors in the above functions should be specified in the range of 0-255 inclusive.
To free any colors that you no longer need, the following routine should be used
void fl_free_colors(FL_COLOR colors[], int ncolors);
Prior to XForms version 0.76, there is a color "leakage" in the
implementation of the internal colormap that prevents the old index from
being freed in the call fl_mapcolor()
, resulting in accelerated
colormap overflow and some other undesirable behavior. Since there may
still be some applications based on older versions of the Forms Library,
a routine is provided to force the library to be compatible with the
(buggy) behavior:
void fl_set_color_leak(int flag);
Due to the use of an internal colormap and the simplified user interface, changing the colormap value for the index may not result in a change of the color for the object. An actual redraw of the object (see below) whose color is changed may be required to have the change take effect. Therefore, a typical sequence of changing the color of a visible object is as follows:
fl_mapcolor(newcol, red, green, blue); /* obj uses newcol */ fl_redraw_object(obj);
Standard color names are listed in a file named rgb.txt and usually resides in /usr/lib/X11/
Next: Bounding Boxes, Up: Changing Attributes [Contents][Index]