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);
44 /*****************************************************************************/
45 /* Convert gLabels color into a GdkColor */
46 /*****************************************************************************/
48 gl_color_to_gdk_color (guint color)
52 gdk_color = g_new0 (GdkColor, 1);
54 gdk_color->red = GL_COLOR_F_RED (color) * 65535;
55 gdk_color->green = GL_COLOR_F_GREEN (color) * 65535;
56 gdk_color->blue = GL_COLOR_F_BLUE (color) * 65535;
62 /*****************************************************************************/
63 /* Convert GdkColor into a gLabels color */
64 /*****************************************************************************/
66 gl_color_from_gdk_color (GdkColor *gdk_color)
70 color = GL_COLOR ((gdk_color->red >>8),
71 (gdk_color->green >>8),
72 (gdk_color->blue >>8));
78 /****************************************************************************/
79 /* Create a single color node with default color. */
80 /****************************************************************************/
82 gl_color_node_new_default (void)
84 glColorNode* color_node;
86 color_node = g_new0(glColorNode,1);
88 color_node->field_flag = FALSE;
89 color_node->color = GL_COLOR_NONE;
90 color_node->key = NULL;
96 /****************************************************************************/
97 /* Copy a single color node. */
98 /****************************************************************************/
100 gl_color_node_dup (glColorNode *src)
104 if ( src == NULL ) return NULL;
106 dst = g_new0 (glColorNode, 1);
108 dst->field_flag = src->field_flag;
109 if (src->key != NULL)
111 dst->key = g_strdup (src->key);
117 dst->color = src->color;
123 /****************************************************************************/
124 /* Compare 2 color nodes for equality. */
125 /****************************************************************************/
127 gl_color_node_equal (glColorNode *color_node1,
128 glColorNode *color_node2)
130 /* First take care of the case of either or both being NULL. */
131 if ( color_node1 == NULL )
133 return ( color_node2 == NULL );
137 if ( color_node2 == NULL )
143 /* Bail if field flags differ. */
144 if ( color_node1->field_flag != color_node2->field_flag )
149 /* Now take care of the case of either or both color fields being different. */
150 if ( color_node1->color != color_node2->color )
155 /* Then take care of the case of either or both key fields being NULL. */
156 if ( color_node1->key == NULL )
158 return ( color_node2->key == NULL );
162 if ( color_node2->key == NULL )
168 /* Field flags are identical, so now compare the keys. */
169 return (strcmp (color_node1->key, color_node2->key) == 0);
173 /****************************************************************************/
174 /* Expand single node into representative color. */
175 /****************************************************************************/
177 gl_color_node_expand (glColorNode *color_node,
178 glMergeRecord *record)
184 if (color_node->field_flag)
188 return GL_COLOR_NONE;
192 text = gl_merge_eval_key (record, color_node->key);
195 gdk_color = g_new0 (GdkColor, 1);
196 if (gdk_color_parse (text, gdk_color))
198 color = gl_color_from_gdk_color (gdk_color);
205 return GL_COLOR_NONE;
210 return GL_COLOR_NONE;
216 return color_node->color;
221 /****************************************************************************/
222 /* Free a single color node. */
223 /****************************************************************************/
225 gl_color_node_free (glColorNode **color_node)
227 if ( *color_node == NULL ) return;
229 g_free ((*color_node)->key);
230 (*color_node)->key = NULL;
231 g_free (*color_node);
238 * Local Variables: -- emacs
240 * c-basic-offset: 8 -- emacs
241 * tab-width: 8 -- emacs
242 * indent-tabs-mode: nil -- emacs