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"
36 * gdk_colormap_get_visual:
37 * @colormap: a #GdkColormap.
39 * Returns the visual for which a given colormap was created.
41 * Return value: the visual of the colormap.
44 gdk_colormap_get_visual (GdkColormap *colormap)
46 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
48 return colormap->visual;
53 * @color: a #GdkColor.
55 * Makes a copy of a color structure. The result
56 * must be freed using gdk_color_free().
58 * Return value: a copy of @color.
61 gdk_color_copy (const GdkColor *color)
65 g_return_val_if_fail (color != NULL, NULL);
67 new_color = g_slice_new (GdkColor);
74 * @color: a #GdkColor.
76 * Frees a color structure created with
80 gdk_color_free (GdkColor *color)
82 g_return_if_fail (color != NULL);
84 g_slice_free (GdkColor, color);
92 * gdk_colormap_alloc_color:
93 * @colormap: a #GdkColormap.
94 * @color: the color to allocate. On return the
95 * <structfield>pixel</structfield> field will be
96 * filled in if allocation succeeds.
97 * @writeable: this parameter has no effect, and it's here for mere
99 * @best_match: If %TRUE, GDK will attempt to do matching against
100 * existing colors if the color cannot be allocated as requested.
102 * Allocates a single color from a colormap.
104 * Return value: %TRUE if the allocation succeeded.
107 gdk_colormap_alloc_color (GdkColormap *colormap,
114 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
122 * @colora: a #GdkColor.
124 * A hash function suitable for using for a hash
125 * table that stores #GdkColor's.
127 * Return value: The hash function applied to @colora
130 gdk_color_hash (const GdkColor *colora)
132 return ((colora->red) +
133 (colora->green << 11) +
134 (colora->blue << 22) +
135 (colora->blue >> 6));
140 * @colora: a #GdkColor.
141 * @colorb: another #GdkColor.
143 * Compares two colors.
145 * Return value: %TRUE if the two colors compare equal
148 gdk_color_equal (const GdkColor *colora,
149 const GdkColor *colorb)
151 g_return_val_if_fail (colora != NULL, FALSE);
152 g_return_val_if_fail (colorb != NULL, FALSE);
154 return ((colora->red == colorb->red) &&
155 (colora->green == colorb->green) &&
156 (colora->blue == colorb->blue));
159 G_DEFINE_BOXED_TYPE (GdkColor, gdk_color,
165 * @spec: the string specifying the color.
166 * @color: (out): the #GdkColor to fill in
168 * Parses a textual specification of a color and fill in the
169 * <structfield>red</structfield>, <structfield>green</structfield>,
170 * and <structfield>blue</structfield> fields of a #GdkColor
171 * structure. The color is <emphasis>not</emphasis> allocated, you
172 * must call gdk_colormap_alloc_color() yourself. The string can
173 * either one of a large set of standard names. (Taken from the X11
174 * <filename>rgb.txt</filename> file), or it can be a hex value in the
175 * form '#rgb' '#rrggbb' '#rrrgggbbb' or
176 * '#rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the
177 * red, green, and blue components of the color, respectively. (White
178 * in the four forms is '#fff' '#ffffff' '#fffffffff' and
179 * '#ffffffffffff')
181 * Return value: %TRUE if the parsing succeeded.
184 gdk_color_parse (const gchar *spec,
187 PangoColor pango_color;
189 if (pango_color_parse (&pango_color, spec))
191 color->red = pango_color.red;
192 color->green = pango_color.green;
193 color->blue = pango_color.blue;
202 * gdk_color_to_string:
203 * @color: a #GdkColor
205 * Returns a textual specification of @color in the hexadecimal form
206 * <literal>#rrrrggggbbbb</literal>, where <literal>r</literal>,
207 * <literal>g</literal> and <literal>b</literal> are hex digits
208 * representing the red, green and blue components respectively.
210 * Return value: a newly-allocated text string
215 gdk_color_to_string (const GdkColor *color)
217 PangoColor pango_color;
219 g_return_val_if_fail (color != NULL, NULL);
221 pango_color.red = color->red;
222 pango_color.green = color->green;
223 pango_color.blue = color->blue;
225 return pango_color_to_string (&pango_color);
229 * gdk_colormap_get_system:
231 * Gets the system's default colormap for the default screen. (See
232 * gdk_colormap_get_system_for_screen ())
234 * Return value: the default colormap.
237 gdk_colormap_get_system (void)
239 return gdk_screen_get_system_colormap (gdk_screen_get_default ());