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"
23 #include <glib/gi18n.h>
29 /*========================================================*/
31 /*========================================================*/
33 struct _glLabelLinePrivate {
35 glColorNode *line_color_node;
39 /*========================================================*/
40 /* Private globals. */
41 /*========================================================*/
44 /*========================================================*/
45 /* Private function prototypes. */
46 /*========================================================*/
48 static void gl_label_line_finalize (GObject *object);
50 static void copy (glLabelObject *dst_object,
51 glLabelObject *src_object);
53 static void set_line_color (glLabelObject *object,
54 glColorNode *line_color_node,
57 static void set_line_width (glLabelObject *object,
61 static glColorNode *get_line_color (glLabelObject *object);
63 static gdouble get_line_width (glLabelObject *object);
65 static void draw_object (glLabelObject *object,
68 glMergeRecord *record);
70 static void draw_shadow (glLabelObject *object,
73 glMergeRecord *record);
75 static gboolean object_at (glLabelObject *object,
81 /*****************************************************************************/
82 /* Boilerplate object stuff. */
83 /*****************************************************************************/
84 G_DEFINE_TYPE (glLabelLine, gl_label_line, GL_TYPE_LABEL_OBJECT)
88 gl_label_line_class_init (glLabelLineClass *class)
90 GObjectClass *object_class = G_OBJECT_CLASS (class);
91 glLabelObjectClass *label_object_class = GL_LABEL_OBJECT_CLASS (class);
93 gl_label_line_parent_class = g_type_class_peek_parent (class);
95 label_object_class->copy = copy;
96 label_object_class->set_line_color = set_line_color;
97 label_object_class->set_line_width = set_line_width;
98 label_object_class->get_line_color = get_line_color;
99 label_object_class->get_line_width = get_line_width;
100 label_object_class->draw_object = draw_object;
101 label_object_class->draw_shadow = draw_shadow;
102 label_object_class->draw_handles = gl_label_object_draw_handles_line;
103 label_object_class->object_at = object_at;
104 label_object_class->handle_at = gl_label_object_line_handle_at;
106 object_class->finalize = gl_label_line_finalize;
111 gl_label_line_init (glLabelLine *lline)
113 lline->priv = g_new0 (glLabelLinePrivate, 1);
118 gl_label_line_finalize (GObject *object)
120 glLabelLine *lline = GL_LABEL_LINE (object);
122 g_return_if_fail (object && GL_IS_LABEL_LINE (object));
124 gl_color_node_free (&(lline->priv->line_color_node));
125 g_free (lline->priv);
127 G_OBJECT_CLASS (gl_label_line_parent_class)->finalize (object);
131 /*****************************************************************************/
132 /* NEW label "line" object. */
133 /*****************************************************************************/
135 gl_label_line_new (glLabel *label,
139 glColorNode *line_color_node;
141 lline = g_object_new (gl_label_line_get_type(), NULL);
147 gl_label_checkpoint (label, _("Create line object"));
150 line_color_node = gl_color_node_new_default ();
152 line_color_node->color = gl_label_get_default_line_color(label);
154 lline->priv->line_width = gl_label_get_default_line_width(label);
155 lline->priv->line_color_node = line_color_node;
157 gl_label_add_object (label, GL_LABEL_OBJECT (lline));
158 gl_label_object_set_parent (GL_LABEL_OBJECT (lline), label);
161 return G_OBJECT (lline);
165 /*****************************************************************************/
166 /* Copy object contents. */
167 /*****************************************************************************/
169 copy (glLabelObject *dst_object,
170 glLabelObject *src_object)
172 glLabelLine *lline = (glLabelLine *)src_object;
173 glLabelLine *new_lline = (glLabelLine *)dst_object;
175 glColorNode *line_color_node;
177 gl_debug (DEBUG_LABEL, "START");
179 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
180 g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
182 line_width = get_line_width (src_object);
183 line_color_node = get_line_color (src_object);
185 set_line_width (dst_object, line_width, FALSE);
186 set_line_color (dst_object, line_color_node, FALSE);
188 gl_color_node_free (&line_color_node);
190 gl_debug (DEBUG_LABEL, "END");
194 /*---------------------------------------------------------------------------*/
195 /* PRIVATE. Set line color method. */
196 /*---------------------------------------------------------------------------*/
198 set_line_color (glLabelObject *object,
199 glColorNode *line_color_node,
202 glLabelLine *lline = (glLabelLine *)object;
205 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
207 if ( !gl_color_node_equal (lline->priv->line_color_node, line_color_node))
211 label = gl_label_object_get_parent (GL_LABEL_OBJECT (lline));
212 gl_label_checkpoint (label, _("Line color"));
215 gl_color_node_free (&(lline->priv->line_color_node ));
216 lline->priv->line_color_node = gl_color_node_dup (line_color_node);
218 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
223 /*---------------------------------------------------------------------------*/
224 /* PRIVATE. Set line width method. */
225 /*---------------------------------------------------------------------------*/
227 set_line_width (glLabelObject *object,
231 glLabelLine *lline = (glLabelLine *)object;
234 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
236 if ( lline->priv->line_width != line_width )
240 label = gl_label_object_get_parent (GL_LABEL_OBJECT (lline));
241 gl_label_checkpoint (label, _("Line width"));
244 lline->priv->line_width = line_width;
245 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
250 /*---------------------------------------------------------------------------*/
251 /* PRIVATE. Get line color method. */
252 /*---------------------------------------------------------------------------*/
254 get_line_width (glLabelObject *object)
256 glLabelLine *lline = (glLabelLine *)object;
258 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
260 return lline->priv->line_width;
264 /*---------------------------------------------------------------------------*/
265 /* PRIVATE. Get line width method. */
266 /*---------------------------------------------------------------------------*/
268 get_line_color (glLabelObject *object)
270 glLabelLine *lline = (glLabelLine *)object;
272 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
274 return gl_color_node_dup (lline->priv->line_color_node);
278 /*****************************************************************************/
279 /* Draw object method. */
280 /*****************************************************************************/
282 draw_object (glLabelObject *object,
284 gboolean screen_flag,
285 glMergeRecord *record)
289 glColorNode *line_color_node;
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 line_color = gl_color_node_expand (line_color_node, record);
300 if (line_color_node->field_flag && screen_flag)
302 line_color = GL_COLOR_MERGE_DEFAULT;
306 cairo_move_to (cr, 0.0, 0.0);
307 cairo_line_to (cr, w, h);
311 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color));
312 cairo_set_line_width (cr, line_width);
315 gl_color_node_free (&line_color_node);
317 gl_debug (DEBUG_LABEL, "END");
321 /*****************************************************************************/
322 /* Draw shadow method. */
323 /*****************************************************************************/
325 draw_shadow (glLabelObject *object,
327 gboolean screen_flag,
328 glMergeRecord *record)
332 glColorNode *line_color_node;
333 glColorNode *shadow_color_node;
334 gdouble shadow_opacity;
335 guint shadow_line_color;
337 gl_debug (DEBUG_LABEL, "START");
339 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
341 line_width = gl_label_object_get_line_width (object);
343 line_color_node = gl_label_object_get_line_color (object);
344 if (line_color_node->field_flag)
346 line_color_node->color = GL_COLOR_MERGE_DEFAULT;
349 shadow_color_node = gl_label_object_get_shadow_color (object);
350 if (shadow_color_node->field_flag)
352 shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
354 shadow_opacity = gl_label_object_get_shadow_opacity (object);
355 shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color);
358 cairo_move_to (cr, 0.0, 0.0);
359 cairo_line_to (cr, w, h);
362 /* Draw outline shadow */
363 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color));
364 cairo_set_line_width (cr, line_width);
368 gl_color_node_free (&line_color_node);
369 gl_color_node_free (&shadow_color_node);
371 gl_debug (DEBUG_LABEL, "END");
375 /*****************************************************************************/
376 /* Is object at coordinates? */
377 /*****************************************************************************/
379 object_at (glLabelObject *object,
387 gl_label_object_get_size (object, &w, &h);
390 cairo_move_to (cr, 0, 0);
391 cairo_line_to (cr, w, h);
393 line_width = gl_label_object_get_line_width (object);
394 cairo_set_line_width (cr, line_width);
395 if (cairo_in_stroke (cr, x, y))
407 * Local Variables: -- emacs
409 * c-basic-offset: 8 -- emacs
410 * tab-width: 8 -- emacs
411 * indent-tabs-mode: nil -- emacs