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/.
30 #include "gdkscreen.h"
32 #include "gdkinternals.h"
37 * @cmap: a #GdkColormap
39 * Deprecated function; use g_object_ref() instead.
41 * Return value: the colormap
44 gdk_colormap_ref (GdkColormap *cmap)
46 return (GdkColormap *) g_object_ref (cmap);
51 * @cmap: a #GdkColormap
53 * Deprecated function; use g_object_ref() instead.
56 gdk_colormap_unref (GdkColormap *cmap)
58 g_object_unref (cmap);
63 * gdk_colormap_get_visual:
64 * @colormap: a #GdkColormap.
66 * Returns the visual for which a given colormap was created.
68 * Return value: the visual of the colormap.
71 gdk_colormap_get_visual (GdkColormap *colormap)
73 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
75 return colormap->visual;
80 * @colormap: a #GdkColormap.
81 * @colors: the new color values.
82 * @ncolors: the number of colors to change.
84 * Changes the value of the first @ncolors colors in
85 * a private colormap. This function is obsolete and
86 * 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_colormap_alloc_color (colormap, color, FALSE, TRUE);
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_colormap_alloc_color (colormap, color, FALSE, TRUE);
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.
257 * Return value: %TRUE if the allocation succeeded.
259 * Deprecated: Use gdk_colormap_alloc_color() instead.
262 gdk_color_alloc (GdkColormap *colormap,
267 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
274 * @colora: a #GdkColor.
276 * A hash function suitable for using for a hash
277 * table that stores #GdkColor's.
279 * Return value: The hash function appled to @colora
282 gdk_color_hash (const GdkColor *colora)
284 return ((colora->red) +
285 (colora->green << 11) +
286 (colora->blue << 22) +
287 (colora->blue >> 6));
292 * @colora: a #GdkColor.
293 * @colorb: another #GdkColor.
295 * Compares two colors.
297 * Return value: %TRUE if the two colors compare equal
300 gdk_color_equal (const GdkColor *colora,
301 const GdkColor *colorb)
303 g_return_val_if_fail (colora != NULL, FALSE);
304 g_return_val_if_fail (colorb != NULL, FALSE);
306 return ((colora->red == colorb->red) &&
307 (colora->green == colorb->green) &&
308 (colora->blue == colorb->blue));
312 gdk_color_get_type (void)
314 static GType our_type = 0;
317 our_type = g_boxed_type_register_static ("GdkColor",
318 (GBoxedCopyFunc)gdk_color_copy,
319 (GBoxedFreeFunc)gdk_color_free);
325 * @spec: the string specifying the color.
326 * @color: the #GdkColor to fill in
328 * Parses a textual specification of a color and fill in
329 * the <structfield>red</structfield>,
330 * <structfield>green</structfield>, and
331 * <structfield>blue</structfield> fields of a
332 * #GdkColor structure. The color is <emphasis>not</emphasis>
333 * allocated, you must call gdk_colormap_alloc_color() yourself.
334 * The text string can be in any of the forms accepted
335 * by <function>XParseColor</function>; these include
336 * name for a color from <filename>rgb.txt</filename>, such as
337 * <literal>DarkSlateGray</literal>, or a hex specification
338 * such as <literal>305050</literal>.
340 * Return value: %TRUE if the parsing succeeded.
343 gdk_color_parse (const gchar *spec,
346 PangoColor pango_color;
348 if (pango_color_parse (&pango_color, spec))
350 color->red = pango_color.red;
351 color->green = pango_color.green;
352 color->blue = pango_color.blue;
361 * gdk_colormap_get_system:
363 * Gets the system's default colormap for the default screen. (See
364 * gdk_colormap_get_system_for_screen ())
366 * Return value: the default colormap.
369 gdk_colormap_get_system (void)
371 return gdk_screen_get_system_colormap (gdk_screen_get_default ());
375 * gdk_cairo_set_source_color:
377 * @color: a #GdkColor
379 * Convenience function to set the specified GdkColor as the
380 * source color of the given Cairo context.
385 gdk_cairo_set_source_color (cairo_t *cr,
388 cairo_set_source_rgb (cr,
390 color->green / 65535.,
391 color->blue / 65535.);
394 #define __GDK_COLOR_C__
395 #include "gdkaliasdef.c"