
21
Color
The X Window System has various ways of allocating, specifying, and using colors. While
all of these methods are available to applications without XView intervening, XView pro-
vides its own model for color specification that may be used as an alternative. It does not
provide anything more than what is already available, but it may provide a simpler interface
to request and specify colors. This model is especially useful when specifying colors for
XView objects, such as panel buttons and scrollbars.
This chapter does not directly discuss how to use colormaps and related Xlib color-specific
functions. For a discussion of them, see Volume One, Xlib Programming Manual, Chapter 7,
Color. This chapter discusses only the XView color model.
Obviously, the user cannot view colors in an application without having a color display. But
you cannot tell at the time your application is written whether the user’s display is going to
be able to support color. You can use the DisplayDepth() macro to determine whether
the user’s display can handle color:
Display *dpy = (Display *)xv_get(frame, XV_DISPLAY);
extern use_color;
if (DefaultDepth(dpy, DefaultScreen(dpy)) < 2)
use_color = False;
21.1 XView Color Model
XView applications deal with color by using colormap segments. Use the CMS package to
create a colormap segment. Figure 21-1 shows the class hierarchy for the CMS package.
As a simple introduction,