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);
108 * @color: a #GdkColor.
110 * Makes a copy of a color structure. The result
111 * must be freed using gdk_color_free().
113 * Return value: a copy of @color.
116 gdk_color_copy (const GdkColor *color)
120 g_return_val_if_fail (color != NULL, NULL);
122 new_color = g_slice_new (GdkColor);
129 * @color: a #GdkColor.
131 * Frees a color structure created with
135 gdk_color_free (GdkColor *color)
137 g_return_if_fail (color != NULL);
139 g_slice_free (GdkColor, color);
144 * @colormap: a #GdkColormap.
145 * @color: the location to store the color.
147 * Returns the white color for a given colormap. The resulting
148 * value has already allocated been allocated.
150 * Return value: %TRUE if the allocation succeeded.
153 gdk_color_white (GdkColormap *colormap,
158 g_return_val_if_fail (colormap != NULL, FALSE);
163 color->green = 65535;
166 return_val = gdk_colormap_alloc_color (colormap, color, FALSE, TRUE);
176 * @colormap: a #GdkColormap.
177 * @color: the location to store the color.
179 * Returns the black color for a given colormap. The resulting
180 * value has already benn allocated.
182 * Return value: %TRUE if the allocation succeeded.
185 gdk_color_black (GdkColormap *colormap,
190 g_return_val_if_fail (colormap != NULL, FALSE);
198 return_val = gdk_colormap_alloc_color (colormap, color, FALSE, TRUE);
206 /********************
208 ********************/
211 * gdk_colormap_alloc_color:
212 * @colormap: a #GdkColormap.
213 * @color: the color to allocate. On return the
214 * <structfield>pixel</structfield> field will be
215 * filled in if allocation succeeds.
216 * @writeable: If %TRUE, the color is allocated writeable
217 * (their values can later be changed using gdk_color_change()).
218 * Writeable colors cannot be shared between applications.
219 * @best_match: If %TRUE, GDK will attempt to do matching against
220 * existing colors if the color cannot be allocated as requested.
222 * Allocates a single color from a colormap.
224 * Return value: %TRUE if the allocation succeeded.
227 gdk_colormap_alloc_color (GdkColormap *colormap,
234 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
242 * @colormap: a #GdkColormap.
243 * @color: The color to allocate. On return, the
244 * <structfield>pixel</structfield> field will be filled in.
246 * Allocates a single color from a colormap.
248 * Return value: %TRUE if the allocation succeeded.
250 * Deprecated: Use gdk_colormap_alloc_color() instead.
253 gdk_color_alloc (GdkColormap *colormap,
258 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
265 * @colora: a #GdkColor.
267 * A hash function suitable for using for a hash
268 * table that stores #GdkColor's.
270 * Return value: The hash function applied to @colora
273 gdk_color_hash (const GdkColor *colora)
275 return ((colora->red) +
276 (colora->green << 11) +
277 (colora->blue << 22) +
278 (colora->blue >> 6));
283 * @colora: a #GdkColor.
284 * @colorb: another #GdkColor.
286 * Compares two colors.
288 * Return value: %TRUE if the two colors compare equal
291 gdk_color_equal (const GdkColor *colora,
292 const GdkColor *colorb)
294 g_return_val_if_fail (colora != NULL, FALSE);
295 g_return_val_if_fail (colorb != NULL, FALSE);
297 return ((colora->red == colorb->red) &&
298 (colora->green == colorb->green) &&
299 (colora->blue == colorb->blue));
303 gdk_color_get_type (void)
305 static GType our_type = 0;
308 our_type = g_boxed_type_register_static (g_intern_static_string ("GdkColor"),
309 (GBoxedCopyFunc)gdk_color_copy,
310 (GBoxedFreeFunc)gdk_color_free);
316 * @spec: the string specifying the color.
317 * @color: the #GdkColor to fill in
319 * Parses a textual specification of a color and fill in
320 * the <structfield>red</structfield>,
321 * <structfield>green</structfield>, and
322 * <structfield>blue</structfield> fields of a
323 * #GdkColor structure. The color is <emphasis>not</emphasis>
324 * allocated, you must call gdk_colormap_alloc_color() yourself.
325 * The text string can be in any of the forms accepted
326 * by <function>XParseColor</function>; these include
327 * name for a color from <filename>rgb.txt</filename>, such as
328 * <literal>DarkSlateGray</literal>, or a hex specification
329 * such as <literal>#3050b2</literal> or <literal>#35b</literal>.
331 * Return value: %TRUE if the parsing succeeded.
334 gdk_color_parse (const gchar *spec,
337 PangoColor pango_color;
339 if (pango_color_parse (&pango_color, spec))
341 color->red = pango_color.red;
342 color->green = pango_color.green;
343 color->blue = pango_color.blue;
352 * gdk_color_to_string:
353 * @color: a #GdkColor
355 * Returns a textual specification of @color in the hexadecimal form
356 * <literal>#rrrrggggbbbb</literal>, where <literal>r</literal>,
357 * <literal>g</literal> and <literal>b</literal> are hex digits
358 * representing the red, green and blue components respectively.
360 * Return value: a newly-allocated text string
365 gdk_color_to_string (const GdkColor *color)
367 PangoColor pango_color;
369 g_return_val_if_fail (color != NULL, NULL);
371 pango_color.red = color->red;
372 pango_color.green = color->green;
373 pango_color.blue = color->blue;
375 return pango_color_to_string (&pango_color);
379 * gdk_colormap_get_system:
381 * Gets the system's default colormap for the default screen. (See
382 * gdk_colormap_get_system_for_screen ())
384 * Return value: the default colormap.
387 gdk_colormap_get_system (void)
389 return gdk_screen_get_system_colormap (gdk_screen_get_default ());
392 #define __GDK_COLOR_C__
393 #include "gdkaliasdef.c"