1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
|
<title> Color </title>
<ul>
<li> <a href="#Color"> Color </a>
<li> <a href="color.html#fFAC"> FreeAllColors </a>
<li> <a href="color.html#fFPC"> FreePrivateColor </a>
<li> <a href="color.html#fGAC"> GetAllColors </a>
<li> <a href="color.html#fGNC"> GetNamedColor </a>
<li> <a href="color.html#fGRGBC"> GetRGBColor </a>
<li> <a href="color.html#fGPC"> GetPrivateColor </a>
<li> <a href="color.html#fGSC"> GetStandardColors </a>
<li> <a href="color.html#fSPC"> SetPrivateColor </a>
<li> <a href="color.html#fSCM"> SetColorMap </a>
<li> <a href="color.html#fSMCM"> SetMyColorMap </a>
<li> <a href="color.html#fSCOL"> SelectColor() </a>
</ul>
<hr>
<p>
<h2> <a name="Color"> Color </a> </h2>
<p>
This file describes the routines for managing colors in your window.
For example if you want to change what the foreground color is, or
need to get specific colors. To get specific colors you use the
functions discussed in here. It is important to remember that you can
not call any of these functions until you have called
<a href="windows.html#fSD"> ShowDisplay() </a>.
<p>
Colors are represented by integers. When you get a color, you are
returned an integer that you can use in calls to
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>,
and
<a href="drawing.html#fSC"> SetColor() </a>. You should attach no meaning to the
numbers, and just because green is 17 does not mean that 18 is a
lighter or darker shade of green.
<p>
There are three ways to manipulate colors with libsx. The first way
handles most of the common cases, and is done with
<a href="color.html#fGNC"> GetNamedColor() </a>
or
<a href="color.html#fGRGBC"> GetRGBColor() </a>.
<p>
The next method,
<a href="color.html#fGPC"> GetPrivateColor() </a>,
allows your application to modify
the actual display color represented by a color number (something you
cannot do with the the previous methods).
<p>
The final method gives you complete control in specifying the entire
colormap. That is, you can determine exactly what integers map to
what colors so you can obtain smooth gradients (so for example black
is color 0, and white is 255). These routines work best on 8 bit
displays but will work on 24 bit displays.
<p>
NOTE: You can NOT call any color function until you have called
<a href="windows.html#fSD"> ShowDisplay() </a>.
<p>
The way colors work for drawing is like this. There are usually 256
available colors on a workstation. This is called an 8-bit display
because 2 to the 8'th power == 256. These colors are stored in a
table (array) of 256 entries. If you allocate a color, and it is in
entry 37, then to draw with the color that is stored there, you must
use 37 as an argument to the
<a href="drawing.html#fSC"> SetColor() </a>
function. When you ask for a
color, it may be taken from anywhere in the array of 256 entries, and
there is <b>NO</b> guarantee that if you allocate a green color that the
next color in the table will be a lighter or darker green. Even if
you allocate many colors using
<a href="color.html#fGNC"> GetNamedColor() </a>
or
<a href="color.html#fGRGBC"> GetRGBColor() </a>,
you have <b>NO</b> assurances about where those colors are in the array
(chances are they won't be contiguous). If you need to have a
contiguous set of numbers, you must use
<a href="color.html#fGAC"> GetAllColors() </a>
and then
<a href="color.html#fSCM"> SetColorMap() </a>
or
<a href="color.html#fSMCM"> SetMyColorMap() </a>
to set up a custom colormap with a
known set of values. When you get a private color, your application
can specify what values that color index should have. This is useful
when you want to interactively modify a color.
<p>
It is important to remember that `getting a color' really means
getting an index into the color table where the actual color is
stored.
<p>
If you actually want to pop up a window allowing selection of color by
users, invoke the <a href="color.html#fSCOL"> SelectColor() </a> function.
It doesn't permanently allocate a color, so you show just do it later
with the other routines.
<hr>
<p>
<a name="fGSC"> <b>
void GetStandardColors(void);
</b> </a>
<p>
This function gets 6 standard colors, RED, GREEN, BLUE, YELLOW, BLACK,
and WHITE. These 6 variables contain values which can be used in
calls to SetColor(), SetFgColor(), SetBgColor(), etc.
<p>
Do not use the values in RED, GREEN, BLUE, YELLOW, BLACK or WHITE
before calling GetStandardColors(). The results are undefined if you
do this.
<p>
In addition to the above 6 standard colors, the library makes use of
3 further colors HILIGHT, BUTTONBG, INPUTBG, as follows:
<p>
HILIGHT is the color of hilighted text to be used in active
input string entries, and INPUTBG the corresponding background color.
BUTTONBG is the default color of buttons for internally defined widgets;
By default, HILIGHT coincides with the foreground color, while INPUTBG
and BUTTONBG coincide with the background color (fg/bg default themselves
to black/white). They can be adjusted to any other color value, once such
a color has been defined through the Get*Color routines.
<p>
NOTE: You can only call
<a href="color.html#fGSC"> GetStandardColors() </a>
after calling the
<a href="windows.html#fSD"> ShowDisplay() </a>
function.
<p>
SEE ALSO :
<a href="color.html#fGNC"> GetNamedColor() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>,
<a href="color.html#fGAC"> GetAllColors() </a>
<a href="drawing.html#fSC"> SetColor() </a>,
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>
<hr>
<p>
<a name="fGNC"> <b>
int GetNamedColor(char *name);
</b> </a>
<p>
This function allocates an entry in the color table for the color
given by the ascii string "name". You can view the list of available
color names with the showrgb command in a shell (some nice ones are
"peachpuff", "burlywood3", "aquamarine", and "paleturquoise3"). Color
names can have spaces in them. The return value of the function is an
integer that you can use in calls to
<a href="drawing.html#fSC"> SetColor() </a>
(or any of the other
SetXXColor() calls). If an error occurred trying to allocate the color
(very possible if you allocate a lot of colors), a -1 is returned.
<p>
NOTE: the return value of zero is valid, a -1 indicates an error
<b>NOT</b> zero.
<p>
NOTE: You can only call
<a href="color.html#fGNC"> GetNamedColor() </a>
after calling the
<a href="windows.html#fSD"> ShowDisplay() </a>
function.
<p>
SEE ALSO :
<a href="color.html#fGSC"> GetStandardColors() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>,
<a href="color.html#fGAC"> GetAllColors() </a>
<a href="drawing.html#fSC"> SetColor() </a>,
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>
<hr>
<p>
<a name="fGRGBC"> <b>
int GetRGBColor(int r, int g, int b);
</b> </a>
<p>
This function tries to allocate the color given by the red, green,
blue triple r,g,b. The arguments r,g, and b should be between 0 and
255. Overflow is not checked for. The return value is an integer
value usable in the
<a href="drawing.html#fSC"> SetColor() </a>
calls or a -1 if an error occurred.
<p>
NOTE: the return value of zero is valid, a -1 indicates an error
<b>NOT</b> zero.
<p>
NOTE: You can only call
<a href="color.html#fGRGBC"> GetRGBColor() </a>
after calling the
<a href="windows.html#fSD"> ShowDisplay() </a>
function.
<p>
SEE ALSO :
<a href="color.html#fGSC"> GetStandardColors() </a>,
<a href="color.html#fGNC"> GetNamedColor() </a>,
<a href="color.html#fGAC"> GetAllColors() </a>
<a href="drawing.html#fSC"> SetColor() </a>,
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>
<hr>
<p>
<a name="fGPC"> <b>
int GetPrivateColor(void);
</b> </a>
<p>
This function allocates a private color cell for use by the
application. A private color cell is one which you can change what
color it represents. For example, if you would like to let the user
interactively manipulate some color, you would need to allocate a
private color cell.
<p>
The integer returned by this function is a reference to a color cell
whose values you can set with
<a href="color.html#fSPC"> SetPrivateColor() </a>.
The intial contents
of the private color cell are undefined and you should probably call
<a href="color.html#fSPC"> SetPrivateColor() </a>
immediately to set it to some known value.
<p>
If an error occurs, a -1 is returned.
<p>
When you are done with a private color cell, you should free it with
<a href="color.html#fFPC"> FreePrivateColor() </a>.
<p>
SEE ALSO:
<a href="color.html#fSPC"> SetPrivateColor() </a>,
<a href="color.html#fFPC"> FreePrivateColor() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>
<hr>
<p>
<a name="fSPC"> <b>
void SetPrivateColor(int which, int r, int g, int b);
</b> </a>
<p>
This function sets the color cell referred to by `which' to have the
r,g,b values specified. The r,g,b values are given in the range 0-255
(inclusive). Once this function is called, any thing drawn in the
display with the color `which' will now have the new color determined
by the r,g,b arguments.
<p>
SEE ALSO:
<a href="color.html#fGPC"> GetPrivateColor() </a>,
<a href="color.html#fFPC"> FreePrivateColor() </a>,
<a href="misc.html#fSFC"> SetFgColor() </a>,
<a href="misc.html#fSBC"> SetBgColor() </a>,
<hr>
<p>
<a name="fFPC"> <b>
void FreePrivateColor(int which);
</b> </a>
<p>
This function returns the color associated with the private color cell
`which' to the system. You should have allocated the color referred
to by `which' with
<a href="color.html#fGPC"> GetPrivateColor() </a>.
<p>
SEE ALSO
<a href="color.html#fGPC"> GetPrivateColor() </a>,
<a href="color.html#fSPC"> SetPrivateColor() </a>.
<hr>
<p>
<a name="fGAC"> <b>
int GetAllColors(void);
</b> </a>
<p>
This function is rather drastic and should be used with caution. It
immediately grabs an entire 256 entry colormap for private use. This
has the unfortunate effect of (temporarily) wiping out the colors in
all the other windows on the display. However this is necessary if
you wish to get a smooth colormap to use in displaying a smooth-shaded
or continuous tone picture. Once
<a href="color.html#fGAC"> GetAllColors() </a>
is called, the entire
colormap is free for manipulation by your program. The colormap
remains allocated until you call
<a href="color.html#fFAC"> FreeAllColors() </a>,
at which time everything goes back to normal.
<p>
If an error occurred (quite possible), this routine returns FALSE. If
everything went ok and the colormap was successfully allocated, TRUE
is returned.
<p>
If you can avoid using this function, try to. It is disconcerting for
the user to have the colormap get wacked out and have most of their
windows disappear (they don't really disappear of course, you just can
see them usually). However it is sometimes necessary to do this as
there is no other way to get a smoothly continuous color map.
<p>
Usually, you will want to call
<a href="color.html#fSCM"> SetColorMap() </a>
or
<a href="color.html#fSMCM"> SetMyColorMap() </a>
right after this function.
<p>
NOTE: On machines with multiple hardware colormaps (e.g. lots of SGI
machines), only the current drawing area gets the colormap, other
widgets and windows are not affected.
<p>
NOTE: You can only call
<a href="color.html#fGAC"> GetAllColors() </a>
after calling the
<a href="windows.html#fSD"> ShowDisplay() </a>
function.
<p>
SEE ALSO :
<a href="color.html#fSCM"> SetColorMap() </a>,
<a href="color.html#fSMCM"> SetMyColorMap() </a>,
<a href="color.html#fFAC"> FreeAllColors() </a>,
<a href="color.html#fGSC"> GetStandardColors() </a>,
<a href="color.html#fGNC"> GetNamedColor() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>
<hr>
<p>
<a name="fFAC"> <b>
void FreeAllColors(void);
</b> </a>
<p>
This function frees a private colormap that was allocated with
<a href="color.html#fGAC"> GetAllColors() </a>.
It has the beneficial effect of immediately restoring
the rest of the colors on the screen and in other windows to those
that existed prior to the call to
<a href="color.html#fGAC"> GetAllColors() </a>.
This function is
useful if wish to let the user restore their original colors
temporarily (although this will happen automatically when the mouse
moves outside the window).
<hr>
<p>
<a name="fSCM"> <b>
void SetColorMap(int num);
</b> </a>
<p>
This function creates several predefined color maps that are very
smoothly continuous. It saves you the hassle of writing them yourself
(even though they are mostly easy). The "num" argument you pass in
should be one of the following #define's :
<p>
<pre>
#define GREY_SCALE_1 0
#define GREY_SCALE_2 1
#define RAINBOW_1 2
#define RAINBOW_2 3
</pre>
<p>
The colormap GREY_SCALE_2 is a complete smooth color ramp from pure
black (color 0) to pure white (color 255). The other grey scale,
GREY_SCALE_1 is a nearly pure ramp from black (color 0) to white
(color 252), but also has a few additional colors thrown in near the
end of the colormap. The two RAINBOW_? colormaps have different types
of smooth changing rainbows of color. This are really only useful for
drawing pretty patterns or doing false coloring.
<p>
NOTE: You should call
<a href="color.html#fGAC"> GetAllColors() </a>
before you call this routine. It
is not necessary, but if you don't, and
<a href="color.html#fGAC"> GetAllColors() </a>
fails, you will never know about it, and your application may not
work very well.
<p>
SEE ALSO :
<a href="color.html#fSMCM"> SetMyColorMap() </a>,
<a href="color.html#fGAC"> GetAllColors() </a>,
<a href="color.html#fGNC"> GetNamedColor() </a>,
<a href="color.html#fGSC"> GetStandardColors() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>
<hr>
<p>
<a name="fSMCM"> <b>
void SetMyColorMap(int n, unsigned char *r, unsigned char *g,unsigned char *b);
</b> </a>
<p>
Occasionally it is necessary to have absolute control over your
colormap, and this function lets you do that. This function lets you
completely specify each and every color that will be in the colormap.
The three arrays r,g, and b are simply the red, green, and blue
components of each color. The values in the array range from 0 to
255, hence they are unsigned char's. You need not specify a full
array of 256 colors, you can in fact only specify a few. The integer
argument "n" indicates how many entries there are in the r,g, and b
arrays. The argument "n" should be greater than 0 and less than 255.
<p>
NOTE: You should call
<a href="color.html#fGAC"> GetAllColors() </a>
before you call this routine. It
is not necessary, but if you don't and
<a href="color.html#fGAC"> GetAllColors() </a>
fails, you will
never know about it, and your application may not work very well.
<p>
SEE ALSO :
<a href="color.html#fSMCM"> SetMyColorMap() </a>,
<a href="color.html#fGAC"> GetAllColors() </a>,
<a href="color.html#fGNC"> GetNamedColor() </a>,
<a href="color.html#fGSC"> GetStandardColors() </a>,
<a href="color.html#fGRGBC"> GetRGBColor() </a>
<hr>
<p>
<a name="fSCOL"> <b>
char *SelectColor(char *inicolor, int output, char *txt, CSelCB func, void *data);</b> </a>
<p>
This is a sophisticated popup which lets the user browse and select
a color. The "mode" button cycles through 3 possible modes: RGB mode
(red-green-blue), HSV mode (hue-saturation-value), CMYK mode
(cyan-magenta-yellow-black). For each mode, the routine provides
scrolls which the user can use to set the parameters. Meanwhile, a
rectangular draw area shows the resulting color. The user can also
browse in the RGB data file (litteral definitions of colors in
/usr/lib/X11/rgb.txt). Finally, the "Grab color" button sets the color
to be the color of any chosen pixel on the screen, and the "Best match"
button selects the predefined standard color which best approximates
the selected color.
<p>
The parameters have the following significance: char *inicolor is the
color to be set when the popup opens. It can be in a variety of different
formats, e.g.
<pre>
"#87CEEB" "135,206,235" "skyblue" "SkyBlue"
</pre>
which are viewed as equivalent denominations of the skyblue color,
whose pixel values are red=135=0x87 green=206=0xce blue=235=0xeb
The output parameter sets which of the three forms should be used
as a return value for the char *SelectColor() procedure:
<pre>
if output=0, the returned string is in hexadecimal form "#87CEEB",
if output=1, the returned string is either hexadecimal or litteral,
and is litteral if there is an exact match
if output=2, the returned string is the litteral best match
</pre>
The next three parameters (txt, func, data) can be used to let
interactively the selection operate on a call-back function func.
The function is activated when the user clicks on an extra button at
the lower right corner, marked with the label char *txt. The
parameter void *data can be passed to the function. The function
func itself should be of the type
<pre>
void func(Widget w, CSelData *cdata)
</pre>
where cdata is a pointer to a complex structure data set, the main
components of which are
<pre>
cdata->r cdata->g cdata->b RGB (float values)
cdata->h cdata->s cdata->v HSV values
cdata->c cdata->m cdata->y cdata->k CMYK values
cdata->rgb_list[1000][60] List of litteral color names
cdata->match_list[1000][60] List of ordered best matches
char *rgb_ptr[1000]; Null terminated pointers to rgb_list
char *match_ptr[1000]; Null terminated pointers to match_list
</pre>
Finally, the initial data pointer used when invoking SelectColor can be
retrieved as cdata->data.
|