# Copyright (c) 1990, 1991 The Regents of the University of California. # Copyright (c) 1994-1996 Sun Microsystems, Inc. # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # =head1 NAME Tk_GetColor, Tk_GetColorByValue, Tk_NameOfColor, Tk_FreeColor - maintain database of colors =for category C Programming =head1 SYNOPSIS B<#include Etk.hE> XColor * B(IB<)> XColor * B(IB<)> char * BIB<)> GC B(I) BIB<)> =head1 ARGUMENTS =over 4 =item Tcl_Interp *interp (in) Interpreter to use for error reporting. =item Tk_Window tkwin (in) Token for window in which color will be used. =item Tk_Uid nameId (in) Textual description of desired color. =item XColor *prefPtr (in) Indicates red, green, and blue intensities of desired color. =item XColor *colorPtr (in) Pointer to X color information. Must have been allocated by previous call to B or B, except when passed to B. =item Drawable drawable (in) Drawable in which the result graphics context will be used. Must have same screen and depth as the window for which the color was allocated. =back =head1 DESCRIPTION The B and B procedures locate pixel values that may be used to render particular colors in the window given by I. In B the desired color is specified with a Tk_Uid (I), which may have any of the following forms: =over 4 =item I Any of the valid textual names for a color defined in the server's color database file, such as B or B. =item B<#>I =item B<#>I =item B<#>I =item B<#>I A numeric specification of the red, green, and blue intensities to use to display the color. Each I, I, or I represents a single hexadecimal digit. The four forms permit colors to be specified with 4-bit, 8-bit, 12-bit or 16-bit values. When fewer than 16 bits are provided for each color, they represent the most significant bits of the color. For example, #3a7 is the same as #3000a0007000. In B, the desired color is indicated with the I, I, and I fields of the structure pointed to by I. If B or B is successful in allocating the desired color, then it returns a pointer to an XColor structure; the structure indicates the exact intensities of the allocated color (which may differ slightly from those requested, depending on the limitations of the screen) and a pixel value that may be used to draw in the color. If the colormap for I is full, B and B will use the closest existing color in the colormap. If B encounters an error while allocating the color (such as an unknown color name) then NULL is returned and an error message is stored in Iresult>; B never returns an error. B and B maintain a database of all the colors currently in use. If the same I is requested multiple times from B (e.g. by different windows), or if the same intensities are requested multiple times from B, then existing pixel values will be re-used. Re-using an existing pixel avoids any interaction with the X server, which makes the allocation much more efficient. For this reason, you should generally use B or B instead of Xlib procedures like B, B, or B. Since different calls to B or B may return the same shared pixel value, callers should never change the color of a pixel returned by the procedures. If you need to change a color value dynamically, you should use B to allocate the pixel value for the color. The procedure B is roughly the inverse of B. If its I argument was created by B, then the return value is the I string that was passed to B to create the color. If I was created by a call to B, or by any other mechanism, then the return value is a string that could be passed to B to return the same color. Note: the string returned by B is only guaranteed to persist until the next call to B. B returns a graphics context whose B field is the pixel allocated for I and whose other fields all have default values. This provides an easy way to do basic drawing with a color. The graphics context is cached with the color and will exist only as long as I exists; it is freed when the last reference to I is freed by calling B. When a pixel value returned by B or B is no longer needed, B should be called to release the color. There should be exactly one call to B for each call to B or B. When a pixel value is no longer in use anywhere (i.e. it has been freed as many times as it has been gotten) B will release it to the X server and delete it from the database. =back =head1 KEYWORDS color, intensity, pixel value