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/.
31 #include "gdkscreen.h"
32 #include "gdkinternals.h"
38 * @Short_description: Manipulation of colors
45 * @color: a #GdkColor.
47 * Makes a copy of a color structure. The result
48 * must be freed using gdk_color_free().
50 * Return value: a copy of @color.
53 gdk_color_copy (const GdkColor *color)
57 g_return_val_if_fail (color != NULL, NULL);
59 new_color = g_slice_new (GdkColor);
66 * @color: a #GdkColor.
68 * Frees a color structure created with
72 gdk_color_free (GdkColor *color)
74 g_return_if_fail (color != NULL);
76 g_slice_free (GdkColor, color);
81 * @colora: a #GdkColor.
83 * A hash function suitable for using for a hash
84 * table that stores #GdkColor's.
86 * Return value: The hash function applied to @colora
89 gdk_color_hash (const GdkColor *colora)
91 return ((colora->red) +
92 (colora->green << 11) +
93 (colora->blue << 22) +
99 * @colora: a #GdkColor.
100 * @colorb: another #GdkColor.
102 * Compares two colors.
104 * Return value: %TRUE if the two colors compare equal
107 gdk_color_equal (const GdkColor *colora,
108 const GdkColor *colorb)
110 g_return_val_if_fail (colora != NULL, FALSE);
111 g_return_val_if_fail (colorb != NULL, FALSE);
113 return ((colora->red == colorb->red) &&
114 (colora->green == colorb->green) &&
115 (colora->blue == colorb->blue));
118 G_DEFINE_BOXED_TYPE (GdkColor, gdk_color,
124 * @spec: the string specifying the color.
125 * @color: (out): the #GdkColor to fill in
127 * Parses a textual specification of a color and fill in the
128 * <structfield>red</structfield>, <structfield>green</structfield>,
129 * and <structfield>blue</structfield> fields of a #GdkColor
130 * structure. The string can either one of a large set of standard
131 * names. (Taken from the X11 <filename>rgb.txt</filename> file), or
132 * it can be a hex value in the form '#rgb' '#rrggbb'
133 * '#rrrgggbbb' or '#rrrrggggbbbb' where 'r', 'g' and 'b' are
134 * hex digits of the red, green, and blue components of the color,
135 * respectively. (White in the four forms is '#fff' '#ffffff'
136 * '#fffffffff' and '#ffffffffffff')
138 * Return value: %TRUE if the parsing succeeded.
141 gdk_color_parse (const gchar *spec,
144 PangoColor pango_color;
146 if (pango_color_parse (&pango_color, spec))
148 color->red = pango_color.red;
149 color->green = pango_color.green;
150 color->blue = pango_color.blue;
159 * gdk_color_to_string:
160 * @color: a #GdkColor
162 * Returns a textual specification of @color in the hexadecimal form
163 * <literal>#rrrrggggbbbb</literal>, where <literal>r</literal>,
164 * <literal>g</literal> and <literal>b</literal> are hex digits
165 * representing the red, green and blue components respectively.
167 * Return value: a newly-allocated text string
172 gdk_color_to_string (const GdkColor *color)
174 PangoColor pango_color;
176 g_return_val_if_fail (color != NULL, NULL);
178 pango_color.red = color->red;
179 pango_color.green = color->green;
180 pango_color.blue = color->blue;
182 return pango_color_to_string (&pango_color);