Debian Codegraph @

pod/pTk/GetColor.pod

raw
1 # Copyright (c) 1990, 1991 The Regents of the University of California.
2 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
3 # See the file "license.terms" for information on usage and redistribution
4 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
5 #
6 #
7
8 =head1 NAME
9
10 Tk_GetColor, Tk_GetColorByValue, Tk_NameOfColor, Tk_FreeColor - maintain database of colors
11
12 =for category C Programming
13
14 =head1 SYNOPSIS
15
16 B<#include E<lt>tk.hE<gt>>
17
18 XColor *
19 B<Tk_GetColor>(I<interp, tkwin, nameId>B<)>
20
21 XColor *
22 B<Tk_GetColorByValue>(I<tkwin, prefPtr>B<)>
23
24 char *
25 B<Tk_NameOfColor(>I<colorPtr>B<)>
26
27 GC
28 B<Tk_GCForColor>(I<colorPtr, drawable>)
29
30 B<Tk_FreeColor(>I<colorPtr>B<)>
31
32 =head1 ARGUMENTS
33
34 =over 4
35
36 =item Tcl_Interp *interp (in)
37
38 Interpreter to use for error reporting.
39
40 =item Tk_Window tkwin (in)
41
42 Token for window in which color will be used.
43
44 =item Tk_Uid nameId (in)
45
46 Textual description of desired color.
47
48 =item XColor *prefPtr (in)
49
50 Indicates red, green, and blue intensities of desired
51 color.
52
53 =item XColor *colorPtr (in)
54
55 Pointer to X color information. Must have been allocated by previous
56 call to B<Tk_GetColor> or B<Tk_GetColorByValue>, except when passed
57 to B<Tk_NameOfColor>.
58
59 =item Drawable drawable (in)
60
61 Drawable in which the result graphics context will be used. Must have
62 same screen and depth as the window for which the color was allocated.
63
64 =back
65
66 =head1 DESCRIPTION
67
68 The B<Tk_GetColor> and B<Tk_GetColorByValue> procedures
69 locate pixel values that may be used to render particular
70 colors in the window given by I<tkwin>. In B<Tk_GetColor>
71 the desired color is specified with a Tk_Uid (I<nameId>), which
72 may have any of the following forms:
73
74 =over 4
75
76 =item I<colorname>
77
78 Any of the valid textual names for a color defined in the
79 server's color database file, such as B<red> or B<PeachPuff>.
80
81 =item B<#>I<RGB>
82
83 =item B<#>I<RRGGBB>
84
85 =item B<#>I<RRRGGGBBB>
86
87 =item B<#>I<RRRRGGGGBBBB>
88
89 A numeric specification of the red, green, and blue intensities
90 to use to display the color. Each I<R>, I<G>, or I<B>
91 represents a single hexadecimal digit. The four forms permit
92 colors to be specified with 4-bit, 8-bit, 12-bit or 16-bit values.
93 When fewer than 16 bits are provided for each color, they represent
94 the most significant bits of the color. For example, #3a7 is the
95 same as #3000a0007000.
96
97 In B<Tk_GetColorByValue>, the desired color is indicated with
98 the I<red>, I<green>, and I<blue> fields of the structure
99 pointed to by I<colorPtr>.
100
101 If B<Tk_GetColor> or B<Tk_GetColorByValue> is successful
102 in allocating the desired color, then it returns a pointer to
103 an XColor structure; the structure indicates the exact intensities of
104 the allocated color (which may differ slightly from those requested,
105 depending on the limitations of the screen) and a pixel value
106 that may be used to draw in the color.
107 If the colormap for I<tkwin> is full, B<Tk_GetColor>
108 and B<Tk_GetColorByValue> will use the closest existing color
109 in the colormap.
110 If B<Tk_GetColor> encounters an error while allocating
111 the color (such as an unknown color name) then NULL is returned and
112 an error message is stored in I<interp-E<gt>result>;
113 B<Tk_GetColorByValue> never returns an error.
114
115 B<Tk_GetColor> and B<Tk_GetColorByValue> maintain a database
116 of all the colors currently in use.
117 If the same I<nameId> is requested multiple times from
118 B<Tk_GetColor> (e.g. by different windows), or if the
119 same intensities are requested multiple times from
120 B<Tk_GetColorByValue>, then existing pixel values will
121 be re-used. Re-using an existing pixel avoids any interaction
122 with the X server, which makes the allocation much more
123 efficient. For this reason, you should generally use
124 B<Tk_GetColor> or B<Tk_GetColorByValue>
125 instead of Xlib procedures like B<XAllocColor>,
126 B<XAllocNamedColor>, or B<XParseColor>.
127
128 Since different calls to B<Tk_GetColor> or B<Tk_GetColorByValue>
129 may return the same shared
130 pixel value, callers should never change the color of a pixel
131 returned by the procedures.
132 If you need to change a color value dynamically, you should use
133 B<XAllocColorCells> to allocate the pixel value for the color.
134
135 The procedure B<Tk_NameOfColor> is roughly the inverse of
136 B<Tk_GetColor>. If its I<colorPtr> argument was created
137 by B<Tk_GetColor>, then the return value is the I<nameId>
138 string that was passed to B<Tk_GetColor> to create the
139 color. If I<colorPtr> was created by a call to B<Tk_GetColorByValue>,
140 or by any other mechanism, then the return value is a string
141 that could be passed to B<Tk_GetColor> to return the same
142 color. Note: the string returned by B<Tk_NameOfColor> is
143 only guaranteed to persist until the next call to B<Tk_NameOfColor>.
144
145 B<Tk_GCForColor> returns a graphics context whose B<Foreground>
146 field is the pixel allocated for I<colorPtr> and whose other fields
147 all have default values.
148 This provides an easy way to do basic drawing with a color.
149 The graphics context is cached with the color and will exist only as
150 long as I<colorPtr> exists; it is freed when the last reference
151 to I<colorPtr> is freed by calling B<Tk_FreeColor>.
152
153 When a pixel value returned by B<Tk_GetColor> or
154 B<Tk_GetColorByValue> is no longer
155 needed, B<Tk_FreeColor> should be called to release the color.
156 There should be exactly one call to B<Tk_FreeColor> for
157 each call to B<Tk_GetColor> or B<Tk_GetColorByValue>.
158 When a pixel value is no longer in
159 use anywhere (i.e. it has been freed as many times as it has been gotten)
160 B<Tk_FreeColor> will release it to the X server and delete it from
161 the database.
162
163 =back
164
165 =head1 KEYWORDS
166
167 color, intensity, pixel value