7.2 Using color in the Window Tool Kit
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"You can use the function> (find-color :color 'red) "RED"
> (find-color :color 1) "RED"
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 NILThe 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"If you try to register a color that is already registered,> (find-color-number :color "RED") 1
> (find-color-number :color "NEWRED") 1
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. NILIf 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.
Generated with Harlequin WebMaker