1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdkscreen.h"
31 #include "gdkinternals.h"
35 * @cmap: a #GdkColormap
37 * Deprecated function; use g_object_ref() instead.
39 * Return value: the colormap
42 gdk_colormap_ref (GdkColormap *cmap)
44 return (GdkColormap *) g_object_ref (cmap);
49 * @cmap: a #GdkColormap
51 * Deprecated function; use g_object_ref() instead.
54 gdk_colormap_unref (GdkColormap *cmap)
56 g_object_unref (cmap);
61 * gdk_colormap_get_visual:
62 * @colormap: a #GdkColormap.
64 * Returns the visual for which a given colormap was created.
66 * Return value: the visual of the colormap.
69 gdk_colormap_get_visual (GdkColormap *colormap)
71 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
73 return colormap->visual;
78 * @colormap: a #GdkColormap.
79 * @colors: the new color values.
80 * @ncolors: the number of colors to change.
82 * Changes the value of the first @ncolors colors in
83 * a private colormap. This function is obsolete and
84 * should not be used. See gdk_color_change().
89 gdk_colors_store (GdkColormap *colormap,
95 for (i = 0; i < ncolors; i++)
97 colormap->colors[i].pixel = colors[i].pixel;
98 colormap->colors[i].red = colors[i].red;
99 colormap->colors[i].green = colors[i].green;
100 colormap->colors[i].blue = colors[i].blue;
103 gdk_colormap_change (colormap, ncolors);
106 static GMemChunk *color_chunk;
110 * @color: a #GdkColor.
112 * Makes a copy of a color structure. The result
113 * must be freed using gdk_color_free().
115 * Return value: a copy of @color.
118 gdk_color_copy (const GdkColor *color)
122 g_return_val_if_fail (color != NULL, NULL);
124 if (color_chunk == NULL)
125 color_chunk = g_mem_chunk_new ("colors",
130 new_color = g_chunk_new (GdkColor, color_chunk);
137 * @color: a #GdkColor.
139 * Frees a color structure created with
143 gdk_color_free (GdkColor *color)
145 g_assert (color_chunk != NULL);
146 g_return_if_fail (color != NULL);
148 g_mem_chunk_free (color_chunk, color);
153 * @colormap: a #GdkColormap.
154 * @color: the location to store the color.
156 * Returns the white color for a given colormap. The resulting
157 * value has already allocated been allocated.
159 * Return value: %TRUE if the allocation succeeded.
162 gdk_color_white (GdkColormap *colormap,
167 g_return_val_if_fail (colormap != NULL, FALSE);
172 color->green = 65535;
175 return_val = gdk_color_alloc (colormap, color);
185 * @colormap: a #GdkColormap.
186 * @color: the location to store the color.
188 * Returns the black color for a given colormap. The resulting
189 * value has already benn allocated.
191 * Return value: %TRUE if the allocation succeeded.
194 gdk_color_black (GdkColormap *colormap,
199 g_return_val_if_fail (colormap != NULL, FALSE);
207 return_val = gdk_color_alloc (colormap, color);
215 /********************
217 ********************/
220 * gdk_colormap_alloc_color:
221 * @colormap: a #GdkColormap.
222 * @color: the color to allocate. On return the
223 * <structfield>pixel</structfield> field will be
224 * filled in if allocation succeeds.
225 * @writeable: If %TRUE, the color is allocated writeable
226 * (their values can later be changed using gdk_color_change()).
227 * Writeable colors cannot be shared between applications.
228 * @best_match: If %TRUE, GDK will attempt to do matching against
229 * existing colors if the color cannot be allocated as requested.
231 * Allocates a single color from a colormap.
233 * Return value: %TRUE if the allocation succeeded.
236 gdk_colormap_alloc_color (GdkColormap *colormap,
243 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
251 * @colormap: a #GdkColormap.
252 * @color: The color to allocate. On return, the
253 * <structfield>pixel</structfield> field will be filled in.
255 * Allocates a single color from a colormap.
256 * This function is obsolete. See gdk_colormap_alloc_color().
258 * Return value: %TRUE if the allocation succeeded.
261 gdk_color_alloc (GdkColormap *colormap,
266 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
273 * @colora: a #GdkColor.
275 * A hash function suitable for using for a hash
276 * table that stores #GdkColor's.
278 * Return value: The hash function appled to @colora
281 gdk_color_hash (const GdkColor *colora)
283 return ((colora->red) +
284 (colora->green << 11) +
285 (colora->blue << 22) +
286 (colora->blue >> 6));
291 * @colora: a #GdkColor.
292 * @colorb: another #GdkColor.
294 * Compares two colors.
296 * Return value: %TRUE if the two colors compare equal
299 gdk_color_equal (const GdkColor *colora,
300 const GdkColor *colorb)
302 g_return_val_if_fail (colora != NULL, FALSE);
303 g_return_val_if_fail (colorb != NULL, FALSE);
305 return ((colora->red == colorb->red) &&
306 (colora->green == colorb->green) &&
307 (colora->blue == colorb->blue));
311 gdk_color_get_type (void)
313 static GType our_type = 0;
316 our_type = g_boxed_type_register_static ("GdkColor",
317 (GBoxedCopyFunc)gdk_color_copy,
318 (GBoxedFreeFunc)gdk_color_free);
324 * @spec: the string specifying the color.
325 * @color: the #GdkColor to fill in
327 * Parses a textual specification of a color and fill in
328 * the <structfield>red</structfield>,
329 * <structfield>green</structfield>, and
330 * <structfield>blue</structfield> fields of a
331 * #GdkColor structure. The color is <emphasis>not</emphasis>
332 * allocated, you must call gdk_colormap_alloc_color() yourself.
333 * The text string can be in any of the forms accepted
334 * by <function>XParseColor</function>; these include
335 * name for a color from <filename>rgb.txt</filename>, such as
336 * <literal>DarkSlateGray</literal>, or a hex specification
337 * such as <literal>305050</literal>.
339 * Return value: %TRUE if the parsing succeeded.
342 gdk_color_parse (const gchar *spec,
345 PangoColor pango_color;
347 if (pango_color_parse (&pango_color, spec))
349 color->red = pango_color.red;
350 color->green = pango_color.green;
351 color->blue = pango_color.blue;
360 * gdk_colormap_get_system:
362 * Gets the system's default colormap for the default screen. (See
363 * gdk_colormap_get_system_for_screen ())
365 * Return value: the default colormap.
368 gdk_colormap_get_system (void)
370 return gdk_screen_get_system_colormap (gdk_screen_get_default ());