1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * label_line.c: GLabels label line object
8 * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "label-line.h"
27 #include <glib/gmem.h>
28 #include <glib/gstrfuncs.h>
29 #include <glib/gmessages.h>
33 /*========================================================*/
35 /*========================================================*/
37 struct _glLabelLinePrivate {
39 glColorNode *line_color_node;
42 /*========================================================*/
43 /* Private globals. */
44 /*========================================================*/
46 /*========================================================*/
47 /* Private function prototypes. */
48 /*========================================================*/
50 static void gl_label_line_finalize (GObject *object);
52 static void copy (glLabelObject *dst_object,
53 glLabelObject *src_object);
55 static void set_line_color (glLabelObject *object,
56 glColorNode *line_color_node);
58 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);
77 /*****************************************************************************/
78 /* Boilerplate object stuff. */
79 /*****************************************************************************/
80 G_DEFINE_TYPE (glLabelLine, gl_label_line, GL_TYPE_LABEL_OBJECT);
83 gl_label_line_class_init (glLabelLineClass *class)
85 GObjectClass *object_class = G_OBJECT_CLASS (class);
86 glLabelObjectClass *label_object_class = GL_LABEL_OBJECT_CLASS (class);
88 gl_label_line_parent_class = g_type_class_peek_parent (class);
90 label_object_class->copy = copy;
91 label_object_class->set_line_color = set_line_color;
92 label_object_class->set_line_width = set_line_width;
93 label_object_class->get_line_color = get_line_color;
94 label_object_class->get_line_width = get_line_width;
95 label_object_class->draw_object = draw_object;
96 label_object_class->draw_shadow = draw_shadow;
98 object_class->finalize = gl_label_line_finalize;
102 gl_label_line_init (glLabelLine *lline)
104 lline->priv = g_new0 (glLabelLinePrivate, 1);
105 lline->priv->line_color_node = gl_color_node_new_default ();
109 gl_label_line_finalize (GObject *object)
111 glLabelLine *lline = GL_LABEL_LINE (object);
113 g_return_if_fail (object && GL_IS_LABEL_LINE (object));
115 gl_color_node_free (&(lline->priv->line_color_node));
116 g_free (lline->priv);
118 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);
136 /*****************************************************************************/
137 /* Copy object contents. */
138 /*****************************************************************************/
140 copy (glLabelObject *dst_object,
141 glLabelObject *src_object)
143 glLabelLine *lline = (glLabelLine *)src_object;
144 glLabelLine *new_lline = (glLabelLine *)dst_object;
146 glColorNode *line_color_node;
148 gl_debug (DEBUG_LABEL, "START");
150 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
151 g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
153 line_width = get_line_width (src_object);
154 line_color_node = get_line_color (src_object);
156 set_line_width (dst_object, line_width);
157 set_line_color (dst_object, line_color_node);
159 gl_color_node_free (&line_color_node);
161 gl_debug (DEBUG_LABEL, "END");
165 /*---------------------------------------------------------------------------*/
166 /* PRIVATE. Set line color method. */
167 /*---------------------------------------------------------------------------*/
169 set_line_color (glLabelObject *object,
170 glColorNode *line_color_node)
172 glLabelLine *lline = (glLabelLine *)object;
174 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
176 if ( !gl_color_node_equal (lline->priv->line_color_node, line_color_node)) {
178 gl_color_node_free (&(lline->priv->line_color_node ));
179 lline->priv->line_color_node = gl_color_node_dup (line_color_node);
181 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
185 /*---------------------------------------------------------------------------*/
186 /* PRIVATE. Set line width method. */
187 /*---------------------------------------------------------------------------*/
189 set_line_width (glLabelObject *object,
192 glLabelLine *lline = (glLabelLine *)object;
194 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
196 if ( lline->priv->line_width != line_width ) {
197 lline->priv->line_width = line_width;
198 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
203 /*---------------------------------------------------------------------------*/
204 /* PRIVATE. Get line color method. */
205 /*---------------------------------------------------------------------------*/
207 get_line_width (glLabelObject *object)
209 glLabelLine *lline = (glLabelLine *)object;
211 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
213 return lline->priv->line_width;
216 /*---------------------------------------------------------------------------*/
217 /* PRIVATE. Get line width method. */
218 /*---------------------------------------------------------------------------*/
220 get_line_color (glLabelObject *object)
222 glLabelLine *lline = (glLabelLine *)object;
224 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
226 return gl_color_node_dup (lline->priv->line_color_node);
229 /*****************************************************************************/
230 /* Draw object method. */
231 /*****************************************************************************/
233 draw_object (glLabelObject *object,
235 gboolean screen_flag,
236 glMergeRecord *record)
240 glColorNode *line_color_node;
243 gl_debug (DEBUG_LABEL, "START");
245 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
247 line_width = gl_label_object_get_line_width (object);
249 line_color_node = gl_label_object_get_line_color (object);
250 line_color = gl_color_node_expand (line_color_node, record);
251 if (line_color_node->field_flag && screen_flag)
253 line_color = GL_COLOR_MERGE_DEFAULT;
257 cairo_move_to (cr, 0.0, 0.0);
258 cairo_line_to (cr, w, h);
262 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color));
263 cairo_set_line_width (cr, line_width);
266 gl_color_node_free (&line_color_node);
268 gl_debug (DEBUG_LABEL, "END");
271 /*****************************************************************************/
272 /* Draw shadow method. */
273 /*****************************************************************************/
275 draw_shadow (glLabelObject *object,
277 gboolean screen_flag,
278 glMergeRecord *record)
282 glColorNode *line_color_node;
283 glColorNode *shadow_color_node;
284 gdouble shadow_opacity;
285 guint shadow_line_color;
287 gl_debug (DEBUG_LABEL, "START");
289 gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
291 line_width = gl_label_object_get_line_width (object);
293 line_color_node = gl_label_object_get_line_color (object);
294 if (line_color_node->field_flag)
296 line_color_node->color = GL_COLOR_MERGE_DEFAULT;
299 shadow_color_node = gl_label_object_get_shadow_color (object);
300 if (shadow_color_node->field_flag)
302 shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
304 shadow_opacity = gl_label_object_get_shadow_opacity (object);
305 shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color);
308 cairo_move_to (cr, 0.0, 0.0);
309 cairo_line_to (cr, w, h);
312 /* Draw outline shadow */
313 cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color));
314 cairo_set_line_width (cr, line_width);
318 gl_color_node_free (&line_color_node);
319 gl_color_node_free (&shadow_color_node);
321 gl_debug (DEBUG_LABEL, "END");