7.2 Using color in the Window Tool Kit

7.2.3 Finding information about registered colors

When you register a color, a color number associates the name of the color, which is a string, with the red, blue, and green saturation attributes that you specified. The color number is the index of the registered color's RGB values in the color map. When you draw to a bitmap using the registered color, the pixels that are drawn on the bitmap have the value of the registered color's color number. The pixel can be a value in the range 0 to 2n - 1. Thus, a valid pixel value for a depth 1 system is 0 or 1; a pixel value for a depth 8 system is in the range from 0 to 255.

A color is registered with a string as a name, but once registered, you can use either a string, a symbol, or a color number to refer to the color in window operations, as the following example shows. Note that the color number can differ from system to system.

> (find-color :color "RED")
"RED"

> (find-color :color 'red) "RED"

> (find-color :color 1) "RED"

You can use the function print-color-registry to see which colors are registered and what RGB value they each have. If you have registered the primary colors,print-color-registry displays information that is similar to the information in this example:

> (print-color-registry)
Color Registry
'RED'     Color-No: 1 Red: 65535 Green: 0     Blue: 0     count: 1
'CYAN'    Color-No: 4 Red: 0     Green: 65535 Blue: 65535 count: 1
'MAGENTA' Color-No: 6 Red: 65535 Green: 0     Blue: 65535 count: 1
'YELLOW'  Color-No: 5 Red: 65535 Green: 65535 Blue: 0     count: 1
'WHITE'   Color-No: 0 Red: 65535 Green: 65535 Blue: 65535 count: 1
'BLACK'   Color-No: 255  Red: 0  Green: 0     Blue: 0     count: 1
'BLUE'    Color-No: 3 Red: 0     Green: 0     Blue: 65535 count: 1
'GREEN'   Color-No: 2 Red: 0     Green: 65535 Blue: 0     count: 1
NIL

The precise color numbers might vary, depending on your system. The red, green, and blue saturations are shown in absolute numbers in the range of min-mic-value to max-mic-value. You can specify the:percentage-values keyword argument toprint-color-registry if you prefer the saturations to be given as percentages of the maximum saturation. The count of a color shows how many registered colors are using this color's entry in the color map. If, for example, you were to register another color with the same RGB value as red, the color registry would simply use the same color number for the new color and increment the count by 1.

> (register-color "NEWRED"
      :red max-mic-value :green min-mic-value :blue min-mic-value)
"NEWRED"

> (find-color-number :color "RED") 1

> (find-color-number :color "NEWRED") 1

If you try to register a color that is already registered, register-color has no effect; it returnsnil. The first registered definition of a color persists until the color is removed from the color registry.

The functionregister-color also takes:delta-red,:delta-green, and:delta-blue keyword arguments. These arguments specify how much variation from RGB values is allowed. If you specify these arguments, the Window Tool Kit looks for an existing color entry in the system color map that is within the allowed tolerance. This technique of specifying colors is useful if you are trying to conserve space in the color table.

For color software development, these operations might be handy:

> (find-color-number :color "RED")
1

> (find-mic :color "RED")
65535 0 0

> (find-color :color 1)
"RED"

You can remove a color from the color registry with the function delete-color:

> (delete-color 'red)
"RED" unregistered.
NIL

If you want to restore the color registry to its original state, use the function reset-color-registry. This function destructively removes any entries that were added to the color registry after the Window Tool Kit was initialized; note that the colors'BLACK and'WHITE are always present in the registry.


The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker