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
43 * Deprecated: 2.0: Use g_object_ref() instead.
46 gdk_colormap_ref (GdkColormap *cmap)
48 return (GdkColormap *) g_object_ref (cmap);
53 * @cmap: a #GdkColormap
55 * Deprecated function; use g_object_unref() instead.
57 * Deprecated: 2.0: Use g_object_unref() instead.
60 gdk_colormap_unref (GdkColormap *cmap)
62 g_object_unref (cmap);
67 * gdk_colormap_get_visual:
68 * @colormap: a #GdkColormap.
70 * Returns the visual for which a given colormap was created.
72 * Return value: the visual of the colormap.
75 gdk_colormap_get_visual (GdkColormap *colormap)
77 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
79 return colormap->visual;
84 * @colormap: a #GdkColormap.
85 * @colors: the new color values.
86 * @ncolors: the number of colors to change.
88 * Changes the value of the first @ncolors colors in
89 * a private colormap. This function is obsolete and
90 * should not be used. See gdk_color_change().
93 gdk_colors_store (GdkColormap *colormap,
99 for (i = 0; i < ncolors; i++)
101 colormap->colors[i].pixel = colors[i].pixel;
102 colormap->colors[i].red = colors[i].red;
103 colormap->colors[i].green = colors[i].green;
104 colormap->colors[i].blue = colors[i].blue;
107 gdk_colormap_change (colormap, ncolors);
112 * @color: a #GdkColor.
114 * Makes a copy of a color structure. The result
115 * must be freed using gdk_color_free().
117 * Return value: a copy of @color.
120 gdk_color_copy (const GdkColor *color)
124 g_return_val_if_fail (color != NULL, NULL);
126 new_color = g_slice_new (GdkColor);
133 * @color: a #GdkColor.
135 * Frees a color structure created with
139 gdk_color_free (GdkColor *color)
141 g_return_if_fail (color != NULL);
143 g_slice_free (GdkColor, color);
148 * @colormap: a #GdkColormap.
149 * @color: the location to store the color.
151 * Returns the white color for a given colormap. The resulting
152 * value has already allocated been allocated.
154 * Return value: %TRUE if the allocation succeeded.
157 gdk_color_white (GdkColormap *colormap,
162 g_return_val_if_fail (colormap != NULL, FALSE);
167 color->green = 65535;
170 return_val = gdk_colormap_alloc_color (colormap, color, FALSE, TRUE);
180 * @colormap: a #GdkColormap.
181 * @color: the location to store the color.
183 * Returns the black color for a given colormap. The resulting
184 * value has already been allocated.
186 * Return value: %TRUE if the allocation succeeded.
189 gdk_color_black (GdkColormap *colormap,
194 g_return_val_if_fail (colormap != NULL, FALSE);
202 return_val = gdk_colormap_alloc_color (colormap, color, FALSE, TRUE);
210 /********************
212 ********************/
215 * gdk_colormap_alloc_color:
216 * @colormap: a #GdkColormap.
217 * @color: the color to allocate. On return the
218 * <structfield>pixel</structfield> field will be
219 * filled in if allocation succeeds.
220 * @writeable: If %TRUE, the color is allocated writeable
221 * (their values can later be changed using gdk_color_change()).
222 * Writeable colors cannot be shared between applications.
223 * @best_match: If %TRUE, GDK will attempt to do matching against
224 * existing colors if the color cannot be allocated as requested.
226 * Allocates a single color from a colormap.
228 * Return value: %TRUE if the allocation succeeded.
231 gdk_colormap_alloc_color (GdkColormap *colormap,
238 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
246 * @colormap: a #GdkColormap.
247 * @color: The color to allocate. On return, the
248 * <structfield>pixel</structfield> field will be filled in.
250 * Allocates a single color from a colormap.
252 * Return value: %TRUE if the allocation succeeded.
254 * Deprecated: 2.2: Use gdk_colormap_alloc_color() instead.
257 gdk_color_alloc (GdkColormap *colormap,
262 gdk_colormap_alloc_colors (colormap, color, 1, FALSE, TRUE, &success);
269 * @colora: a #GdkColor.
271 * A hash function suitable for using for a hash
272 * table that stores #GdkColor's.
274 * Return value: The hash function applied to @colora
277 gdk_color_hash (const GdkColor *colora)
279 return ((colora->red) +
280 (colora->green << 11) +
281 (colora->blue << 22) +
282 (colora->blue >> 6));
287 * @colora: a #GdkColor.
288 * @colorb: another #GdkColor.
290 * Compares two colors.
292 * Return value: %TRUE if the two colors compare equal
295 gdk_color_equal (const GdkColor *colora,
296 const GdkColor *colorb)
298 g_return_val_if_fail (colora != NULL, FALSE);
299 g_return_val_if_fail (colorb != NULL, FALSE);
301 return ((colora->red == colorb->red) &&
302 (colora->green == colorb->green) &&
303 (colora->blue == colorb->blue));
307 gdk_color_get_type (void)
309 static GType our_type = 0;
312 our_type = g_boxed_type_register_static (g_intern_static_string ("GdkColor"),
313 (GBoxedCopyFunc)gdk_color_copy,
314 (GBoxedFreeFunc)gdk_color_free);
320 * @spec: the string specifying the color.
321 * @color: the #GdkColor to fill in
323 * Parses a textual specification of a color and fill in the
324 * <structfield>red</structfield>, <structfield>green</structfield>,
325 * and <structfield>blue</structfield> fields of a #GdkColor
326 * structure. The color is <emphasis>not</emphasis> allocated, you
327 * must call gdk_colormap_alloc_color() yourself. The string can
328 * either one of a large set of standard names. (Taken from the X11
329 * <filename>rgb.txt</filename> file), or it can be a hex value in the
330 * form '#rgb' '#rrggbb' '#rrrgggbbb' or
331 * '#rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the
332 * red, green, and blue components of the color, respectively. (White
333 * in the four forms is '#fff' '#ffffff' '#fffffffff' and
334 * '#ffffffffffff')
336 * Return value: %TRUE if the parsing succeeded.
339 gdk_color_parse (const gchar *spec,
342 PangoColor pango_color;
344 if (pango_color_parse (&pango_color, spec))
346 color->red = pango_color.red;
347 color->green = pango_color.green;
348 color->blue = pango_color.blue;
357 * gdk_color_to_string:
358 * @color: a #GdkColor
360 * Returns a textual specification of @color in the hexadecimal form
361 * <literal>#rrrrggggbbbb</literal>, where <literal>r</literal>,
362 * <literal>g</literal> and <literal>b</literal> are hex digits
363 * representing the red, green and blue components respectively.
365 * Return value: a newly-allocated text string
370 gdk_color_to_string (const GdkColor *color)
372 PangoColor pango_color;
374 g_return_val_if_fail (color != NULL, NULL);
376 pango_color.red = color->red;
377 pango_color.green = color->green;
378 pango_color.blue = color->blue;
380 return pango_color_to_string (&pango_color);
384 * gdk_colormap_get_system:
386 * Gets the system's default colormap for the default screen. (See
387 * gdk_colormap_get_system_for_screen ())
389 * Return value: the default colormap.
392 gdk_colormap_get_system (void)
394 return gdk_screen_get_system_colormap (gdk_screen_get_default ());
397 #define __GDK_COLOR_C__
398 #include "gdkaliasdef.c"