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 * gdk_colormap_get_visual:
38 * @colormap: a #GdkColormap.
40 * Returns the visual for which a given colormap was created.
42 * Return value: the visual of the colormap.
45 gdk_colormap_get_visual (GdkColormap *colormap)
47 g_return_val_if_fail (GDK_IS_COLORMAP (colormap), NULL);
49 return colormap->visual;
54 * @color: a #GdkColor.
56 * Makes a copy of a color structure. The result
57 * must be freed using gdk_color_free().
59 * Return value: a copy of @color.
62 gdk_color_copy (const GdkColor *color)
66 g_return_val_if_fail (color != NULL, NULL);
68 new_color = g_slice_new (GdkColor);
75 * @color: a #GdkColor.
77 * Frees a color structure created with
81 gdk_color_free (GdkColor *color)
83 g_return_if_fail (color != NULL);
85 g_slice_free (GdkColor, color);
93 * gdk_colormap_alloc_color:
94 * @colormap: a #GdkColormap.
95 * @color: the color to allocate. On return the
96 * <structfield>pixel</structfield> field will be
97 * filled in if allocation succeeds.
98 * @writeable: this parameter has no effect, and it's here for mere
100 * @best_match: If %TRUE, GDK will attempt to do matching against
101 * existing colors if the color cannot be allocated as requested.
103 * Allocates a single color from a colormap.
105 * Return value: %TRUE if the allocation succeeded.
108 gdk_colormap_alloc_color (GdkColormap *colormap,
115 gdk_colormap_alloc_colors (colormap, color, 1, writeable, best_match,
123 * @colora: a #GdkColor.
125 * A hash function suitable for using for a hash
126 * table that stores #GdkColor's.
128 * Return value: The hash function applied to @colora
131 gdk_color_hash (const GdkColor *colora)
133 return ((colora->red) +
134 (colora->green << 11) +
135 (colora->blue << 22) +
136 (colora->blue >> 6));
141 * @colora: a #GdkColor.
142 * @colorb: another #GdkColor.
144 * Compares two colors.
146 * Return value: %TRUE if the two colors compare equal
149 gdk_color_equal (const GdkColor *colora,
150 const GdkColor *colorb)
152 g_return_val_if_fail (colora != NULL, FALSE);
153 g_return_val_if_fail (colorb != NULL, FALSE);
155 return ((colora->red == colorb->red) &&
156 (colora->green == colorb->green) &&
157 (colora->blue == colorb->blue));
161 gdk_color_get_type (void)
163 static GType our_type = 0;
166 our_type = g_boxed_type_register_static (g_intern_static_string ("GdkColor"),
167 (GBoxedCopyFunc)gdk_color_copy,
168 (GBoxedFreeFunc)gdk_color_free);
174 * @spec: the string specifying the color.
175 * @color: (out): the #GdkColor to fill in
177 * Parses a textual specification of a color and fill in the
178 * <structfield>red</structfield>, <structfield>green</structfield>,
179 * and <structfield>blue</structfield> fields of a #GdkColor
180 * structure. The color is <emphasis>not</emphasis> allocated, you
181 * must call gdk_colormap_alloc_color() yourself. The string can
182 * either one of a large set of standard names. (Taken from the X11
183 * <filename>rgb.txt</filename> file), or it can be a hex value in the
184 * form '#rgb' '#rrggbb' '#rrrgggbbb' or
185 * '#rrrrggggbbbb' where 'r', 'g' and 'b' are hex digits of the
186 * red, green, and blue components of the color, respectively. (White
187 * in the four forms is '#fff' '#ffffff' '#fffffffff' and
188 * '#ffffffffffff')
190 * Return value: %TRUE if the parsing succeeded.
193 gdk_color_parse (const gchar *spec,
196 PangoColor pango_color;
198 if (pango_color_parse (&pango_color, spec))
200 color->red = pango_color.red;
201 color->green = pango_color.green;
202 color->blue = pango_color.blue;
211 * gdk_color_to_string:
212 * @color: a #GdkColor
214 * Returns a textual specification of @color in the hexadecimal form
215 * <literal>#rrrrggggbbbb</literal>, where <literal>r</literal>,
216 * <literal>g</literal> and <literal>b</literal> are hex digits
217 * representing the red, green and blue components respectively.
219 * Return value: a newly-allocated text string
224 gdk_color_to_string (const GdkColor *color)
226 PangoColor pango_color;
228 g_return_val_if_fail (color != NULL, NULL);
230 pango_color.red = color->red;
231 pango_color.green = color->green;
232 pango_color.blue = color->blue;
234 return pango_color_to_string (&pango_color);
238 * gdk_colormap_get_system:
240 * Gets the system's default colormap for the default screen. (See
241 * gdk_colormap_get_system_for_screen ())
243 * Return value: the default colormap.
246 gdk_colormap_get_system (void)
248 return gdk_screen_get_system_colormap (gdk_screen_get_default ());
251 #define __GDK_COLOR_C__
252 #include "gdkaliasdef.c"