Colors
The data type color represents all colors available
in drawing operations of windows.
Each color value corresponds to a triple of integers (r,g,b)
with 0<=r,g,b<=255.
The number of available colors is restricted and depends on the underlying
hardware. Colors can be created from the rgb-values, from names in a color
data base (X11), or from the following integer constants black, white,
red, green, blue, yellow, violet, orange, cyan, brown, pink, green2, blue2,
grey1, grey2, grey3.
Checking for Failed Color Definition
A color definition may fail for the following reasons
- system dependent limitation of colors
- illegal rgb-value
- color name not present in system color data base or system does not
have color data base
If the definition of a color fails, we say that the constructed color is
bad; otherwise it is good. The operation
bool col.is_good()
tests whether a color is good or bad.
Example:
The program below implements a simple color definition panel. It
uses three slider items for adjusting
the (r,g,b)-values of the color.
On the right there is a screenshot of the program. Clicking on
the picture shows the window in original
size.
#include <LEDA/graphics/window.h>
#include <LEDA/graphics/color.h>
using namespace leda;
static int r,g,b;
void slider_red(int x)
{window::get_call_window()->clear(color(r,g,b));}
void slider_green(int x)
{window::get_call_window()->clear(color(r,g,b));}
void slider_blue(int x)
{window::get_call_window()->clear(color(r,g,b));}
int main()
{
window W(320,300,"define color");
color col=green2;
col.get_rgb(r,g,b);
W.int_item("red ",r,0,255,slider_red);
W.int_item("green",g,0,255,slider_green);
W.int_item("blue ",b,0,255,slider_blue);
if (col.is_good()) W.set_bg_color(col);
W.display(window::center,window::center);
W.read_mouse();
W.screenshot("color_panel");
return 0;
}
|
 |
|
See also:
Drawing Operations
Windows and Panels
Panel Items
Manual Pages:
Manual
Page Colors
|