3 * Copyright (C) 2001-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/>.
21 #include "label-line.h"
28 /*========================================================*/
30 /*========================================================*/
32 struct _glLabelLinePrivate {
34 glColorNode *line_color_node;
38 /*========================================================*/
39 /* Private globals. */
40 /*========================================================*/
43 /*========================================================*/
44 /* Private function prototypes. */
45 /*========================================================*/
47 static void gl_label_line_finalize (GObject *object);
49 static void copy (glLabelObject *dst_object,
50 glLabelObject *src_object);
52 static void set_line_color (glLabelObject *object,
53 glColorNode *line_color_node);
55 static void set_line_width (glLabelObject *object,
58 static glColorNode *get_line_color (glLabelObject *object);
60 static gdouble get_line_width (glLabelObject *object);
62 static void draw_object (glLabelObject *object,
65 glMergeRecord *record);
67 static void draw_shadow (glLabelObject *object,
70 glMergeRecord *record);
73 /*****************************************************************************/
74 /* Boilerplate object stuff. */
75 /*****************************************************************************/
76 G_DEFINE_TYPE (glLabelLine, gl_label_line, GL_TYPE_LABEL_OBJECT);
80 gl_label_line_class_init (glLabelLineClass *class)
82 GObjectClass *object_class = G_OBJECT_CLASS (class);
83 glLabelObjectClass *label_object_class = GL_LABEL_OBJECT_CLASS (class);
85 gl_label_line_parent_class = g_type_class_peek_parent (class);
87 label_object_class->copy = copy;
88 label_object_class->set_line_color = set_line_color;
89 label_object_class->set_line_width = set_line_width;
90 label_object_class->get_line_color = get_line_color;
91 label_object_class->get_line_width = get_line_width;
92 label_object_class->draw_object = draw_object;
93 label_object_class->draw_shadow = draw_shadow;
95 object_class->finalize = gl_label_line_finalize;
100 gl_label_line_init (glLabelLine *lline)
102 lline->priv = g_new0 (glLabelLinePrivate, 1);
103 lline->priv->line_color_node = gl_color_node_new_default ();
108 gl_label_line_finalize (GObject *object)
110 glLabelLine *lline = GL_LABEL_LINE (object);
112 g_return_if_fail (object && GL_IS_LABEL_LINE (object));
114 gl_color_node_free (&(lline->priv->line_color_node));
115 g_free (lline->priv);
117 G_OBJECT_CLASS (gl_label_line_parent_class)->finalize (object);
121 /*****************************************************************************/
122 /* NEW label "line" object. */
123 /*****************************************************************************/
125 gl_label_line_new (glLabel *label)
129 lline = g_object_new (gl_label_line_get_type(), NULL);
131 gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
133 return G_OBJECT (lline);
137 /*****************************************************************************/
138 /* Copy object contents. */
139 /*****************************************************************************/
141 copy (glLabelObject *dst_object,
142 glLabelObject *src_object)
144 glLabelLine *lline = (glLabelLine *)src_object;
145 glLabelLine *new_lline = (glLabelLine *)dst_object;
147 glColorNode *line_color_node;
149 gl_debug (DEBUG_LABEL, "START");
151 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
152 g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
154 line_width = get_line_width (src_object);
155 line_color_node = get_line_color (src_object);
157 set_line_width (dst_object, line_width);
158 set_line_color (dst_object, line_color_node);
160 gl_color_node_free (&line_color_node);
162 gl_debug (DEBUG_LABEL, "END");
166 /*---------------------------------------------------------------------------*/
167 /* PRIVATE. Set line color method. */
168 /*---------------------------------------------------------------------------*/
170 set_line_color (glLabelObject *object,
171 glColorNode *line_color_node)
173 glLabelLine *lline = (glLabelLine *)object;
175 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
177 if ( !gl_color_node_equal (lline->priv->line_color_node, line_color_node)) {
179 gl_color_node_free (&(lline->priv->line_color_node ));
180 lline->priv->line_color_node = gl_color_node_dup (line_color_node);
182 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
187 /*---------------------------------------------------------------------------*/
188 /* PRIVATE. Set line width method. */
189 /*---------------------------------------------------------------------------*/
191 set_line_width (glLabelObject *object,
194 glLabelLine *lline = (glLabelLine *)object;
196 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
198 if ( lline->priv->line_width != line_width ) {
199 lline->priv->line_width = line_width;
200 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
205 /*---------------------------------------------------------------------------*/
206 /* PRIVATE. Get line color method. */
207 /*---------------------------------------------------------------------------*/
209 get_line_width (glLabelObject *object)
211 glLabelLine *lline = (glLabelLine *)object;
213 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
215 return lline->priv->line_width;
219 /*---------------------------------------------------------------------------*/
220 /* PRIVATE. Get line width method. */
221 /*---------------------------------------------------------------------------*/
223 get_line_color (glLabelObject *object)
225 glLabelLine *lline = (glLabelLine *)object;
227 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
229 return gl_color_node_dup (lline->priv->line_color_node);
233 /*****************************************************************************/
234 /* Draw object method. */
235 /*****************************************************************************/
237 draw_object (glLabelObject *object,
239 gboolean screen_flag,
240 glMergeRecord *record)
244 glColorNode *line_color_node;
247 gl_debug (DEBUG_LABEL, "START");
249 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
251 line_width = gl_label_object_get_line_width (object);
253 line_color_node = gl_label_object_get_line_color (object);
254 line_color = gl_color_node_expand (line_color_node, record);
255 if (line_color_node->field_flag && screen_flag)
257 line_color = GL_COLOR_MERGE_DEFAULT;
261 cairo_move_to (cr, 0.0, 0.0);
262 cairo_line_to (cr, w, h);
266 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color));
267 cairo_set_line_width (cr, line_width);
270 gl_color_node_free (&line_color_node);
272 gl_debug (DEBUG_LABEL, "END");
276 /*****************************************************************************/
277 /* Draw shadow method. */
278 /*****************************************************************************/
280 draw_shadow (glLabelObject *object,
282 gboolean screen_flag,
283 glMergeRecord *record)
287 glColorNode *line_color_node;
288 glColorNode *shadow_color_node;
289 gdouble shadow_opacity;
290 guint shadow_line_color;
292 gl_debug (DEBUG_LABEL, "START");
294 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
296 line_width = gl_label_object_get_line_width (object);
298 line_color_node = gl_label_object_get_line_color (object);
299 if (line_color_node->field_flag)
301 line_color_node->color = GL_COLOR_MERGE_DEFAULT;
304 shadow_color_node = gl_label_object_get_shadow_color (object);
305 if (shadow_color_node->field_flag)
307 shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
309 shadow_opacity = gl_label_object_get_shadow_opacity (object);
310 shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color);
313 cairo_move_to (cr, 0.0, 0.0);
314 cairo_line_to (cr, w, h);
317 /* Draw outline shadow */
318 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color));
319 cairo_set_line_width (cr, line_width);
323 gl_color_node_free (&line_color_node);
324 gl_color_node_free (&shadow_color_node);
326 gl_debug (DEBUG_LABEL, "END");
333 * Local Variables: -- emacs
335 * c-basic-offset: 8 -- emacs
336 * tab-width: 8 -- emacs
337 * indent-tabs-mode: nil -- emacs