Foundation > Graphic Resources > IlvColor: The Color Class
 
IlvColor: The Color Class
Color is described in the topics:
*Color Models
*Using the IlvColor Class
*Converting between Color Models
*Computing Shadow Colors
Color Models
The description of a color, in Rogue Wave® Views, is stored in an instance of IlvColor.
RGB
Colors can be handled in Rogue Wave Views using the familiar RGB (red/green/blue) system. In this system, a color is entirely defined through its three component values: red, green and blue. These values are stored as unsigned 16-bit numbers. For example, black  is defined with its three components set to zero, and white  has its three components set to 65535.
HSV
Alternatively, you can use the HSV (hue/saturation/value of luminosity) model, shown here:
Figure 3.1    Hue, Saturation, and Value of Luminosity (HSV) Model
The preceding figure illustrates a mathematical model based upon three parameters: H (hue), S (saturation) and V (value of luminosity). Following are their possible values:
*H  The hue parameter, H, is an angle from 0 to 360°. For fixed values of the S and V parameters (somewhere towards their upper limits), varying the angle H through a full circle would take you through the entire spectrum of colors.
*S  For a given H parameter, varying the S value changes the vividness of the color. At the vertical axis of the cone, where S is zero, there is a total absence of any chromatic intensity, which means that there is a shade of gray . On the outer surface of the cone, where S has the value 1.0, the intensity is maximal, which means that colors are as vivid as possible.
*V  The third parameter, V, determines the quantity of light in which the colors are bathed, in other words, the brightness  of the spectrum obtained by varying the angle H through a full circle. The bottom point of the cone, where V is zero, represents the color black. As we ascend, the spectrum of the hue circle becomes increasingly brighter. The top of the vertical axis, where V has the value 1.0, represents the color white.
Using the IlvColor Class
In Rogue Wave Views, the IlvColor class lets you manipulate both the RGB and the HSV color models. You obtain a color by requesting your IlvDisplay object to get it for you.
Colors are generally stored in a color table—sometimes referred to as a lookup table—that is maintained internally by your IlvDisplay object. You can obtain the index of a color object (a long unsigned integer) by means of the member function getIndex. You can then use this number for remapping processes involving color bitmaps when you want to map pixel values to color objects.
Color Name
Colors always have a name. Rogue Wave Views has a predefined set of color names. The naming mechanism comes from the X Window color-naming scheme. Each name in this set is associated with a specific RGB triplet. If a color is not specified by a predefined name but by an RGB value, this color gets a default name of the following form: “#RRRRGGGGBBBB”, where each of the red, green and blue values is represented by four hexadecimal digits.
Only mutable colors can be renamed, however. The name of a static color cannot be modified. It either belongs to the set of predefined color names or is computed from the RGB values defining the color.
New Colors
IlvColor does not have a public constructor; you must get the colors from the display. Several IlvDisplay::getColor member functions enable you to obtain a new color, specifying either RGB values, HSV values, or a name. You can also indicate if the color must be mutable or not. If a problem arises making it impossible to create the desired color, these member functions return 0.
The IlvDisplay class provides two member functions returning internal resources that are often used as callback values for unspecified colors. These functions are:
IlvColor* defaultForeground();
IlvColor* defaultBackground();
Usually, these foreground and background colors are black and gray respectively. They can easily be set to whatever colors you like by means of your display system resource mechanism.
Mutable Colors
A Rogue Wave Views color can be either static (impossible to modify after its creation) or mutable. In the latter case, you can use modifier member functions that are set to dynamically modify a color, even when there are drawings with this color on the screen.
Mutable colors can be renamed using the method IlvResource::setName. Unlike static colors, mutable colors are not transparently shared. The method IlvDisplay::getColor always creates a new object if the parameter mutable is IlTrue. Mutable colors are more costly, in terms of internal resource management.
Converting between Color Models
Two global functions are available to convert color values from the RGB system to HSV, and the reverse.
*IlvRGBtoHSV
*IlvHSVtoRGB
Computing Shadow Colors
Use the IlvComputeReliefColors global function to compute the colors that make a shadow effect.

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.