| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 |
* |
| 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. |
| 8 |
* |
| 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. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
/* |
| 19 |
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
| 20 |
* file for a list of people on the GTK+ Team. See the ChangeLog |
| 21 |
* files for a list of changes. These files are distributed with |
| 22 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include "gdkcolor.h" |
| 28 |
|
| 29 |
#include "gdkscreen.h" |
| 30 |
#include "gdkinternals.h" |
| 31 |
|
| 32 |
#include <time.h> |
| 33 |
|
| 34 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 35 |
|
| 36 |
/** |
| 37 |
* SECTION:colors |
| 38 |
* @Short_description: Manipulation of colors |
| 39 |
* @Title: Colors |
| 40 |
* |
| 41 |
* A #GdkColor represents a color. |
| 42 |
* |
| 43 |
* When working with cairo, it is often more convenient |
| 44 |
* to use a #GdkRGBA instead, and #GdkColor has been |
| 45 |
* deprecated in favor of #GdkRGBA. |
| 46 |
*/ |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* gdk_color_copy: |
| 51 |
* @color: a #GdkColor |
| 52 |
* |
| 53 |
* Makes a copy of a #GdkColor. |
| 54 |
* |
| 55 |
* The result must be freed using gdk_color_free(). |
| 56 |
* |
| 57 |
* Returns: a copy of @color |
| 58 |
* |
| 59 |
* Deprecated: 3.14: Use #GdkRGBA |
| 60 |
*/ |
| 61 |
GdkColor* |
| 62 |
gdk_color_copy (const GdkColor *color) |
| 63 |
{ |
| 64 |
GdkColor *new_color; |
| 65 |
|
| 66 |
g_return_val_if_fail (color != NULL, NULL); |
| 67 |
|
| 68 |
new_color = g_slice_new (GdkColor); |
| 69 |
*new_color = *color; |
| 70 |
return new_color; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* gdk_color_free: |
| 75 |
* @color: a #GdkColor |
| 76 |
* |
| 77 |
* Frees a #GdkColor created with gdk_color_copy(). |
| 78 |
* |
| 79 |
* Deprecated: 3.14: Use #GdkRGBA |
| 80 |
*/ |
| 81 |
void |
| 82 |
gdk_color_free (GdkColor *color) |
| 83 |
{ |
| 84 |
g_return_if_fail (color != NULL); |
| 85 |
|
| 86 |
g_slice_free (GdkColor, color); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* gdk_color_hash: |
| 91 |
* @color: a #GdkColor |
| 92 |
* |
| 93 |
* A hash function suitable for using for a hash |
| 94 |
* table that stores #GdkColors. |
| 95 |
* |
| 96 |
* Returns: The hash function applied to @color |
| 97 |
* |
| 98 |
* Deprecated: 3.14: Use #GdkRGBA |
| 99 |
*/ |
| 100 |
guint |
| 101 |
gdk_color_hash (const GdkColor *color) |
| 102 |
{ |
| 103 |
return ((color->red) + |
| 104 |
(color->green << 11) + |
| 105 |
(color->blue << 22) + |
| 106 |
(color->blue >> 6)); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* gdk_color_equal: |
| 111 |
* @colora: a #GdkColor |
| 112 |
* @colorb: another #GdkColor |
| 113 |
* |
| 114 |
* Compares two colors. |
| 115 |
* |
| 116 |
* Returns: %TRUE if the two colors compare equal |
| 117 |
* |
| 118 |
* Deprecated: 3.14: Use #GdkRGBA |
| 119 |
*/ |
| 120 |
gboolean |
| 121 |
gdk_color_equal (const GdkColor *colora, |
| 122 |
const GdkColor *colorb) |
| 123 |
{ |
| 124 |
g_return_val_if_fail (colora != NULL, FALSE); |
| 125 |
g_return_val_if_fail (colorb != NULL, FALSE); |
| 126 |
|
| 127 |
return ((colora->red == colorb->red) && |
| 128 |
(colora->green == colorb->green) && |
| 129 |
(colora->blue == colorb->blue)); |
| 130 |
} |
| 131 |
|
| 132 |
G_DEFINE_BOXED_TYPE (GdkColor, gdk_color, |
| 133 |
gdk_color_copy, |
| 134 |
gdk_color_free) |
| 135 |
|
| 136 |
/** |
| 137 |
* gdk_color_parse: |
| 138 |
* @spec: the string specifying the color |
| 139 |
* @color: (out): the #GdkColor to fill in |
| 140 |
* |
| 141 |
* Parses a textual specification of a color and fill in the |
| 142 |
* @red, @green, and @blue fields of a #GdkColor. |
| 143 |
* |
| 144 |
* The string can either one of a large set of standard names |
| 145 |
* (taken from the X11 `rgb.txt` file), or it can be a hexadecimal |
| 146 |
* value in the form “\#rgb” “\#rrggbb”, “\#rrrgggbbb” or |
| 147 |
* “\#rrrrggggbbbb” where “r”, “g” and “b” are hex digits of |
| 148 |
* the red, green, and blue components of the color, respectively. |
| 149 |
* (White in the four forms is “\#fff”, “\#ffffff”, “\#fffffffff” |
| 150 |
* and “\#ffffffffffff”). |
| 151 |
* |
| 152 |
* Returns: %TRUE if the parsing succeeded |
| 153 |
* |
| 154 |
* Deprecated: 3.14: Use #GdkRGBA |
| 155 |
*/ |
| 156 |
gboolean |
| 157 |
gdk_color_parse (const gchar *spec, |
| 158 |
GdkColor *color) |
| 159 |
{ |
| 160 |
PangoColor pango_color; |
| 161 |
|
| 162 |
if (pango_color_parse (&pango_color, spec)) |
| 163 |
{ |
| 164 |
color->red = pango_color.red; |
| 165 |
color->green = pango_color.green; |
| 166 |
color->blue = pango_color.blue; |
| 167 |
|
| 168 |
return TRUE; |
| 169 |
} |
| 170 |
else |
| 171 |
return FALSE; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* gdk_color_to_string: |
| 176 |
* @color: a #GdkColor |
| 177 |
* |
| 178 |
* Returns a textual specification of @color in the hexadecimal |
| 179 |
* form “\#rrrrggggbbbb” where “r”, “g” and “b” are hex digits |
| 180 |
* representing the red, green and blue components respectively. |
| 181 |
* |
| 182 |
* The returned string can be parsed by gdk_color_parse(). |
| 183 |
* |
| 184 |
* Returns: a newly-allocated text string |
| 185 |
* |
| 186 |
* Since: 2.12 |
| 187 |
* |
| 188 |
* Deprecated: 3.14: Use #GdkRGBA |
| 189 |
*/ |
| 190 |
gchar * |
| 191 |
gdk_color_to_string (const GdkColor *color) |
| 192 |
{ |
| 193 |
PangoColor pango_color; |
| 194 |
|
| 195 |
g_return_val_if_fail (color != NULL, NULL); |
| 196 |
|
| 197 |
pango_color.red = color->red; |
| 198 |
pango_color.green = color->green; |
| 199 |
pango_color.blue = color->blue; |
| 200 |
|
| 201 |
return pango_color_to_string (&pango_color); |
| 202 |
} |