3 * Copyright (C) 2002-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
28 /*****************************************************************************/
29 /* Apply given opacity to given color. */
30 /*****************************************************************************/
32 gl_color_set_opacity (guint color,
37 new_color = (color & 0xFFFFFF00) | (((guint)(255.0*opacity)) & 0xFF);
43 /*****************************************************************************/
44 /* Resolve actual shadow color by adjusting opacity. */
45 /*****************************************************************************/
47 gl_color_shadow (guint base_color,
53 color = gl_color_set_opacity (base_color,
54 opacity * GL_COLOR_F_ALPHA (object_color));
60 /*****************************************************************************/
61 /* Convert gLabels color into a GdkColor */
62 /*****************************************************************************/
64 gl_color_to_gdk_color (guint color)
68 gdk_color = g_new0 (GdkColor, 1);
70 gdk_color->red = GL_COLOR_F_RED (color) * 65535;
71 gdk_color->green = GL_COLOR_F_GREEN (color) * 65535;
72 gdk_color->blue = GL_COLOR_F_BLUE (color) * 65535;
78 /*****************************************************************************/
79 /* Convert GdkColor into a gLabels color */
80 /*****************************************************************************/
82 gl_color_from_gdk_color (GdkColor *gdk_color)
86 color = GL_COLOR ((gdk_color->red >>8),
87 (gdk_color->green >>8),
88 (gdk_color->blue >>8));
94 /****************************************************************************/
95 /* Create a single color node with default color. */
96 /****************************************************************************/
98 gl_color_node_new_default (void)
100 glColorNode* color_node;
102 color_node = g_new0(glColorNode,1);
104 color_node->field_flag = FALSE;
105 color_node->color = GL_COLOR_NONE;
106 color_node->key = NULL;
112 /****************************************************************************/
113 /* Copy a single color node. */
114 /****************************************************************************/
116 gl_color_node_dup (glColorNode *src)
120 if ( src == NULL ) return NULL;
122 dst = g_new0 (glColorNode, 1);
124 dst->field_flag = src->field_flag;
125 if (src->key != NULL)
127 dst->key = g_strdup (src->key);
133 dst->color = src->color;
139 /****************************************************************************/
140 /* Compare 2 color nodes for equality. */
141 /****************************************************************************/
143 gl_color_node_equal (glColorNode *color_node1,
144 glColorNode *color_node2)
146 /* First take care of the case of either or both being NULL. */
147 if ( color_node1 == NULL )
149 return ( color_node2 == NULL );
153 if ( color_node2 == NULL )
159 /* Bail if field flags differ. */
160 if ( color_node1->field_flag != color_node2->field_flag )
165 /* Now take care of the case of either or both color fields being different. */
166 if ( color_node1->color != color_node2->color )
171 /* Then take care of the case of either or both key fields being NULL. */
172 if ( color_node1->key == NULL )
174 return ( color_node2->key == NULL );
178 if ( color_node2->key == NULL )
184 /* Field flags are identical, so now compare the keys. */
185 return (strcmp (color_node1->key, color_node2->key) == 0);
189 /****************************************************************************/
190 /* Expand single node into representative color. */
191 /****************************************************************************/
193 gl_color_node_expand (glColorNode *color_node,
194 glMergeRecord *record)
200 if (color_node->field_flag)
204 return GL_COLOR_NONE;
208 text = gl_merge_eval_key (record, color_node->key);
211 gdk_color = g_new0 (GdkColor, 1);
212 if (gdk_color_parse (text, gdk_color))
214 color = gl_color_from_gdk_color (gdk_color);
221 return GL_COLOR_NONE;
226 return GL_COLOR_NONE;
232 return color_node->color;
237 /****************************************************************************/
238 /* Free a single color node. */
239 /****************************************************************************/
241 gl_color_node_free (glColorNode **color_node)
243 if ( *color_node == NULL ) return;
245 g_free ((*color_node)->key);
246 (*color_node)->key = NULL;
247 g_free (*color_node);
254 * Local Variables: -- emacs
256 * c-basic-offset: 8 -- emacs
257 * tab-width: 8 -- emacs
258 * indent-tabs-mode: nil -- emacs