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/>.
23 #include "view-line.h"
25 #include <glib/gi18n.h>
29 #include "object-editor.h"
32 #include "pixmaps/cursor_line.xbm"
33 #include "pixmaps/cursor_line_mask.xbm"
38 /*========================================================*/
39 /* Private macros and constants. */
40 /*========================================================*/
43 /*========================================================*/
45 /*========================================================*/
47 struct _glViewLinePrivate {
51 /*========================================================*/
52 /* Private globals. */
53 /*========================================================*/
56 /*========================================================*/
57 /* Private function prototypes. */
58 /*========================================================*/
60 static void gl_view_line_finalize (GObject *object);
62 static GtkWidget *construct_properties_editor (glViewObject *view_object);
64 static void update_object_from_editor_cb (glObjectEditor *editor,
65 glLabelObject *object);
67 static void update_editor_from_object_cb (glLabelObject *object,
68 glObjectEditor *editor);
70 static void update_editor_from_move_cb (glLabelObject *object,
73 glObjectEditor *editor);
75 static gboolean object_at (glViewObject *view_object,
81 /*****************************************************************************/
82 /* Boilerplate object stuff. */
83 /*****************************************************************************/
84 G_DEFINE_TYPE (glViewLine, gl_view_line, GL_TYPE_VIEW_OBJECT);
88 gl_view_line_class_init (glViewLineClass *class)
90 GObjectClass *object_class = G_OBJECT_CLASS (class);
91 glViewObjectClass *view_object_class = GL_VIEW_OBJECT_CLASS (class);
93 gl_debug (DEBUG_VIEW, "START");
95 gl_view_line_parent_class = g_type_class_peek_parent (class);
97 object_class->finalize = gl_view_line_finalize;
99 view_object_class->construct_editor = construct_properties_editor;
100 view_object_class->object_at = object_at;
102 gl_debug (DEBUG_VIEW, "END");
107 gl_view_line_init (glViewLine *view_line)
109 gl_debug (DEBUG_VIEW, "START");
111 view_line->priv = g_new0 (glViewLinePrivate, 1);
113 gl_debug (DEBUG_VIEW, "END");
118 gl_view_line_finalize (GObject *object)
120 glViewLine *view_line = GL_VIEW_LINE (object);
122 gl_debug (DEBUG_VIEW, "START");
124 g_return_if_fail (object && GL_IS_VIEW_LINE (object));
126 g_free (view_line->priv);
128 G_OBJECT_CLASS (gl_view_line_parent_class)->finalize (object);
130 gl_debug (DEBUG_VIEW, "END");
134 /*****************************************************************************/
135 /* NEW line object view. */
136 /*****************************************************************************/
138 gl_view_line_new (glLabelLine *object,
141 glViewLine *view_line;
143 gl_debug (DEBUG_VIEW, "START");
145 g_return_val_if_fail (object && GL_IS_LABEL_LINE (object), NULL);
146 g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
148 view_line = g_object_new (gl_view_line_get_type(), NULL);
150 gl_view_object_set_object (GL_VIEW_OBJECT(view_line),
151 GL_LABEL_OBJECT(object),
152 GL_VIEW_OBJECT_HANDLES_LINE);
153 gl_view_object_set_view (GL_VIEW_OBJECT(view_line), view);
155 gl_debug (DEBUG_VIEW, "END");
157 return GL_VIEW_OBJECT (view_line);
161 /*****************************************************************************/
162 /* Create a properties dialog for a line object. */
163 /*****************************************************************************/
165 construct_properties_editor (glViewObject *view_object)
168 glViewLine *view_line = (glViewLine *)view_object;
169 glLabelObject *object;
171 gl_debug (DEBUG_VIEW, "START");
173 object = gl_view_object_get_object (GL_VIEW_OBJECT(view_line));
176 editor = gl_object_editor_new (GL_STOCK_LINE, _("Line object properties"),
178 GL_OBJECT_EDITOR_SHADOW_PAGE,
179 GL_OBJECT_EDITOR_POSITION_PAGE,
180 GL_OBJECT_EDITOR_SIZE_LINE_PAGE,
181 GL_OBJECT_EDITOR_LINE_PAGE,
185 update_editor_from_object_cb (object, GL_OBJECT_EDITOR(editor));
186 update_editor_from_move_cb (object, 0, 0, GL_OBJECT_EDITOR(editor));
188 /* Connect signals. */
189 g_signal_connect (G_OBJECT (editor), "changed",
190 G_CALLBACK(update_object_from_editor_cb), object);
191 g_signal_connect (G_OBJECT (object), "changed",
192 G_CALLBACK (update_editor_from_object_cb), editor);
193 g_signal_connect (G_OBJECT (object), "moved",
194 G_CALLBACK (update_editor_from_move_cb), editor);
196 gl_debug (DEBUG_VIEW, "END");
202 /*---------------------------------------------------------------------------*/
203 /* PRIVATE. editor "changed" callback. */
204 /*---------------------------------------------------------------------------*/
206 update_object_from_editor_cb (glObjectEditor *editor,
207 glLabelObject *object)
210 glColorNode *line_color_node;
212 gboolean shadow_state;
213 gdouble shadow_x, shadow_y;
214 glColorNode *shadow_color_node;
215 gdouble shadow_opacity;
218 gl_debug (DEBUG_VIEW, "START");
220 g_signal_handlers_block_by_func (G_OBJECT(object),
221 update_editor_from_object_cb,
223 g_signal_handlers_block_by_func (G_OBJECT(object),
224 update_editor_from_move_cb,
227 gl_object_editor_get_position (editor, &x, &y);
228 gl_label_object_set_position (object, x, y);
230 gl_object_editor_get_lsize (editor, &w, &h);
231 gl_label_object_set_size (object, w, h);
233 line_color_node = gl_object_editor_get_line_color (editor);
234 gl_label_object_set_line_color (object, line_color_node);
235 gl_color_node_free (&line_color_node);
237 line_width = gl_object_editor_get_line_width (editor);
238 gl_label_object_set_line_width (object, line_width);
240 shadow_state = gl_object_editor_get_shadow_state (editor);
241 gl_label_object_set_shadow_state (object, shadow_state);
243 gl_object_editor_get_shadow_offset (editor, &shadow_x, &shadow_y);
244 gl_label_object_set_shadow_offset (object, shadow_x, shadow_y);
246 shadow_color_node = gl_object_editor_get_shadow_color (editor);
247 gl_label_object_set_shadow_color (object, shadow_color_node);
248 gl_color_node_free (&shadow_color_node);
250 shadow_opacity = gl_object_editor_get_shadow_opacity (editor);
251 gl_label_object_set_shadow_opacity (object, shadow_opacity);
253 g_signal_handlers_unblock_by_func (G_OBJECT(object),
254 update_editor_from_object_cb,
256 g_signal_handlers_unblock_by_func (G_OBJECT(object),
257 update_editor_from_move_cb,
260 gl_debug (DEBUG_VIEW, "END");
264 /*---------------------------------------------------------------------------*/
265 /* PRIVATE. label object "changed" callback. */
266 /*---------------------------------------------------------------------------*/
268 update_editor_from_object_cb (glLabelObject *object,
269 glObjectEditor *editor)
272 glColorNode *line_color_node;
274 gboolean shadow_state;
275 gdouble shadow_x, shadow_y;
276 glColorNode *shadow_color_node;
277 gdouble shadow_opacity;
280 gl_debug (DEBUG_VIEW, "START");
282 gl_label_object_get_size (object, &w, &h);
283 gl_object_editor_set_lsize (editor, w, h);
284 merge = gl_label_get_merge (GL_LABEL(object->parent));
286 line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
287 gl_object_editor_set_line_color (editor, (merge != NULL), line_color_node);
288 gl_color_node_free (&line_color_node);
290 line_width = gl_label_object_get_line_width (GL_LABEL_OBJECT(object));
291 gl_object_editor_set_line_width (editor, line_width);
293 shadow_state = gl_label_object_get_shadow_state (object);
294 gl_object_editor_set_shadow_state (editor, shadow_state);
296 gl_label_object_get_shadow_offset (object, &shadow_x, &shadow_y);
297 gl_object_editor_set_shadow_offset (editor, shadow_x, shadow_y);
299 shadow_color_node = gl_label_object_get_shadow_color (object);
300 gl_object_editor_set_shadow_color (editor, (merge != NULL), shadow_color_node);
301 gl_color_node_free (&shadow_color_node);
303 shadow_opacity = gl_label_object_get_shadow_opacity (object);
304 gl_object_editor_set_shadow_opacity (editor, shadow_opacity);
306 gl_debug (DEBUG_VIEW, "END");
310 /*---------------------------------------------------------------------------*/
311 /* PRIVATE. label object "moved" callback. */
312 /*---------------------------------------------------------------------------*/
314 update_editor_from_move_cb (glLabelObject *object,
317 glObjectEditor *editor)
321 gl_debug (DEBUG_VIEW, "START");
323 gl_label_object_get_position (object, &x, &y);
324 gl_object_editor_set_position (editor, x, y);
326 gl_debug (DEBUG_VIEW, "END");
330 /*****************************************************************************/
331 /* Is object at (x,y)? */
332 /*****************************************************************************/
334 object_at (glViewObject *view_object,
339 glLabelObject *object;
343 object = gl_view_object_get_object (view_object);
345 gl_label_object_get_size (object, &w, &h);
347 cairo_move_to (cr, 0.0, 0.0);
348 cairo_line_to (cr, w, h);
350 line_width = gl_label_object_get_line_width (object);
351 cairo_set_line_width (cr, line_width);
352 if (cairo_in_stroke (cr, x, y))
361 /*****************************************************************************/
362 /* Return apropos cursor for create object mode. */
363 /*****************************************************************************/
365 gl_view_line_get_create_cursor (void)
367 GdkCursor *cursor = NULL;
368 GdkPixmap *pixmap_data, *pixmap_mask;
369 GdkColor fg = { 0, 0, 0, 0 };
370 GdkColor bg = { 0, 65535, 65535, 65535 };
372 gl_debug (DEBUG_VIEW, "START");
374 pixmap_data = gdk_bitmap_create_from_data (NULL,
375 (gchar *)cursor_line_bits,
378 pixmap_mask = gdk_bitmap_create_from_data (NULL,
379 (gchar *)cursor_line_mask_bits,
380 cursor_line_mask_width,
381 cursor_line_mask_height);
382 cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
383 &bg, cursor_line_x_hot,
386 gl_debug (DEBUG_VIEW, "END");
392 /*****************************************************************************/
393 /* Object creation handler: button press event. */
394 /*****************************************************************************/
396 gl_view_line_create_button_press_event (glView *view,
401 glColorNode *line_color_node;
403 gl_view_unselect_all (view);
405 line_color_node = gl_color_node_new_default ();
407 object = gl_label_line_new (view->label);
408 gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
409 gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
410 line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
411 gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
412 gl_view_get_default_line_width(view));
413 gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
416 gl_color_node_free (&line_color_node);
418 view->create_object = GL_LABEL_OBJECT (object);
424 /*****************************************************************************/
425 /* Object creation handler: motion event. */
426 /*****************************************************************************/
428 gl_view_line_create_motion_event (glView *view,
434 w = x - view->create_x0;
435 h = y - view->create_y0;
436 gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
440 /*****************************************************************************/
441 /* Object creation handler: button relesase event. */
442 /*****************************************************************************/
444 gl_view_line_create_button_release_event (glView *view,
448 glColorNode *line_color_node;
451 line_color_node = gl_color_node_new_default ();
453 if ((view->create_x0 == x) && (view->create_y0 == y)) {
454 x = view->create_x0 + 36.0;
455 y = view->create_y0 + 36.0;
457 w = x - view->create_x0;
458 h = y - view->create_y0;
459 gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
460 line_color_node->color = gl_view_get_default_line_color(view);
461 gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
462 gl_color_node_free (&line_color_node);
468 * Local Variables: -- emacs
470 * c-basic-offset: 8 -- emacs
471 * tab-width: 8 -- emacs
472 * indent-tabs-mode: nil -- emacs