+2007-03-23 Jim Evins <evins@snaught.com>
+
+ Merged all changes from experimental cairo branch to trunk.
+ Trunk no longer depends on libgnomecanvas or libgnomeprint[ui].
+
+2007-03-23 Jim Evins <evins@snaught.com>
+
+ * src/label-object.h:
+ * src/label-object.c: (gl_label_object_class_init),
+ (gl_label_object_get_raw_size), (gl_label_object_get_size):
+ Created "get_raw_size" method.
+ * src/label-barcode.c: (get_size):
+ * src/xml-label.c: (xml_create_object_text),
+ (xml_create_object_barcode):
+ Use new "get_raw_size" method on label-objects when apropos.
+ * src/label-text.h:
+ * src/label-text.c: (get_size), (draw_object), (draw_shadow),
+ (auto_shrink_font_size):
+ Added "auto shrink" functionality back.
+
+2007-03-19 Jim Evins <evins@snaught.com>
+
+ * src/label-text.c: (draw_object), (draw_shadow):
+ Don't use negative scales in workaround from previous commit.
+
+
+2007-03-18 Jim Evins <evins@snaught.com>
+
+ * src/xml-label.c:
+ Forgot to remove include of xml-lable-191 in previous commit.
+ * src/label-text.c: (get_size), (draw_object), (draw_shadow):
+ Workaround for pango Bug #341481. Render text at device scale,
+ and scale font size accordingly. Also, don't do any hinting.
+
+2007-03-18 Jim Evins <evins@snaught.com>
+
+ * src/cairo-ellipse-path.c:
+ * src/cairo-ellipse-path.h:
+ Forgot to add these new files during last mass commit.
+
+2007-03-18 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/xml-label-191.c:
+ * src/xml-label-191.h:
+ Removed -- Very buggy. Version 1.91 is a very old "unstable" version,
+ so there is no need to keep compatability.
+ * src/base64.c:
+ * src/bc-iec16022.c:
+ * src/cairo-label-path.c:
+ * src/cairo-label-path.h:
+ * src/cairo-markup-path.c:
+ * src/color.c:
+ * src/debug.c:
+ * src/file.c:
+ * src/glabels-batch.c:
+ * src/glabels.c:
+ * src/label-barcode.c:
+ * src/label-box.c:
+ * src/label-ellipse.c:
+ * src/label-image.c:
+ * src/label-line.c:
+ * src/label-object.c:
+ * src/label-object.h:
+ * src/label-text.c:
+ * src/label.c:
+ * src/label.h:
+ * src/merge-properties-dialog.c:
+ * src/merge.c:
+ * src/new-label-dialog.c:
+ * src/object-editor-bc-page.c:
+ * src/object-editor-data-page.c:
+ * src/object-editor-edit-page.c:
+ * src/object-editor-fill-page.c:
+ * src/object-editor-image-page.c:
+ * src/object-editor-line-page.c:
+ * src/object-editor-private.h:
+ * src/object-editor-shadow-page.c:
+ * src/object-editor-text-page.c:
+ * src/object-editor.c:
+ * src/pixbuf-cache.c:
+ * src/print-op.c:
+ * src/print.c:
+ * src/recent.c:
+ * src/stock.c:
+ * src/template-designer.c:
+ * src/text-node.c:
+ * src/ui-property-bar.c:
+ * src/ui.c:
+ * src/view-barcode.c:
+ * src/view-box.c:
+ * src/view-ellipse.c:
+ * src/view-image.c:
+ * src/view-line.c:
+ * src/view-object.c:
+ * src/view-object.h:
+ * src/view-text.c:
+ * src/view.c:
+ * src/wdgt-media-select.c:
+ * src/wdgt-print-copies.c:
+ * src/wdgt-print-merge.c:
+ * src/window.c:
+ * src/xml-label-04.c:
+ * src/xml-label.c:
+ Many changes, including:
+ - Move draw methods from view-*() to label-*().
+ - Use same drawing code for on screen view and printing.
+ - Fix all issues exposed with '-Wall -Werror'.
+
+2007-03-14 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-handle-path.c:
+ * src/cairo-handle-path.h:
+ * src/cairo-object-path.c:
+ * src/cairo-object-path.h:
+ Removed cairo-handle-path.[ch] and cairo-object-path.[ch].
+ * src/view-barcode.c: (gl_view_barcode_class_init), (draw_object),
+ (object_at):
+ * src/view-box.c: (gl_view_box_class_init), (draw_object),
+ (draw_shadow), (object_at):
+ * src/view-ellipse.c: (gl_view_ellipse_class_init),
+ (create_ellipse_path), (draw_object), (draw_shadow), (object_at):
+ * src/view-image.c: (gl_view_image_class_init), (draw_object),
+ (object_at):
+ * src/view-line.c: (gl_view_line_class_init), (draw_object),
+ (draw_shadow), (object_at):
+ * src/view-object.c: (gl_view_object_draw), (gl_view_object_at),
+ (create_handle_path), (gl_view_object_draw_handles),
+ (gl_view_object_handle_at):
+ * src/view-object.h:
+ * src/view-text.c: (gl_view_text_class_init), (draw_object),
+ (draw_shadow), (object_at):
+ * src/view.c: (motion_notify_event_cb), (button_press_event_cb):
+ Some restructuring of new code.
+
+2007-03-12 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-object-path.c:
+ * src/view-barcode.c:
+ * src/view-barcode.h:
+ * src/view.c:
+ Added barcode object support to view.
+
+2007-03-12 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/view-text.h:
+ * src/view-text.c:
+ * src/view.c:
+ * src/cairo-object-path.c:
+ * src/cairo-object-path.h:
+ * src/view-box.c:
+ * src/view-ellipse.c:
+ * src/view-image.c:
+ * src/view-line.c:
+ * src/view-object.c:
+ * src/view-object.h:
+ Added text object support to view. Added object_at method to all
+ view_objects.
+
+2007-03-11 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-object-path.c: (gl_cairo_object_path),
+ (gl_cairo_image_object_path):
+ * src/view-image.c: (gl_view_image_class_init),
+ (gl_view_image_finalize), (gl_view_image_new),
+ (update_editor_from_label_cb), (draw),
+ (gl_view_image_get_create_cursor),
+ (gl_view_image_create_button_press_event),
+ (gl_view_image_create_motion_event),
+ (gl_view_image_create_button_release_event):
+ * src/view-image.h:
+ * src/view.c: (gl_view_construct), (gl_view_object_create_mode),
+ (selection_received_cb), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb):
+ Added image object support to view.
+
+2007-03-11 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-object-path.c: (gl_cairo_object_path),
+ (gl_cairo_line_object_path):
+ * src/view-line.c: (gl_view_line_class_init), (gl_view_line_new),
+ (update_object_from_editor_cb), (update_editor_from_object_cb),
+ (update_editor_from_label_cb), (draw),
+ (gl_view_line_get_create_cursor),
+ (gl_view_line_create_button_press_event),
+ (gl_view_line_create_motion_event),
+ (gl_view_line_create_button_release_event):
+ * src/view-line.h:
+ * src/view-object.c: (gl_view_object_resize_event):
+ * src/view.c: (gl_view_construct), (gl_view_object_create_mode),
+ (selection_received_cb), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb):
+ Added line object support to view.
+ * src/cairo-handle-path.c:
+ Made handles slightly larger.
+
+
+2007-03-11 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-handle-path.c:
+ * src/cairo-label-path.c: (gl_cairo_rect_label_path),
+ (gl_cairo_round_label_path), (gl_cairo_cd_label_path):
+ * src/cairo-markup-path.c: (gl_cairo_markup_margin_rect_path),
+ (gl_cairo_markup_margin_round_path),
+ (gl_cairo_markup_margin_cd_path), (gl_cairo_markup_circle_path):
+ * src/cairo-object-path.c: (gl_cairo_object_path),
+ (gl_cairo_ellipse_object_path):
+ * src/label-object.c: (gl_label_object_rotate):
+ * src/view-box.c:
+ * src/view-box.h:
+ * src/view-ellipse.c: (gl_view_ellipse_class_init),
+ (gl_view_ellipse_new), (update_object_from_editor_cb),
+ (update_editor_from_object_cb), (update_editor_from_label_cb),
+ (draw), (gl_view_ellipse_get_create_cursor),
+ (gl_view_ellipse_create_button_press_event),
+ (gl_view_ellipse_create_motion_event),
+ (gl_view_ellipse_create_button_release_event):
+ * src/view-ellipse.h:
+ * src/view-object.c:
+ * src/view-object.h:
+ * src/view.c: (gl_view_construct), (gl_view_object_create_mode),
+ (select_object_real), (selection_received_cb),
+ (motion_notify_event_cb), (button_press_event_cb),
+ (button_release_event_cb):
+ * src/view.h:
+ Added ellipse object support to view. Plus other cleanup.
+
+2007-03-11 Jim Evins <evins@snaught.com>
+
+ * src/view-box.h:
+ * src/view-box.c: (gl_view_box_get_create_cursor),
+ (gl_view_box_create_button_press_event),
+ (gl_view_box_create_motion_event),
+ (gl_view_box_create_button_release_event):
+ * src/view-object.c: (gl_view_object_set_view),
+ (gl_view_object_handle_at):
+ * src/view.h:
+ * src/view.c: (gl_view_arrow_mode), (gl_view_object_create_mode),
+ (motion_notify_event_cb), (button_press_event_cb),
+ (button_release_event_cb), (key_press_event_cb):
+ Added creation code for box object.
+
+2007-03-09 Jim Evins <evins@snaught.com>
+
+ * src/view-object.c: (gl_view_object_resize_event):
+ * src/view-object.h:
+ * src/view.c: (motion_notify_event_cb):
+ Fix bugs with resizing transformed objects.
+ * src/cairo-handle-path.c: (gl_cairo_handle_path):
+ * src/cairo-object-path.c: (gl_cairo_object_path):
+ * src/cairo-object-path.h:
+ * src/label-object.c: (gl_label_object_init),
+ (gl_label_object_dup), (gl_label_object_get_extent),
+ (gl_label_object_flip_horiz), (gl_label_object_flip_vert),
+ (gl_label_object_rotate), (gl_label_object_set_matrix),
+ (gl_label_object_get_matrix):
+ * src/label-object.h:
+ * src/print.c: (draw_object):
+ * src/view-box.c:
+ * src/view-highlight.c:
+ * src/view-highlight.h:
+ * src/xml-label-191.c: (xml191_parse_object):
+ * src/xml-label.c: (xml_parse_affine_attrs),
+ (xml_create_affine_attrs):
+ Replace libart affine matrices with cairo matrices.
+
+2007-03-08 Jim Evins <evins@snaught.com>
+
+ * src/view-object.h:
+ * src/view.c: (gl_view_update), (motion_notify_event_cb):
+ * src/view-object.c: (gl_view_object_handle_at),
+ (gl_view_object_resize_event):
+ Added resize code -- still a bit buggy.
+
+2007-03-07 Jim Evins <evins@snaught.com>
+
+ * src/Makefile.am:
+ * src/cairo-handle-path.c:
+ * src/cairo-handle-path.h:
+ * src/view-box.c: (gl_view_box_new):
+ * src/view-object.c: (gl_view_object_set_object),
+ (gl_view_object_draw_handles), (gl_view_object_handle_at):
+ * src/view-object.h:
+ * src/view.c: (draw_highlight_layer), (select_object_real),
+ (unselect_object_real), (view_handle_at), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb),
+ (key_press_event_cb):
+ * src/view.h:
+ Added beginnings of object resize handles.
+
+2007-03-07 Jim Evins <evins@snaught.com>
+
+ * src/view.h:
+ * src/view.c: (gl_view_init), (gl_view_arrow_mode),
+ (gl_view_object_create_mode), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb),
+ (key_press_event_cb):
+ Added move selection support.
+
+2007-03-05 Jim Evins <evins@snaught.com>
+
+ * src/cairo-object-path.c: (gl_cairo_object_path):
+ * src/view-object.c: (gl_view_object_draw),
+ (gl_view_object_draw_highlight):
+ * src/view.c: (view_object_at), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb):
+ Additional refinements to select logic.
+
+2007-03-05 Jim Evins <evins@snaught.com>
+
+ * src/view.h:
+ * src/view.c: (gl_view_init), (gl_view_construct),
+ (label_changed_cb), (draw_layers), (draw_select_region_layer),
+ (gl_view_select_region), (object_at), (motion_notify_event_cb),
+ (button_press_event_cb), (button_release_event_cb):
+ Added initial select region support and context menu.
+
+2007-03-04 Jim Evins <evins@snaught.com>
+
+ * configure.in:
+ * src/Makefile.am:
+ * src/debug.c:
+ * src/debug.h:
+ * src/file.c:
+ * src/label.c:
+ * src/label.h:
+ * src/print-op.c:
+ * src/print.c:
+ * src/ui-commands.c:
+ * src/view-box.c:
+ * src/view-box.h:
+ * src/view-object.c:
+ * src/view-object.h:
+ * src/view.c:
+ * src/view.h:
+ * src/wdgt-print-copies.c:
+ * src/wdgt-print-merge.c:
+ * src/xml-label.c:
+ Initial port to a raw Cairo canvas. This removes all remaining
+ dependencies on libgnomecanvas and libgnomeprint[ui]. Basically
+ the view is becoming a canvas widget in its own right. Still needs
+ a lot of work.
+ * src/cairo-label-path.c:
+ * src/cairo-label-path.h:
+ * src/cairo-markup-path.c:
+ * src/cairo-markup-path.h:
+ * src/cairo-object-path.c:
+ * src/cairo-object-path.h:
+ New files to support cairo canvas.
+ * src/canvas-hacktext.c:
+ * src/canvas-hacktext.h:
+ Removed.
+
2007-02-18 Jim Evins <evins@snaught.com>
* src/bc.h:
LIBGNOME_REQUIRED=2.16.0
LIBGNOMEUI_REQUIRED=2.16.0
LIBXML_REQUIRED=2.6.0
-LIBGNOMEPRINT_REQUIRED=2.12.0
-LIBGNOMEPRINTUI_REQUIRED=2.12.0
-LIBGNOMECANVAS_REQUIRED=2.14.0
LIBGLADE_REQUIRED=2.6.0
LIBEBOOK_REQUIRED=1.8.0
AC_SUBST(LIBGNOME_REQUIRED)
AC_SUBST(LIBGNOMEUI_REQUIRED)
AC_SUBST(LIBXML_REQUIRED)
-AC_SUBST(LIBGNOMEPRINT_REQUIRED)
-AC_SUBST(LIBGNOMEPRINTUI_REQUIRED)
-AC_SUBST(LIBGNOMECANVAS_REQUIRED)
AC_SUBST(LIBGLADE_REQUIRED)
AC_SUBST(LIBEBOOK_REQUIRED)
libgnome-2.0 >= $LIBGNOME_REQUIRED \
libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED \
libxml-2.0 >= $LIBXML_REQUIRED \
-libgnomeprint-2.2 >= $LIBGNOMEPRINT_REQUIRED \
-libgnomeprintui-2.2 >= $LIBGNOMEPRINTUI_REQUIRED \
-libgnomecanvas-2.0 >= $LIBGNOMECANVAS_REQUIRED \
libglade-2.0 >= $LIBGLADE_REQUIRED \
$OPTIONAL_MODULES \
)
view-text.h \
view-barcode.c \
view-barcode.h \
- view-highlight.c \
- view-highlight.h \
merge-properties-dialog.c \
merge-properties-dialog.h \
object-editor.c \
xml-label.h \
xml-label-04.c \
xml-label-04.h \
- xml-label-191.c \
- xml-label-191.h \
pixbuf-cache.c \
pixbuf-cache.h \
base64.c \
wdgt-rotate-label.h \
wdgt-chain-button.c \
wdgt-chain-button.h \
+ cairo-label-path.c \
+ cairo-label-path.h \
+ cairo-markup-path.c \
+ cairo-markup-path.h \
+ cairo-ellipse-path.c \
+ cairo-ellipse-path.h \
util.c \
util.h \
color.c \
color.h \
- canvas-hacktext.c \
- canvas-hacktext.h \
debug.c \
debug.h \
$(BUILT_SOURCES)
+
glabels_batch_SOURCES = \
glabels-batch.c \
print.c \
xml-label.h \
xml-label-04.c \
xml-label-04.h \
- xml-label-191.c \
- xml-label-191.h \
pixbuf-cache.c \
pixbuf-cache.h \
base64.c \
wdgt-mini-preview.c \
wdgt-mini-preview.h \
hig.h \
+ cairo-label-path.c \
+ cairo-label-path.h \
+ cairo-ellipse-path.c \
+ cairo-ellipse-path.h \
$(BUILT_SOURCES)
marshal.h: marshal.list $(GLIB_GENMARSHAL)
#include "base64.h"
#include <glib/gmem.h>
+#include <ctype.h>
#include <string.h>
/*========================================================*/
#include <ctype.h>
#include <string.h>
+#include <stdlib.h>
#include <glib/gmessages.h>
#include "iec16022ecc200.h"
i_width = 0;
i_height = 0;
- grid = iec16022ecc200 (&i_width, &i_height, NULL,
- strlen (digits), (char *)digits,
- NULL, NULL, NULL);
+ grid = (gchar *)iec16022ecc200 (&i_width, &i_height, NULL,
+ strlen (digits), (unsigned char *)digits,
+ NULL, NULL, NULL);
/* now render with our custom back-end,
to create appropriate intermdediate format */
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_ellipse_path.c: Cairo ellipse path module
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+
+#include "cairo-ellipse-path.h"
+
+#include <math.h>
+#include <glib.h>
+
+#include "debug.h"
+
+/*===========================================*/
+/* Private macros and constants. */
+/*===========================================*/
+
+#define ARC_FINE 2
+
+/*===========================================*/
+/* Private types */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes */
+/*===========================================*/
+
+
+\f
+/*****************************************************************************/
+/* Create ellipse path */
+/*****************************************************************************/
+void
+gl_cairo_ellipse_path (cairo_t *cr,
+ gdouble rx,
+ gdouble ry)
+{
+ gdouble x, y;
+ gint i_theta;
+
+ gl_debug (DEBUG_VIEW, "START");
+
+ cairo_new_path (cr);
+ cairo_move_to (cr, 2*rx, ry);
+ for (i_theta = ARC_FINE; i_theta <= 360; i_theta += ARC_FINE) {
+ x = rx + rx * cos (i_theta * G_PI / 180.0);
+ y = ry + ry * sin (i_theta * G_PI / 180.0);
+ cairo_line_to (cr, x, y);
+ }
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_VIEW, "END");
+}
+
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_ellipse_path.h: Cairo ellipse path module header file
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __CAIRO_ELLIPSE_PATH_H__
+#define __CAIRO_ELLIPSE_PATH_H__
+
+#include <glib.h>
+#include <cairo.h>
+
+G_BEGIN_DECLS
+
+void gl_cairo_ellipse_path (cairo_t *cr,
+ gdouble rx,
+ gdouble ry);
+
+
+G_END_DECLS
+
+#endif
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_label_path.c: Cairo label path module
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+
+#include "cairo-label-path.h"
+
+#include <math.h>
+#include <glib.h>
+
+#include "debug.h"
+
+/*===========================================*/
+/* Private types */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes */
+/*===========================================*/
+
+static void gl_cairo_rect_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag);
+static void gl_cairo_round_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag);
+static void gl_cairo_cd_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag);
+
+\f
+/*--------------------------------------------------------------------------*/
+/* Create label path */
+/*--------------------------------------------------------------------------*/
+void
+gl_cairo_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag)
+{
+ const glTemplateLabelType *label_type;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+
+ switch (label_type->shape) {
+
+ case GL_TEMPLATE_SHAPE_RECT:
+ gl_cairo_rect_label_path (cr, label, waste_flag);
+ break;
+
+ case GL_TEMPLATE_SHAPE_ROUND:
+ gl_cairo_round_label_path (cr, label, waste_flag);
+ break;
+
+ case GL_TEMPLATE_SHAPE_CD:
+ gl_cairo_cd_label_path (cr, label, waste_flag);
+ break;
+
+ default:
+ g_message ("Unknown label style");
+ break;
+ }
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*--------------------------------------------------------------------------*/
+/* Create rectangular label path */
+/*--------------------------------------------------------------------------*/
+static void
+gl_cairo_rect_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag)
+{
+ const glTemplateLabelType *label_type;
+ gdouble w, h, r;
+ gdouble x_waste, y_waste;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+ gl_label_get_size (label, &w, &h);
+ r = label_type->size.rect.r;
+
+ if (waste_flag)
+ {
+ x_waste = label_type->size.rect.x_waste;
+ y_waste = label_type->size.rect.x_waste;
+ }
+ else
+ {
+ x_waste = 0.0;
+ y_waste = 0.0;
+ }
+
+ if ( r == 0.0 )
+ {
+ cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste);
+ }
+ else
+ {
+ cairo_new_path (cr);
+ cairo_arc_negative (cr, r-x_waste, r-y_waste, r, 3*G_PI/2, G_PI);
+ cairo_arc_negative (cr, r-x_waste, h-r+y_waste, r, G_PI, G_PI/2);
+ cairo_arc_negative (cr, w-r+x_waste, h-r+y_waste, r, G_PI/2, 0.);
+ cairo_arc_negative (cr, w-r+x_waste, r-y_waste, r, 2*G_PI, 3*G_PI/2);
+ cairo_close_path (cr);
+ }
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*--------------------------------------------------------------------------*/
+/* Create round label path */
+/*--------------------------------------------------------------------------*/
+static void
+gl_cairo_round_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag)
+{
+ const glTemplateLabelType *label_type;
+ gdouble w, h;
+ gdouble waste;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+ gl_label_get_size (label, &w, &h);
+
+ if (waste_flag)
+ {
+ waste = label_type->size.round.waste;
+ }
+ else
+ {
+ waste = 0.0;
+ }
+
+ cairo_arc (cr, w/2, h/2, w/2+waste, 0.0, 2*G_PI);
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*--------------------------------------------------------------------------*/
+/* Create cd label path */
+/*--------------------------------------------------------------------------*/
+static void
+gl_cairo_cd_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag)
+{
+ const glTemplateLabelType *label_type;
+ gdouble w, h;
+ gdouble xc, yc;
+ gdouble r1, r2;
+ gdouble theta1, theta2;
+ gdouble waste;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+ gl_label_get_size (label, &w, &h);
+
+ xc = w/2.0;
+ yc = h/2.0;
+
+ r1 = label_type->size.cd.r1;
+ r2 = label_type->size.cd.r2;
+
+ if (waste_flag)
+ {
+ waste = label_type->size.cd.waste;
+ }
+ else
+ {
+ waste = 0.0;
+ }
+
+ /*
+ * Outer path (may be clipped in the case of a business card type CD)
+ */
+ theta1 = acos (w / (2.0*r1));
+ theta2 = asin (h / (2.0*r1));
+
+ cairo_new_path (cr);
+ cairo_arc (cr, xc, yc, r1+waste, theta1, theta2);
+ cairo_arc (cr, xc, yc, r1+waste, G_PI-theta2, G_PI-theta1);
+ cairo_arc (cr, xc, yc, r1+waste, G_PI+theta1, G_PI+theta2);
+ cairo_arc (cr, xc, yc, r1+waste, 2*G_PI-theta2, 2*G_PI-theta1);
+ cairo_close_path (cr);
+
+
+ /*
+ * Inner path (hole)
+ */
+ cairo_new_sub_path (cr);
+ cairo_arc (cr, xc, yc, r2-waste, 0.0, 2*G_PI);
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_label_path.h: Cairo label path module header file
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __CAIRO_LABEL_PATH_H__
+#define __CAIRO_LABEL_PATH_H__
+
+#include <cairo.h>
+#include "label.h"
+
+G_BEGIN_DECLS
+
+void gl_cairo_label_path (cairo_t *cr,
+ glLabel *label,
+ gboolean waste_flag);
+
+G_END_DECLS
+
+#endif
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_markup_path.c: Cairo markup path module
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <config.h>
+
+#include "cairo-markup-path.h"
+
+#include <math.h>
+#include <glib.h>
+
+#include "debug.h"
+
+/*===========================================*/
+/* Private types */
+/*===========================================*/
+
+/*===========================================*/
+/* Private globals */
+/*===========================================*/
+
+/*===========================================*/
+/* Local function prototypes */
+/*===========================================*/
+
+static void gl_cairo_markup_margin_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label);
+
+static void gl_cairo_markup_margin_rect_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label);
+
+static void gl_cairo_markup_margin_round_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label);
+
+static void gl_cairo_markup_margin_cd_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label);
+
+static void gl_cairo_markup_line_path (cairo_t *cr,
+ const glTemplateMarkup *markup);
+
+static void gl_cairo_markup_circle_path (cairo_t *cr,
+ const glTemplateMarkup *markup);
+
+\f
+/*--------------------------------------------------------------------------*/
+/* Create markup path */
+/*--------------------------------------------------------------------------*/
+void
+gl_cairo_markup_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label)
+{
+ gl_debug (DEBUG_PATH, "START");
+
+ switch (markup->type) {
+ case GL_TEMPLATE_MARKUP_MARGIN:
+ gl_cairo_markup_margin_path (cr, markup, label);
+ break;
+ case GL_TEMPLATE_MARKUP_LINE:
+ gl_cairo_markup_line_path (cr, markup);
+ break;
+ case GL_TEMPLATE_MARKUP_CIRCLE:
+ gl_cairo_markup_circle_path (cr, markup);
+ break;
+ default:
+ g_message ("Unknown template markup type");
+ break;
+ }
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw margin markup. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_margin_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label)
+{
+ const glTemplateLabelType *label_type;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+
+ switch (label_type->shape) {
+
+ case GL_TEMPLATE_SHAPE_RECT:
+ gl_cairo_markup_margin_rect_path (cr, markup, label);
+ break;
+
+ case GL_TEMPLATE_SHAPE_ROUND:
+ gl_cairo_markup_margin_round_path (cr, markup, label);
+ break;
+
+ case GL_TEMPLATE_SHAPE_CD:
+ gl_cairo_markup_margin_cd_path (cr, markup, label);
+ break;
+
+ default:
+ g_message ("Unknown template label style");
+ break;
+ }
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw simple recangular margin. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_margin_rect_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label)
+{
+ const glTemplateLabelType *label_type;
+ gdouble w, h, r, m;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+
+ m = markup->data.margin.size;
+
+ gl_label_get_size (label, &w, &h);
+ w = w - 2*m;
+ h = h - 2*m;
+ r = MAX (label_type->size.rect.r - m, 0.0);
+
+ if ( r == 0.0 )
+ {
+ cairo_rectangle (cr, m, m, w, h);
+ }
+ else
+ {
+ cairo_new_path (cr);
+ cairo_arc_negative (cr, m+r, m+r, r, 3*G_PI/2, G_PI);
+ cairo_arc_negative (cr, m+r, m+h-r, r, G_PI, G_PI/2);
+ cairo_arc_negative (cr, m+w-r, m+h-r, r, G_PI/2, 0.);
+ cairo_arc_negative (cr, m+w-r, m+r, r, 2*G_PI, 3*G_PI/2);
+ cairo_close_path (cr);
+ }
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw round margin. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_margin_round_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label)
+{
+ const glTemplateLabelType *label_type;
+ gdouble r, m;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+
+ r = label_type->size.round.r;
+ m = markup->data.margin.size;
+
+ cairo_arc (cr, r, r, r-m, 0, 2*G_PI);
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw CD margins. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_margin_cd_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label)
+{
+ const glTemplateLabelType *label_type;
+ gdouble m, r1, r2;
+ gdouble theta1, theta2;
+ gdouble xc, yc;
+ gdouble w, h;
+
+ gl_debug (DEBUG_PATH, "START");
+
+ label_type = gl_template_get_first_label_type (label->template);
+
+ gl_label_get_size (label, &w, &h);
+ xc = w/2.0;
+ yc = h/2.0;
+
+ m = markup->data.margin.size;
+ r1 = label_type->size.cd.r1 - m;
+ r2 = label_type->size.cd.r2 + m;
+
+
+ /*
+ * Outer path (may be clipped)
+ */
+ theta1 = acos ((w-2*m) / (2.0*r1));
+ theta2 = asin ((h-2*m) / (2.0*r1));
+
+ cairo_new_path (cr);
+ cairo_arc (cr, xc, yc, r1, theta1, theta2);
+ cairo_arc (cr, xc, yc, r1, G_PI-theta2, G_PI-theta1);
+ cairo_arc (cr, xc, yc, r1, G_PI+theta1, G_PI+theta2);
+ cairo_arc (cr, xc, yc, r1, 2*G_PI-theta2, 2*G_PI-theta1);
+ cairo_close_path (cr);
+
+
+ /* Inner path (hole) */
+ cairo_new_sub_path (cr);
+ cairo_arc (cr, xc, yc, r2, 0.0, 2*G_PI);
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw line markup. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_line_path (cairo_t *cr,
+ const glTemplateMarkup *markup)
+{
+ gl_debug (DEBUG_PATH, "START");
+
+ cairo_move_to (cr, markup->data.line.x1, markup->data.line.y1);
+ cairo_line_to (cr, markup->data.line.x2, markup->data.line.y2);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw circle markup. */
+/*---------------------------------------------------------------------------*/
+static void
+gl_cairo_markup_circle_path (cairo_t *cr,
+ const glTemplateMarkup *markup)
+{
+ gl_debug (DEBUG_PATH, "START");
+
+ cairo_arc (cr,
+ markup->data.circle.x0, markup->data.circle.y0,
+ markup->data.circle.r,
+ 0.0, 2*G_PI);
+ cairo_close_path (cr);
+
+ gl_debug (DEBUG_PATH, "END");
+}
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * cairo_markup_path.h: Cairo markup path module header file
+ *
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __CAIRO_MARKUP_PATH_H__
+#define __CAIRO_MARKUP_PATH_H__
+
+#include <cairo.h>
+#include <libglabels/template.h>
+#include "label.h"
+
+G_BEGIN_DECLS
+
+void gl_cairo_markup_path (cairo_t *cr,
+ const glTemplateMarkup *markup,
+ glLabel *label);
+
+G_END_DECLS
+
+#endif
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- * gnome-canvas-hacktext.c: Hacktext item type for GnomeCanvas widget
- * This is mainly used for gnome-print preview context
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public License
- * as published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Authors:
- * Federico Mena <federico@nuclecu.unam.mx>
- * Raph Levien <raph@acm.org>
- * Lauris Kaplinski <lauris@helixcode.com>
- *
- * Copyright (C) 1998-1999 The Free Software Foundation
- * Copyright (C) 2000-2002 Ximian Inc.
- *
- *
- * Modified by Jim Evins <evins@snaught.com> for gLabels.
- */
-
-#include <config.h>
-
-#include <math.h>
-#include <string.h>
-#include <libgnomeprint/gnome-font.h>
-#include <libgnomeprint/gnome-rfont.h>
-#include <libgnomeprint/gnome-pgl.h>
-#include "canvas-hacktext.h"
-
-enum {
- ARG_0,
- ARG_TEXT,
- ARG_GLYPHLIST,
- ARG_FILL_COLOR,
- ARG_FILL_COLOR_RGBA,
- ARG_FONT,
- ARG_X,
- ARG_Y
-};
-
-
-static void gl_canvas_hacktext_class_init (glCanvasHacktextClass *class);
-static void gl_canvas_hacktext_init (glCanvasHacktext *hacktext);
-static void gl_canvas_hacktext_destroy (GtkObject *object);
-static void gl_canvas_hacktext_set_arg (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gl_canvas_hacktext_get_arg (GObject *object,
- guint arg_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void gl_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags);
-static void gl_canvas_hacktext_realize (GnomeCanvasItem *item);
-static void gl_canvas_hacktext_unrealize (GnomeCanvasItem *item);
-static double gl_canvas_hacktext_point (GnomeCanvasItem *item, double x, double y,
- int cx, int cy, GnomeCanvasItem **actual_item);
-static void gl_canvas_hacktext_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2);
-static void gl_canvas_hacktext_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf);
-static void gl_canvas_hacktext_req_repaint (glCanvasHacktext *hacktext, ArtIRect *bbox);
-
-
-static GnomeCanvasItemClass *parent_class;
-
-struct _glCanvasHacktextPriv {
- GnomeFont * font;
-
- GnomeGlyphList * glyphlist;
- GnomePosGlyphList * pgl;
- double affine[6]; /* the text to world transform (NB! mirrored Y) */
-};
-
-GType
-gl_canvas_hacktext_get_type (void)
-{
- static GType type = 0;
-
- if (!type) {
- static const GTypeInfo info = {
- sizeof (glCanvasHacktextClass),
- NULL,
- NULL,
- (GClassInitFunc) gl_canvas_hacktext_class_init,
- NULL,
- NULL,
- sizeof (glCanvasHacktext),
- 0,
- (GInstanceInitFunc) gl_canvas_hacktext_init,
- NULL
- };
-
- type = g_type_register_static (GNOME_TYPE_CANVAS_ITEM,
- "glCanvasHacktext",
- &info, 0);
- }
-
- return type;
-}
-
-static void
-gl_canvas_hacktext_class_init (glCanvasHacktextClass *class)
-{
- GObjectClass *gobject_class;
- GtkObjectClass *object_class;
- GnomeCanvasItemClass *item_class;
-
- gobject_class = (GObjectClass *) class;
- object_class = (GtkObjectClass *) class;
- item_class = (GnomeCanvasItemClass *) class;
-
- parent_class = g_type_class_peek_parent (class);
-
- gobject_class->set_property = gl_canvas_hacktext_set_arg;
- gobject_class->get_property = gl_canvas_hacktext_get_arg;
-
- g_object_class_install_property
- (gobject_class,
- ARG_TEXT,
- g_param_spec_string ("text", NULL, NULL,
- NULL,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_GLYPHLIST,
- g_param_spec_pointer ("glyphlist", NULL, NULL,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_FILL_COLOR,
- g_param_spec_string ("fill_color", NULL, NULL,
- NULL,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_FILL_COLOR_RGBA,
- g_param_spec_uint ("fill_color_rgba", NULL, NULL,
- 0, G_MAXUINT, 0,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_FONT,
- g_param_spec_pointer ("font", NULL, NULL,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_X,
- g_param_spec_double ("x", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
- g_object_class_install_property
- (gobject_class,
- ARG_Y,
- g_param_spec_double ("y", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-
-
- object_class->destroy = gl_canvas_hacktext_destroy;
-
- item_class->update = gl_canvas_hacktext_update;
- item_class->realize = gl_canvas_hacktext_realize;
- item_class->unrealize = gl_canvas_hacktext_unrealize;
- item_class->point = gl_canvas_hacktext_point;
- item_class->bounds = gl_canvas_hacktext_bounds;
- item_class->render = gl_canvas_hacktext_render;
-}
-
-static void
-gl_canvas_hacktext_init (glCanvasHacktext *hacktext)
-{
- hacktext->text = NULL;
- hacktext->priv = g_new (glCanvasHacktextPriv, 1);
- hacktext->priv->font = NULL;
- hacktext->priv->glyphlist = NULL;
- hacktext->priv->pgl = NULL;
-
- art_affine_identity (hacktext->priv->affine);
-}
-
-static void
-gl_canvas_hacktext_destroy (GtkObject *object)
-{
- glCanvasHacktext *hacktext;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GL_IS_CANVAS_HACKTEXT (object));
-
- hacktext = GL_CANVAS_HACKTEXT (object);
-
- if (hacktext->text) {
- g_free (hacktext->text);
- hacktext->text = NULL;
- }
-
- if (hacktext->priv) {
- if (hacktext->priv->font) gnome_font_unref (hacktext->priv->font);
- if (hacktext->priv->glyphlist) gnome_glyphlist_unref (hacktext->priv->glyphlist);
- if (hacktext->priv->pgl) gnome_pgl_destroy (hacktext->priv->pgl);
- g_free (hacktext->priv);
- hacktext->priv = NULL;
- }
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
-}
-
-static void
-art_drect_hacktext (ArtDRect *bbox, glCanvasHacktext *hacktext)
-{
- g_assert (bbox != NULL);
- g_assert (hacktext != NULL);
-
- g_return_if_fail (hacktext->priv);
-
- if (GTK_OBJECT_FLAGS (hacktext) & GNOME_CANVAS_UPDATE_REQUESTED) {
- gnome_canvas_update_now (GNOME_CANVAS_ITEM (hacktext)->canvas);
- }
-
- if (!hacktext->priv->pgl) return;
-
- gnome_pgl_bbox (hacktext->priv->pgl, bbox);
-}
-
-/* Computes the bounding box of the hacktext. Assumes that the number of points in the hacktext is
- * not zero.
- */
-static void
-get_bounds (glCanvasHacktext *hacktext, double *bx1, double *by1, double *bx2, double *by2)
-{
- ArtDRect bbox;
-
- /* Compute bounds of hacktext */
- art_drect_hacktext (&bbox, hacktext);
-
- /* Done */
-
- *bx1 = bbox.x0;
- *by1 = bbox.y0;
- *bx2 = bbox.x1;
- *by2 = bbox.y1;
-}
-
-#ifdef IFED_OUT_BY_CHEMA_TO_KILL_COMPILE_WARNING
-/* Convenience function to set a GC's foreground color to the specified pixel value */
-static void
-set_gc_foreground (GdkGC *gc, gulong pixel)
-{
- GdkColor c;
-
- if (!gc)
- return;
-
- c.pixel = pixel;
- gdk_gc_set_foreground (gc, &c);
-}
-#endif
-
-static void
-gl_canvas_hacktext_set_arg (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GnomeCanvasItem *item;
- glCanvasHacktext *bp;
- GnomeGlyphList * gl;
- GdkColor color;
- GnomeFont * font;
-
- item = GNOME_CANVAS_ITEM (object);
- bp = GL_CANVAS_HACKTEXT (object);
-
- switch (arg_id) {
- case ARG_TEXT:
- if (bp->text) {
- g_free (bp->text);
- bp->text = NULL;
- }
-
- if (bp->priv->glyphlist) {
- gnome_glyphlist_unref (bp->priv->glyphlist);
- bp->priv->glyphlist = NULL;
- }
-
- bp->text = g_value_dup_string (value);
-
- gnome_canvas_item_request_update (item);
- break;
-
- case ARG_GLYPHLIST:
- gl = g_value_get_pointer (value);
-
- if (bp->text) {
- g_free (bp->text);
- bp->text = NULL;
- }
-
- if (bp->priv->glyphlist) {
- gnome_glyphlist_unref (bp->priv->glyphlist);
- bp->priv->glyphlist = NULL;
- }
-
- /* fixme: should be duplicate() */
-
- if (gl) gnome_glyphlist_ref (gl);
-
- bp->priv->glyphlist = gl;
-
- gnome_canvas_item_request_update (item);
-
- break;
-
- case ARG_FILL_COLOR:
- if (gnome_canvas_get_color (item->canvas, g_value_get_string(value), &color)) {
- bp->fill_set = TRUE;
- bp->fill_pixel = color.pixel;
- bp->fill_rgba =
- ((color.red & 0xff00) << 16) |
- ((color.green & 0xff00) << 8) |
- (color.blue & 0xff00) |
- 0xff;
- } else {
- bp->fill_set = FALSE;
- bp->fill_rgba = 0;
- }
-
- gnome_canvas_item_request_update (item);
- break;
-
- case ARG_FILL_COLOR_RGBA:
- bp->fill_set = TRUE;
- bp->fill_rgba = g_value_get_uint (value);
-
- /* should probably request repaint on the fill_svp */
- gnome_canvas_item_request_update (item);
-
- break;
-
- case ARG_FONT:
- font = g_value_get_pointer (value);
- if (font) gnome_font_ref (font);
- if (bp->priv->font) gnome_font_unref (bp->priv->font);
- bp->priv->font = font;
- bp->size = gnome_font_get_size (bp->priv->font);
- gnome_canvas_item_request_update (item);
- break;
-
- case ARG_X:
- bp->x = g_value_get_double (value);
- gnome_canvas_item_request_update (item);
- break;
-
- case ARG_Y:
- bp->y = g_value_get_double (value);
- gnome_canvas_item_request_update (item);
- break;
-
- default:
- break;
- }
-}
-
-static void
-gl_canvas_hacktext_get_arg (GObject *object,
- guint arg_id,
- GValue *value,
- GParamSpec *pspec)
-{
- glCanvasHacktext *bp;
-
- bp = GL_CANVAS_HACKTEXT (object);
-
- switch (arg_id) {
- case ARG_TEXT:
- if (bp->text) {
- g_value_set_string (value, g_strdup (bp->text));
- } else
- g_value_set_string (value, NULL);
- break;
- case ARG_FILL_COLOR_RGBA:
- g_value_set_uint (value, bp->fill_color);
- break;
-
- case ARG_FONT:
- g_value_set_pointer (value, bp->priv->font);
- break;
-
- case ARG_X:
- g_value_set_double (value, bp->x);
- break;
-
- case ARG_Y:
- g_value_set_double (value, bp->y);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- break;
- }
-}
-
-static void
-gl_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
-{
- glCanvasHacktext *hacktext;
- ArtIRect ibbox = {0, 0, 0, 0};
-
- hacktext = (glCanvasHacktext *) item;
-
- if (parent_class->update)
- (* parent_class->update) (item, affine, clip_path, flags);
-
- if (hacktext->priv->pgl) gl_canvas_hacktext_req_repaint (hacktext, NULL);
-
- gnome_canvas_item_reset_bounds (item);
-
- hacktext->priv->affine[0] = affine[0];
- hacktext->priv->affine[1] = affine[1];
- hacktext->priv->affine[2] = -affine[2];
- hacktext->priv->affine[3] = -affine[3];
- hacktext->priv->affine[4] = affine[4] + hacktext->x * affine[0] + hacktext->y * affine[2];
- hacktext->priv->affine[5] = affine[5] + hacktext->x * affine[1] + hacktext->y * affine[3];
-
- if (hacktext->text) {
- if (hacktext->priv->glyphlist) {
- gnome_glyphlist_unref (hacktext->priv->glyphlist);
- hacktext->priv->glyphlist = NULL;
- }
-
- if (!hacktext->priv->font) return;
-
- hacktext->priv->glyphlist = gnome_glyphlist_from_text_dumb (
- hacktext->priv->font, hacktext->fill_rgba,
- 0.0, 0.0,
- (guchar *)hacktext->text);
- }
-
- if (hacktext->priv->glyphlist) {
- GnomePosGlyphList * pgl;
-
- pgl = gnome_pgl_from_gl (hacktext->priv->glyphlist, hacktext->priv->affine, GNOME_PGL_RENDER_DEFAULT);
-
- if (hacktext->priv->pgl) gnome_pgl_destroy (hacktext->priv->pgl);
-
- hacktext->priv->pgl = pgl;
- }
-
- gl_canvas_hacktext_req_repaint (hacktext, &ibbox);
-
- hacktext->item.x1 = ibbox.x0;
- hacktext->item.y1 = ibbox.y0;
- hacktext->item.x2 = ibbox.x1;
- hacktext->item.y2 = ibbox.y1;
-}
-
-static void
-gl_canvas_hacktext_realize (GnomeCanvasItem *item)
-{
- glCanvasHacktext *hacktext;
-
- hacktext = (glCanvasHacktext *) item;
-
- if (parent_class->realize)
- (* parent_class->realize) (item);
-}
-
-static void
-gl_canvas_hacktext_unrealize (GnomeCanvasItem *item)
-{
- glCanvasHacktext *hacktext;
-
- hacktext = (glCanvasHacktext *) item;
-
- if (parent_class->unrealize)
- (* parent_class->unrealize) (item);
-}
-
-static double
-gl_canvas_hacktext_point (GnomeCanvasItem *item, double mx, double my,
- int cx, int cy, GnomeCanvasItem **actual_item)
-{
- glCanvasHacktext * hacktext;
-
- hacktext = (glCanvasHacktext *) item;
-
- if (!hacktext->priv->pgl) return 1e18;
-
- *actual_item = item;
-
- if (gnome_pgl_test_point (hacktext->priv->pgl, cx, cy)) return 0.0;
-
- return 1e18;
-}
-
-static void
-gl_canvas_hacktext_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
-{
- glCanvasHacktext *hacktext;
-
- g_return_if_fail (item != NULL);
- g_return_if_fail (GL_IS_CANVAS_HACKTEXT (item));
-
- hacktext = GL_CANVAS_HACKTEXT (item);
-
- if (hacktext->text == NULL) {
- *x1 = *y1 = *x2 = *y2 = 0.0;
- return;
- }
-
- get_bounds (hacktext, x1, y1, x2, y2);
-}
-
-static void
-gl_canvas_hacktext_req_repaint (glCanvasHacktext *hacktext,
- ArtIRect *bbox)
-{
- ArtDRect gbbox;
-
- g_return_if_fail (hacktext->priv);
-
- if (!hacktext->priv->pgl) return;
-
- if (gnome_pgl_bbox (hacktext->priv->pgl, &gbbox)) {
- ArtIRect ibox;
- art_drect_to_irect (&ibox, &gbbox);
-
- /* hack: bounding box seems to be underestimated.
- * It may be doesn't take into account antialiasing*/
-
- ibox.x0--;
- ibox.y0--;
- ibox.x1++;
- ibox.y1++;
-
- gnome_canvas_request_redraw (hacktext->item.canvas, ibox.x0, ibox.y0, ibox.x1, ibox.y1);
- if (bbox) art_irect_union (bbox, bbox, &ibox);
- }
-}
-
-static void
-gl_canvas_hacktext_render (GnomeCanvasItem *item,
- GnomeCanvasBuf *buf)
-{
- glCanvasHacktext * hacktext;
-
- hacktext = (glCanvasHacktext *) item;
-
- g_return_if_fail (hacktext->priv);
-
- if (!hacktext->priv->pgl) return;
-
- gnome_canvas_buf_ensure_buf (buf);
- buf->is_buf = TRUE;
- buf->is_bg = FALSE;
-
- gnome_rfont_render_pgl_rgb8 (hacktext->priv->pgl,
- -buf->rect.x0, -buf->rect.y0,
- buf->buf,
- buf->rect.x1 - buf->rect.x0,
- buf->rect.y1 - buf->rect.y0,
- buf->buf_rowstride,
- GNOME_RFONT_RENDER_DEFAULT);
-}
-
-
-
-
-
-
-
-
-
-
-
-
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-#ifndef __GL_CANVAS_HACKTEXT_H__
-#define __GL_CANVAS_HACKTEXT_H__
-
-/* Hacktext item type for GnomeCanvas widget
- *
- * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is
- * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
- *
- * Copyright (C) 1998,1999 The Free Software Foundation
- *
- * Authors: Federico Mena <federico@nuclecu.unam.mx>
- * Raph Levien <raph@acm.org>
- *
- * Modified by Jim Evins <evins@snaught.com> for gLabels.
- */
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/* Hacktext item for the canvas. The API is totally unstable - it needs to be replaced with one
- * that supports Unicode and the merged GnomeText/GScript API. However, I need a text item now,
- * and the GnomeText/GScript integration is going to take a bit more effort.
- *
- * The following object arguments are available:
- *
- * name type read/write description
- * ------------------------------------------------------------------------------------------
- * text char * RW The string of the text item.
- * glyphlist GnomeGlyphList * W Glyphlist
- * fill_color string W X color specification for fill color,
- * or NULL pointer for no color (transparent).
- * fill_color_gdk GdkColor* RW Allocated GdkColor for fill.
- */
-
-#define GL_TYPE_CANVAS_HACKTEXT (gl_canvas_hacktext_get_type ())
-#define GL_CANVAS_HACKTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_CANVAS_HACKTEXT, glCanvasHacktext))
-#define GL_CANVAS_HACKTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_CANVAS_HACKTEXT, glCanvasHacktextClass))
-#define GL_IS_CANVAS_HACKTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_CANVAS_HACKTEXT))
-#define GL_IS_CANVAS_HACKTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_CANVAS_HACKTEXT))
-
-typedef struct _glCanvasHacktext glCanvasHacktext;
-typedef struct _glCanvasHacktextPriv glCanvasHacktextPriv;
-typedef struct _glCanvasHacktextClass glCanvasHacktextClass;
-
-#include <libgnomecanvas/libgnomecanvas.h>
-
-struct _glCanvasHacktext {
- GnomeCanvasItem item;
-
- char *text; /* String of the text item */
- guint fill_color; /* Fill color, RGBA */
- gulong fill_pixel; /* Color for fill */
- guint fill_set : 1; /* Is fill color set? */
-
- double size; /* size in user units */
- double x, y; /* x, y coords of text origin */
- /* Antialiased specific stuff follows */
- guint32 fill_rgba; /* RGBA color for filling */
- glCanvasHacktextPriv *priv; /* Private data */
-};
-
-struct _glCanvasHacktextClass {
- GnomeCanvasItemClass parent_class;
-};
-
-
-GType gl_canvas_hacktext_get_type (void) G_GNUC_CONST;
-
-
-G_END_DECLS
-
-#endif
#include "color.h"
+#include <string.h>
+
/*****************************************************************************/
/* Apply given opacity to given color. */
/*****************************************************************************/
#include <glib/gutils.h>
#include <glib/gmessages.h>
#include <glib/gstrfuncs.h>
+#include <glib/gmem.h>
glDebugSection debug_flags = GLABELS_DEBUG_NONE;
debug_flags |= GLABELS_DEBUG_EDITOR;
if (g_getenv ("GLABELS_DEBUG_WDGT") != NULL)
debug_flags |= GLABELS_DEBUG_WDGT;
+ if (g_getenv ("GLABELS_DEBUG_PATH") != NULL)
+ debug_flags |= GLABELS_DEBUG_PATH;
}
GLABELS_DEBUG_PIXBUF_CACHE = 1 << 18,
GLABELS_DEBUG_EDITOR = 1 << 19,
GLABELS_DEBUG_WDGT = 1 << 20,
+ GLABELS_DEBUG_PATH = 1 << 21,
} glDebugSection;
#define DEBUG_MEDIA_SELECT GLABELS_DEBUG_MEDIA_SELECT, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_MINI_PREVIEW GLABELS_DEBUG_MINI_PREVIEW, __FILE__, __LINE__, __FUNCTION__
#define DEBUG_PIXBUF_CACHE GLABELS_DEBUG_PIXBUF_CACHE, __FILE__, __LINE__, __FUNCTION__
-#define DEBUG_EDITOR GLABELS_DEBUG_EDITOR, __FILE__, __LINE__, __FUNCTION__
-#define DEBUG_WDGT GLABELS_DEBUG_WDGT, __FILE__, __LINE__, __FUNCTION__
+#define DEBUG_EDITOR GLABELS_DEBUG_EDITOR, __FILE__, __LINE__, __FUNCTION__
+#define DEBUG_WDGT GLABELS_DEBUG_WDGT, __FILE__, __LINE__, __FUNCTION__
+#define DEBUG_PATH GLABELS_DEBUG_PATH, __FILE__, __LINE__, __FUNCTION__
void gl_debug_init (void);
#include "file.h"
#include <glib/gi18n.h>
+#include <gtk/gtkmain.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkfilechooserdialog.h>
glWindow *window)
{
GtkWidget *dialog;
- glTemplate *template;
- gboolean rotate_flag;
gl_debug (DEBUG_FILE, "START");
g_signal_connect (G_OBJECT(dialog), "response",
G_CALLBACK (properties_response), dialog);
- template = gl_label_get_template (label);
- rotate_flag = gl_label_get_rotate_flag (label);
-
- if (template->page_size != NULL) {
+ if (label->template->page_size != NULL) {
gl_new_label_dialog_set_filter_parameters (GL_NEW_LABEL_DIALOG (dialog),
- template->page_size, NULL);
+ label->template->page_size,
+ NULL);
}
- if (template->name != NULL) {
- gchar *template_name = gl_template_get_name_with_desc (template);
+ if (label->template->name != NULL) {
+ gchar *template_name = gl_template_get_name_with_desc (label->template);
gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog),
template_name);
gl_new_label_dialog_set_template_name (GL_NEW_LABEL_DIALOG (dialog),
g_free (template_name);
}
gl_new_label_dialog_set_rotate_state (GL_NEW_LABEL_DIALOG (dialog),
- rotate_flag);
+ label->rotate_flag);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_widget_show_all (GTK_WIDGET (dialog));
{
glTemplate *template;
glLabel *label;
- glWindow *window;
- GtkWidget *new_window;
gl_debug (DEBUG_FILE, "START");
gchar *raw_filename;
gchar *filename;
GtkWidget *dialog;
- gint ret;
gl_debug (DEBUG_FILE, "START");
gchar *abs_filename;
glLabel *label;
glXMLLabelStatus status;
- gint ret;
GtkWidget *new_window;
gl_debug (DEBUG_FILE, "START");
glWindow *window)
{
glXMLLabelStatus status;
- GError *error = NULL;
gchar *filename = NULL;
gl_debug (DEBUG_FILE, "");
label = view->label;
if (gl_label_is_modified (label)) {
- GtkWidget *dialog, *w;
+ GtkWidget *dialog;
gchar *fname = NULL;
gint ret;
- gboolean exiting;
fname = gl_label_get_short_name (label);
/*============================================*/
/* Private globals */
/*============================================*/
-static gboolean help_flag = FALSE;
-static gboolean version_flag = FALSE;
static gchar *output = "output.pdf";
static gint n_copies = 1;
static gint n_sheets = 1;
{
GOptionContext *option_context;
GnomeProgram *program;
- gint rc;
GList *p, *file_list = NULL;
gchar *abs_fn;
glLabel *label = NULL;
#include <libgnomeui/libgnomeui.h>
#include <libgnomeui/gnome-window-icon.h>
+#include "warning-handler.h"
#include "critical-error-handler.h"
#include "stock.h"
#include "merge-init.h"
*
* label_barcode.c: GLabels label text object
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "label-barcode.h"
+#include <glib/gi18n.h>
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
-
-#include "pixmaps/checkerboard.xpm"
+#include <cairo.h>
+#include <pango/pangocairo.h>
#include "debug.h"
/* Private macros and constants. */
/*========================================================*/
+#define FONT_SCALE (72.0/96.0)
+
/*========================================================*/
/* Private types. */
/*========================================================*/
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static glColorNode *get_line_color (glLabelObject *object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
\f
/*****************************************************************************/
label_object_class->get_size = get_size;
label_object_class->set_line_color = set_line_color;
label_object_class->get_line_color = get_line_color;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = NULL;
object_class->finalize = gl_label_barcode_finalize;
}
g_return_if_fail (lbc && GL_IS_LABEL_BARCODE (lbc));
- (* GL_LABEL_OBJECT_CLASS (gl_label_barcode_parent_class)->get_size) (object, &w_parent, &h_parent);
-
+ gl_label_object_get_raw_size (object, &w_parent, &h_parent);
if (lbc->priv->text_node->field_flag) {
data = gl_barcode_default_digits (lbc->priv->id,
{
glLabelBarcode *lbarcode = (glLabelBarcode *)object;
- g_return_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode));
+ g_return_val_if_fail (lbarcode && GL_IS_LABEL_BARCODE (lbarcode), NULL);
return gl_color_node_dup (lbarcode->priv->color_node);
}
+
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ glBarcode *gbc;
+ glBarcodeLine *line;
+ glBarcodeChar *bchar;
+ GList *li;
+ gdouble y_offset;
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ gchar *text, *cstring;
+ glTextNode *text_node;
+ gchar *id;
+ gboolean text_flag;
+ gboolean checksum_flag;
+ guint color;
+ glColorNode *color_node;
+ guint format_digits;
+ gdouble w, h;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE (object));
+ gl_label_barcode_get_props (GL_LABEL_BARCODE (object),
+ &id, &text_flag, &checksum_flag, &format_digits);
+
+ color_node = gl_label_object_get_line_color (object);
+ color = gl_color_node_expand (color_node, record);
+ if (color_node->field_flag && screen_flag)
+ {
+ color = GL_COLOR_MERGE_DEFAULT;
+ }
+ gl_color_node_free (&color_node);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
+ text = gl_text_node_expand (text_node, record);
+ if (text_node->field_flag && screen_flag) {
+ text = gl_barcode_default_digits (id, format_digits);
+ }
+
+ gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, text);
+
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (color),
+ GL_COLOR_F_GREEN (color),
+ GL_COLOR_F_BLUE (color),
+ GL_COLOR_F_ALPHA (color));
+
+ if (gbc == NULL) {
+
+ layout = pango_cairo_create_layout (cr);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, GL_BARCODE_FONT_FAMILY);
+ pango_font_description_set_size (desc, 12 * PANGO_SCALE * FONT_SCALE);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ if (text == NULL || *text == '\0')
+ {
+ pango_layout_set_text (layout, _("Barcode data empty"), -1);
+ }
+ else
+ {
+ pango_layout_set_text (layout, _("Invalid barcode data"), -1);
+ }
+
+ pango_cairo_show_layout (cr, layout);
+
+ g_object_unref (layout);
+
+ } else {
+
+ for (li = gbc->lines; li != NULL; li = li->next) {
+ line = (glBarcodeLine *) li->data;
+
+ cairo_move_to (cr, line->x, line->y);
+ cairo_line_to (cr, line->x, line->y + line->length);
+ cairo_set_line_width (cr, line->width);
+ cairo_stroke (cr);
+ }
+
+ for (li = gbc->chars; li != NULL; li = li->next) {
+ bchar = (glBarcodeChar *) li->data;
+
+ layout = pango_cairo_create_layout (cr);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, GL_BARCODE_FONT_FAMILY);
+ pango_font_description_set_size (desc, bchar->fsize * PANGO_SCALE * FONT_SCALE);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ cstring = g_strdup_printf ("%c", bchar->c);
+ pango_layout_set_text (layout, cstring, -1);
+ g_free (cstring);
+
+ y_offset = 0.2 * bchar->fsize;
+
+ cairo_move_to (cr, bchar->x, bchar->y-y_offset);
+ pango_cairo_show_layout (cr, layout);
+
+ g_object_unref (layout);
+
+ }
+
+ gl_barcode_free (&gbc);
+
+ }
+
+ g_free (text);
+ gl_text_node_free (&text_node);
+ g_free (id);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
*
* label_box.c: GLabels label box object
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static gdouble get_line_width (glLabelObject *object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+static void draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+
+
\f
/*****************************************************************************/
label_object_class->get_fill_color = get_fill_color;
label_object_class->get_line_color = get_line_color;
label_object_class->get_line_width = get_line_width;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = draw_shadow;
object_class->finalize = gl_label_box_finalize;
}
return gl_color_node_dup (lbox->priv->fill_color_node);
}
+
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ glColorNode *fill_color_node;
+ guint line_color;
+ guint fill_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (object, &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ fill_color_node = gl_label_object_get_fill_color (object);
+ line_color = gl_color_node_expand (line_color_node, record);
+ fill_color = gl_color_node_expand (fill_color_node, record);
+ if (line_color_node->field_flag && screen_flag)
+ {
+ line_color = GL_COLOR_MERGE_DEFAULT;
+ }
+ if (fill_color_node->field_flag && screen_flag)
+ {
+ fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
+ }
+
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+ /* Paint fill color */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (fill_color),
+ GL_COLOR_F_GREEN (fill_color),
+ GL_COLOR_F_BLUE (fill_color),
+ GL_COLOR_F_ALPHA (fill_color));
+ cairo_fill_preserve (cr);
+
+ /* Draw outline */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (line_color),
+ GL_COLOR_F_GREEN (line_color),
+ GL_COLOR_F_BLUE (line_color),
+ GL_COLOR_F_ALPHA (line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+ gl_color_node_free (&line_color_node);
+ gl_color_node_free (&fill_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Draw shadow method. */
+/*****************************************************************************/
+static void
+draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ glColorNode *fill_color_node;
+ guint line_color;
+ guint fill_color;
+ glColorNode *shadow_color_node;
+ guint shadow_color;
+ gdouble shadow_opacity;
+ guint shadow_line_color;
+ guint shadow_fill_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (object, &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ fill_color_node = gl_label_object_get_fill_color (object);
+ line_color = gl_color_node_expand (line_color_node, record);
+ fill_color = gl_color_node_expand (fill_color_node, record);
+ if (line_color_node->field_flag && screen_flag)
+ {
+ line_color = GL_COLOR_MERGE_DEFAULT;
+ }
+ if (fill_color_node->field_flag && screen_flag)
+ {
+ fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
+ }
+
+ shadow_color_node = gl_label_object_get_shadow_color (object);
+ shadow_color = gl_color_node_expand (shadow_color_node, record);
+ if (shadow_color_node->field_flag && screen_flag)
+ {
+ shadow_color = GL_COLOR_SHADOW_MERGE_DEFAULT;
+ }
+ shadow_opacity = gl_label_object_get_shadow_opacity (object);
+ shadow_line_color = gl_color_shadow (shadow_color, shadow_opacity, line_color_node->color);
+ shadow_fill_color = gl_color_shadow (shadow_color, shadow_opacity, fill_color_node->color);
+
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+
+ /* Draw fill shadow */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_fill_color),
+ GL_COLOR_F_GREEN (shadow_fill_color),
+ GL_COLOR_F_BLUE (shadow_fill_color),
+ GL_COLOR_F_ALPHA (shadow_fill_color));
+
+ /* Draw outline shadow */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_line_color),
+ GL_COLOR_F_GREEN (shadow_line_color),
+ GL_COLOR_F_BLUE (shadow_line_color),
+ GL_COLOR_F_ALPHA (shadow_line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+
+ gl_color_node_free (&line_color_node);
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&shadow_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
*
* label_ellipse.c: GLabels label ellipse object
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
+#include <math.h>
+
+#include "cairo-ellipse-path.h"
#include "debug.h"
+/*========================================================*/
+/* Private macros and constants. */
+/*========================================================*/
+
/*========================================================*/
/* Private types. */
/*========================================================*/
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static gdouble get_line_width (glLabelObject *object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+static void draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+
\f
/*****************************************************************************/
label_object_class->get_fill_color = get_fill_color;
label_object_class->get_line_color = get_line_color;
label_object_class->get_line_width = get_line_width;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = draw_shadow;
object_class->finalize = gl_label_ellipse_finalize;
}
return gl_color_node_dup (lellipse->priv->fill_color_node);
}
+
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ glColorNode *fill_color_node;
+ guint line_color;
+ guint fill_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (object, &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ fill_color_node = gl_label_object_get_fill_color (object);
+ line_color = gl_color_node_expand (line_color_node, record);
+ fill_color = gl_color_node_expand (fill_color_node, record);
+ if (line_color_node->field_flag && screen_flag)
+ {
+ line_color = GL_COLOR_MERGE_DEFAULT;
+ }
+ if (fill_color_node->field_flag && screen_flag)
+ {
+ fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
+ }
+
+
+ gl_cairo_ellipse_path (cr, w/2, h/2);
+
+ /* Paint fill color */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (fill_color),
+ GL_COLOR_F_GREEN (fill_color),
+ GL_COLOR_F_BLUE (fill_color),
+ GL_COLOR_F_ALPHA (fill_color));
+ cairo_fill_preserve (cr);
+
+ /* Draw outline */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (line_color),
+ GL_COLOR_F_GREEN (line_color),
+ GL_COLOR_F_BLUE (line_color),
+ GL_COLOR_F_ALPHA (line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+ gl_color_node_free (&line_color_node);
+ gl_color_node_free (&fill_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Draw shadow method. */
+/*****************************************************************************/
+static void
+draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ glColorNode *fill_color_node;
+ guint line_color;
+ guint fill_color;
+ glColorNode *shadow_color_node;
+ guint shadow_color;
+ gdouble shadow_opacity;
+ guint shadow_line_color;
+ guint shadow_fill_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (object, &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ fill_color_node = gl_label_object_get_fill_color (object);
+ line_color = gl_color_node_expand (line_color_node, record);
+ fill_color = gl_color_node_expand (fill_color_node, record);
+ if (line_color_node->field_flag && screen_flag)
+ {
+ line_color = GL_COLOR_MERGE_DEFAULT;
+ }
+ if (fill_color_node->field_flag && screen_flag)
+ {
+ fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
+ }
+
+ shadow_color_node = gl_label_object_get_shadow_color (object);
+ shadow_color = gl_color_node_expand (shadow_color_node, record);
+ if (shadow_color_node->field_flag && screen_flag)
+ {
+ shadow_color = GL_COLOR_SHADOW_MERGE_DEFAULT;
+ }
+ shadow_opacity = gl_label_object_get_shadow_opacity (object);
+ shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color);
+ shadow_fill_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, fill_color_node->color);
+
+
+ gl_cairo_ellipse_path (cr, w/2, h/2);
+
+
+ /* Draw fill shadow */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_fill_color),
+ GL_COLOR_F_GREEN (shadow_fill_color),
+ GL_COLOR_F_BLUE (shadow_fill_color),
+ GL_COLOR_F_ALPHA (shadow_fill_color));
+
+ /* Draw outline shadow */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_line_color),
+ GL_COLOR_F_GREEN (shadow_line_color),
+ GL_COLOR_F_BLUE (shadow_line_color),
+ GL_COLOR_F_ALPHA (shadow_line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+
+ gl_color_node_free (&line_color_node);
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&shadow_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
*
* label_image.c: GLabels label image object
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
+#include <gdk/gdkcairo.h>
#include "pixmaps/checkerboard.xpm"
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
static GdkPixbuf *default_pixbuf = NULL;
/*========================================================*/
static void copy (glLabelObject *dst_object,
glLabelObject *src_object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+
\f
/*****************************************************************************/
/* Boilerplate object stuff. */
gl_label_image_parent_class = g_type_class_peek_parent (class);
- label_object_class->copy = copy;
+ label_object_class->copy = copy;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = NULL;
object_class->finalize = gl_label_image_finalize;
}
}
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble x0, y0;
+ gdouble w, h;
+ const GdkPixbuf *pixbuf;
+ gint image_w, image_h;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (object, &w, &h);
+ gl_label_object_get_position (object, &x0, &y0);
+
+ pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE (object), record);
+ image_w = gdk_pixbuf_get_width (pixbuf);
+ image_h = gdk_pixbuf_get_height (pixbuf);
+
+ cairo_save (cr);
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+ cairo_clip (cr);
+
+ cairo_scale (cr, w/image_w, h/image_h);
+ gdk_cairo_set_source_pixbuf (cr, (GdkPixbuf *)pixbuf, 0, 0);
+ cairo_paint (cr);
+
+ cairo_restore (cr);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
*
* label_line.c: GLabels label line object
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static gdouble get_line_width (glLabelObject *object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+static void draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
\f
/*****************************************************************************/
label_object_class->set_line_width = set_line_width;
label_object_class->get_line_color = get_line_color;
label_object_class->get_line_width = get_line_width;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = draw_shadow;
object_class->finalize = gl_label_line_finalize;
}
return gl_color_node_dup (lline->priv->line_color_node);
}
+
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ guint line_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ line_color = gl_color_node_expand (line_color_node, record);
+ if (line_color_node->field_flag && screen_flag)
+ {
+ line_color = GL_COLOR_MERGE_DEFAULT;
+ }
+
+
+ cairo_move_to (cr, 0.0, 0.0);
+ cairo_line_to (cr, w, h);
+
+
+ /* Draw line */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (line_color),
+ GL_COLOR_F_GREEN (line_color),
+ GL_COLOR_F_BLUE (line_color),
+ GL_COLOR_F_ALPHA (line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+ gl_color_node_free (&line_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Draw shadow method. */
+/*****************************************************************************/
+static void
+draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble w, h;
+ gdouble line_width;
+ glColorNode *line_color_node;
+ glColorNode *shadow_color_node;
+ gdouble shadow_opacity;
+ guint shadow_line_color;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
+
+ line_width = gl_label_object_get_line_width (object);
+
+ line_color_node = gl_label_object_get_line_color (object);
+ if (line_color_node->field_flag)
+ {
+ line_color_node->color = GL_COLOR_MERGE_DEFAULT;
+ }
+
+ shadow_color_node = gl_label_object_get_shadow_color (object);
+ if (shadow_color_node->field_flag)
+ {
+ shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
+ }
+ shadow_opacity = gl_label_object_get_shadow_opacity (object);
+ shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color);
+
+
+ cairo_move_to (cr, 0.0, 0.0);
+ cairo_line_to (cr, w, h);
+
+
+ /* Draw outline shadow */
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_line_color),
+ GL_COLOR_F_GREEN (shadow_line_color),
+ GL_COLOR_F_BLUE (shadow_line_color),
+ GL_COLOR_F_ALPHA (shadow_line_color));
+ cairo_set_line_width (cr, line_width);
+ cairo_stroke (cr);
+
+
+ gl_color_node_free (&line_color_node);
+ gl_color_node_free (&shadow_color_node);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
#include <glib/gmem.h>
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
-#include <libart_lgpl/libart.h>
+#include <math.h>
#include "marshal.h"
gchar *name;
gdouble x, y;
gdouble w, h;
- gdouble affine[6];
+ cairo_matrix_t matrix;
gdouble aspect_ratio;
gdouble w,
gdouble h);
-static void get_size (glLabelObject *object,
- gdouble *w,
- gdouble *h);
\f
/*****************************************************************************/
object_class->finalize = gl_label_object_finalize;
class->set_size = set_size;
- class->get_size = get_size;
signals[CHANGED] =
g_signal_new ("changed",
object->priv->name = g_strdup_printf ("object%d", instance++);
- art_affine_identity (object->priv->affine);
+ cairo_matrix_init_identity (&object->priv->matrix);
object->priv->shadow_state = FALSE;
object->priv->shadow_x = DEFAULT_SHADOW_X_OFFSET;
{
glLabelObject *dst_object;
gdouble x, y, w, h;
- gdouble affine[6];
+ cairo_matrix_t matrix;
gboolean shadow_state;
gdouble shadow_x, shadow_y;
glColorNode *shadow_color_node;
gl_debug (DEBUG_LABEL, "START");
- g_return_if_fail (src_object && GL_IS_LABEL_OBJECT (src_object));
+ g_return_val_if_fail (src_object && GL_IS_LABEL_OBJECT (src_object), NULL);
dst_object = g_object_new (G_OBJECT_TYPE(src_object), NULL);
gl_label_object_get_position (src_object, &x, &y);
gl_label_object_get_size (src_object, &w, &h);
- gl_label_object_get_affine (src_object, affine);
+ gl_label_object_get_matrix (src_object, &matrix);
gl_label_object_get_shadow_offset (src_object, &shadow_x, &shadow_y);
shadow_color_node = gl_label_object_get_shadow_color (src_object);
shadow_opacity = gl_label_object_get_shadow_opacity (src_object);
gl_label_object_set_position (dst_object, x, y);
gl_label_object_set_size (dst_object, w, h);
- gl_label_object_set_affine (dst_object, affine);
+ gl_label_object_set_matrix (dst_object, &matrix);
gl_label_object_set_shadow_offset (dst_object, shadow_x, shadow_y);
gl_label_object_set_shadow_color (dst_object, shadow_color_node);
gl_label_object_set_shadow_opacity (dst_object, shadow_opacity);
{
gl_debug (DEBUG_LABEL, "START");
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), NULL);
gl_debug (DEBUG_LABEL, "END");
{
gl_debug (DEBUG_LABEL, "START");
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), NULL);
gl_debug (DEBUG_LABEL, "END");
gl_debug (DEBUG_LABEL, "END");
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Default get size method. */
-/*---------------------------------------------------------------------------*/
-static void
-get_size (glLabelObject *object,
- gdouble *w,
- gdouble *h)
+/*****************************************************************************/
+/* Get raw size method (don't let object content adjust size). */
+/*****************************************************************************/
+void
+gl_label_object_get_raw_size (glLabelObject *object,
+ gdouble *w,
+ gdouble *h)
{
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
} else {
- get_size (object, w, h);
+ gl_label_object_get_raw_size (object, w, h);
}
gdouble *y2)
{
gdouble w, h;
- ArtPoint a1, a2, a3, a4, b1, b2, b3, b4;
- gdouble affine[6];
+ gdouble xa1, ya1, xa2, ya2, xa3, ya3, xa4, ya4;
+ cairo_matrix_t matrix;
gl_debug (DEBUG_LABEL, "START");
gl_label_object_get_size (object, &w, &h);
/* setup untransformed corners of bounding box */
- a1.x = 0.0;
- a1.y = 0.0;
- a2.x = w;
- a2.y = 0.0;
- a3.x = w;
- a3.y = h;
- a4.x = 0.0;
- a4.y = h;
+ xa1 = 0.0;
+ ya1 = 0.0;
+ xa2 = w;
+ ya2 = 0.0;
+ xa3 = w;
+ ya3 = h;
+ xa4 = 0.0;
+ ya4 = h;
/* transform these points */
- gl_label_object_get_affine (object, affine);
- art_affine_point (&b1, &a1, affine);
- art_affine_point (&b2, &a2, affine);
- art_affine_point (&b3, &a3, affine);
- art_affine_point (&b4, &a4, affine);
+ gl_label_object_get_matrix (object, &matrix);
+ cairo_matrix_transform_point (&matrix, &xa1, &ya1);
+ cairo_matrix_transform_point (&matrix, &xa2, &ya2);
+ cairo_matrix_transform_point (&matrix, &xa3, &ya3);
+ cairo_matrix_transform_point (&matrix, &xa4, &ya4);
/* now find the maximum extent of these points in x and y */
- *x1 = MIN (b1.x, MIN (b2.x, MIN (b3.x, b4.x))) + object->priv->x;
- *y1 = MIN (b1.y, MIN (b2.y, MIN (b3.y, b4.y))) + object->priv->y;
- *x2 = MAX (b1.x, MAX (b2.x, MAX (b3.x, b4.x))) + object->priv->x;
- *y2 = MAX (b1.y, MAX (b2.y, MAX (b3.y, b4.y))) + object->priv->y;
-
+ *x1 = MIN (xa1, MIN (xa2, MIN (xa3, xa4))) + object->priv->x;
+ *y1 = MIN (ya1, MIN (ya2, MIN (ya3, ya4))) + object->priv->y;
+ *x2 = MAX (xa1, MAX (xa2, MAX (xa3, xa4))) + object->priv->x;
+ *y2 = MAX (ya1, MAX (ya2, MAX (ya3, ya4))) + object->priv->y;
+
gl_debug (DEBUG_LABEL, "END");
}
void
gl_label_object_flip_horiz (glLabelObject *object)
{
- gdouble flip_affine[6];
+ cairo_matrix_t flip_matrix;
gl_debug (DEBUG_LABEL, "START");
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- art_affine_scale (flip_affine, -1.0, 1.0);
- art_affine_multiply (object->priv->affine, object->priv->affine, flip_affine);
+ cairo_matrix_init_scale (&flip_matrix, -1.0, 1.0);
+ cairo_matrix_multiply (&object->priv->matrix, &object->priv->matrix, &flip_matrix);
g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0);
void
gl_label_object_flip_vert (glLabelObject *object)
{
- gdouble flip_affine[6];
+ cairo_matrix_t flip_matrix;
gl_debug (DEBUG_LABEL, "START");
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- art_affine_scale (flip_affine, 1.0, -1.0);
- art_affine_multiply (object->priv->affine, object->priv->affine, flip_affine);
+ cairo_matrix_init_scale (&flip_matrix, 1.0, -1.0);
+ cairo_matrix_multiply (&object->priv->matrix, &object->priv->matrix, &flip_matrix);
g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0);
gl_label_object_rotate (glLabelObject *object,
gdouble theta_degs)
{
- gdouble rotate_affine[6];
+ cairo_matrix_t rotate_matrix;
gl_debug (DEBUG_LABEL, "START");
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- art_affine_rotate (rotate_affine, theta_degs);
- art_affine_multiply (object->priv->affine, object->priv->affine, rotate_affine);
+ cairo_matrix_init_rotate (&rotate_matrix, theta_degs*(G_PI/180.));
+ cairo_matrix_multiply (&object->priv->matrix, &object->priv->matrix, &rotate_matrix);
g_signal_emit (G_OBJECT(object), signals[FLIP_ROTATE], 0);
/* Set raw affine */
/****************************************************************************/
void
-gl_label_object_set_affine (glLabelObject *object,
- gdouble affine[6])
+gl_label_object_set_matrix (glLabelObject *object,
+ cairo_matrix_t *matrix)
{
gl_debug (DEBUG_LABEL, "");
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- object->priv->affine[0] = affine[0];
- object->priv->affine[1] = affine[1];
- object->priv->affine[2] = affine[2];
- object->priv->affine[3] = affine[3];
- object->priv->affine[4] = affine[4];
- object->priv->affine[5] = affine[5];
+ object->priv->matrix = *matrix;
}
/****************************************************************************/
/* Get raw affine */
/****************************************************************************/
void
-gl_label_object_get_affine (glLabelObject *object,
- gdouble affine[6])
-{
- gl_debug (DEBUG_LABEL, "");
-
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- affine[0] = object->priv->affine[0];
- affine[1] = object->priv->affine[1];
- affine[2] = object->priv->affine[2];
- affine[3] = object->priv->affine[3];
- affine[4] = object->priv->affine[4];
- affine[5] = object->priv->affine[5];
-}
-
-/****************************************************************************/
-/* Get i2w affine, i.e. applied affine + translation. */
-/****************************************************************************/
-void
-gl_label_object_get_i2w_affine (glLabelObject *object,
- gdouble affine[6])
-{
- gdouble x, y;
- gdouble translation[6];
-
- gl_debug (DEBUG_LABEL, "");
-
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- gl_label_object_get_affine (object, affine);
- gl_label_object_get_position (object, &x, &y);
-
- art_affine_translate (translation, x, y);
- art_affine_multiply (affine, affine, translation);
-}
-
-/****************************************************************************/
-/* Get w2i affine, i.e. inverse of applied affine + translation. */
-/****************************************************************************/
-void
-gl_label_object_get_w2i_affine (glLabelObject *object,
- gdouble affine[6])
+gl_label_object_get_matrix (glLabelObject *object,
+ cairo_matrix_t *matrix)
{
- gdouble i2w[6];
gl_debug (DEBUG_LABEL, "");
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- gl_label_object_get_i2w_affine (object, i2w);
- art_affine_invert (affine, i2w);
+ *matrix = object->priv->matrix;
}
/****************************************************************************/
{
gl_label_object_emit_changed (object);
}
+
+/*****************************************************************************/
+/* Draw object */
+/*****************************************************************************/
+void
+gl_label_object_draw (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+
+{
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gboolean shadow_state;
+ gdouble shadow_x, shadow_y;
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ cairo_save (cr);
+ cairo_translate (cr, x0, y0);
+
+ if ( GL_LABEL_OBJECT_GET_CLASS(object)->draw_shadow != NULL ) {
+
+ shadow_state = gl_label_object_get_shadow_state (object);
+
+ if ( shadow_state )
+ {
+ gl_label_object_get_shadow_offset (object, &shadow_x, &shadow_y);
+
+ cairo_save (cr);
+ cairo_translate (cr, shadow_x, shadow_y);
+ cairo_transform (cr, &matrix);
+
+ GL_LABEL_OBJECT_GET_CLASS(object)->draw_shadow (object,
+ cr,
+ screen_flag,
+ record);
+
+ cairo_restore (cr);
+ }
+ }
+
+ if ( GL_LABEL_OBJECT_GET_CLASS(object)->draw_object != NULL ) {
+
+ cairo_save (cr);
+ cairo_transform (cr, &matrix);
+
+ GL_LABEL_OBJECT_GET_CLASS(object)->draw_object (object,
+ cr,
+ screen_flag,
+ record);
+
+ cairo_restore (cr);
+ }
+
+ cairo_restore (cr);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
#include <glib-object.h>
#include <pango/pango.h>
+#include <cairo.h>
G_BEGIN_DECLS
void (*copy) (glLabelObject *dst_object,
glLabelObject *src_object);
+ /*
+ * Draw methods
+ */
+ void (*draw_shadow) (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+ void (*draw_object) (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+
/*
* Signals
*/
gdouble *w,
gdouble *h);
+void gl_label_object_get_raw_size (glLabelObject *object,
+ gdouble *w,
+ gdouble *h);
+
void gl_label_object_get_extent (glLabelObject *object,
gdouble *x1,
gdouble *y1,
void gl_label_object_rotate (glLabelObject *object,
gdouble theta_degs);
-void gl_label_object_set_affine (glLabelObject *object,
- gdouble affine[6]);
-
-void gl_label_object_get_affine (glLabelObject *object,
- gdouble affine[6]);
-
-void gl_label_object_get_i2w_affine (glLabelObject *object,
- gdouble affine[6]);
+void gl_label_object_set_matrix (glLabelObject *object,
+ cairo_matrix_t *matrix);
-void gl_label_object_get_w2i_affine (glLabelObject *object,
- gdouble affine[6]);
+void gl_label_object_get_matrix (glLabelObject *object,
+ cairo_matrix_t *matrix);
void gl_label_object_set_shadow_state (glLabelObject *object,
gboolean state);
gdouble gl_label_object_get_shadow_opacity (glLabelObject *object);
+void gl_label_object_draw (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+
+
G_END_DECLS
#include <glib/gstrfuncs.h>
#include <glib/gmessages.h>
#include <pango/pango.h>
+#include <math.h>
#include "util.h"
#define DEFAULT_TEXT_LINE_SPACING 1.0
#define DEFAULT_AUTO_SHRINK FALSE
-#define FONT_SCALE (72.0/96.0)
-
/*========================================================*/
/* Private types. */
/*========================================================*/
/* Private globals. */
/*========================================================*/
-static guint instance = 0;
-
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static gboolean get_font_italic_flag (glLabelObject *object);
-static PangoAlignment get_text_alignment (glLabelObject *object);
+static PangoAlignment get_text_alignment (glLabelObject *object);
static gdouble get_text_line_spacing (glLabelObject *object);
static glColorNode* get_text_color (glLabelObject *object);
+static void draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+static void draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
+static gdouble auto_shrink_font_size (cairo_t *cr,
+ gchar *family,
+ gdouble size,
+ PangoWeight weight,
+ PangoStyle style,
+ gchar *text,
+ gdouble width);
+
+
\f
/*****************************************************************************/
/* Boilerplate object stuff. */
gl_label_text_parent_class = g_type_class_peek_parent (class);
- label_object_class->copy = copy;
+ label_object_class->copy = copy;
- label_object_class->get_size = get_size;
+ label_object_class->get_size = get_size;
- label_object_class->set_font_family = set_font_family;
- label_object_class->set_font_size = set_font_size;
- label_object_class->set_font_weight = set_font_weight;
- label_object_class->set_font_italic_flag = set_font_italic_flag;
- label_object_class->set_text_alignment = set_text_alignment;
+ label_object_class->set_font_family = set_font_family;
+ label_object_class->set_font_size = set_font_size;
+ label_object_class->set_font_weight = set_font_weight;
+ label_object_class->set_font_italic_flag = set_font_italic_flag;
+ label_object_class->set_text_alignment = set_text_alignment;
label_object_class->set_text_line_spacing = set_text_line_spacing;
- label_object_class->set_text_color = set_text_color;
- label_object_class->get_font_family = get_font_family;
- label_object_class->get_font_size = get_font_size;
- label_object_class->get_font_weight = get_font_weight;
- label_object_class->get_font_italic_flag = get_font_italic_flag;
- label_object_class->get_text_alignment = get_text_alignment;
+ label_object_class->set_text_color = set_text_color;
+ label_object_class->get_font_family = get_font_family;
+ label_object_class->get_font_size = get_font_size;
+ label_object_class->get_font_weight = get_font_weight;
+ label_object_class->get_font_italic_flag = get_font_italic_flag;
+ label_object_class->get_text_alignment = get_text_alignment;
label_object_class->get_text_line_spacing = get_text_line_spacing;
- label_object_class->get_text_color = get_text_color;
+ label_object_class->get_text_color = get_text_color;
+ label_object_class->draw_object = draw_object;
+ label_object_class->draw_shadow = draw_shadow;
object_class->finalize = gl_label_text_finalize;
}
return lines;
}
-void
-gl_label_text_get_box (glLabelText *ltext,
- gdouble *w,
- gdouble *h)
-{
- g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
-
- /* peek at the parent size. */
- (* GL_LABEL_OBJECT_CLASS (gl_label_text_parent_class)->get_size) (GL_LABEL_OBJECT(ltext), w, h);
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. text buffer "changed" callback. */
/*---------------------------------------------------------------------------*/
g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
- (* GL_LABEL_OBJECT_CLASS (gl_label_text_parent_class)->get_size) (object, &w_parent, &h_parent);
+ gl_label_object_get_raw_size (object, &w_parent, &h_parent);
if ( (w_parent != 0.0) || (h_parent != 0.0) ) {
*w = w_parent;
context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
options = cairo_font_options_create ();
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
pango_cairo_context_set_font_options (context, options);
cairo_font_options_destroy (options);
pango_font_description_set_family (desc, GL_LABEL_TEXT (object)->priv->font_family);
pango_font_description_set_weight (desc, GL_LABEL_TEXT (object)->priv->font_weight);
pango_font_description_set_style (desc, style);
- pango_font_description_set_size (desc, GL_LABEL_TEXT (object)->priv->font_size * PANGO_SCALE * FONT_SCALE);
+ pango_font_description_set_size (desc, GL_LABEL_TEXT (object)->priv->font_size * PANGO_SCALE);
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
}
/*****************************************************************************/
-/* Query auto shrink flag.
+/* Query auto shrink flag. */
/*****************************************************************************/
gboolean
gl_label_text_get_auto_shrink (glLabelText *ltext)
return ltext->priv->auto_shrink;
}
+
+/*****************************************************************************/
+/* Draw object method. */
+/*****************************************************************************/
+static void
+draw_object (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble object_w, object_h;
+ gdouble raw_w, raw_h;
+ gchar *text;
+ GList *lines;
+ gchar *font_family;
+ gdouble font_size;
+ PangoWeight font_weight;
+ gboolean font_italic_flag;
+ glColorNode *color_node;
+ gboolean auto_shrink;
+ guint color;
+ gdouble text_line_spacing;
+ PangoAlignment alignment;
+ PangoStyle style;
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ gdouble scale_x, scale_y;
+ cairo_font_options_t *font_options;
+ PangoContext *context;
+
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ gl_label_object_get_size (object, &object_w, &object_h);
+ gl_label_object_get_raw_size (object, &raw_w, &raw_h);
+ lines = gl_label_text_get_lines (GL_LABEL_TEXT (object));
+ font_family = gl_label_object_get_font_family (object);
+ font_size = gl_label_object_get_font_size (object);
+ font_weight = gl_label_object_get_font_weight (object);
+ font_italic_flag = gl_label_object_get_font_italic_flag (object);
+
+ color_node = gl_label_object_get_text_color (object);
+ color = gl_color_node_expand (color_node, record);
+ if (color_node->field_flag && screen_flag)
+ {
+ color = GL_COLOR_MERGE_DEFAULT;
+ }
+ gl_color_node_free (&color_node);
+
+ alignment = gl_label_object_get_text_alignment (object);
+ text_line_spacing =
+ gl_label_object_get_text_line_spacing (object);
+ auto_shrink = gl_label_text_get_auto_shrink (GL_LABEL_TEXT (object));
+
+ text = gl_text_node_lines_expand (lines, record);
+
+ style = font_italic_flag ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
+
+
+ if (!screen_flag && record && auto_shrink && (raw_w != 0.0))
+ {
+ font_size = auto_shrink_font_size (cr,
+ font_family,
+ font_size,
+ font_weight,
+ style,
+ text,
+ object_w);
+ g_print ("Autosize new size = %g\n", font_size);
+ }
+
+
+ /*
+ * Workaround for pango Bug#341481.
+ * Render font at device scale and scale font size accordingly.
+ */
+ scale_x = 1.0;
+ scale_y = 1.0;
+ cairo_device_to_user_distance (cr, &scale_x, &scale_y);
+ scale_x = fabs (scale_x);
+ scale_y = fabs (scale_y);
+ cairo_save (cr);
+ cairo_scale (cr, scale_x, scale_y);
+
+ layout = pango_cairo_create_layout (cr);
+
+ font_options = cairo_font_options_create ();
+ cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
+ cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
+ context = pango_layout_get_context (layout);
+ pango_cairo_context_set_font_options (context, font_options);
+ cairo_font_options_destroy (font_options);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, font_family);
+ pango_font_description_set_weight (desc, font_weight);
+ pango_font_description_set_style (desc, style);
+ pango_font_description_set_size (desc, font_size * PANGO_SCALE / scale_x);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_spacing (layout, font_size * (text_line_spacing-1) * PANGO_SCALE / scale_x);
+ if (raw_w == 0.0)
+ {
+ pango_layout_set_width (layout, -1);
+ }
+ else
+ {
+ pango_layout_set_width (layout, object_w * PANGO_SCALE / scale_x);
+ }
+ pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
+ pango_layout_set_alignment (layout, alignment);
+
+
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (color),
+ GL_COLOR_F_GREEN (color),
+ GL_COLOR_F_BLUE (color),
+ GL_COLOR_F_ALPHA (color));
+
+ cairo_move_to (cr, GL_LABEL_TEXT_MARGIN, 0);
+ pango_cairo_show_layout (cr, layout);
+
+ cairo_restore (cr);
+
+ g_object_unref (layout);
+
+
+ gl_text_node_lines_free (&lines);
+ g_free (font_family);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Draw shadow method. */
+/*****************************************************************************/
+static void
+draw_shadow (glLabelObject *object,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble object_w, object_h;
+ gdouble raw_w, raw_h;
+ gchar *text;
+ GList *lines;
+ gchar *font_family;
+ gdouble font_size;
+ PangoWeight font_weight;
+ gboolean font_italic_flag;
+ gboolean auto_shrink;
+ guint color;
+ glColorNode *color_node;
+ gdouble text_line_spacing;
+ glColorNode *shadow_color_node;
+ gdouble shadow_opacity;
+ guint shadow_color;
+ PangoAlignment alignment;
+ PangoStyle style;
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ gdouble scale_x, scale_y;
+ cairo_font_options_t *font_options;
+ PangoContext *context;
+
+
+ gl_debug (DEBUG_LABEL, "START");
+
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+
+ gl_label_object_get_size (object, &object_w, &object_h);
+ gl_label_object_get_raw_size (object, &raw_w, &raw_h);
+ lines = gl_label_text_get_lines (GL_LABEL_TEXT (object));
+ font_family = gl_label_object_get_font_family (object);
+ font_size = gl_label_object_get_font_size (object);
+ font_weight = gl_label_object_get_font_weight (object);
+ font_italic_flag = gl_label_object_get_font_italic_flag (object);
+
+ color_node = gl_label_object_get_text_color (object);
+ color = gl_color_node_expand (color_node, record);
+ gl_color_node_free (&color_node);
+
+ alignment = gl_label_object_get_text_alignment (object);
+ text_line_spacing =
+ gl_label_object_get_text_line_spacing (object);
+ auto_shrink = gl_label_text_get_auto_shrink (GL_LABEL_TEXT (object));
+
+ shadow_color_node = gl_label_object_get_shadow_color (object);
+ if (shadow_color_node->field_flag)
+ {
+ shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
+ }
+ shadow_opacity = gl_label_object_get_shadow_opacity (object);
+ shadow_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, color);
+ gl_color_node_free (&shadow_color_node);
+
+ text = gl_text_node_lines_expand (lines, record);
+
+ style = font_italic_flag ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
+
+
+ if (!screen_flag && record && auto_shrink && (raw_w != 0.0))
+ {
+ font_size = auto_shrink_font_size (cr,
+ font_family,
+ font_size,
+ font_weight,
+ style,
+ text,
+ object_w);
+ }
+
+
+ /*
+ * Workaround for pango Bug#341481.
+ * Render font at device scale and scale font size accordingly.
+ */
+ scale_x = 1.0;
+ scale_y = 1.0;
+ cairo_device_to_user_distance (cr, &scale_x, &scale_y);
+ scale_x = fabs (scale_x);
+ scale_y = fabs (scale_y);
+ cairo_save (cr);
+ cairo_scale (cr, scale_x, scale_y);
+
+ layout = pango_cairo_create_layout (cr);
+
+ font_options = cairo_font_options_create ();
+ cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
+ cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
+ context = pango_layout_get_context (layout);
+ pango_cairo_context_set_font_options (context, font_options);
+ cairo_font_options_destroy (font_options);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, font_family);
+ pango_font_description_set_weight (desc, font_weight);
+ pango_font_description_set_style (desc, style);
+ pango_font_description_set_size (desc, font_size * PANGO_SCALE / scale_x);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_spacing (layout, font_size * (text_line_spacing-1) * PANGO_SCALE / scale_x);
+ if (raw_w == 0.0)
+ {
+ pango_layout_set_width (layout, -1);
+ }
+ else
+ {
+ pango_layout_set_width (layout, object_w * PANGO_SCALE / scale_x);
+ }
+ pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
+ pango_layout_set_alignment (layout, alignment);
+
+ cairo_set_source_rgba (cr,
+ GL_COLOR_F_RED (shadow_color),
+ GL_COLOR_F_GREEN (shadow_color),
+ GL_COLOR_F_BLUE (shadow_color),
+ GL_COLOR_F_ALPHA (shadow_color));
+
+ cairo_move_to (cr, GL_LABEL_TEXT_MARGIN, 0);
+ pango_cairo_show_layout (cr, layout);
+
+
+ cairo_restore (cr);
+
+ g_object_unref (layout);
+
+ gl_text_node_lines_free (&lines);
+ g_free (font_family);
+
+ gl_debug (DEBUG_LABEL, "END");
+}
+
+/*****************************************************************************/
+/* Automatically shrink text size to fit within horizontal width. */
+/*****************************************************************************/
+static gdouble
+auto_shrink_font_size (cairo_t *cr,
+ gchar *family,
+ gdouble size,
+ PangoWeight weight,
+ PangoStyle style,
+ gchar *text,
+ gdouble width)
+{
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ gint iw, ih;
+ gdouble layout_width;
+ gdouble new_size;
+
+ layout = pango_cairo_create_layout (cr);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, family);
+ pango_font_description_set_weight (desc, weight);
+ pango_font_description_set_style (desc, style);
+ pango_font_description_set_size (desc, size * PANGO_SCALE);
+
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_set_text (layout, text, -1);
+ pango_layout_set_width (layout, -1);
+ pango_layout_get_size (layout, &iw, &ih);
+ layout_width = (gdouble)iw / (gdouble)PANGO_SCALE;
+
+ g_object_unref (layout);
+
+ g_print ("Object w = %g, layout w = %g\n", width, layout_width);
+
+ if ( layout_width > width )
+ {
+ /* Scale down. */
+ new_size = size * (width-2*GL_LABEL_TEXT_MARGIN)/layout_width;
+
+ /* Round down to nearest 1/2 point */
+ new_size = (int)(new_size*2.0) / 2.0;
+
+ /* don't get ridiculously small. */
+ if (new_size < 1.0)
+ {
+ new_size = 1.0;
+ }
+ }
+ else
+ {
+ new_size = size;
+ }
+
+ return new_size;
+}
+
GList *lines);
GtkTextBuffer *gl_label_text_get_buffer (glLabelText *ltext);
GList *gl_label_text_get_lines (glLabelText *ltext);
-void gl_label_text_get_box (glLabelText *ltext,
- gdouble *w,
- gdouble *h);
void gl_label_text_set_auto_shrink (glLabelText *ltext,
gboolean auto_shrink);
*
* label.c: GLabels label module
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
struct _glLabelPrivate {
- glTemplate *template;
- gboolean rotate_flag;
-
gchar *filename;
gint compression;
gboolean modified_flag;
{
gl_debug (DEBUG_LABEL, "START");
+ label->template = NULL;
+ label->rotate_flag = FALSE;
+ label->objects = NULL;
+
label->priv = g_new0 (glLabelPrivate, 1);
- label->priv->template = NULL;
label->priv->filename = NULL;
label->priv->merge = NULL;
label->priv->pixbuf_cache = gl_pixbuf_cache_new ();
g_object_unref (G_OBJECT(p->data));
}
- gl_template_free (label->priv->template);
+ gl_template_free (label->template);
g_free (label->priv->filename);
if (label->priv->merge != NULL) {
g_object_unref (G_OBJECT(label->priv->merge));
g_return_if_fail (label && GL_IS_LABEL (label));
- if ((label->priv->template == NULL) ||
- (g_strcasecmp (template->name, label->priv->template->name) != 0)) {
+ if ((label->template == NULL) ||
+ (g_strcasecmp (template->name, label->template->name) != 0)) {
- gl_template_free (label->priv->template);
- label->priv->template = gl_template_dup (template);
+ gl_template_free (label->template);
+ label->template = gl_template_dup (template);
label->priv->modified_flag = TRUE;
g_return_if_fail (label && GL_IS_LABEL (label));
- if (rotate_flag != label->priv->rotate_flag) {
+ if (rotate_flag != label->rotate_flag) {
- label->priv->rotate_flag = rotate_flag;
+ label->rotate_flag = rotate_flag;
label->priv->modified_flag = TRUE;
gl_debug (DEBUG_LABEL, "END");
}
-/****************************************************************************/
-/* Get template. */
-/****************************************************************************/
-glTemplate *
-gl_label_get_template (glLabel *label)
-{
- gl_debug (DEBUG_LABEL, "START");
-
- g_return_if_fail (label && GL_IS_LABEL (label));
-
- gl_debug (DEBUG_LABEL, "END");
-
- return gl_template_dup (label->priv->template);
-}
-
-/****************************************************************************/
-/* Get rotate flag. */
-/****************************************************************************/
-gboolean
-gl_label_get_rotate_flag (glLabel *label)
-{
- gl_debug (DEBUG_LABEL, "START");
-
- g_return_if_fail (label && GL_IS_LABEL (label));
-
- gl_debug (DEBUG_LABEL, "END");
-
- return label->priv->rotate_flag;
-}
-
/****************************************************************************/
/* Get label size. */
/****************************************************************************/
g_return_if_fail (label && GL_IS_LABEL (label));
- template = label->priv->template;
+ template = label->template;
if ( !template ) {
gl_debug (DEBUG_LABEL, "END -- template NULL");
*w = *h = 0;
}
label_type = gl_template_get_first_label_type (template);
- if (!label->priv->rotate_flag) {
+ if (!label->rotate_flag) {
gl_template_get_label_size (label_type, w, h);
} else {
gl_template_get_label_size (label_type, h, w);
{
gl_debug (DEBUG_LABEL, "START");
- g_return_if_fail (label && GL_IS_LABEL (label));
+ g_return_val_if_fail (label && GL_IS_LABEL (label), NULL);
gl_debug (DEBUG_LABEL, "END");
return label->priv->compression;
}
+
+/****************************************************************************/
+/* Draw label. */
+/****************************************************************************/
+void
+gl_label_draw (glLabel *label,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record)
+{
+ GList *p_obj;
+ glLabelObject *object;
+
+ g_return_if_fail (label && GL_IS_LABEL (label));
+
+ for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next)
+ {
+ object = GL_LABEL_OBJECT (p_obj->data);
+
+ gl_label_object_draw (object, cr, screen_flag, record);
+ }
+}
*
* label.h: GLabels label module header file
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <libglabels/template.h>
#include "merge.h"
#include "pixbuf-cache.h"
+#include <cairo.h>
G_BEGIN_DECLS
struct _glLabel {
GObject object;
+ glTemplate *template;
+ gboolean rotate_flag;
+
GList *objects;
glLabelPrivate *priv;
void gl_label_set_rotate_flag (glLabel *label,
gboolean rotate_flag);
-
-glTemplate *gl_label_get_template (glLabel *label);
-
-gboolean gl_label_get_rotate_flag (glLabel *label);
-
void gl_label_get_size (glLabel *label,
gdouble *w,
gdouble *h);
gint gl_label_get_compression (glLabel *label);
+void gl_label_draw (glLabel *label,
+ cairo_t *cr,
+ gboolean screen_flag,
+ glMergeRecord *record);
+
G_END_DECLS
#include <gtk/gtkcombobox.h>
#include <gtk/gtkstock.h>
#include <gtk/gtktreestore.h>
+#include <gtk/gtktreeselection.h>
#include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtklabel.h>
+#include <string.h>
#include "label.h"
#include "merge.h"
gchar *name;
gchar *src;
glMergeSrcType src_type;
- GtkWidget *wentry;
gl_debug (DEBUG_MERGE, "START");
glMergePropertiesDialog *dialog)
{
gchar *src, *orig_src;
- GtkWidget *wentry;
gl_debug (DEBUG_MERGE, "START");
class = g_type_class_ref (type);
if (class == NULL) {
g_message ("%s: unknown object type %d",
- G_STRLOC, type);
+ G_STRLOC, (int)type);
break;
}
pspec = g_object_class_find_property (class, pname);
static void
gl_new_label_dialog_init (glNewLabelDialog *dialog)
{
- GtkWidget *pp_button;
-
gl_debug (DEBUG_FILE, "START");
g_return_if_fail (GL_IS_NEW_LABEL_DIALOG (dialog));
#include "prefs.h"
#include "mygal/widget-color-combo.h"
#include "color.h"
+#include "util.h"
#include "object-editor-private.h"
#include <math.h>
#include "prefs.h"
+#include "util.h"
#include "object-editor-private.h"
void
gl_object_editor_prepare_data_page (glObjectEditor *editor)
{
- GdkColor *gdk_color;
-
gl_debug (DEBUG_EDITOR, "START");
/* Extract widgets from XML tree. */
#include "prefs.h"
#include "mygal/widget-color-combo.h"
#include "color.h"
+#include "util.h"
#include "object-editor-private.h"
void
gl_object_editor_prepare_edit_page (glObjectEditor *editor)
{
- GList *family_names = NULL;
- GtkWidget *label;
-
gl_debug (DEBUG_EDITOR, "START");
/* Extract widgets from XML tree. */
#include "prefs.h"
#include "mygal/widget-color-combo.h"
#include "color.h"
+#include "util.h"
#include "object-editor-private.h"
#include <math.h>
#include "prefs.h"
+#include "util.h"
#include "object-editor-private.h"
void
gl_object_editor_prepare_image_page (glObjectEditor *editor)
{
- GdkColor *gdk_color;
- GtkFileFilter *filter;
GtkWidget *preview;
#include "prefs.h"
#include "mygal/widget-color-combo.h"
#include "color.h"
+#include "util.h"
#include "object-editor-private.h"
void gl_object_editor_prepare_data_page (glObjectEditor *editor);
+void gl_object_editor_prepare_shadow_page (glObjectEditor *editor);
+
void gl_object_editor_changed_cb (glObjectEditor *editor);
void gl_object_editor_size_changed_cb (glObjectEditor *editor);
void lsize_prefs_changed_cb (glObjectEditor *editor);
void size_prefs_changed_cb (glObjectEditor *editor);
void position_prefs_changed_cb (glObjectEditor *editor);
+void shadow_prefs_changed_cb (glObjectEditor *editor);
G_END_DECLS
#include "prefs.h"
#include "mygal/widget-color-combo.h"
#include "color.h"
+#include "util.h"
#include "object-editor-private.h"
glColorNode *text_color_node)
{
GdkColor *gdk_color;
- gint pos;
gl_debug (DEBUG_EDITOR, "START");
#include "color.h"
#include "wdgt-chain-button.h"
#include "marshal.h"
+#include "util.h"
#include "object-editor-private.h"
GdkPixbuf *pixbuf)
{
CacheRecord *test_record, *record;
- gchar *key;
gl_debug (DEBUG_PIXBUF_CACHE, "START");
gl_print_op_class_init (glPrintOpClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
- GtkPrintOperationClass *print_class = GTK_PRINT_OPERATION_CLASS (class);
gl_debug (DEBUG_PRINT, "");
static void
gl_print_op_init (glPrintOp *op)
{
- GtkWidget *pp_button;
-
gl_debug (DEBUG_PRINT, "");
gtk_print_operation_set_use_full_page (GTK_PRINT_OPERATION (op), TRUE);
{
glMerge *merge = NULL;
- glTemplate *template = NULL;
const glTemplateLabelType *label_type = NULL;
op->priv->label = label;
merge = gl_label_get_merge (label);
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
+ label_type = gl_template_get_first_label_type (label->template);
if (merge == NULL)
{
op->priv->merge_flag = FALSE;
g_object_unref (G_OBJECT(merge));
}
- gl_template_free (template);
gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION (op),
filename);
if (!op->priv->gui) {
g_warning ("Could not open print-op.glade, reinstall glabels!");
- return;
+ return NULL;
}
vbox = glade_xml_get_widget (op->priv->gui, "print_custom_widget_vbox");
#include <ctype.h>
#include "label.h"
-#include "label-text.h"
-#include "label-box.h"
-#include "label-line.h"
-#include "label-ellipse.h"
-#include "label-image.h"
-#include "label-barcode.h"
-#include "bc.h"
#include <libglabels/template.h>
-#include "color.h"
+#include "cairo-label-path.h"
#include "debug.h"
-#define ARC_FINE 2 /* Resolution in degrees of large arcs */
+/*===========================================*/
+/* Private macros and constants. */
+/*===========================================*/
-#define FONT_SCALE (72.0/96.0)
#define TICK_OFFSET 2.25
#define TICK_LENGTH 18.0
gboolean reverse_flag);
-static void draw_label (PrintInfo *pi,
- glLabel *label,
- glMergeRecord *record);
-
-
-static void draw_object (PrintInfo *pi,
- glLabelObject *object,
- glMergeRecord *record);
-
-static void draw_text_object (PrintInfo *pi,
- glLabelText *object,
- glMergeRecord *record);
-
-static void draw_box_object (PrintInfo *pi,
- glLabelBox *object,
- glMergeRecord *record);
-
-static void draw_line_object (PrintInfo *pi,
- glLabelLine *object,
- glMergeRecord *record);
-
-static void draw_ellipse_object (PrintInfo *pi,
- glLabelEllipse *object,
- glMergeRecord *record);
-
-static void draw_image_object (PrintInfo *pi,
- glLabelImage *object,
- glMergeRecord *record);
-
-static void draw_barcode_object (PrintInfo *pi,
- glLabelBarcode *object,
- glMergeRecord *record);
-
-
static void draw_outline (PrintInfo *pi,
glLabel *label);
static void clip_to_outline (PrintInfo *pi,
glLabel *label);
-static void clip_punchouts (PrintInfo *pi,
- glLabel *label);
-
-
-static void create_rounded_rectangle_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble w,
- gdouble h,
- gdouble r);
-
-static void create_ellipse_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble rx,
- gdouble ry);
-
-static void create_cd_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble w,
- gdouble h,
- gdouble r1,
- gdouble r2);
\f
/*****************************************************************************/
glLabel *label)
{
PrintInfo *pi = g_new0 (PrintInfo, 1);
- glTemplate *template;
gl_debug (DEBUG_PRINT, "START");
g_return_val_if_fail (label && GL_IS_LABEL (label), NULL);
- template = gl_label_get_template (label);
-
- g_return_val_if_fail (template, NULL);
- g_return_val_if_fail (template->page_size, NULL);
- g_return_val_if_fail (template->page_width > 0, NULL);
- g_return_val_if_fail (template->page_height > 0, NULL);
+ g_return_val_if_fail (label->template, NULL);
+ g_return_val_if_fail (label->template->page_size, NULL);
+ g_return_val_if_fail (label->template->page_width > 0, NULL);
+ g_return_val_if_fail (label->template->page_height > 0, NULL);
pi->cr = cr;
gl_debug (DEBUG_PRINT,
- "setting page size = \"%s\"", template->page_size);
+ "setting page size = \"%s\"", label->template->page_size);
- pi->page_width = template->page_width;
- pi->page_height = template->page_height;
+ pi->page_width = label->template->page_width;
+ pi->page_height = label->template->page_height;
- pi->template = template;
- pi->label_rotate_flag = gl_label_get_rotate_flag (label);
+ pi->template = label->template;
+ pi->label_rotate_flag = label->rotate_flag;
gl_debug (DEBUG_PRINT, "END");
{
gl_debug (DEBUG_PRINT, "START");
- gl_template_free ((*pi)->template);
- (*pi)->template = NULL;
g_free (*pi);
*pi = NULL;
/* Transform coordinate system to be relative to upper corner */
/* of the current label */
cairo_translate (pi->cr, x, y);
- if (gl_label_get_rotate_flag (label)) {
+ if (label->rotate_flag) {
gl_debug (DEBUG_PRINT, "Rotate flag set");
cairo_rotate (pi->cr, -M_PI/2.0);
cairo_translate (pi->cr, -width, 0.0);
}
clip_to_outline (pi, label);
- draw_label (pi, label, record);
+ gl_label_draw (label, pi->cr, FALSE, record);
if (outline_flag) {
draw_outline (pi, label);
}
gl_debug (DEBUG_PRINT, "END");
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw label. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_label (PrintInfo *pi,
- glLabel *label,
- glMergeRecord *record)
-{
- GList *p_obj;
- glLabelObject *object;
-
- gl_debug (DEBUG_PRINT, "START");
-
- for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
- object = (glLabelObject *) p_obj->data;
-
- draw_object (pi, object, record);
- }
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_object (PrintInfo *pi,
- glLabelObject *object,
- glMergeRecord *record)
-{
- gdouble x0, y0;
- gdouble a[6];
- cairo_matrix_t matrix;
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_position (object, &x0, &y0);
- gl_label_object_get_affine (object, a);
- cairo_matrix_init (&matrix, a[0], a[1], a[2], a[3], a[4], a[5]);
-
- cairo_save (pi->cr);
-
- cairo_translate (pi->cr, x0, y0);
- cairo_transform (pi->cr, &matrix);
-
-
- if (GL_IS_LABEL_TEXT(object)) {
- draw_text_object (pi, GL_LABEL_TEXT(object), record);
- } else if (GL_IS_LABEL_BOX(object)) {
- draw_box_object (pi, GL_LABEL_BOX(object), record);
- } else if (GL_IS_LABEL_LINE(object)) {
- draw_line_object (pi, GL_LABEL_LINE(object), record);
- } else if (GL_IS_LABEL_ELLIPSE(object)) {
- draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object), record);
- } else if (GL_IS_LABEL_IMAGE(object)) {
- draw_image_object (pi, GL_LABEL_IMAGE(object), record);
- } else if (GL_IS_LABEL_BARCODE(object)) {
- draw_barcode_object (pi, GL_LABEL_BARCODE(object), record);
- }
-
- cairo_restore (pi->cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw text object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_text_object (PrintInfo *pi,
- glLabelText *object,
- glMergeRecord *record)
-{
- gint i;
- gdouble x_offset, y_offset, w, object_w, object_h;
- gchar *text;
- GList *lines;
- gchar *font_family;
- gdouble font_size;
- PangoWeight font_weight;
- gboolean font_italic_flag;
- guint color;
- glColorNode *color_node;
- gboolean auto_shrink;
- gdouble text_line_spacing;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_color;
- PangoAlignment alignment;
- PangoStyle style;
- PangoLayout *layout;
- PangoFontDescription *desc;
-
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h);
- lines = gl_label_text_get_lines (object);
- font_family = gl_label_object_get_font_family (GL_LABEL_OBJECT(object));
- font_size = gl_label_object_get_font_size (GL_LABEL_OBJECT(object));
- font_weight = gl_label_object_get_font_weight (GL_LABEL_OBJECT(object));
- font_italic_flag = gl_label_object_get_font_italic_flag (GL_LABEL_OBJECT(object));
-
- color_node = gl_label_object_get_text_color (GL_LABEL_OBJECT(object));
- color = gl_color_node_expand (color_node, record);
- gl_color_node_free (&color_node);
-
- alignment = gl_label_object_get_text_alignment (GL_LABEL_OBJECT(object));
- text_line_spacing =
- gl_label_object_get_text_line_spacing (GL_LABEL_OBJECT(object));
- auto_shrink = gl_label_text_get_auto_shrink (object);
-
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, color);
- gl_color_node_free (&shadow_color_node);
-
- text = gl_text_node_lines_expand (lines, record);
-
- style = font_italic_flag ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
-
-
- if (record && auto_shrink) {
-
- /* auto shrink text size to keep within text box limits. */
-
- layout = pango_cairo_create_layout (pi->cr);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, font_family);
- pango_font_description_set_weight (desc, font_weight);
- pango_font_description_set_style (desc, style);
- pango_font_description_set_size (desc, font_size * PANGO_SCALE * FONT_SCALE);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
-
- pango_layout_set_text (layout, text, -1);
- w = pango_layout_get_width (layout) / PANGO_SCALE;
-
- g_object_unref (layout);
-
- if ( w > object_w )
- {
- /* Scale down. */
- font_size *= (object_w-2*GL_LABEL_TEXT_MARGIN)/w;
-
- /* Round down to nearest 1/2 point */
- font_size = (int)(font_size*2.0) / 2.0;
-
- /* don't get ridiculously small. */
- if (font_size < 1.0)
- {
- font_size = 1.0;
- }
- }
- }
-
-
- layout = pango_cairo_create_layout (pi->cr);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, font_family);
- pango_font_description_set_weight (desc, font_weight);
- pango_font_description_set_style (desc, style);
- pango_font_description_set_size (desc, font_size * PANGO_SCALE * FONT_SCALE);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
-
- pango_layout_set_text (layout, text, -1);
- pango_layout_set_spacing (layout, font_size * (text_line_spacing-1) * PANGO_SCALE);
- pango_layout_set_width (layout, object_w * PANGO_SCALE);
- pango_layout_set_alignment (layout, alignment);
-
- if (shadow_state)
- {
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_color),
- GL_COLOR_F_GREEN (shadow_color),
- GL_COLOR_F_BLUE (shadow_color),
- GL_COLOR_F_ALPHA (shadow_color));
-
- cairo_move_to (pi->cr, shadow_x + GL_LABEL_TEXT_MARGIN, shadow_y);
- pango_cairo_show_layout (pi->cr, layout);
- }
-
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (color),
- GL_COLOR_F_GREEN (color),
- GL_COLOR_F_BLUE (color),
- GL_COLOR_F_ALPHA (color));
-
- cairo_move_to (pi->cr, GL_LABEL_TEXT_MARGIN, 0);
- pango_cairo_show_layout (pi->cr, layout);
-
- g_object_unref (layout);
-
-
- gl_text_node_lines_free (&lines);
- g_free (font_family);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw box object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_box_object (PrintInfo *pi,
- glLabelBox *object,
- glMergeRecord *record)
-{
- gdouble w, h;
- gdouble line_width;
- guint line_color;
- glColorNode *line_color_node;
- glColorNode *fill_color_node;
- guint fill_color;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
- guint shadow_fill_color;
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width (GL_LABEL_OBJECT(object));
-
- line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
- fill_color_node = gl_label_object_get_fill_color (GL_LABEL_OBJECT(object));
- line_color = gl_color_node_expand (line_color_node, record);
- fill_color = gl_color_node_expand (fill_color_node, record);
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
-
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color);
- shadow_fill_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, fill_color);
- gl_color_node_free (&shadow_color_node);
-
- if (shadow_state)
- {
- /* Draw fill shadow */
- cairo_rectangle (pi->cr, shadow_x, shadow_y, w, h);
-
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_fill_color),
- GL_COLOR_F_GREEN (shadow_fill_color),
- GL_COLOR_F_BLUE (shadow_fill_color),
- GL_COLOR_F_ALPHA (shadow_fill_color));
- cairo_fill_preserve (pi->cr);
-
- /* Draw outline shadow */
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_line_color),
- GL_COLOR_F_GREEN (shadow_line_color),
- GL_COLOR_F_BLUE (shadow_line_color),
- GL_COLOR_F_ALPHA (shadow_line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
- }
-
- /* Paint fill color */
- cairo_rectangle (pi->cr, 0.0, 0.0, w, h);
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (fill_color),
- GL_COLOR_F_GREEN (fill_color),
- GL_COLOR_F_BLUE (fill_color),
- GL_COLOR_F_ALPHA (fill_color));
- cairo_fill_preserve (pi->cr);
-
- /* Draw outline */
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (line_color),
- GL_COLOR_F_GREEN (line_color),
- GL_COLOR_F_BLUE (line_color),
- GL_COLOR_F_ALPHA (line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw line object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_line_object (PrintInfo *pi,
- glLabelLine *object,
- glMergeRecord *record)
-{
- gdouble w, h;
- gdouble line_width;
- guint line_color;
- glColorNode *line_color_node;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width (GL_LABEL_OBJECT(object));
-
- line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
- line_color = gl_color_node_expand (line_color_node, record);
- gl_color_node_free (&line_color_node);
-
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color);
- gl_color_node_free (&shadow_color_node);
-
- if (shadow_state)
- {
- cairo_move_to (pi->cr, shadow_x, shadow_y);
- cairo_line_to (pi->cr, shadow_x + w, shadow_y + h);
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_line_color),
- GL_COLOR_F_GREEN (shadow_line_color),
- GL_COLOR_F_BLUE (shadow_line_color),
- GL_COLOR_F_ALPHA (shadow_line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
- }
-
- cairo_move_to (pi->cr, 0.0, 0.0);
- cairo_line_to (pi->cr, w, h);
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (line_color),
- GL_COLOR_F_GREEN (line_color),
- GL_COLOR_F_BLUE (line_color),
- GL_COLOR_F_ALPHA (line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw ellipse object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_ellipse_object (PrintInfo *pi,
- glLabelEllipse *object,
- glMergeRecord *record)
-{
- gdouble x0, y0, rx, ry, w, h;
- gdouble line_width;
- glColorNode *line_color_node;
- glColorNode *fill_color_node;
- guint line_color;
- guint fill_color;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
- guint shadow_fill_color;
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width (GL_LABEL_OBJECT(object));
-
- line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
- fill_color_node = gl_label_object_get_fill_color (GL_LABEL_OBJECT(object));
- line_color = gl_color_node_expand (line_color_node, record);
- fill_color = gl_color_node_expand (fill_color_node, record);
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
-
- rx = w / 2.0;
- ry = h / 2.0;
- x0 = rx;
- y0 = ry;
-
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color);
- shadow_fill_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, fill_color);
- gl_color_node_free (&shadow_color_node);
-
- if (shadow_state)
- {
- /* Draw fill shadow */
- create_ellipse_path (pi->cr, x0+shadow_x, y0+shadow_y, rx, ry);
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_fill_color),
- GL_COLOR_F_GREEN (shadow_fill_color),
- GL_COLOR_F_BLUE (shadow_fill_color),
- GL_COLOR_F_ALPHA (shadow_fill_color));
- cairo_fill_preserve (pi->cr);
-
- /* Draw outline shadow */
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (shadow_line_color),
- GL_COLOR_F_GREEN (shadow_line_color),
- GL_COLOR_F_BLUE (shadow_line_color),
- GL_COLOR_F_ALPHA (shadow_line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
- }
-
- /* Paint fill color */
- create_ellipse_path (pi->cr, x0, y0, rx, ry);
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (fill_color),
- GL_COLOR_F_GREEN (fill_color),
- GL_COLOR_F_BLUE (fill_color),
- GL_COLOR_F_ALPHA (fill_color));
- cairo_fill_preserve (pi->cr);
-
- /* Draw outline */
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (line_color),
- GL_COLOR_F_GREEN (line_color),
- GL_COLOR_F_BLUE (line_color),
- GL_COLOR_F_ALPHA (line_color));
- cairo_set_line_width (pi->cr, line_width);
- cairo_stroke (pi->cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw image object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_image_object (PrintInfo *pi,
- glLabelImage *object,
- glMergeRecord *record)
-{
- gdouble w, h;
- const GdkPixbuf *pixbuf;
- gint image_w, image_h;
-
- gl_debug (DEBUG_PRINT, "START");
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
-
- pixbuf = gl_label_image_get_pixbuf (object, record);
- image_w = gdk_pixbuf_get_width (pixbuf);
- image_h = gdk_pixbuf_get_height (pixbuf);
-
- cairo_save (pi->cr);
- cairo_rectangle (pi->cr, 0.0, 0.0, w, h);
- cairo_clip (pi->cr);
- cairo_scale (pi->cr, w/image_w, h/image_h);
- gdk_cairo_set_source_pixbuf (pi->cr, (GdkPixbuf *)pixbuf, 0, 0);
- cairo_paint (pi->cr);
-
- cairo_restore (pi->cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw barcode object. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_barcode_object (PrintInfo *pi,
- glLabelBarcode *object,
- glMergeRecord *record)
-{
- glBarcode *gbc;
- glBarcodeLine *line;
- glBarcodeChar *bchar;
- GList *li;
- gdouble y_offset;
- PangoLayout *layout;
- PangoFontDescription *desc;
- gchar *text, *cstring;
- glTextNode *text_node;
- gchar *id;
- gboolean text_flag;
- gboolean checksum_flag;
- guint color;
- glColorNode *color_node;
- guint format_digits;
- gdouble w, h;
-
- gl_debug (DEBUG_PRINT, "START");
-
- text_node = gl_label_barcode_get_data (object);
- gl_label_barcode_get_props (object,
- &id, &text_flag, &checksum_flag, &format_digits);
-
- color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
- color = gl_color_node_expand (color_node, record);
- gl_color_node_free (&color_node);
-
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
-
- text = gl_text_node_expand (text_node, record);
-
- if (text == NULL || *text == '\0') {
-
- g_free(text);
- gl_text_node_free(&text_node);
- g_free(id);
-
- return;
- }
-
- gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, text);
- g_free (text);
- gl_text_node_free (&text_node);
- g_free (id);
-
- cairo_set_source_rgba (pi->cr,
- GL_COLOR_F_RED (color),
- GL_COLOR_F_GREEN (color),
- GL_COLOR_F_BLUE (color),
- GL_COLOR_F_ALPHA (color));
-
- if (gbc == NULL) {
-
- layout = pango_cairo_create_layout (pi->cr);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, GL_BARCODE_FONT_FAMILY);
- pango_font_description_set_size (desc, 12 * PANGO_SCALE * FONT_SCALE);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
-
- pango_layout_set_text (layout, _("Invalid barcode data"), -1);
-
- pango_cairo_show_layout (pi->cr, layout);
-
- g_object_unref (layout);
-
- } else {
-
- for (li = gbc->lines; li != NULL; li = li->next) {
- line = (glBarcodeLine *) li->data;
-
- cairo_move_to (pi->cr, line->x, line->y);
- cairo_line_to (pi->cr, line->x, line->y + line->length);
- cairo_set_line_width (pi->cr, line->width);
- cairo_stroke (pi->cr);
- }
-
- for (li = gbc->chars; li != NULL; li = li->next) {
- bchar = (glBarcodeChar *) li->data;
-
- layout = pango_cairo_create_layout (pi->cr);
-
- desc = pango_font_description_new ();
- pango_font_description_set_family (desc, GL_BARCODE_FONT_FAMILY);
- pango_font_description_set_size (desc, bchar->fsize * PANGO_SCALE * FONT_SCALE);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
-
- cstring = g_strdup_printf ("%c", bchar->c);
- pango_layout_set_text (layout, cstring, -1);
- g_free (cstring);
-
- y_offset = 0.2 * bchar->fsize;
-
- cairo_move_to (pi->cr, bchar->x, bchar->y-y_offset);
- pango_cairo_show_layout (pi->cr, layout);
-
- g_object_unref (layout);
-
- }
-
- gl_barcode_free (&gbc);
-
- }
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. Draw outline. */
/*---------------------------------------------------------------------------*/
draw_outline (PrintInfo *pi,
glLabel *label)
{
- const glTemplateLabelType *label_type;
- gdouble w, h, r;
- gdouble r1, r2;
-
gl_debug (DEBUG_PRINT, "START");
- label_type = gl_template_get_first_label_type (pi->template);
-
cairo_save (pi->cr);
cairo_set_source_rgba (pi->cr, 0.0, 0.0, 0.0, 1.0);
cairo_set_line_width (pi->cr, 0.25);
- switch (label_type->shape) {
-
- case GL_TEMPLATE_SHAPE_RECT:
- gl_label_get_size (label, &w, &h);
- r = label_type->size.rect.r;
- if (r == 0.0) {
- /* simple rectangle */
- cairo_rectangle (pi->cr, 0.0, 0.0, w, h);
- } else {
- /* rectangle with rounded corners */
- create_rounded_rectangle_path (pi->cr, 0.0, 0.0,
- w, h, r);
- }
- cairo_stroke (pi->cr);
- break;
-
- case GL_TEMPLATE_SHAPE_ROUND:
- /* Round style */
- r1 = label_type->size.round.r;
- create_ellipse_path (pi->cr, r1, r1, r1, r1);
- cairo_stroke (pi->cr);
- break;
-
- case GL_TEMPLATE_SHAPE_CD:
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
- if ((label_type->size.cd.h == 0) && (label_type->size.cd.w == 0)) {
- /* CD style, round label w/ concentric round hole */
- create_cd_path (pi->cr, r1, r1, 2*r1, 2*r1, r1, r2);
-
- cairo_stroke (pi->cr);
- } else {
- /* Business Card CD style, clipped round label w/ hole */
- gl_label_get_size (label, &w, &h);
- create_cd_path (pi->cr, w/2, h/2, w, h, r1, r2);
- cairo_stroke (pi->cr);
- }
- break;
+ gl_cairo_label_path (pi->cr, label, FALSE);
- default:
- g_message ("Unknown template label style");
- break;
- }
+ cairo_stroke (pi->cr);
cairo_restore (pi->cr);
clip_to_outline (PrintInfo *pi,
glLabel *label)
{
- const glTemplateLabelType *label_type;
- gdouble w, h, r;
- gdouble r1, r2;
- gdouble waste, x_waste, y_waste;
-
gl_debug (DEBUG_PRINT, "START");
- label_type = gl_template_get_first_label_type (pi->template);
-
- switch (label_type->shape) {
-
- case GL_TEMPLATE_SHAPE_RECT:
- gl_label_get_size (label, &w, &h);
- r = label_type->size.rect.r;
- x_waste = label_type->size.rect.x_waste;
- y_waste = label_type->size.rect.y_waste;
- if (r == 0.0) {
- /* simple rectangle */
- cairo_rectangle (pi->cr,
- -x_waste, -y_waste,
- w+2*x_waste, h+2*y_waste);
- } else {
- /* rectangle with rounded corners */
- create_rounded_rectangle_path (pi->cr,
- -x_waste, -y_waste,
- w+2*x_waste, h+2*y_waste, r);
- }
- cairo_clip (pi->cr);
- break;
-
- case GL_TEMPLATE_SHAPE_ROUND:
- r1 = label_type->size.round.r;
- waste = label_type->size.round.waste;
- create_ellipse_path (pi->cr, r1, r1, r1+waste, r1+waste);
- cairo_clip (pi->cr);
- break;
-
- case GL_TEMPLATE_SHAPE_CD:
- waste = label_type->size.cd.waste;
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
- if ((label_type->size.cd.h == 0) && (label_type->size.cd.w == 0)) {
- /* CD style, round label w/ concentric round hole */
- create_cd_path (pi->cr,
- r1, r1,
- 2*(r1+waste), 2*(r1+waste),
- r1+waste,
- r2-waste);
- } else {
- /* Business Card CD style, clipped round label w/ hole */
- gl_label_get_size (label, &w, &h);
- create_cd_path (pi->cr,
- w/2, h/2,
- w+2*waste, h+2*waste,
- r1+waste,
- r2-waste);
- }
- cairo_set_fill_rule (pi->cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_clip (pi->cr);
- break;
+ gl_cairo_label_path (pi->cr, label, TRUE);
- default:
- g_message ("Unknown template label style");
- break;
- }
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Path creation utilities. */
-/*---------------------------------------------------------------------------*/
-static void
-create_rounded_rectangle_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble w,
- gdouble h,
- gdouble r)
-{
- gdouble x, y;
- gint i_theta;
-
- gl_debug (DEBUG_PRINT, "START");
-
- cairo_new_path (cr);
-
- cairo_arc_negative (cr, x0+r, y0+r, r, 3*M_PI/2, M_PI);
- cairo_arc_negative (cr, x0+r, y0+h-r, r, M_PI, M_PI/2);
- cairo_arc_negative (cr, x0+w-r, y0+h-r, r, M_PI/2, 0.);
- cairo_arc_negative (cr, x0+w-r, y0+r, r, 2*M_PI, 3*M_PI/2);
- cairo_close_path (cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
-
-static void
-create_ellipse_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble rx,
- gdouble ry)
-{
- gdouble x, y;
- gint i_theta;
-
- gl_debug (DEBUG_PRINT, "START");
-
- cairo_new_path (cr);
- cairo_move_to (cr, x0 + rx, y0);
- for (i_theta = ARC_FINE; i_theta <= 360; i_theta += ARC_FINE) {
- x = x0 + rx * cos (i_theta * G_PI / 180.0);
- y = y0 + ry * sin (i_theta * G_PI / 180.0);
- cairo_line_to (cr, x, y);
- }
- cairo_close_path (cr);
+ cairo_set_fill_rule (pi->cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_clip (pi->cr);
gl_debug (DEBUG_PRINT, "END");
}
-static void
-create_cd_path (cairo_t *cr,
- gdouble x0,
- gdouble y0,
- gdouble w,
- gdouble h,
- gdouble r1,
- gdouble r2)
-{
- gdouble theta1, theta2;
-
- gl_debug (DEBUG_PRINT, "START");
-
- /*
- * Outer radius. (may be clipped)
- */
- theta1 = acos (w / (2.0*r1));
- theta2 = asin (h / (2.0*r1));
-
- cairo_new_path (cr);
- cairo_arc (cr, x0, y0, r1, theta1, theta2);
- cairo_arc (cr, x0, y0, r1, M_PI-theta2, M_PI-theta1);
- cairo_arc (cr, x0, y0, r1, M_PI+theta1, M_PI+theta2);
- cairo_arc (cr, x0, y0, r1, 2*M_PI-theta2, 2*M_PI-theta1);
- cairo_close_path (cr);
-
- /*
- * Inner radius. (hole)
- */
- cairo_new_sub_path (cr);
- cairo_arc (cr, x0, y0, r2, 0.0, 2*M_PI);
- cairo_close_path (cr);
-
- gl_debug (DEBUG_PRINT, "END");
-}
recent_filter = gtk_recent_filter_new ();
gtk_recent_filter_add_mime_type (recent_filter, GLABELS_MIME_TYPE);
- gtk_recent_chooser_set_filter (recent_menu, recent_filter);
+ gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (recent_menu), recent_filter);
gl_debug (DEBUG_RECENT, "END");
return recent_menu;
/* Local function prototypes */
/*===========================================*/
-static add_icons (GtkIconFactory *factory,
- const gchar *stock_id,
- const guchar *inline_24,
- const guchar *inline_16);
+static void add_icons (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24,
+ const guchar *inline_16);
-static add_button_icon (GtkIconFactory *factory,
- const gchar *stock_id,
- const guchar *inline_24);
+static void add_button_icon (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24);
\f
/****************************************************************************/
/*--------------------------------------------------------------------------*/
/* PRIVATE. Unpack and associate given icons with stock_id. */
/*--------------------------------------------------------------------------*/
-static add_icons (GtkIconFactory *factory,
- const gchar *stock_id,
- const guchar *inline_24,
- const guchar *inline_16)
+static void
+add_icons (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24,
+ const guchar *inline_16)
{
GdkPixbuf *pixbuf;
GtkIconSet *icon_set;
/*--------------------------------------------------------------------------*/
/* PRIVATE. Unpack and associate given button icon with stock_id. */
/*--------------------------------------------------------------------------*/
-static add_button_icon (GtkIconFactory *factory,
- const gchar *stock_id,
- const guchar *inline_24)
+static void
+add_button_icon (GtkIconFactory *factory,
+ const gchar *stock_id,
+ const guchar *inline_24)
{
GtkIconSet *icon_set;
GdkPixbuf *pixbuf;
#include <libglabels/template.h>
#include "wdgt-mini-preview.h"
#include "print-op.h"
+#include "util.h"
#include "debug.h"
return -1;
}
+ return -1;
}
/*--------------------------------------------------------------------------*/
layout_page_prepare_cb (glTemplateDesigner *dialog)
{
gdouble page_w, page_h;
- gdouble w, h, x_waste, y_waste;
+ gdouble w=0, h=0, x_waste=0, y_waste=0;
gint max_nx, max_ny;
gint nlayouts;
gdouble nx_1, ny_1, x0_1, y0_1, dx_1, dy_1;
gchar *page_size_name;
glPaper *paper;
glTemplateLabelShape shape;
- glTemplateLabelType *label_type;
- gdouble w, h, r, radius, hole, waste, x_waste, y_waste, margin;
+ glTemplateLabelType *label_type=NULL;
+ gdouble w=0, h=0, r=0, radius=0, hole=0, waste=0, x_waste=0, y_waste=0, margin=0;
gint nlayouts;
gdouble nx_1, ny_1, x0_1, y0_1, dx_1, dy_1;
gdouble nx_2, ny_2, x0_2, y0_2, dx_2, dy_2;
if (text != NULL) {
return text;
} else {
- return g_strdup_printf ("");
+ return g_strdup_printf ("%s", "");
}
}
} else {
GList *p_line, *line, *p_node;
glTextNode *node;
- for (p_line = src_lines; p_line != NULL; p_line = p_line->next) {
+ for (p_line = src_lines; p_line != NULL; p_line = p_line->next)
+ {
line = NULL;
- for (p_node = (GList *) p_line->data; p_node != NULL;
- p_node = p_node->next) {
+ for (p_node = (GList *) p_line->data; p_node != NULL; p_node = p_node->next)
+ {
node = gl_text_node_dup ((glTextNode *)p_node->data);
line = g_list_append (line, node);
}
gl_text_node_lines_free (GList **lines)
{
GList *p_line, *p_node;
-
- for (p_line = *lines; p_line != NULL; p_line = p_line->next) {
- for (p_node = (GList *) p_line->data; p_node != NULL;
- p_node = p_node->next) {
- gl_text_node_free ( (glTextNode **) &(p_node->data) );
+ glTextNode *text_node;
+
+ for (p_line = *lines; p_line != NULL; p_line = p_line->next)
+ {
+ for (p_node = (GList *) p_line->data; p_node != NULL; p_node = p_node->next)
+ {
+ text_node = (glTextNode *)p_node->data;
+ p_node->data = NULL;
+ gl_text_node_free ( &text_node );
}
g_list_free ((GList *) p_line->data);
p_line->data = NULL;
utf8_filename = gl_recent_get_utf8_filename (item);
gl_debug (DEBUG_COMMANDS, "Selected %s\n", utf8_filename);
-#if 1
gl_file_open_recent (utf8_filename, window);
-#endif
gtk_recent_info_unref (item);
is_same_font_family = TRUE;
selection_font_family = NULL;
selection_font_size = -1;
+ selection_align = PANGO_ALIGN_LEFT;
+ selection_is_italic = TRUE;
+ selection_is_bold = TRUE;
+ selection_text_color = 0;
+
is_first_object = TRUE;
for (p = view->selected_object_list; p != NULL; p = p->next) {
is_same_fill_color = TRUE;
is_first_object = TRUE;
+ selection_fill_color = 0;
for (p = view->selected_object_list; p != NULL; p = p->next) {
is_same_line_color = TRUE;
is_first_object = TRUE;
+ selection_line_color = 0;
for (p = view->selected_object_list; p != NULL; p = p->next) {
is_same_line_width = TRUE;
is_first_object = TRUE;
+ selection_line_width = 0;
for (p = view->selected_object_list; p != NULL; p = p->next) {
static void menu_item_deselect_cb (GtkMenuItem *proxy,
glWindow *window);
-static char *recent_tooltip_func (GtkRecentInfo *item,
- gpointer user_data);
-
-
/*==========================================================================*/
/* Private globals */
void
gl_ui_unref (GtkUIManager *ui)
{
- GObject *recent_view;
-
gl_debug (DEBUG_UI, "START");
g_object_unref(ui);
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_text.c: GLabels label text object widget
+ * view_barcode.c: GLabels label barcode object view
*
- * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
-#include <glib/glist.h>
-#include <gtk/gtkmenu.h>
-#include <libgnomeprint/gnome-glyphlist.h>
-#include <string.h>
-#include <math.h>
-
-#include "canvas-hacktext.h"
-#include "view-highlight.h"
+
#include "color.h"
#include "object-editor.h"
#include "stock.h"
/*========================================================*/
struct _glViewBarcodePrivate {
-
- GList *item_list;
-
};
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
-static void gl_view_barcode_finalize (GObject *object);
+static void gl_view_barcode_finalize (GObject *object);
-static GtkWidget *construct_properties_editor (glViewObject *view_object);
+static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewBarcode *view_bc);
+static void update_object_from_editor_cb (glObjectEditor *editor,
+ glLabelObject *object);
-static void update_object_from_editor_cb (glObjectEditor *editor,
- glLabelObject *object);
+static void update_editor_from_object_cb (glLabelObject *object,
+ glObjectEditor *editor);
-static void update_editor_from_object_cb (glLabelObject *object,
- glObjectEditor *editor);
+static void update_editor_from_move_cb (glLabelObject *object,
+ gdouble dx,
+ gdouble dy,
+ glObjectEditor *editor);
-static void update_editor_from_move_cb (glLabelObject *object,
- gdouble dx,
- gdouble dy,
- glObjectEditor *editor);
+static void update_editor_from_label_cb (glLabel *label,
+ glObjectEditor *editor);
-static void update_editor_from_label_cb (glLabel *label,
- glObjectEditor *editor);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
-static void draw_barcode (glViewBarcode *view_bc);
\f
/*****************************************************************************/
G_DEFINE_TYPE (glViewBarcode, gl_view_barcode, GL_TYPE_VIEW_OBJECT);
+
static void
gl_view_barcode_class_init (glViewBarcodeClass *class)
{
object_class->finalize = gl_view_barcode_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
static void
-gl_view_barcode_init (glViewBarcode *view_bc)
+gl_view_barcode_init (glViewBarcode *view_barcode)
{
gl_debug (DEBUG_VIEW, "START");
- view_bc->priv = g_new0 (glViewBarcodePrivate, 1);
+ view_barcode->priv = g_new0 (glViewBarcodePrivate, 1);
gl_debug (DEBUG_VIEW, "END");
}
static void
gl_view_barcode_finalize (GObject *object)
{
- glViewBarcode *view_bc = GL_VIEW_BARCODE (object);
+ glViewBarcode *view_barcode = GL_VIEW_BARCODE (object);
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (object && GL_IS_VIEW_BARCODE (object));
- g_free (view_bc->priv);
+ g_free (view_barcode->priv);
G_OBJECT_CLASS (gl_view_barcode_parent_class)->finalize (object);
/*****************************************************************************/
glViewObject *
gl_view_barcode_new (glLabelBarcode *object,
- glView *view)
+ glView *view)
{
- glViewBarcode *view_bc;
- GtkMenu *menu;
+ glViewBarcode *view_barcode;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_BARCODE (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+
+ g_return_val_if_fail (object && GL_IS_LABEL_BARCODE (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
- view_bc = g_object_new (gl_view_barcode_get_type(), NULL);
+ view_barcode = g_object_new (gl_view_barcode_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_bc), view);
- gl_view_object_set_object (GL_VIEW_OBJECT(view_bc),
+ gl_view_object_set_object (GL_VIEW_OBJECT(view_barcode),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
-
- /* Create analogous canvas items. */
- draw_barcode (view_bc);
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_bc);
+ GL_VIEW_OBJECT_HANDLES_BOX);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_barcode), view);
gl_debug (DEBUG_VIEW, "END");
- return GL_VIEW_OBJECT (view_bc);
+ return GL_VIEW_OBJECT (view_barcode);
}
/*****************************************************************************/
-/* Create a properties editor for a barcode object. */
+/* Create a properties dialog for a barcode object. */
/*****************************************************************************/
static GtkWidget *
construct_properties_editor (glViewObject *view_object)
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewBarcode *view_bc)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- /* Adjust appearance of analogous canvas item. */
- draw_barcode (view_bc);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
glObjectEditor *editor)
{
gdouble label_width, label_height;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+ if (cairo_in_fill (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_barcode_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_barcode_bits,
- cursor_barcode_width,
- cursor_barcode_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_barcode_mask_bits,
- cursor_barcode_mask_width,
- cursor_barcode_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_barcode_x_hot,
- cursor_barcode_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_barcode_bits,
+ cursor_barcode_width,
+ cursor_barcode_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_barcode_mask_bits,
+ cursor_barcode_mask_width,
+ cursor_barcode_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_barcode_x_hot,
+ cursor_barcode_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating barcode objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_barcode_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_barcode_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_barcode;
- static GObject *object;
- gdouble x, y;
- glTextNode *text_node;
- glColorNode *color_node;
-
- gl_debug (DEBUG_VIEW, "");
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
- switch (event->button.button) {
- case 1:
- color_node = gl_color_node_new_default ();
- dragging = TRUE;
- gnome_canvas_item_grab (canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_barcode_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- text_node = gl_text_node_new_from_text ("123456789");
- gl_label_barcode_set_data (GL_LABEL_BARCODE(object),
- text_node);
- gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- "POSTNET",
- FALSE,
- TRUE,
- 0);
- color_node->color = gl_color_set_opacity (
- gl_view_get_default_line_color(view),
- 0.5);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- color_node);
- view_barcode = gl_view_barcode_new (GL_LABEL_BARCODE(object),
- view);
- x0 = x;
- y0 = y;
- gl_color_node_free (&color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
- switch (event->button.button) {
- case 1:
- color_node = gl_color_node_new_default ();
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- "POSTNET",
- FALSE,
- TRUE,
- 0);
- color_node->color = gl_view_get_default_line_color(view);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- color_node);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_barcode));
- gl_view_arrow_mode (view);
- gl_color_node_free (&color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
-
+ GObject *object;
+ glTextNode *text_node;
+ glColorNode *line_color_node;
+ glViewObject *view_barcode;
+
+ line_color_node = gl_color_node_new_default ();
+
+ object = gl_label_barcode_new (view->label);
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ text_node = gl_text_node_new_from_text ("123456789");
+ gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
+ line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
+ line_color_node);
+
+ gl_color_node_free (&line_color_node);
+
+ gl_view_unselect_all (view);
+ view_barcode = gl_view_barcode_new (GL_LABEL_BARCODE(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_barcode));
+
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
}
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Draw barcode to item (group). */
-/*--------------------------------------------------------------------------*/
-static void
-draw_barcode (glViewBarcode *view_barcode)
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_barcode_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- glLabelObject *object;
- GnomeCanvasItem *item;
- glTextNode *text_node;
- gchar *id;
- gboolean text_flag;
- gboolean checksum_flag;
- glColorNode *color_node;
- gdouble w, h;
- glBarcodeLine *line;
- glBarcodeChar *bchar;
- glBarcode *gbc;
- GList *li;
- GList *item_list = NULL;
- GnomeCanvasPoints *points;
- gchar *digits, *cstring;
- GnomeFont *font;
- GnomeGlyphList *glyphlist;
- gdouble y_offset;
- guint format_digits;
- ArtDRect bbox;
- gdouble affine[6];
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query label object and properties */
- object = gl_view_object_get_object (GL_VIEW_OBJECT(view_barcode));
- gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
- &id, &text_flag, &checksum_flag, &format_digits);
- color_node = gl_label_object_get_line_color (object);
- if (color_node->field_flag)
- {
- color_node->color = GL_COLOR_MERGE_DEFAULT;
- }
- gl_label_object_get_size (object, &w, &h);
- text_node = gl_label_barcode_get_data(GL_LABEL_BARCODE(object));
- if (text_node->field_flag) {
- digits = gl_barcode_default_digits (id, format_digits);
- } else {
- digits = gl_text_node_expand (text_node, NULL);
- }
-
- /* remove previous items from group. */
- for (li = view_barcode->priv->item_list; li!=NULL; li = li->next) {
- gl_debug (DEBUG_VIEW, "in loop");
- gtk_object_destroy (GTK_OBJECT (li->data));
- }
- gl_debug (DEBUG_VIEW, "1");
- g_list_free (view_barcode->priv->item_list);
- view_barcode->priv->item_list = NULL;
- gl_debug (DEBUG_VIEW, "2");
-
- /* get Gnome Font */
- font = gnome_font_find_closest_from_weight_slant ((guchar *)GL_BARCODE_FONT_FAMILY,
- GL_BARCODE_FONT_WEIGHT,
- FALSE,
- 10.0);
-
- gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, digits);
- if (gbc == NULL) {
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode),
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", w,
- "y2", h,
- "outline_color_rgba", color_node->color,
- "width_pixels", 1,
- NULL);
- view_barcode->priv->item_list =
- g_list_prepend (view_barcode->priv->item_list, item);
-
- if (digits == NULL || *digits == '\0')
- {
- cstring = _("Barcode data empty");
- }
- else
- {
- cstring = _("Invalid barcode data");
- }
-
- glyphlist = gnome_glyphlist_from_text_sized_dumb (font,
- color_node->color,
- 0.0, 0.0,
- (guchar *)cstring,
- strlen (cstring));
- y_offset = 10.0 - fabs (gnome_font_get_descender (font));
- art_affine_identity (affine);
- gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode),
- gl_canvas_hacktext_get_type (),
- "x", w/2 - bbox.x1/2,
- "y", h/2 - bbox.y1/2 + y_offset,
- "glyphlist", glyphlist, NULL);
-
- gnome_glyphlist_unref (glyphlist);
-
- view_barcode->priv->item_list =
- g_list_prepend (view_barcode->priv->item_list, item);
- } else {
-
- points = gnome_canvas_points_new (2);
- for (li = gbc->lines; li != NULL; li = li->next) {
- line = (glBarcodeLine *) li->data;
-
- points->coords[0] = line->x;
- points->coords[1] = line->y;
- points->coords[2] = line->x;
- points->coords[3] = line->y + line->length;
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode),
- gnome_canvas_line_get_type (),
- "points", points,
- "width_units", line->width,
- "fill_color_rgba", color_node->color,
- NULL);
- view_barcode->priv->item_list =
- g_list_prepend (view_barcode->priv->item_list, item);
- }
- gnome_canvas_points_free (points);
-
- for (li = gbc->chars; li != NULL; li = li->next) {
- bchar = (glBarcodeChar *) li->data;
-
- font = gnome_font_find_closest_from_weight_slant (
- (guchar *)GL_BARCODE_FONT_FAMILY,
- GL_BARCODE_FONT_WEIGHT,
- FALSE, bchar->fsize);
- glyphlist = gnome_glyphlist_from_text_sized_dumb (
- font,
- color_node->color,
- 0.0, 0.0,
- (guchar *)&(bchar->c), 1);
- y_offset =
- bchar->fsize - fabs (gnome_font_get_descender (font));
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode),
- gl_canvas_hacktext_get_type (),
- "x", bchar->x,
- "y", bchar->y + y_offset,
- "glyphlist", glyphlist,
- NULL);
-
- gnome_glyphlist_unref (glyphlist);
-
- view_barcode->priv->item_list =
- g_list_prepend (view_barcode->priv->item_list, item);
-
- }
-
- }
-
- /* clean up */
- gl_color_node_free (&color_node);
- gl_barcode_free (&gbc);
- g_free (digits);
- g_free (id);
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
+}
- gl_debug (DEBUG_VIEW, "END");
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_barcode_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ glColorNode *line_color_node;
+
+ line_color_node = gl_color_node_new_default ();
+
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
+ line_color_node->color = gl_view_get_default_line_color(view);
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
+ gl_color_node_free (&line_color_node);
}
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_barcode.h: GLabels canvas item wrapper widget
+ * view_barcode.h: GLabels label barcode object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
typedef struct _glViewBarcodePrivate glViewBarcodePrivate;
struct _glViewBarcode {
- glViewObject parent_object;
+ glViewObject parent_object;
- glViewBarcodePrivate *priv;
+ glViewBarcodePrivate *priv;
};
struct _glViewBarcodeClass {
- glViewObjectClass parent_class;
+ glViewObjectClass parent_class;
};
GType gl_view_barcode_get_type (void) G_GNUC_CONST;
glViewObject *gl_view_barcode_new (glLabelBarcode *object,
- glView *view);
+ glView *view);
/* cursor for creating barcode objects */
GdkCursor *gl_view_barcode_get_create_cursor (void);
-/* event handler for creating barcode objects */
-gint gl_view_barcode_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_barcode_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_barcode_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_barcode_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_box.c: GLabels label box object widget
+ * view_box.c: GLabels label box object view
*
- * Copyright (C) 2001-2006 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
-#include "view-highlight.h"
#include "color.h"
#include "object-editor.h"
#include "stock.h"
/* Private macros and constants. */
/*========================================================*/
-#define DELTA 0.01
/*========================================================*/
/* Private types. */
/*========================================================*/
struct _glViewBoxPrivate {
- GnomeCanvasItem *object_item;
- GnomeCanvasItem *shadow_item;
};
/*========================================================*/
static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewBox *view_box);
-
static void update_object_from_editor_cb (glObjectEditor *editor,
glLabelObject *object);
static void update_editor_from_label_cb (glLabel *label,
glObjectEditor *editor);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
+
+
\f
/*****************************************************************************/
object_class->finalize = gl_view_box_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_BOX (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_val_if_fail (object && GL_IS_LABEL_BOX (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
view_box = g_object_new (gl_view_box_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_box), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_box),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
-
- /* Create analogous canvas items. */
- view_box->priv->shadow_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_box),
- gnome_canvas_rect_get_type (),
- NULL);
- view_box->priv->object_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_box),
- gnome_canvas_rect_get_type (),
- NULL);
- update_canvas_item_from_object_cb (GL_LABEL_OBJECT(object), view_box);
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_box);
+ GL_VIEW_OBJECT_HANDLES_BOX);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_box), view);
gl_debug (DEBUG_VIEW, "END");
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewBox *view_box)
-{
- gdouble line_width;
- glColorNode *line_color_node;
- gdouble w, h;
- glColorNode *fill_color_node;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
- guint shadow_fill_color;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query properties of object. */
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width(GL_LABEL_OBJECT(object));
- line_color_node = gl_label_object_get_line_color(GL_LABEL_OBJECT(object));
- if (line_color_node->field_flag)
- {
- line_color_node->color = GL_COLOR_MERGE_DEFAULT;
- }
- fill_color_node = gl_label_object_get_fill_color(GL_LABEL_OBJECT(object));
- if (fill_color_node->field_flag)
- {
- fill_color_node->color = GL_COLOR_FILL_MERGE_DEFAULT;
- }
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- line_color_node->color);
- shadow_fill_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- fill_color_node->color);
-
- /* Adjust appearance of analogous canvas items. */
- gnome_canvas_item_set (view_box->priv->shadow_item,
- "x1", shadow_x,
- "y1", shadow_y,
- "x2", shadow_x + w + DELTA,
- "y2", shadow_y + h + DELTA,
- "width_units", line_width,
- "outline_color_rgba", shadow_line_color,
- "fill_color_rgba", shadow_fill_color,
- NULL);
-
- if (shadow_state)
- {
- gnome_canvas_item_show (view_box->priv->shadow_item);
- }
- else
- {
- gnome_canvas_item_hide (view_box->priv->shadow_item);
- }
-
- gnome_canvas_item_set (view_box->priv->object_item,
- "x2", w + DELTA,
- "y2", h + DELTA,
- "width_units", line_width,
- "outline_color_rgba", line_color_node->color,
- "fill_color_rgba", fill_color_node->color,
- NULL);
-
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&shadow_color_node);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+ gdouble line_width;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+ if (cairo_in_fill (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ line_width = gl_label_object_get_line_width (object);
+ cairo_set_line_width (cr, line_width);
+ if (cairo_in_stroke (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_box_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_box_bits,
- cursor_box_width,
- cursor_box_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_box_mask_bits,
- cursor_box_mask_width,
- cursor_box_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_box_x_hot,
- cursor_box_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_box_bits,
+ cursor_box_width,
+ cursor_box_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_box_mask_bits,
+ cursor_box_mask_width,
+ cursor_box_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_box_x_hot,
+ cursor_box_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating box objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_box_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_box_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_box;
- static GObject *object;
- glColorNode *line_color_node;
- gdouble x, y, w, h;
+ GObject *object;
glColorNode *fill_color_node;
+ glColorNode *line_color_node;
+ glViewObject *view_box;
- gl_debug (DEBUG_VIEW, "");
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- fill_color_node = gl_color_node_new_default ();
- line_color_node = gl_color_node_new_default ();
-
- dragging = TRUE;
- gnome_canvas_item_grab ( canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_box_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- 0.0, 0.0);
- line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
- fill_color_node->color = gl_color_set_opacity (gl_view_get_default_fill_color(view), 0.5);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
- gl_view_get_default_line_width(view));
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- line_color_node);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object),
- fill_color_node);
- view_box = gl_view_box_new (GL_LABEL_BOX(object),
- view);
-
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&line_color_node);
- x0 = x;
- y0 = y;
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- fill_color_node = gl_color_node_new_default ();
- line_color_node = gl_color_node_new_default ();
+ fill_color_node = gl_color_node_new_default ();
+ line_color_node = gl_color_node_new_default ();
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- if ((x0 == x) && (y0 == y)) {
- x = x0 + 36.0;
- y = y0 + 36.0;
- }
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- line_color_node->color = gl_view_get_default_line_color(view);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), line_color_node);
- fill_color_node->color = gl_view_get_default_fill_color(view);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object), fill_color_node);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_box));
- gl_view_arrow_mode (view);
+ object = gl_label_box_new (view->label);
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
+ line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
+ fill_color_node->color = gl_color_set_opacity (gl_view_get_default_fill_color(view), 0.5);
+ gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
+ gl_view_get_default_line_width(view));
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
+ line_color_node);
+ gl_label_object_set_fill_color (GL_LABEL_OBJECT(object),
+ fill_color_node);
+
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&line_color_node);
+
+ gl_view_unselect_all (view);
+ view_box = gl_view_box_new (GL_LABEL_BOX(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_box));
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&line_color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
+}
+
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_box_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
}
+
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_box_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ glColorNode *fill_color_node;
+ glColorNode *line_color_node;
+ gdouble w, h;
+
+ fill_color_node = gl_color_node_new_default ();
+ line_color_node = gl_color_node_new_default ();
+
+ if ((view->create_x0 == x) && (view->create_y0 == y)) {
+ x = view->create_x0 + 36.0;
+ y = view->create_y0 + 36.0;
+ }
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+ line_color_node->color = gl_view_get_default_line_color(view);
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
+ fill_color_node->color = gl_view_get_default_fill_color(view);
+ gl_label_object_set_fill_color (GL_LABEL_OBJECT(view->create_object), fill_color_node);
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&line_color_node);
+}
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_box.h: GLabels canvas item wrapper widget
+ * view_box.h: GLabels label box object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* cursor for creating box objects */
GdkCursor *gl_view_box_get_create_cursor (void);
-/* event handler for creating box objects */
-gint gl_view_box_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_box_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_box_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_box_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_ellipse.c: GLabels label ellipse object widget
+ * view_ellipse.c: GLabels label ellipse object view
*
- * Copyright (C) 2001-2006 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
+#include <math.h>
-#include "view-highlight.h"
+#include "cairo-ellipse-path.h"
#include "color.h"
#include "object-editor.h"
#include "stock.h"
/* Private macros and constants. */
/*========================================================*/
-#define DELTA 0.01
-
/*========================================================*/
/* Private types. */
/*========================================================*/
struct _glViewEllipsePrivate {
- GnomeCanvasItem *object_item;
- GnomeCanvasItem *shadow_item;
};
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
-static void gl_view_ellipse_finalize (GObject *object);
-
-static GtkWidget *construct_properties_editor (glViewObject *view_object);
+static void gl_view_ellipse_finalize (GObject *object);
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewEllipse *view_ellipse);
+static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_object_from_editor_cb (glObjectEditor *editor,
- glLabelObject *object);
+static void update_object_from_editor_cb (glObjectEditor *editor,
+ glLabelObject *object);
-static void update_editor_from_object_cb (glLabelObject *object,
- glObjectEditor *editor);
+static void update_editor_from_object_cb (glLabelObject *object,
+ glObjectEditor *editor);
-static void update_editor_from_move_cb (glLabelObject *object,
- gdouble dx,
- gdouble dy,
- glObjectEditor *editor);
+static void update_editor_from_move_cb (glLabelObject *object,
+ gdouble dx,
+ gdouble dy,
+ glObjectEditor *editor);
static void update_editor_from_label_cb (glLabel *label,
glObjectEditor *editor);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
+
\f
/*****************************************************************************/
/*****************************************************************************/
G_DEFINE_TYPE (glViewEllipse, gl_view_ellipse, GL_TYPE_VIEW_OBJECT);
+
static void
gl_view_ellipse_class_init (glViewEllipseClass *class)
{
object_class->finalize = gl_view_ellipse_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
glViewObject *
gl_view_ellipse_new (glLabelEllipse *object,
- glView *view)
+ glView *view)
{
- glViewEllipse *view_ellipse;
+ glViewEllipse *view_ellipse;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_ELLIPSE (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_val_if_fail (object && GL_IS_LABEL_ELLIPSE (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
view_ellipse = g_object_new (gl_view_ellipse_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_ellipse), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_ellipse),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE);
-
- /* Create analogous canvas items. */
- view_ellipse->priv->shadow_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_ellipse),
- gnome_canvas_ellipse_get_type (),
- NULL);
- view_ellipse->priv->object_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_ellipse),
- gnome_canvas_ellipse_get_type (),
- NULL);
- update_canvas_item_from_object_cb (GL_LABEL_OBJECT(object), view_ellipse);
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_ellipse);
+ GL_VIEW_OBJECT_HANDLES_BOX);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_ellipse), view);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Create a properties editor for an ellipse object. */
+/* Create a properties dialog for a ellipse object. */
/*****************************************************************************/
static GtkWidget *
construct_properties_editor (glViewObject *view_object)
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewEllipse *view_ellipse)
-{
- gdouble line_width;
- glColorNode *line_color_node;
- gdouble w, h;
- glColorNode *fill_color_node;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
- guint shadow_fill_color;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query properties of object. */
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width(GL_LABEL_OBJECT(object));
- line_color_node = gl_label_object_get_line_color(GL_LABEL_OBJECT(object));
- if (line_color_node->field_flag)
- {
- line_color_node->color = GL_COLOR_MERGE_DEFAULT;
- }
- fill_color_node = gl_label_object_get_fill_color(GL_LABEL_OBJECT(object));
- if (fill_color_node->field_flag)
- {
- fill_color_node->color = GL_COLOR_FILL_MERGE_DEFAULT;
- }
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- line_color_node->color);
- shadow_fill_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- fill_color_node->color);
-
- /* Adjust appearance of analogous canvas items. */
- gnome_canvas_item_set (view_ellipse->priv->shadow_item,
- "x1", shadow_x,
- "y1", shadow_y,
- "x2", shadow_x + w + DELTA,
- "y2", shadow_y + h + DELTA,
- "width_units", line_width,
- "outline_color_rgba", shadow_line_color,
- "fill_color_rgba", shadow_fill_color,
- NULL);
-
- if (shadow_state)
- {
- gnome_canvas_item_show (view_ellipse->priv->shadow_item);
- }
- else
- {
- gnome_canvas_item_hide (view_ellipse->priv->shadow_item);
- }
-
- gnome_canvas_item_set (view_ellipse->priv->object_item,
- "x2", w + DELTA,
- "y2", h + DELTA,
- "width_units", line_width,
- "outline_color_rgba", line_color_node->color,
- "fill_color_rgba", fill_color_node->color,
- NULL);
-
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&shadow_color_node);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
gdouble x, y, w, h;
glColorNode *line_color_node;
gdouble line_width;
- glColorNode *fill_color_node;
+ glColorNode *fill_color_node;
gboolean shadow_state;
gdouble shadow_x, shadow_y;
glColorNode *shadow_color_node;
gdouble shadow_opacity;
-
+
gl_debug (DEBUG_VIEW, "START");
gdouble shadow_x, shadow_y;
glColorNode *shadow_color_node;
gdouble shadow_opacity;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
gl_label_object_get_size (object, &w, &h);
gl_object_editor_set_size (editor, w, h);
merge = gl_label_get_merge (GL_LABEL(object->parent));
-
+
fill_color_node = gl_label_object_get_fill_color (GL_LABEL_OBJECT(object));
gl_object_editor_set_fill_color (editor, (merge != NULL), fill_color_node);
gl_color_node_free (&fill_color_node);
glObjectEditor *editor)
{
gdouble label_width, label_height;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+ gdouble line_width;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ gl_cairo_ellipse_path (cr, w/2, h/2);
+
+ if (cairo_in_fill (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ line_width = gl_label_object_get_line_width (object);
+ cairo_set_line_width (cr, line_width);
+ if (cairo_in_stroke (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_ellipse_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_ellipse_bits,
- cursor_ellipse_width,
- cursor_ellipse_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_ellipse_mask_bits,
- cursor_ellipse_mask_width,
- cursor_ellipse_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_ellipse_x_hot,
- cursor_ellipse_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_ellipse_bits,
+ cursor_ellipse_width,
+ cursor_ellipse_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_ellipse_mask_bits,
+ cursor_ellipse_mask_width,
+ cursor_ellipse_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_ellipse_x_hot,
+ cursor_ellipse_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating ellipse objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_ellipse_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_ellipse_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_ellipse;
- static GObject *object;
- glColorNode *line_color_node;
- gdouble x, y, w, h;
+ GObject *object;
glColorNode *fill_color_node;
+ glColorNode *line_color_node;
+ glViewObject *view_ellipse;
- gl_debug (DEBUG_VIEW, "");
-
-
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- fill_color_node = gl_color_node_new_default ();
- line_color_node = gl_color_node_new_default ();
+ fill_color_node = gl_color_node_new_default ();
+ line_color_node = gl_color_node_new_default ();
- dragging = TRUE;
- gnome_canvas_item_grab ( canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_ellipse_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- 0.0, 0.0);
- line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
- fill_color_node->color = gl_color_set_opacity (gl_view_get_default_fill_color(view), 0.5);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
- gl_view_get_default_line_width(view));
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- line_color_node);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object),
- fill_color_node);
- view_ellipse = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object),
- view);
+ object = gl_label_ellipse_new (view->label);
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
+ line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
+ fill_color_node->color = gl_color_set_opacity (gl_view_get_default_fill_color(view), 0.5);
+ gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
+ gl_view_get_default_line_width(view));
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
+ line_color_node);
+ gl_label_object_set_fill_color (GL_LABEL_OBJECT(object),
+ fill_color_node);
+
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&line_color_node);
+
+ gl_view_unselect_all (view);
+ view_ellipse = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_ellipse));
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&line_color_node);
- x0 = x;
- y0 = y;
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- fill_color_node = gl_color_node_new_default ();
- line_color_node = gl_color_node_new_default ();
-
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- if ((x0 == x) && (y0 == y)) {
- x = x0 + 36.0;
- y = y0 + 36.0;
- }
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- line_color_node->color = gl_view_get_default_line_color(view);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), line_color_node);
-
- fill_color_node->color = gl_view_get_default_fill_color(view);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object), fill_color_node);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_ellipse));
- gl_view_arrow_mode (view);
-
- gl_color_node_free (&fill_color_node);
- gl_color_node_free (&line_color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
+}
+
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_ellipse_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+}
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_ellipse_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ glColorNode *fill_color_node;
+ glColorNode *line_color_node;
+ gdouble w, h;
+
+ fill_color_node = gl_color_node_new_default ();
+ line_color_node = gl_color_node_new_default ();
+
+ if ((view->create_x0 == x) && (view->create_y0 == y)) {
+ x = view->create_x0 + 36.0;
+ y = view->create_y0 + 36.0;
+ }
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+ line_color_node->color = gl_view_get_default_line_color(view);
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
+ fill_color_node->color = gl_view_get_default_fill_color(view);
+ gl_label_object_set_fill_color (GL_LABEL_OBJECT(view->create_object), fill_color_node);
+ gl_color_node_free (&fill_color_node);
+ gl_color_node_free (&line_color_node);
}
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_ellipse.h: GLabels canvas item wrapper widget
+ * view_ellipse.h: GLabels label ellipse object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
typedef struct _glViewEllipsePrivate glViewEllipsePrivate;
struct _glViewEllipse {
- glViewObject parent_object;
+ glViewObject parent_object;
- glViewEllipsePrivate *priv;
+ glViewEllipsePrivate *priv;
};
struct _glViewEllipseClass {
- glViewObjectClass parent_class;
+ glViewObjectClass parent_class;
};
GType gl_view_ellipse_get_type (void) G_GNUC_CONST;
glViewObject *gl_view_ellipse_new (glLabelEllipse *object,
- glView *view);
+ glView *view);
/* cursor for creating ellipse objects */
GdkCursor *gl_view_ellipse_get_create_cursor (void);
-/* event handler for creating ellipse objects */
-gint gl_view_ellipse_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_ellipse_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_ellipse_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_ellipse_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * view_highlight.c: GLabels Resizable Highlight module
- *
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <config.h>
-
-#include "view-highlight.h"
-
-#include <math.h>
-
-#include "debug.h"
-
-/*===========================================*/
-/* Private constants and macros. */
-/*===========================================*/
-
-#define MIN_ITEM_SIZE 1.0
-#define FG_COLOR GNOME_CANVAS_COLOR_A (0, 200, 0, 100)
-#define BG_COLOR GNOME_CANVAS_COLOR_A (0, 0, 0, 200)
-#define HANDLE_PIXELS 3.0 /* 2*HANDLE_PIXELS = handle size */
-
-/*===========================================*/
-/* Private data types */
-/*===========================================*/
-
-struct _glViewHighlightPrivate {
- glViewHighlightStyle style;
- glLabelObject *object;
- glView *view;
-
- GnomeCanvasItem *position_group;
- GnomeCanvasItem *group;
- GnomeCanvasItem *outline;
- GnomeCanvasItem *tl, *tr, *bl, *br; /* Corner handles */
- GnomeCanvasItem *sl, *sr, *st, *sb; /* Side handles */
- GnomeCanvasItem *p1, *p2; /* Line endpoint handles */
-};
-
-/*===========================================*/
-/* Private globals */
-/*===========================================*/
-
-
-/*===========================================*/
-/* Local function prototypes */
-/*===========================================*/
-
-static void gl_view_highlight_finalize (GObject *object);
-
-
-static void highlight_resizable_box_construct (glViewHighlight *view_highlight,
- glViewObject *view_object,
- glViewHighlightStyle style);
-
-static void highlight_resizable_line_construct (glViewHighlight *view_highlight,
- glViewObject *view_object);
-
-static void highlight_simple_construct (glViewHighlight *view_highlight,
- glViewObject *view_object);
-
-static void object_moved_cb (glLabelObject *object,
- gdouble x,
- gdouble y,
- glViewHighlight *view_highlight);
-
-static void flip_rotate_object_cb (glLabelObject *object,
- glViewHighlight *view_highlight);
-
-static void object_changed_cb (glLabelObject *object,
- glViewHighlight *view_highlight);
-
-static void view_scale_changed_cb (glView *view,
- gdouble scale,
- glViewHighlight *view_highlight);
-
-
-static void update_resizable_box (glViewHighlight *view_highlight);
-
-static void update_resizable_line (glViewHighlight *view_highlight);
-
-static void update_simple (glViewHighlight *view_highlight);
-
-
-static void get_origin_and_corners (glViewHighlight *view_highlight,
- gdouble *x0,
- gdouble *y0,
- gdouble *x1,
- gdouble *y1,
- gdouble *x2,
- gdouble *y2);
-
-static int tl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int tr_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int bl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int br_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-
-static int sl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int sr_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int st_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int sb_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-
-static int p1_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-static int p2_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight);
-
-static int passthrough_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewObject *view_object);
-\f
-/*****************************************************************************/
-/* Boilerplate object stuff. */
-/*****************************************************************************/
-G_DEFINE_TYPE (glViewHighlight, gl_view_highlight, G_TYPE_OBJECT);
-
-static void
-gl_view_highlight_class_init (glViewHighlightClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- gl_debug (DEBUG_VIEW, "START");
-
- gl_view_highlight_parent_class = g_type_class_peek_parent (class);
-
- object_class->finalize = gl_view_highlight_finalize;
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-static void
-gl_view_highlight_init (glViewHighlight *view_highlight)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- view_highlight->priv = g_new0 (glViewHighlightPrivate, 1);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-static void
-gl_view_highlight_finalize (GObject *object)
-{
- glViewHighlight *view_highlight = GL_VIEW_HIGHLIGHT (object);
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (object && GL_IS_VIEW_HIGHLIGHT (object));
-
- /* Free up handler owned by view. */
- g_signal_handlers_disconnect_by_func (G_OBJECT (view_highlight->priv->view),
- G_CALLBACK (view_scale_changed_cb),
- object);
-
- gtk_object_destroy (GTK_OBJECT(view_highlight->priv->position_group));
-
- if (view_highlight->priv) {
- g_free (view_highlight->priv);
- }
-
- G_OBJECT_CLASS (gl_view_highlight_parent_class)->finalize (object);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*****************************************************************************/
-/* Create a resizable highlight for given object. */
-/*****************************************************************************/
-GObject *
-gl_view_highlight_new (glViewObject *view_object,
- glViewHighlightStyle style)
-{
- glViewHighlight *view_highlight;
- glView *view;
- glLabelObject *object;
- gdouble x, y;
- gdouble affine[6];
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT(view_object));
-
- view = gl_view_object_get_view (view_object);
- object = gl_view_object_get_object (view_object);
- gl_label_object_get_position (object, &x, &y);
-
- view_highlight = g_object_new (gl_view_highlight_get_type (), NULL);
-
- view_highlight->priv->style = style;
- view_highlight->priv->view = view;
- view_highlight->priv->object = object;
- view_highlight->priv->position_group =
- gnome_canvas_item_new (view->highlight_group,
- gnome_canvas_group_get_type (),
- "x", x,
- "y", y,
- NULL);
-
- switch (style) {
-
- case GL_VIEW_HIGHLIGHT_BOX_RESIZABLE:
- case GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE:
- highlight_resizable_box_construct (view_highlight, view_object, style);
- break;
-
- case GL_VIEW_HIGHLIGHT_LINE_RESIZABLE:
- highlight_resizable_line_construct (view_highlight, view_object);
- break;
-
- case GL_VIEW_HIGHLIGHT_SIMPLE:
- highlight_simple_construct (view_highlight, view_object);
- break;
-
- default:
- g_message ("Invalid resizable highlight style");
-
- }
-
-
- gl_label_object_get_affine (view_highlight->priv->object, affine);
- gnome_canvas_item_affine_absolute (view_highlight->priv->group, affine);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->object), "moved",
- G_CALLBACK (object_moved_cb), view_highlight);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->object), "changed",
- G_CALLBACK (object_changed_cb), view_highlight);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->object), "flip_rotate",
- G_CALLBACK (flip_rotate_object_cb), view_highlight);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->view), "zoom_changed",
- G_CALLBACK (view_scale_changed_cb), view_highlight);
-
- gl_debug (DEBUG_VIEW, "END");
-
- return G_OBJECT (view_highlight);
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create a resizable box highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-highlight_resizable_box_construct (glViewHighlight *view_highlight,
- glViewObject *view_object,
- glViewHighlightStyle style)
-{
- gdouble w, h;
- GnomeCanvasItem *group;
- GnomeCanvasGroup *position_group;
- glView *view;
- glLabelObject *object;
- gdouble scale;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
-
- view = view_highlight->priv->view;
- scale = view->zoom * view->home_scale;
-
- object = view_highlight->priv->object;
-
- position_group = GNOME_CANVAS_GROUP(view_highlight->priv->position_group);
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- gl_label_object_get_size (object, &w, &h);
-
- view_highlight->priv->group =
- gnome_canvas_item_new (position_group,
- gnome_canvas_group_get_type (),
- "x", 0.0, "y", 0.0, NULL);
- gnome_canvas_item_hide (view_highlight->priv->group);
- group = view_highlight->priv->group;
-
-#ifdef SHOW_OUTLINE
- switch (style) {
- case GL_VIEW_HIGHLIGHT_BOX_RESIZABLE:
- view_highlight->priv->outline =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -0.5,
- "y1", -0.5,
- "x2", w + 0.5,
- "y2", h + 0.5,
- "width_pixels", 3,
- "outline_color_rgba", FG_COLOR,
- NULL);
- break;
- case GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE:
- view_highlight->priv->outline =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_ellipse_get_type (),
- "x1", -0.5,
- "y1", -0.5,
- "x2", w + 0.5,
- "y2", h + 0.5,
- "width_pixels", 3,
- "outline_color_rgba", FG_COLOR,
- NULL);
- break;
- default:
- view_highlight->priv->outline = NULL;
- g_message ("Invalid resizable highlight style");
- }
-#endif
-
- view_highlight->priv->tl =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->tr =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", w - HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->bl =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->br =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", w - HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->sl =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -HANDLE_PIXELS/scale,
- "y1", h / 2.0 - HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", h / 2.0 + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->sr =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", w - HANDLE_PIXELS/scale,
- "y1", h / 2.0 - HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", h / 2.0 + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->st =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", w / 2.0 - HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", w / 2.0 + HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->sb =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", w / 2.0 - HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", w / 2.0 + HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->tl), "event",
- G_CALLBACK (tl_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->tr), "event",
- G_CALLBACK (tr_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->bl), "event",
- G_CALLBACK (bl_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->br), "event",
- G_CALLBACK (br_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->sl), "event",
- G_CALLBACK (sl_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->sr), "event",
- G_CALLBACK (sr_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->st), "event",
- G_CALLBACK (st_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->sb), "event",
- G_CALLBACK (sb_resize_event_handler), view_highlight);
-
-#ifdef SHOW_OUTLINE
- g_signal_connect (G_OBJECT (view_highlight->priv->outline), "event",
- G_CALLBACK (passthrough_event_handler), view_object);
-#endif
-
- gnome_canvas_item_raise_to_top (group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create a resizable line highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-highlight_resizable_line_construct (glViewHighlight *view_highlight,
- glViewObject *view_object)
-{
- gdouble dx, dy;
- GnomeCanvasItem *group;
- GnomeCanvasGroup *position_group;
-#ifdef SHOW_OUTLINE
- GnomeCanvasPoints *points;
-#endif
- glView *view;
- glLabelObject *object;
- gdouble scale;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
-
- view = view_highlight->priv->view;
- scale = view->zoom * view->home_scale;
-
- object = view_highlight->priv->object;
-
- position_group = GNOME_CANVAS_GROUP(view_highlight->priv->position_group);
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- gl_label_object_get_size (object, &dx, &dy);
-
-#ifdef SHOW_OUTLINE
- points = gnome_canvas_points_new (2);
-#endif
-
- view_highlight->priv->group =
- gnome_canvas_item_new (position_group,
- gnome_canvas_group_get_type (),
- "x", 0.0, "y", 0.0, NULL);
- gnome_canvas_item_hide (view_highlight->priv->group);
- group = view_highlight->priv->group;
-
-#ifdef SHOW_OUTLINE
- points->coords[0] = 0.0;
- points->coords[1] = 0.0;
- points->coords[2] = dx;
- points->coords[3] = dy;
- view_highlight->priv->outline =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_line_get_type (),
- "points", points,
- "width_pixels", 3,
- "fill_color_rgba", FG_COLOR,
- NULL);
-#endif
-
- view_highlight->priv->p1 =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- view_highlight->priv->p2 =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", dx - HANDLE_PIXELS/scale,
- "y1", dy - HANDLE_PIXELS/scale,
- "x2", dx + HANDLE_PIXELS/scale,
- "y2", dy + HANDLE_PIXELS/scale,
- "width_pixels", 1,
- "fill_color_rgba", FG_COLOR,
- "outline_color_rgba", BG_COLOR,
- NULL);
-
- g_signal_connect (G_OBJECT (view_highlight->priv->p1), "event",
- G_CALLBACK (p1_resize_event_handler), view_highlight);
- g_signal_connect (G_OBJECT (view_highlight->priv->p2), "event",
- G_CALLBACK (p2_resize_event_handler), view_highlight);
-
-#ifdef SHOW_OUTLINE
- g_signal_connect (G_OBJECT (view_highlight->priv->outline), "event",
- G_CALLBACK (passthrough_event_handler), view_object);
-#endif
-
-#ifdef SHOW_OUTLINE
- gnome_canvas_points_free (points);
-#endif
-
- gnome_canvas_item_raise_to_top (group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create a simple box highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-highlight_simple_construct (glViewHighlight *view_highlight,
- glViewObject *view_object)
-{
- gdouble w, h;
- GnomeCanvasItem *group;
- GnomeCanvasGroup *position_group;
- glView *view;
- glLabelObject *object;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
-
- view = view_highlight->priv->view;
-
- object = view_highlight->priv->object;
-
- position_group = GNOME_CANVAS_GROUP(view_highlight->priv->position_group);
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- gl_label_object_get_size (object, &w, &h);
-
-
- view_highlight->priv->group =
- gnome_canvas_item_new (position_group,
- gnome_canvas_group_get_type (),
- "x", 0.0, "y", 0.0, NULL);
- gnome_canvas_item_hide (view_highlight->priv->group);
- group = view_highlight->priv->group;
-
- view_highlight->priv->outline =
- gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
- gnome_canvas_rect_get_type (),
- "x1", -0.5,
- "y1", -0.5,
- "x2", w + 0.5,
- "y2", h + 0.5,
- "width_pixels", 3,
- "outline_color_rgba", FG_COLOR,
- NULL);
-
-
- g_signal_connect (G_OBJECT (view_highlight->priv->outline), "event",
- G_CALLBACK (passthrough_event_handler), view_object);
-
- gnome_canvas_item_raise_to_top (group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/****************************************************************************/
-/* Show highlight. */
-/****************************************************************************/
-void
-gl_view_highlight_show (glViewHighlight *view_highlight)
-{
- gnome_canvas_item_show (view_highlight->priv->group);
-
- gnome_canvas_item_raise_to_top (view_highlight->priv->group);
-}
-
-/****************************************************************************/
-/* Hide highlight. */
-/****************************************************************************/
-void
-gl_view_highlight_hide (glViewHighlight *view_highlight)
-{
- gnome_canvas_item_hide (view_highlight->priv->group);
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "moved" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-object_moved_cb (glLabelObject *object,
- gdouble dx,
- gdouble dy,
- glViewHighlight *view_highlight)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- /* Adjust location of outer canvas group. */
- gnome_canvas_item_move (view_highlight->priv->position_group, dx, dy);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Flip/rotate object callback. */
-/*---------------------------------------------------------------------------*/
-static void
-flip_rotate_object_cb (glLabelObject *object,
- glViewHighlight *view_highlight)
-{
- gdouble affine[6];
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Adjust affine of inner canvas group. */
- gl_label_object_get_affine (object, affine);
- gnome_canvas_item_affine_absolute (view_highlight->priv->group, affine);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-object_changed_cb (glLabelObject *object,
- glViewHighlight *view_highlight)
-{
- gdouble affine[6];
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
- g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
-
- switch (view_highlight->priv->style) {
-
- case GL_VIEW_HIGHLIGHT_BOX_RESIZABLE:
- case GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE:
- update_resizable_box (view_highlight);
- break;
-
- case GL_VIEW_HIGHLIGHT_LINE_RESIZABLE:
- update_resizable_line (view_highlight);
- break;
-
- case GL_VIEW_HIGHLIGHT_SIMPLE:
- update_simple (view_highlight);
- break;
-
- default:
- g_message ("Invalid resizable highlight style");
-
- }
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. view scale (zoom) changed callback. */
-/*---------------------------------------------------------------------------*/
-static void
-view_scale_changed_cb (glView *view,
- gdouble scale,
- glViewHighlight *view_highlight)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
- g_return_if_fail (view && GL_IS_VIEW (view));
-
- switch (view_highlight->priv->style) {
-
- case GL_VIEW_HIGHLIGHT_BOX_RESIZABLE:
- case GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE:
- update_resizable_box (view_highlight);
- break;
-
- case GL_VIEW_HIGHLIGHT_LINE_RESIZABLE:
- update_resizable_line (view_highlight);
- break;
-
- case GL_VIEW_HIGHLIGHT_SIMPLE:
- update_simple (view_highlight);
- break;
-
- default:
- g_message ("Invalid resizable highlight style");
-
- }
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Update a resizable box highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-update_resizable_box (glViewHighlight *view_highlight)
-{
- gdouble w, h;
- gdouble scale;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
-
- scale = view_highlight->priv->view->zoom *
- view_highlight->priv->view->home_scale;
-
- gl_label_object_get_size (view_highlight->priv->object, &w, &h);
-
-
-#ifdef SHOW_OUTLINE
- gnome_canvas_item_set (view_highlight->priv->outline,
- "x1", -0.5,
- "y1", -0.5,
- "x2", w + 0.5,
- "y2", h + 0.5,
- NULL);
-#endif
-
- gnome_canvas_item_set (view_highlight->priv->tl,
- "x1", -HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->tr,
- "x1", w - HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->bl,
- "x1", -HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->br,
- "x1", w - HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->sl,
- "x1", -HANDLE_PIXELS/scale,
- "y1", h / 2.0 - HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", h / 2.0 + HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->sr,
- "x1", w - HANDLE_PIXELS/scale,
- "y1", h / 2.0 - HANDLE_PIXELS/scale,
- "x2", w + HANDLE_PIXELS/scale,
- "y2", h / 2.0 + HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->st,
- "x1", w / 2.0 - HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", w / 2.0 + HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->sb,
- "x1", w / 2.0 - HANDLE_PIXELS/scale,
- "y1", h - HANDLE_PIXELS/scale,
- "x2", w / 2.0 + HANDLE_PIXELS/scale,
- "y2", h + HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_raise_to_top (view_highlight->priv->group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Update a resizable line highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-update_resizable_line (glViewHighlight *view_highlight)
-{
- gdouble dx, dy;
-#ifdef SHOW_OUTLINE
- GnomeCanvasPoints *points;
-#endif
- gdouble scale;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
-
- scale = view_highlight->priv->view->zoom *
- view_highlight->priv->view->home_scale;
-
- gl_label_object_get_size (view_highlight->priv->object, &dx, &dy);
-
-#ifdef SHOW_OUTLINE
- points = gnome_canvas_points_new (2);
-
- points->coords[0] = 0.0;
- points->coords[1] = 0.0;
- points->coords[2] = dx;
- points->coords[3] = dy;
- gnome_canvas_item_set (view_highlight->priv->outline, "points", points, NULL);
-#endif
-
- gnome_canvas_item_set (view_highlight->priv->p1,
- "x1", -HANDLE_PIXELS/scale,
- "y1", -HANDLE_PIXELS/scale,
- "x2", +HANDLE_PIXELS/scale,
- "y2", +HANDLE_PIXELS/scale,
- NULL);
-
- gnome_canvas_item_set (view_highlight->priv->p2,
- "x1", dx - HANDLE_PIXELS/scale,
- "y1", dy - HANDLE_PIXELS/scale,
- "x2", dx + HANDLE_PIXELS/scale,
- "y2", dy + HANDLE_PIXELS/scale,
- NULL);
-
-#ifdef SHOW_OUTLINE
- gnome_canvas_points_free (points);
-#endif
-
- gnome_canvas_item_raise_to_top (view_highlight->priv->group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Update a simple box highlight. */
-/*---------------------------------------------------------------------------*/
-static void
-update_simple (glViewHighlight *view_highlight)
-{
- gdouble w, h;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_highlight && GL_IS_VIEW_HIGHLIGHT (view_highlight));
-
- gl_label_object_get_size (view_highlight->priv->object, &w, &h);
-
- gnome_canvas_item_set (view_highlight->priv->outline,
- "x2", w + 0.5,
- "y2", h + 0.5,
- NULL);
-
- gnome_canvas_item_raise_to_top (view_highlight->priv->group);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Get origin and corners relative to object. */
-/*---------------------------------------------------------------------------*/
-static void
-get_origin_and_corners (glViewHighlight *view_highlight,
- gdouble *x0,
- gdouble *y0,
- gdouble *x1,
- gdouble *y1,
- gdouble *x2,
- gdouble *y2)
-{
- glLabelObject *object;
-
- object = view_highlight->priv->object;;
-
- /* origin, relative to item */
- gl_label_object_get_position (object, x0, y0);
- gnome_canvas_item_w2i (view_highlight->priv->group, x0, y0);
-
- /* Top left corner, relative to item */
- *x1 = 0.0;
- *y1 = 0.0;
-
- /* Bottom right corner, relative to item */
- gl_label_object_get_size (object, x2, y2);
-}
-
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Top-left" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-tl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- static gboolean is_control_pressed;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- is_control_pressed = event->button.state & GDK_CONTROL_MASK;
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
- h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->motion.x, MIN_ITEM_SIZE);
- h = MAX (y2 - event->motion.y, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Top-right" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-tr_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- static gboolean is_control_pressed;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- is_control_pressed = event->button.state & GDK_CONTROL_MASK;
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Bottom-left" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-bl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- static gboolean is_control_pressed;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- is_control_pressed = event->button.state & GDK_CONTROL_MASK;
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Bottom-right" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-br_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- static gboolean is_control_pressed;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
- switch (event->button.button) {
- case 1:
- is_control_pressed = event->button.state & GDK_CONTROL_MASK;
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- /* x1 unchanged */
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- if (is_control_pressed) {
- gl_label_object_set_size_honor_aspect (object, w, h);
- } else {
- gl_label_object_set_size (object, w, h);
- }
- x0 = x0 + x1;
- y0 = y0 + y1;
- /* x1 unchanged */
- /* y1 unchanged */
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- gl_debug (DEBUG_VIEW, "ENTER_NOTIFY");
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- gl_debug (DEBUG_VIEW, "LEAVE_NOTIFY");
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- gl_debug (DEBUG_VIEW, "default");
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Left-side" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-sl_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
- h = y2 - y1;
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (x2 - event->button.x, MIN_ITEM_SIZE);
- h = y2 - y1;
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- x1 = x2 - w;
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Right-side" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-sr_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = y2 - y1;
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = MAX (event->button.x - x1, MIN_ITEM_SIZE);
- h = y2 - y1;
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Top-side" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-st_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = x2 - x1;
- h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = x2 - x1;
- h = MAX (y2 - event->button.y, MIN_ITEM_SIZE);
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- y1 = y2 - h;
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. "Bottom-side" Resize event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-sb_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, w, h;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = x2 - x1;
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- w = x2 - x1;
- h = MAX (event->button.y - x1, MIN_ITEM_SIZE);
- gl_label_object_set_size (object, w, h);
- gl_label_object_get_size (object, &w, &h);
- /* x1 unchanged */
- /* y1 unchanged */
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Resize "P1" event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-p1_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, dx, dy;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- x1 = event->button.x;
- y1 = event->button.y;
- dx = (x2 - event->button.x);
- dy = (y2 - event->button.y);
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- gl_label_object_set_size (object, dx, dy);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- x1 = event->button.x;
- y1 = event->button.y;
- dx = (x2 - event->button.x);
- dy = (y2 - event->button.y);
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- gl_label_object_set_size (object, dx, dy);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Resize "P2" event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-p2_resize_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewHighlight *view_highlight)
-{
- gdouble x0, y0, dx, dy;
- gdouble x1, y1, x2, y2;
- static gboolean dragging = FALSE;
- glLabelObject *object;
- GdkCursor *cursor;
-
- if ( view_highlight->priv->view->state != GL_VIEW_STATE_ARROW ) {
- /* don't interfere with object creation modes */
- return FALSE;
- }
-
- object = view_highlight->priv->object;;
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (handle_item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_ungrab (handle_item,
- event->button.time);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- /* x1 unchanged */
- /* y1 unchanged */
- dx = (event->button.x - x1);
- dy = (event->button.y - x1);
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- gl_label_object_set_size (object, dx, dy);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- get_origin_and_corners (view_highlight,
- &x0, &y0, &x1, &y1, &x2, &y2);
- gnome_canvas_item_w2i (view_highlight->priv->group,
- &event->button.x, &event->button.y);
- /* x1 unchanged */
- /* y1 unchanged */
- dx = (event->button.x - x1);
- dy = (event->button.y - x1);
- x0 = x0 + x1;
- y0 = y0 + y1;
- gnome_canvas_item_i2w (view_highlight->priv->group, &x0, &y0);
- gl_label_object_set_position (object, x0, y0);
- gl_label_object_set_size (object, dx, dy);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_ENTER_NOTIFY:
- cursor = gdk_cursor_new (GDK_CROSSHAIR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view_highlight->priv->view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- return FALSE;
- }
-
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Passthrough event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-passthrough_event_handler (GnomeCanvasItem *handle_item,
- GdkEvent *event,
- glViewObject *view_object)
-{
- GnomeCanvasItem *group;
-
- group = gl_view_object_get_group (view_object);
- return gl_view_object_item_event_cb (group, event, view_object);
-}
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * view_highlight.h: GLabels Resizable Highlight module header file
- *
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __VIEW_HIGHLIGHT_H__
-#define __VIEW_HIGHLIGHT_H__
-
-typedef enum {
- GL_VIEW_HIGHLIGHT_BOX_RESIZABLE,
- GL_VIEW_HIGHLIGHT_ELLIPSE_RESIZABLE,
- GL_VIEW_HIGHLIGHT_LINE_RESIZABLE,
- GL_VIEW_HIGHLIGHT_SIMPLE,
-} glViewHighlightStyle;
-
-#include "view.h"
-#include "label-object.h"
-
-G_BEGIN_DECLS
-
-#define GL_TYPE_VIEW_HIGHLIGHT (gl_view_highlight_get_type ())
-#define GL_VIEW_HIGHLIGHT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_VIEW_HIGHLIGHT, glViewHighlight))
-#define GL_VIEW_HIGHLIGHT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_VIEW_HIGHLIGHT, glViewHighlightClass))
-#define GL_IS_VIEW_HIGHLIGHT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_VIEW_HIGHLIGHT))
-#define GL_IS_VIEW_HIGHLIGHT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_VIEW_HIGHLIGHT))
-
-typedef struct _glViewHighlight glViewHighlight;
-typedef struct _glViewHighlightClass glViewHighlightClass;
-
-typedef struct _glViewHighlightPrivate glViewHighlightPrivate;
-
-
-struct _glViewHighlight {
- GObject parent_object;
-
- glViewHighlightPrivate *priv;
-};
-
-struct _glViewHighlightClass {
- GObjectClass parent_class;
-};
-
-
-
-GType gl_view_highlight_get_type (void) G_GNUC_CONST;
-
-GObject *gl_view_highlight_new (glViewObject *view_object,
- glViewHighlightStyle style);
-
-void gl_view_highlight_show (glViewHighlight *view_highlight);
-void gl_view_highlight_hide (glViewHighlight *view_highlight);
-
-G_END_DECLS
-
-#endif
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_image.c: GLabels label image object widget
+ * view_image.c: GLabels label image object view
*
- * Copyright (C) 2001-2003 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
-#include "view-highlight.h"
#include "color.h"
#include "object-editor.h"
#include "stock.h"
/* Private macros and constants. */
/*========================================================*/
-#define MIN_IMAGE_SIZE 0.01
/*========================================================*/
/* Private types. */
/*========================================================*/
struct _glViewImagePrivate {
- GnomeCanvasItem *item;
};
/*========================================================*/
/* Private globals. */
/*========================================================*/
-/* Save state of image file entry */
-static gchar *image_path = NULL;
/*========================================================*/
/* Private function prototypes. */
static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewImage *view_image);
-
static void update_object_from_editor_cb (glObjectEditor *editor,
glLabelObject *object);
static void update_editor_from_label_cb (glLabel *label,
glObjectEditor *editor);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
+
\f
/*****************************************************************************/
/*****************************************************************************/
G_DEFINE_TYPE (glViewImage, gl_view_image, GL_TYPE_VIEW_OBJECT);
+
static void
gl_view_image_class_init (glViewImageClass *class)
{
object_class->finalize = gl_view_image_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
static void
gl_view_image_finalize (GObject *object)
{
- glViewImage *view_image = GL_VIEW_IMAGE (object);
+ glViewImage *view_image = GL_VIEW_IMAGE (object);
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (object && GL_IS_VIEW_IMAGE (object));
- g_free (view_image->priv);
+ g_free (view_image->priv);
G_OBJECT_CLASS (gl_view_image_parent_class)->finalize (object);
/*****************************************************************************/
glViewObject *
gl_view_image_new (glLabelImage *object,
- glView *view)
+ glView *view)
{
- glViewImage *view_image;
- const GdkPixbuf *pixbuf;
- gdouble w, h;
+ glViewImage *view_image;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_IMAGE (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+
+ g_return_val_if_fail (object && GL_IS_LABEL_IMAGE (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
view_image = g_object_new (gl_view_image_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_image), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_image),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
-
- /* Query properties of object. */
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- pixbuf = gl_label_image_get_pixbuf(object, NULL);
-
- /* Create analogous canvas item. */
- view_image->priv->item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_image),
- gnome_canvas_pixbuf_get_type (),
- "x", 0.0,
- "y", 0.0,
- "width_set", TRUE,
- "height_set", TRUE,
- "width", w,
- "height", h,
- "pixbuf", pixbuf,
- NULL);
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_image);
+ GL_VIEW_OBJECT_HANDLES_BOX);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_image), view);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Create a properties editor for an image object. */
+/* Create a properties dialog for a image object. */
/*****************************************************************************/
static GtkWidget *
construct_properties_editor (glViewObject *view_object)
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewImage *view_image)
-{
- const GdkPixbuf *pixbuf;
- gdouble w, h;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query properties of object. */
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- w = MAX (w, MIN_IMAGE_SIZE);
- h = MAX (h, MIN_IMAGE_SIZE);
- pixbuf = gl_label_image_get_pixbuf (GL_LABEL_IMAGE(object), NULL);
-
- /* Adjust appearance of analogous canvas item. */
- gnome_canvas_item_set (view_image->priv->item,
- "width_set", TRUE,
- "height_set", TRUE,
- "width", w,
- "height", h,
- "pixbuf", pixbuf,
- NULL);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
glObjectEditor *editor)
{
gdouble label_width, label_height;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
label_width, label_height);
gl_object_editor_set_max_size (GL_OBJECT_EDITOR (editor),
label_width, label_height);
-
+
merge = gl_label_get_merge (label);
gl_object_editor_set_key_names (editor, merge);
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+ if (cairo_in_fill (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_image_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_image_bits,
- cursor_image_width,
- cursor_image_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_image_mask_bits,
- cursor_image_mask_width,
- cursor_image_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_image_x_hot,
- cursor_image_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_image_bits,
+ cursor_image_width,
+ cursor_image_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_image_mask_bits,
+ cursor_image_mask_width,
+ cursor_image_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_image_x_hot,
+ cursor_image_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating image objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_image_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_image_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_image;
- static GObject *object;
- gdouble x, y, w, h;
-
- gl_debug (DEBUG_VIEW, "");
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- dragging = TRUE;
- gnome_canvas_item_grab (canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_image_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- 1.0, 1.0);
- view_image = gl_view_image_new (GL_LABEL_IMAGE(object),
- view);
- x0 = x;
- y0 = y;
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- if ((x0 == x) && (y0 == y)) {
- x = x0 + 36.0;
- y = y0 + 36.0;
- }
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_image));
- gl_view_arrow_mode (view);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- MIN (x, x0), MIN (y, y0));
- w = MAX (x, x0) - MIN (x, x0);
- h = MAX (y, y0) - MIN (y, y0);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
+ GObject *object;
+ glViewObject *view_image;
+
+ object = gl_label_image_new (view->label);
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
+
+ gl_view_unselect_all (view);
+ view_image = gl_view_image_new (GL_LABEL_IMAGE(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_image));
+
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
+}
+
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_image_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
}
+
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_image_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+
+ if ((view->create_x0 == x) && (view->create_y0 == y)) {
+ x = view->create_x0 + 36.0;
+ y = view->create_y0 + 36.0;
+ }
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object),
+ MIN (x, view->create_x0), MIN (y, view->create_y0));
+ w = MAX (x, view->create_x0) - MIN (x, view->create_x0);
+ h = MAX (y, view->create_y0) - MIN (y, view->create_y0);
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+}
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_image.h: GLabels canvas item wrapper widget
+ * view_image.h: GLabels label image object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
typedef struct _glViewImagePrivate glViewImagePrivate;
struct _glViewImage {
- glViewObject parent_object;
+ glViewObject parent_object;
- glViewImagePrivate *priv;
+ glViewImagePrivate *priv;
};
struct _glViewImageClass {
- glViewObjectClass parent_class;
+ glViewObjectClass parent_class;
};
GType gl_view_image_get_type (void) G_GNUC_CONST;
glViewObject *gl_view_image_new (glLabelImage *object,
- glView *view);
+ glView *view);
/* cursor for creating image objects */
GdkCursor *gl_view_image_get_create_cursor (void);
-/* event handler for creating image objects */
-gint gl_view_image_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_image_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_image_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_image_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_line.c: GLabels label line object widget
+ * view_line.c: GLabels label line object view
*
- * Copyright (C) 2001-2006 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
-#include "view-highlight.h"
#include "color.h"
#include "object-editor.h"
#include "stock.h"
/* Private macros and constants. */
/*========================================================*/
+
/*========================================================*/
/* Private types. */
/*========================================================*/
struct _glViewLinePrivate {
- GnomeCanvasItem *object_item;
- GnomeCanvasItem *shadow_item;
};
/*========================================================*/
/* Private globals. */
/*========================================================*/
+
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewLine *view_line);
-
static void update_object_from_editor_cb (glObjectEditor *editor,
glLabelObject *object);
static void update_editor_from_label_cb (glLabel *label,
glObjectEditor *editor);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
+
\f
/*****************************************************************************/
/*****************************************************************************/
G_DEFINE_TYPE (glViewLine, gl_view_line, GL_TYPE_VIEW_OBJECT);
+
static void
gl_view_line_class_init (glViewLineClass *class)
{
object_class->finalize = gl_view_line_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
}
/*****************************************************************************/
-/* NEW line object view. */
+/* NEW line object view. */
/*****************************************************************************/
glViewObject *
gl_view_line_new (glLabelLine *object,
- glView *view)
+ glView *view)
{
- glViewLine *view_line;
+ glViewLine *view_line;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_LINE (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_val_if_fail (object && GL_IS_LABEL_LINE (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
view_line = g_object_new (gl_view_line_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_line), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_line),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_LINE_RESIZABLE);
-
- /* Create analogous canvas item. */
- view_line->priv->shadow_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_line),
- gnome_canvas_line_get_type (),
- NULL);
- view_line->priv->object_item =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_line),
- gnome_canvas_line_get_type (),
- NULL);
- update_canvas_item_from_object_cb (GL_LABEL_OBJECT(object), view_line);
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_line);
+ GL_VIEW_OBJECT_HANDLES_LINE);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_line), view);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Create a properties editor for a line object. */
+/* Create a properties dialog for a line object. */
/*****************************************************************************/
static GtkWidget *
construct_properties_editor (glViewObject *view_object)
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewLine *view_line)
-{
- gdouble line_width;
- glColorNode *line_color_node;
- gdouble w, h;
- GnomeCanvasPoints *points;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_line_color;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query properties of object. */
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- line_width = gl_label_object_get_line_width(GL_LABEL_OBJECT(object));
- line_color_node = gl_label_object_get_line_color(GL_LABEL_OBJECT(object));
- if (line_color_node->field_flag)
- {
- line_color_node->color = GL_COLOR_MERGE_DEFAULT;
- }
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_line_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- line_color_node->color);
-
- /* Adjust appearance of analogous canvas item. */
- points = gnome_canvas_points_new (2);
- points->coords[0] = shadow_x;
- points->coords[1] = shadow_y;
- points->coords[2] = shadow_x + w;
- points->coords[3] = shadow_y + h;
- gnome_canvas_item_set (view_line->priv->shadow_item,
- "points", points,
- "width_units", line_width,
- "fill_color_rgba", shadow_line_color,
- NULL);
-
- if (shadow_state)
- {
- gnome_canvas_item_show (view_line->priv->shadow_item);
- }
- else
- {
- gnome_canvas_item_hide (view_line->priv->shadow_item);
- }
-
- points->coords[0] = 0.0;
- points->coords[1] = 0.0;
- points->coords[2] = w;
- points->coords[3] = h;
- gnome_canvas_item_set (view_line->priv->object_item,
- "points", points,
- "width_units", line_width,
- "fill_color_rgba", line_color_node->color,
- NULL);
-
- gnome_canvas_points_free (points);
-
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&shadow_color_node);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
gdouble shadow_x, shadow_y;
glColorNode *shadow_color_node;
gdouble shadow_opacity;
+
gl_debug (DEBUG_VIEW, "START");
update_editor_from_move_cb,
editor);
-
gl_object_editor_get_position (editor, &x, &y);
gl_label_object_set_position (object, x, y);
gl_object_editor_get_lsize (editor, &w, &h);
gl_label_object_set_size (object, w, h);
-
+
line_color_node = gl_object_editor_get_line_color (editor);
gl_label_object_set_line_color (object, line_color_node);
gl_color_node_free (&line_color_node);
shadow_opacity = gl_object_editor_get_shadow_opacity (editor);
gl_label_object_set_shadow_opacity (object, shadow_opacity);
-
g_signal_handlers_unblock_by_func (G_OBJECT(object),
update_editor_from_object_cb,
editor);
gl_label_object_get_size (object, &w, &h);
gl_object_editor_set_lsize (editor, w, h);
-
merge = gl_label_get_merge (GL_LABEL(object->parent));
-
+
line_color_node = gl_label_object_get_line_color (GL_LABEL_OBJECT(object));
gl_object_editor_set_line_color (editor, (merge != NULL), line_color_node);
gl_color_node_free (&line_color_node);
glObjectEditor *editor)
{
gdouble label_width, label_height;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
gl_object_editor_set_max_position (GL_OBJECT_EDITOR (editor),
label_width, label_height);
gl_object_editor_set_max_lsize (GL_OBJECT_EDITOR (editor),
- label_width, label_height);
+ label_width, label_height);
gl_object_editor_set_max_shadow_offset (GL_OBJECT_EDITOR (editor),
label_width, label_height);
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+ gdouble line_width;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ cairo_move_to (cr, 0.0, 0.0);
+ cairo_line_to (cr, w, h);
+
+ line_width = gl_label_object_get_line_width (object);
+ cairo_set_line_width (cr, line_width);
+ if (cairo_in_stroke (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_line_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_line_bits,
- cursor_line_width,
- cursor_line_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_line_mask_bits,
- cursor_line_mask_width,
- cursor_line_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_line_x_hot,
- cursor_line_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_line_bits,
+ cursor_line_width,
+ cursor_line_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_line_mask_bits,
+ cursor_line_mask_width,
+ cursor_line_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_line_x_hot,
+ cursor_line_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating line objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_line_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_line_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_line;
- static GObject *object;
- gdouble x, y, w, h;
+ GObject *object;
glColorNode *line_color_node;
+ glViewObject *view_line;
+
+ line_color_node = gl_color_node_new_default ();
+
+ object = gl_label_line_new (view->label);
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ gl_label_object_set_size (GL_LABEL_OBJECT(object), 0.0, 0.0);
+ line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
+ gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
+ gl_view_get_default_line_width(view));
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
+ line_color_node);
+
+ gl_color_node_free (&line_color_node);
+
+ gl_view_unselect_all (view);
+ view_line = gl_view_line_new (GL_LABEL_LINE(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_line));
+
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
+}
- gl_debug (DEBUG_VIEW, "");
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- switch (event->button.button) {
- case 1:
- line_color_node = gl_color_node_new_default ();
- dragging = TRUE;
- gnome_canvas_item_grab (canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_line_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- 0.0, 0.0);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object),
- gl_view_get_default_line_width(view));
- line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- line_color_node);
- view_line = gl_view_line_new (GL_LABEL_LINE(object),
- view);
- x0 = x;
- y0 = y;
- gl_color_node_free (&line_color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- switch (event->button.button) {
- case 1:
- line_color_node = gl_color_node_new_default ();
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- if ((x0 == x) && (y0 == y)) {
- x = x0 + 36.0;
- y = y0 + 36.0;
- }
- w = x - x0;
- h = y - y0;
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- line_color_node->color = gl_view_get_default_line_color(view);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
- line_color_node);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_line));
- gl_view_arrow_mode (view);
- gl_color_node_free (&line_color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- w = x - x0;
- h = y - y0;
- gl_label_object_set_size (GL_LABEL_OBJECT(object),
- w, h);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_line_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ gdouble w, h;
+ w = x - view->create_x0;
+ h = y - view->create_y0;
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
}
+
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_line_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
+{
+ glColorNode *line_color_node;
+ gdouble w, h;
+
+ line_color_node = gl_color_node_new_default ();
+
+ if ((view->create_x0 == x) && (view->create_y0 == y)) {
+ x = view->create_x0 + 36.0;
+ y = view->create_y0 + 36.0;
+ }
+ w = x - view->create_x0;
+ h = y - view->create_y0;
+ gl_label_object_set_size (GL_LABEL_OBJECT(view->create_object), w, h);
+ line_color_node->color = gl_view_get_default_line_color(view);
+ gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
+ gl_color_node_free (&line_color_node);
+}
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_line.h: GLabels canvas item wrapper widget
+ * view_line.h: GLabels label line object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
typedef struct _glViewLinePrivate glViewLinePrivate;
struct _glViewLine {
- glViewObject parent_object;
+ glViewObject parent_object;
- glViewLinePrivate *priv;
+ glViewLinePrivate *priv;
};
struct _glViewLineClass {
- glViewObjectClass parent_class;
+ glViewObjectClass parent_class;
};
GType gl_view_line_get_type (void) G_GNUC_CONST;
glViewObject *gl_view_line_new (glLabelLine *object,
- glView *view);
+ glView *view);
/* cursor for creating line objects */
GdkCursor *gl_view_line_get_create_cursor (void);
-/* event handler for creating line objects */
-gint gl_view_line_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_line_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_line_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_line_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
*
* view_object.c: GLabels label object base class
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <glib.h>
#include "view-object.h"
-#include "libart_lgpl/libart.h"
+#include <glib.h>
#include "debug.h"
/* Private constants and macros. */
/*========================================================*/
-/* Used for a workaround for a bug with images when flipped or rotated by 90 degrees. */
-#define DELTA_DEG 0.001
+#define HANDLE_PIXELS 7
/*========================================================*/
/* Private types. */
struct _glViewObjectPrivate {
- glView *view;
glLabelObject *object;
- GnomeCanvasItem *group;
- glViewHighlight *highlight;
+ glView *view;
+ glViewObjectHandlesStyle handles_style;
GtkWidget *property_editor;
};
static void gl_view_object_finalize (GObject *object);
-static void object_moved_cb (glLabelObject *object,
- gdouble x,
- gdouble y,
- glViewObject *view_object);
-
-static void raise_object_cb (glLabelObject *object,
- glViewObject *view_object);
-
-static void lower_object_cb (glLabelObject *object,
- glViewObject *view_object);
-
-static void flip_rotate_object_cb (glLabelObject *object,
- glViewObject *view_object);
-
-static gint item_event_arrow_mode (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object);
g_list_remove (view->selected_object_list, object);
g_object_unref (view_object->priv->object);
- g_object_unref (G_OBJECT(view_object->priv->highlight));
- gtk_object_destroy (GTK_OBJECT(view_object->priv->group));
if (view_object->priv->property_editor) {
gtk_object_destroy (GTK_OBJECT(view_object->priv->property_editor));
}
view_object->priv->view = view;
- view->object_list = g_list_prepend (view->object_list, view_object);
+ view->object_list = g_list_append (view->object_list, view_object);
+
+ g_signal_connect_swapped (G_OBJECT (view_object->priv->object), "changed",
+ G_CALLBACK (gl_view_update), view);
+ g_signal_connect_swapped (G_OBJECT (view_object->priv->object), "moved",
+ G_CALLBACK (gl_view_update), view);
gl_debug (DEBUG_VIEW, "END");
}
/* Set Label object to follow. */
/*****************************************************************************/
void
-gl_view_object_set_object (glViewObject *view_object,
- glLabelObject *object,
- glViewHighlightStyle style)
+gl_view_object_set_object (glViewObject *view_object,
+ glLabelObject *object,
+ glViewObjectHandlesStyle style)
{
- GnomeCanvas *canvas;
- GnomeCanvasGroup *root;
- gdouble x, y, w, h;
-
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
view_object->priv->object = object;
-
- gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y);
- gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
-
- /* create canvas group to contain items representing object */
- view_object->priv->group =
- gnome_canvas_item_new (view_object->priv->view->label_group,
- gnome_canvas_group_get_type (),
- "x", x,
- "y", y,
- NULL);
-
- /* Create appropriate selection highlight canvas item. */
- view_object->priv->highlight =
- GL_VIEW_HIGHLIGHT (gl_view_highlight_new (view_object, style));
-
- g_signal_connect (G_OBJECT (object), "moved",
- G_CALLBACK (object_moved_cb),
- view_object);
-
- g_signal_connect (G_OBJECT (object), "top",
- G_CALLBACK (raise_object_cb),
- view_object);
-
- g_signal_connect (G_OBJECT (object), "bottom",
- G_CALLBACK (lower_object_cb),
- view_object);
-
- g_signal_connect (G_OBJECT (object), "flip_rotate",
- G_CALLBACK (flip_rotate_object_cb),
- view_object);
-
- g_signal_connect (G_OBJECT (view_object->priv->group), "event",
- G_CALLBACK (gl_view_object_item_event_cb),
- view_object);
+ view_object->priv->handles_style = style;
gl_debug (DEBUG_VIEW, "END");
}
{
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+ g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), NULL);
gl_debug (DEBUG_VIEW, "END");
{
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+ g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), NULL);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Return canvas item representing our object in this view. */
-/*****************************************************************************/
-GnomeCanvasItem *
-gl_view_object_get_group (glViewObject *view_object)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
-
- gl_debug (DEBUG_VIEW, "END");
-
- return view_object->priv->group;
-}
-
-/*****************************************************************************/
-/* Create canvas item for this object. */
+/* Get property editor. */
/*****************************************************************************/
-GnomeCanvasItem *
-gl_view_object_item_new (glViewObject *view_object,
- GType type,
- const gchar *first_arg_name,
- ...)
+GtkWidget *
+gl_view_object_get_editor (glViewObject *view_object)
{
- GnomeCanvasItem *item;
- va_list args;
- gdouble affine[6], delta_affine[6];
-
gl_debug (DEBUG_VIEW, "START");
g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), NULL);
- item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(view_object->priv->group),
- type, NULL);
+ if ( GL_VIEW_OBJECT_GET_CLASS(view_object)->construct_editor != NULL ) {
+
+ if (view_object->priv->property_editor == NULL) {
+ view_object->priv->property_editor =
+ GL_VIEW_OBJECT_GET_CLASS(view_object)->construct_editor (view_object);
+ }
+ g_signal_connect (G_OBJECT (view_object->priv->property_editor),
+ "destroy",
+ G_CALLBACK (gtk_widget_destroyed),
+ &view_object->priv->property_editor);
- va_start (args, first_arg_name);
- gnome_canvas_item_set_valist (item, first_arg_name, args);
- va_end (args);
+ gtk_widget_show (view_object->priv->property_editor);
- gl_label_object_get_affine (view_object->priv->object, affine);
+ }
- /* Apply a very small rotation, fixes problems with flipped or rotated images */
- art_affine_rotate (delta_affine, DELTA_DEG);
- art_affine_multiply (affine, affine, delta_affine);
-
- gnome_canvas_item_affine_absolute (item, affine);
gl_debug (DEBUG_VIEW, "END");
- return item;
+ return view_object->priv->property_editor;
}
+
/*****************************************************************************/
-/* Highlight view of object. */
+/* Select object. */
/*****************************************************************************/
void
-gl_view_object_show_highlight (glViewObject *view_object)
+gl_view_object_select (glViewObject *view_object)
{
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
- g_return_if_fail (view_object->priv->highlight);
-
- gl_view_highlight_show (view_object->priv->highlight);
+ gl_view_select_object(view_object->priv->view, view_object);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Remove highlight from view of object. */
+/* Is object at (x,y)? */
/*****************************************************************************/
-void
-gl_view_object_hide_highlight (glViewObject *view_object)
+gboolean
+gl_view_object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
{
+ glLabelObject *object = view_object->priv->object;
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gboolean return_val = FALSE;
+
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
- g_return_if_fail (view_object->priv->highlight);
-
- gl_view_highlight_hide (view_object->priv->highlight);
+ g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), FALSE);
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), FALSE);
- gl_debug (DEBUG_VIEW, "END");
-}
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
+ cairo_save (cr);
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
-/*****************************************************************************/
-/* Get property editor. */
-/*****************************************************************************/
-GtkWidget *
-gl_view_object_get_editor (glViewObject *view_object)
-{
- gl_debug (DEBUG_VIEW, "START");
+ cairo_device_to_user (cr, &x, &y);
- g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), NULL);
+ if ( GL_VIEW_OBJECT_GET_CLASS(view_object)->object_at != NULL ) {
- if ( GL_VIEW_OBJECT_GET_CLASS(view_object)->construct_editor != NULL ) {
+ return_val = GL_VIEW_OBJECT_GET_CLASS(view_object)->object_at (view_object, cr, x, y);
- if (view_object->priv->property_editor == NULL) {
- view_object->priv->property_editor =
- GL_VIEW_OBJECT_GET_CLASS(view_object)->construct_editor (view_object);
- }
- g_signal_connect (G_OBJECT (view_object->priv->property_editor),
- "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &view_object->priv->property_editor);
-
- gtk_widget_show (view_object->priv->property_editor);
+ }
- }
+ cairo_restore (cr);
+ return return_val;
gl_debug (DEBUG_VIEW, "END");
-
- return view_object->priv->property_editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Object moved callback. */
-/*---------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
+/* Create handle path */
+/*--------------------------------------------------------------------------*/
static void
-object_moved_cb (glLabelObject *object,
- gdouble dx,
- gdouble dy,
- glViewObject *view_object)
+create_handle_path (cairo_t *cr,
+ glLabelObject *object,
+ gdouble scale,
+ gdouble x_handle,
+ gdouble y_handle)
{
- gl_debug (DEBUG_VIEW, "START");
+ gl_debug (DEBUG_VIEW, "START");
- /* Adjust location of analogous canvas group. */
- gnome_canvas_item_move (view_object->priv->group, dx, dy);
+ cairo_rectangle (cr,
+ x_handle - HANDLE_PIXELS/scale/2, y_handle - HANDLE_PIXELS/scale/2,
+ HANDLE_PIXELS/scale, HANDLE_PIXELS/scale);
- gl_debug (DEBUG_VIEW, "END");
+ gl_debug (DEBUG_VIEW, "END");
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. raise item to front callback. */
-/*---------------------------------------------------------------------------*/
-static void
-raise_object_cb (glLabelObject *object,
- glViewObject *view_object)
+/*****************************************************************************/
+/* Draw object handles */
+/*****************************************************************************/
+void
+gl_view_object_draw_handles (glViewObject *view_object,
+ cairo_t *cr)
{
+ glLabelObject *object = view_object->priv->object;
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble scale;
+ gdouble w, h;
+
gl_debug (DEBUG_VIEW, "START");
- /* send to top */
- gnome_canvas_item_raise_to_top (view_object->priv->group);
+ g_return_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object));
+ g_return_if_fail (object && GL_IS_LABEL_OBJECT (object));
- gl_debug (DEBUG_VIEW, "END");
-}
+ scale = view_object->priv->view->home_scale * view_object->priv->view->zoom;
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. lower item to back callback. */
-/*---------------------------------------------------------------------------*/
-static void
-lower_object_cb (glLabelObject *object,
- glViewObject *view_object)
-{
- gl_debug (DEBUG_VIEW, "START");
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
- /* Send to bottom */
- gnome_canvas_item_lower_to_bottom (view_object->priv->group);
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- gl_debug (DEBUG_VIEW, "END");
-}
+ cairo_save (cr);
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Flip/rotate object callback. */
-/*---------------------------------------------------------------------------*/
-static void
-flip_rotate_object_cb (glLabelObject *object,
- glViewObject *view_object)
-{
- gdouble affine[6], delta_affine[6];
- GList *p, *item_list;
- GnomeCanvasItem *item;
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
- gl_debug (DEBUG_VIEW, "START");
+ switch (view_object->priv->handles_style)
+ {
+ case GL_VIEW_OBJECT_HANDLES_BOX:
- gl_label_object_get_affine (object, affine);
+ /* North */
+ cairo_new_path (cr);
+ create_handle_path (cr, object, scale, w/2, 0);
- /* Apply a very small rotation, fixes problems with flipped or rotated images */
- art_affine_rotate (delta_affine, DELTA_DEG);
- art_affine_multiply (affine, affine, delta_affine);
-
- item_list = GNOME_CANVAS_GROUP(view_object->priv->group)->item_list;
- for ( p=item_list; p != NULL; p=p->next ) {
- item = GNOME_CANVAS_ITEM(p->data);
- gnome_canvas_item_affine_absolute (item, affine);
- }
+ /* North East */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, w, 0);
+
+ /* East */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, w, h/2);
+
+ /* South East */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, w, h);
+
+ /* South */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, w/2, h);
+
+ /* South West */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, 0, h);
+
+ /* West */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, 0, h/2);
+
+ /* North West */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, 0, 0);
+
+ break;
+
+ case GL_VIEW_OBJECT_HANDLES_LINE:
+ /* P1 */
+ cairo_new_path (cr);
+ create_handle_path (cr, object, scale, 0, 0);
+
+ /* P2 */
+ cairo_new_sub_path (cr);
+ create_handle_path (cr, object, scale, w, h);
+
+ break;
+ }
+
+ cairo_set_source_rgba (cr, 0, 0.75, 0, 0.4);
+ cairo_fill_preserve (cr);
+
+ cairo_set_line_width (cr, 1/scale);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.8);
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Select object. */
+/* Is there an object handle at (x,y). */
/*****************************************************************************/
-void
-gl_view_object_select (glViewObject *view_object)
+glViewObjectHandle
+gl_view_object_handle_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
{
+ glLabelObject *object = view_object->priv->object;
+ gdouble x0, y0;
+ cairo_matrix_t matrix;
+ gdouble scale;
+ gdouble w, h;
+ glViewObjectHandle handle = GL_VIEW_OBJECT_HANDLE_NONE;
+
gl_debug (DEBUG_VIEW, "START");
- gl_view_select_object(view_object->priv->view, view_object);
+ g_return_val_if_fail (view_object && GL_IS_VIEW_OBJECT (view_object), handle);
+ g_return_val_if_fail (object && GL_IS_LABEL_OBJECT (object), handle);
- gl_debug (DEBUG_VIEW, "END");
-}
+ scale = view_object->priv->view->home_scale * view_object->priv->view->zoom;
-/*****************************************************************************/
-/* Item event handler. */
-/*****************************************************************************/
-gint
-gl_view_object_item_event_cb (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object)
-{
- glView *view;
+ gl_label_object_get_position (object, &x0, &y0);
+ gl_label_object_get_matrix (object, &matrix);
- gl_debug (DEBUG_VIEW, "");
+ gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h);
- view = gl_view_object_get_view(view_object);
- switch (view->state) {
+ cairo_save (cr);
- case GL_VIEW_STATE_ARROW:
- return item_event_arrow_mode (item, event, view_object);
+ cairo_translate (cr, x0, y0);
+ cairo_transform (cr, &matrix);
- default:
- return FALSE;
+ cairo_device_to_user (cr, &x, &y);
- }
+ switch (view_object->priv->handles_style)
+ {
+ case GL_VIEW_OBJECT_HANDLES_BOX:
-}
+ /* South East */
+ create_handle_path (cr, object, scale, w, h);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_SE; break;}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Item event handler (arrow mode) */
-/*---------------------------------------------------------------------------*/
-static gint
-item_event_arrow_mode (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object)
-{
- static gdouble x, y;
- static gboolean dragging = FALSE;
- glView *view;
- GdkCursor *cursor;
- gdouble item_x, item_y;
- gdouble new_x, new_y;
- gboolean control_key_pressed;
-
- gl_debug (DEBUG_VIEW, "");
-
- item_x = event->button.x;
- item_y = event->button.y;
- gnome_canvas_item_w2i (item->parent, &item_x, &item_y);
-
- view = gl_view_object_get_view(view_object);
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
- control_key_pressed = event->button.state & GDK_CONTROL_MASK;
- switch (event->button.button) {
- case 1:
- if (control_key_pressed) {
- if (gl_view_is_object_selected (view, view_object)) {
- /* Un-selecting a selected item */
- gl_view_unselect_object (view,
- view_object);
- return TRUE;
- } else {
- /* Add to current selection */
- gl_view_select_object (view,
- view_object);
- }
- } else {
- if (!gl_view_is_object_selected (view, view_object)) {
- /* No control, key so remove any selections before adding */
- gl_view_unselect_all (view);
- /* Add to current selection */
- gl_view_select_object (view,
- view_object);
- }
- }
- /* Go into dragging mode while button remains pressed. */
- x = item_x;
- y = item_y;
- cursor = gdk_cursor_new (GDK_FLEUR);
- gnome_canvas_item_grab (item,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- cursor, event->button.time);
- gdk_cursor_unref (cursor);
- dragging = TRUE;
- return TRUE;
-
- default:
- return FALSE;
- }
+ /* South West */
+ create_handle_path (cr, object, scale, 0, h);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_SW; break;}
- case GDK_BUTTON_RELEASE:
- gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
- switch (event->button.button) {
- case 1:
- /* Exit dragging mode */
- gnome_canvas_item_ungrab (item, event->button.time);
- dragging = FALSE;
- return TRUE;
-
- default:
- return FALSE;
- }
+ /* North East */
+ create_handle_path (cr, object, scale, w, 0);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_NE; break;}
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- /* Dragging mode, move selection */
- new_x = item_x;
- new_y = item_y;
- gl_view_move_selection (view, (new_x - x), (new_y - y));
- x = new_x;
- y = new_y;
- return TRUE;
- } else {
- return FALSE;
- }
+ /* North West */
+ create_handle_path (cr, object, scale, 0, 0);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_NW; break;}
- case GDK_2BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "2BUTTON_PRESS");
- switch (event->button.button) {
- case 1:
- /* Also exit dragging mode w/ double-click */
- gnome_canvas_item_ungrab (item, event->button.time);
- dragging = FALSE;
- gl_view_select_object (view, view_object);
- return TRUE;
-
- default:
- return FALSE;
- }
+ /* East */
+ create_handle_path (cr, object, scale, w, h/2);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_E; break;}
- case GDK_ENTER_NOTIFY:
- gl_debug (DEBUG_VIEW, "ENTER_NOTIFY");
- cursor = gdk_cursor_new (GDK_FLEUR);
- gdk_window_set_cursor (view->canvas->window, cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- gl_debug (DEBUG_VIEW, "LEAVE_NOTIFY");
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view->canvas->window, cursor);
- gdk_cursor_unref (cursor);
- return TRUE;
-
- default:
- gl_debug (DEBUG_VIEW, "default");
- return FALSE;
- }
+ /* South */
+ create_handle_path (cr, object, scale, w/2, h);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_S; break;}
+
+ /* West */
+ create_handle_path (cr, object, scale, 0, h/2);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_W; break;}
+
+ /* North */
+ create_handle_path (cr, object, scale, w/2, 0);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_N; break;}
+
+ break;
+
+ case GL_VIEW_OBJECT_HANDLES_LINE:
+ /* P2 */
+ create_handle_path (cr, object, scale, w, h);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_P2; break;}
+ /* P1 */
+ create_handle_path (cr, object, scale, 0, 0);
+ if (cairo_in_fill (cr, x, y)) {handle = GL_VIEW_OBJECT_HANDLE_P1; break;}
+
+ break;
+
+ }
+
+ cairo_restore (cr);
+
+ return handle;
}
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Resize object. */
+/*---------------------------------------------------------------------------*/
+void
+gl_view_object_resize_event (glViewObject *view_object,
+ glViewObjectHandle handle,
+ gboolean honor_aspect,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ cairo_matrix_t matrix;
+ gdouble x0, y0, x1, y1, x2, y2;
+ gdouble w, h;
+ gdouble dx=0, dy=0;
+
+ gl_debug (DEBUG_VIEW, "x,y world = %g, %g", x, y);
+
+ object = view_object->priv->object;
+
+ /*
+ * Change to item relative coordinates
+ */
+ cairo_save (cr);
+ gl_label_object_get_position (object, &x0, &y0);
+ cairo_translate (cr, x0, y0);
+ gl_label_object_get_matrix (object, &matrix);
+ cairo_transform (cr, &matrix);
+
+ /*
+ * Initialize origin and 2 corners in object relative coordinates.
+ */
+ x0 = 0.0;
+ y0 = 0.0;
+
+ x1 = 0.0;
+ y1 = 0.0;
+
+ gl_label_object_get_size (object, &x2, &y2);
+
+ gl_debug (DEBUG_VIEW, "x0,y0 object = %g, %g", x0, y0);
+ gl_debug (DEBUG_VIEW, "x1,y1 object = %g, %g", x1, y1);
+ gl_debug (DEBUG_VIEW, "x2,y2 object = %g, %g", x2, y2);
+
+ /*
+ * Translate x,y into object relative coordinates.
+ */
+ cairo_device_to_user (cr, &x, &y);
+
+ gl_debug (DEBUG_VIEW, "x,y object = %g, %g", x, y);
+
+ /*
+ * Get new size
+ */
+ switch (handle)
+ {
+
+ case GL_VIEW_OBJECT_HANDLE_NW:
+ w = MAX (x2 - x, 0);
+ h = MAX (y2 - y, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_N:
+ w = x2 - x1;
+ h = MAX (y2 - y, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_NE:
+ w = MAX (x - x1, 0);
+ h = MAX (y2 - y, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_E:
+ w = MAX (x - x1, 0);
+ h = y2 - y1;
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_SE:
+ w = MAX (x - x1, 0);
+ h = MAX (y - y1, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_S:
+ w = x2 - x1;
+ h = MAX (y - y1, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_SW:
+ w = MAX (x2 - x, 0);
+ h = MAX (y - y1, 0);
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_W:
+ w = MAX (x2 - x, 0);
+ h = y2 - y1;
+ break;
+ case GL_VIEW_OBJECT_HANDLE_P1:
+ x1 = x;
+ y1 = y;
+ dx = (x2 - x);
+ dy = (y2 - y);
+ x0 = x0 + x1;
+ y0 = y0 + y1;
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_P2:
+ dx = x - x1;
+ dy = y - y1;
+ x0 = x0 + x1;
+ y0 = y0 + y1;
+ break;
+
+ default:
+ g_print ("Invalid handle.\n"); /* Should not happen! */
+
+ }
+ if ( (handle != GL_VIEW_OBJECT_HANDLE_P1) && (handle != GL_VIEW_OBJECT_HANDLE_P2) )
+ {
+ if ( honor_aspect )
+ {
+ gl_label_object_set_size_honor_aspect (object, w, h);
+ }
+ else
+ {
+ gl_label_object_set_size (object, w, h);
+ }
+
+ /*
+ * Query the new size in case it was constrained.
+ */
+ gl_label_object_get_size (object, &w, &h);
+
+ /*
+ * Get new position
+ */
+ switch (handle)
+ {
+
+ case GL_VIEW_OBJECT_HANDLE_NW:
+ x0 += x2 - w;
+ y0 += y2 - h;
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_N:
+ case GL_VIEW_OBJECT_HANDLE_NE:
+ /* x unchanged */
+ y0 += y2 - h;
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_E:
+ case GL_VIEW_OBJECT_HANDLE_SE:
+ case GL_VIEW_OBJECT_HANDLE_S:
+ /* unchanged */
+ break;
+
+ case GL_VIEW_OBJECT_HANDLE_SW:
+ case GL_VIEW_OBJECT_HANDLE_W:
+ x0 += x2 - w;
+ /* y unchanged */
+ break;
+
+ default:
+ g_print ("Invalid handle.\n"); /* Should not happen! */
+ }
+ }
+ else
+ {
+ gl_label_object_set_size (object, dx, dy);
+ }
+
+ /*
+ * Put new origin back into world coordinates and set.
+ */
+ cairo_user_to_device (cr, &x0, &y0);
+ cairo_restore (cr);
+ cairo_device_to_user (cr, &x0, &y0);
+ gl_label_object_set_position (object, x0, y0);
+}
*
* view_object.h: GLabels canvas item wrapper widget
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib-object.h>
#include "label-object.h"
+typedef enum {
+ GL_VIEW_OBJECT_HANDLES_BOX,
+ GL_VIEW_OBJECT_HANDLES_LINE,
+} glViewObjectHandlesStyle;
+
+typedef enum {
+ GL_VIEW_OBJECT_HANDLE_NONE = 0,
+ GL_VIEW_OBJECT_HANDLE_N,
+ GL_VIEW_OBJECT_HANDLE_E,
+ GL_VIEW_OBJECT_HANDLE_W,
+ GL_VIEW_OBJECT_HANDLE_S,
+ GL_VIEW_OBJECT_HANDLE_NW,
+ GL_VIEW_OBJECT_HANDLE_NE,
+ GL_VIEW_OBJECT_HANDLE_SE,
+ GL_VIEW_OBJECT_HANDLE_SW,
+ GL_VIEW_OBJECT_HANDLE_P1,
+ GL_VIEW_OBJECT_HANDLE_P2,
+} glViewObjectHandle;
+
+
#define GL_TYPE_VIEW_OBJECT (gl_view_object_get_type ())
#define GL_VIEW_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_VIEW_OBJECT, glViewObject))
#define GL_VIEW_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_VIEW_OBJECT, glViewObjectClass))
#include "view.h"
-#include "view-highlight.h"
+
+#include "cairo.h"
struct _glViewObject {
GObject parent_object;
*/
GtkWidget * (*construct_editor) (glViewObject *view_object);
+
+ gboolean (*object_at) (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x_device,
+ gdouble y_device);
};
-G_BEGIN_DECLS
-GType gl_view_object_get_type (void) G_GNUC_CONST;
-GObject *gl_view_object_new (void);
+G_BEGIN_DECLS
+
+GType gl_view_object_get_type (void) G_GNUC_CONST;
+GObject *gl_view_object_new (void);
-void gl_view_object_set_view (glViewObject *view_object,
- glView *view);
-void gl_view_object_set_object (glViewObject *view_object,
- glLabelObject *object,
- glViewHighlightStyle style);
+void gl_view_object_set_view (glViewObject *view_object,
+ glView *view);
-glView *gl_view_object_get_view (glViewObject *view_object);
+void gl_view_object_set_object (glViewObject *view_object,
+ glLabelObject *object,
+ glViewObjectHandlesStyle style);
-glLabelObject *gl_view_object_get_object (glViewObject *view_object);
+gboolean gl_view_object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
-GnomeCanvasItem *gl_view_object_get_group (glViewObject *view_object);
+void gl_view_object_draw_handles (glViewObject *view_object,
+ cairo_t *cr);
-GnomeCanvasItem *gl_view_object_item_new (glViewObject *view_object,
- GType type,
- const gchar *first_arg_name,
- ...);
+glViewObjectHandle gl_view_object_handle_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
-void gl_view_object_show_highlight (glViewObject *view_object);
+glView *gl_view_object_get_view (glViewObject *view_object);
-void gl_view_object_hide_highlight (glViewObject *view_object);
+glLabelObject *gl_view_object_get_object (glViewObject *view_object);
-GtkWidget *gl_view_object_get_editor (glViewObject *view_object);
+GtkWidget *gl_view_object_get_editor (glViewObject *view_object);
-void gl_view_object_select (glViewObject *view_object);
+void gl_view_object_select (glViewObject *view_object);
+void gl_view_object_resize_event (glViewObject *view_object,
+ glViewObjectHandle handle,
+ gboolean honor_aspect,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
-gint gl_view_object_item_event_cb (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object);
G_END_DECLS
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_text.c: GLabels label text object widget
+ * view_text.c: GLabels label text object view
*
- * Copyright (C) 2001-2006 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <glib/gmem.h>
-#include <gtk/gtkmenu.h>
-#include <libgnomeprint/gnome-glyphlist.h>
-
-#include "canvas-hacktext.h"
-#include "view-highlight.h"
#include "color.h"
#include "object-editor.h"
/* Private macros and constants. */
/*========================================================*/
-#define CURSOR_COLOR GL_COLOR_A (0, 0, 255, 128)
-
-#define CURSOR_ON_TIME 800
-#define CURSOR_OFF_TIME 400
-
/*========================================================*/
/* Private types. */
/*========================================================*/
struct _glViewTextPrivate {
-
- GList *object_item_list;
- GList *shadow_item_list;
-
-#ifdef EDIT_TEXT_IN_PLACE
- GnomeCanvasItem *cursor;
- gboolean cursor_visible;
- gboolean cursor_state;
- guint cursor_timeout;
-#endif
};
/*========================================================*/
/* Private globals. */
/*========================================================*/
+
/*========================================================*/
/* Private function prototypes. */
/*========================================================*/
-static void gl_view_text_finalize (GObject *object);
-
-static GtkWidget *construct_properties_editor (glViewObject *view_object);
-
-static void update_canvas_item_from_object_cb (glLabelObject *object,
- glViewText *view_text);
+static void gl_view_text_finalize (GObject *object);
-static void update_object_from_editor_cb (glObjectEditor *editor,
- glLabelObject *object);
+static GtkWidget *construct_properties_editor (glViewObject *view_object);
-static void update_object_from_editor_size_cb (glObjectEditor *editor,
- glLabelObject *object);
+static void update_object_from_editor_cb (glObjectEditor *editor,
+ glLabelObject *object);
-static void update_editor_from_object_cb (glLabelObject *object,
- glObjectEditor *editor);
+static void update_object_from_editor_size_cb (glObjectEditor *editor,
+ glLabelObject *object);
-static void update_editor_from_move_cb (glLabelObject *object,
- gdouble dx,
- gdouble dy,
- glObjectEditor *editor);
+static void update_editor_from_object_cb (glLabelObject *object,
+ glObjectEditor *editor);
-static void update_editor_from_label_cb (glLabel *label,
- glObjectEditor *editor);
+static void update_editor_from_move_cb (glLabelObject *object,
+ gdouble dx,
+ gdouble dy,
+ glObjectEditor *editor);
-static void draw_hacktext (glViewText *view_text);
+static void update_editor_from_label_cb (glLabel *label,
+ glObjectEditor *editor);
-static void draw_cursor (glViewText *view_text);
+static gboolean object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
-static void mark_set_cb (GtkTextBuffer *textbuffer,
- GtkTextIter *iter,
- GtkTextMark *mark,
- glViewText *view_text);
-
-static void blink_start (glViewText *view_text);
-static void blink_stop (glViewText *view_text);
-static gboolean blink_cb (glViewText *view_text);
-
-static gint item_event_cb (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object);
\f
/*****************************************************************************/
G_DEFINE_TYPE (glViewText, gl_view_text, GL_TYPE_VIEW_OBJECT);
+
static void
gl_view_text_class_init (glViewTextClass *class)
{
object_class->finalize = gl_view_text_finalize;
view_object_class->construct_editor = construct_properties_editor;
+ view_object_class->object_at = object_at;
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
glViewObject *
gl_view_text_new (glLabelText *object,
- glView *view)
+ glView *view)
{
glViewText *view_text;
- GnomeCanvasItem *group;
-#ifdef EDIT_TEXT_IN_PLACE
- GtkTextBuffer *buffer;
-#endif
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (object && GL_IS_LABEL_TEXT (object));
- g_return_if_fail (view && GL_IS_VIEW (view));
+
+ g_return_val_if_fail (object && GL_IS_LABEL_TEXT (object), NULL);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
view_text = g_object_new (gl_view_text_get_type(), NULL);
- gl_view_object_set_view (GL_VIEW_OBJECT(view_text), view);
gl_view_object_set_object (GL_VIEW_OBJECT(view_text),
GL_LABEL_OBJECT(object),
- GL_VIEW_HIGHLIGHT_BOX_RESIZABLE);
-
- group = gl_view_object_get_group (GL_VIEW_OBJECT(view_text));
-
- /* Create analogous canvas item. */
- draw_hacktext (view_text);
-#ifdef EDIT_TEXT_IN_PLACE
- draw_cursor (view_text);
-#endif
-
- g_signal_connect (G_OBJECT (object), "changed",
- G_CALLBACK (update_canvas_item_from_object_cb), view_text);
-
- g_signal_connect (G_OBJECT (group), "event",
- G_CALLBACK (item_event_cb), view_text);
-
-#ifdef EDIT_TEXT_IN_PLACE
- buffer = gl_label_text_get_buffer (object);
- g_signal_connect (G_OBJECT (buffer), "mark-set",
- G_CALLBACK (mark_set_cb), view_text);
-#endif
+ GL_VIEW_OBJECT_HANDLES_BOX);
+ gl_view_object_set_view (GL_VIEW_OBJECT(view_text), view);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Create a properties editor for a text object. */
+/* Create a properties dialog for a text object. */
/*****************************************************************************/
static GtkWidget *
construct_properties_editor (glViewObject *view_object)
return editor;
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. label object "changed" callback. */
-/*---------------------------------------------------------------------------*/
-static void
-update_canvas_item_from_object_cb (glLabelObject *object,
- glViewText *view_text)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- /* Adjust appearance of analogous canvas item. */
- draw_hacktext (view_text);
-#ifdef EDIT_TEXT_IN_PLACE
- draw_cursor (view_text);
-#endif
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. editor "changed" callback. */
/*---------------------------------------------------------------------------*/
gdouble x, y;
gchar *font_family;
gdouble font_size;
- GnomeFontWeight font_weight;
+ PangoWeight font_weight;
gboolean font_italic_flag;
glColorNode *color_node;
PangoAlignment align;
gdouble shadow_x, shadow_y;
glColorNode *shadow_color_node;
gdouble shadow_opacity;
- glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
gdouble w, h;
gchar *font_family;
gdouble font_size;
- GnomeFontWeight font_weight;
+ PangoWeight font_weight;
gboolean font_italic_flag;
glColorNode *color_node;
PangoAlignment align;
glObjectEditor *editor)
{
gdouble label_width, label_height;
- glMerge *merge;
+ glMerge *merge;
gl_debug (DEBUG_VIEW, "START");
label_width, label_height);
gl_object_editor_set_max_shadow_offset (GL_OBJECT_EDITOR (editor),
label_width, label_height);
-
+
merge = gl_label_get_merge (label);
gl_object_editor_set_key_names (editor, merge);
gl_debug (DEBUG_VIEW, "END");
}
+/*****************************************************************************/
+/* Is object at (x,y)? */
+/*****************************************************************************/
+static gboolean
+object_at (glViewObject *view_object,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
+{
+ glLabelObject *object;
+ gdouble w, h;
+
+ object = gl_view_object_get_object (view_object);
+
+ gl_label_object_get_size (object, &w, &h);
+
+ cairo_rectangle (cr, 0.0, 0.0, w, h);
+
+ if (cairo_in_fill (cr, x, y))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/*****************************************************************************/
/* Return apropos cursor for create object mode. */
/*****************************************************************************/
GdkCursor *
gl_view_text_get_create_cursor (void)
{
- static GdkCursor *cursor = NULL;
- GdkPixmap *pixmap_data, *pixmap_mask;
+ GdkCursor *cursor = NULL;
+ GdkPixmap *pixmap_data, *pixmap_mask;
GdkColor fg = { 0, 0, 0, 0 };
GdkColor bg = { 0, 65535, 65535, 65535 };
gl_debug (DEBUG_VIEW, "START");
- if (!cursor) {
- pixmap_data = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_text_bits,
- cursor_text_width,
- cursor_text_height);
- pixmap_mask = gdk_bitmap_create_from_data (NULL,
- (gchar *)cursor_text_mask_bits,
- cursor_text_mask_width,
- cursor_text_mask_height);
- cursor =
- gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
- &bg, cursor_text_x_hot,
- cursor_text_y_hot);
- }
+ pixmap_data = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_text_bits,
+ cursor_text_width,
+ cursor_text_height);
+ pixmap_mask = gdk_bitmap_create_from_data (NULL,
+ (gchar *)cursor_text_mask_bits,
+ cursor_text_mask_width,
+ cursor_text_mask_height);
+ cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
+ &bg, cursor_text_x_hot,
+ cursor_text_y_hot);
gl_debug (DEBUG_VIEW, "END");
}
/*****************************************************************************/
-/* Canvas event handler for creating text objects. */
+/* Object creation handler: button press event. */
/*****************************************************************************/
-int
-gl_view_text_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
+void
+gl_view_text_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static glViewObject *view_text;
- static GObject *object;
- gdouble x, y;
+ GObject *object;
+ glViewObject *view_text;
GList *lines;
gchar *family;
glColorNode *color_node;
- gl_debug (DEBUG_VIEW, "");
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
- switch (event->button.button) {
- case 1:
- color_node = gl_color_node_new_default ();
- dragging = TRUE;
- gnome_canvas_item_grab (canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- object = gl_label_text_new (view->label);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- family = gl_view_get_default_font_family (view);
- gl_label_object_set_font_family (GL_LABEL_OBJECT(object), family);
- gl_label_object_set_font_size (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_size (view));
- gl_label_object_set_font_weight (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_weight (view));
- gl_label_object_set_font_italic_flag (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_italic_flag (view));
+ object = gl_label_text_new (view->label);
+ color_node = gl_color_node_new_default ();
+ gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
+ family = gl_view_get_default_font_family (view);
+ gl_label_object_set_font_family (GL_LABEL_OBJECT(object), family);
+ gl_label_object_set_font_size (GL_LABEL_OBJECT(object),
+ gl_view_get_default_font_size (view));
+ gl_label_object_set_font_weight (GL_LABEL_OBJECT(object),
+ gl_view_get_default_font_weight (view));
+ gl_label_object_set_font_italic_flag (GL_LABEL_OBJECT(object),
+ gl_view_get_default_font_italic_flag (view));
- color_node->color = gl_color_set_opacity (gl_view_get_default_text_color (view), 0.5);
- gl_label_object_set_text_color (GL_LABEL_OBJECT(object),
+ color_node->color = gl_color_set_opacity (gl_view_get_default_text_color (view), 0.5);
+ gl_label_object_set_text_color (GL_LABEL_OBJECT(object),
color_node);
- gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object),
- gl_view_get_default_text_alignment (view));
- gl_label_object_set_text_line_spacing (GL_LABEL_OBJECT(object), gl_view_get_default_text_line_spacing (view));
+ gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object),
+ gl_view_get_default_text_alignment (view));
+ gl_label_object_set_text_line_spacing (GL_LABEL_OBJECT(object), gl_view_get_default_text_line_spacing (view));
- g_free (family);
- lines = gl_text_node_lines_new_from_text (_("Text"));
- gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
- view_text = gl_view_text_new (GL_LABEL_TEXT(object),
- view);
- x0 = x;
- y0 = y;
- gl_color_node_free (&color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
- switch (event->button.button) {
- case 1:
- color_node = gl_color_node_new_default ();
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root, event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- family = gl_view_get_default_font_family (view);
- gl_label_object_set_font_family (GL_LABEL_OBJECT(object), family);
- gl_label_object_set_font_size (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_size (view));
- gl_label_object_set_font_weight (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_weight (view));
- gl_label_object_set_font_italic_flag (GL_LABEL_OBJECT(object),
- gl_view_get_default_font_italic_flag (view));
+ g_free (family);
+ lines = gl_text_node_lines_new_from_text (_("Text"));
+ gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
+ view_text = gl_view_text_new (GL_LABEL_TEXT(object), view);
+ gl_color_node_free (&color_node);
+
+ gl_view_unselect_all (view);
+ view_text = gl_view_text_new (GL_LABEL_TEXT(object), view);
+ gl_view_object_select (GL_VIEW_OBJECT(view_text));
- color_node->color = gl_view_get_default_text_color (view);
- gl_label_object_set_text_color (GL_LABEL_OBJECT(object),
- color_node);
- gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object),
- gl_view_get_default_text_alignment (view));
- gl_label_object_set_text_line_spacing (GL_LABEL_OBJECT(object), gl_view_get_default_text_line_spacing (view));
-
- g_free (family);
- gl_view_unselect_all (view);
- gl_view_object_select (GL_VIEW_OBJECT(view_text));
- gl_view_arrow_mode (view);
- gl_color_node_free (&color_node);
- return TRUE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- gl_label_object_set_position (GL_LABEL_OBJECT(object),
- x, y);
- return TRUE;
- } else {
- return FALSE;
- }
-
- default:
- return FALSE;
- }
-
+ view->create_object = GL_LABEL_OBJECT (object);
+ view->create_x0 = x;
+ view->create_y0 = y;
}
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Draw hacktext to item (group). */
-/*--------------------------------------------------------------------------*/
-static void
-draw_hacktext (glViewText *view_text)
-{
- glLabelObject *object;
- GnomeCanvasItem *item;
- GtkTextBuffer *buffer;
- GtkTextIter start, end;
- gchar *text;
- gchar *font_family;
- GnomeFontWeight font_weight;
- gboolean font_italic_flag;
- gdouble font_size;
- gdouble text_line_spacing;
- glColorNode *color_node;
- PangoAlignment align;
- GnomeFont *font;
- GnomeGlyphList *glyphlist;
- ArtDRect bbox;
- gdouble affine[6];
- gdouble x_offset, y_offset, w, object_w, object_h;
- gint i;
- gchar **line;
- GList *li;
- gboolean shadow_state;
- gdouble shadow_x, shadow_y;
- glColorNode *shadow_color_node;
- gdouble shadow_opacity;
- guint shadow_color;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query label object and properties */
- object = gl_view_object_get_object (GL_VIEW_OBJECT(view_text));
- gl_label_object_get_size (object, &object_w, &object_h);
- font_family = gl_label_object_get_font_family (object);
- font_size = gl_label_object_get_font_size (object);
- text_line_spacing = gl_label_object_get_text_line_spacing (object);
- font_weight = gl_label_object_get_font_weight (object);
- font_italic_flag = gl_label_object_get_font_italic_flag (object);
- color_node = gl_label_object_get_text_color (object);
- if (color_node->field_flag)
- {
- color_node->color = GL_COLOR_MERGE_DEFAULT;
- }
- align = gl_label_object_get_text_alignment (object);
- buffer = gl_label_text_get_buffer(GL_LABEL_TEXT(object));
- gtk_text_buffer_get_bounds (buffer, &start, &end);
- text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
- line = g_strsplit (text, "\n", -1);
- shadow_state = gl_label_object_get_shadow_state (GL_LABEL_OBJECT (object));
- gl_label_object_get_shadow_offset (GL_LABEL_OBJECT (object), &shadow_x, &shadow_y);
- shadow_color_node = gl_label_object_get_shadow_color (GL_LABEL_OBJECT (object));
- if (shadow_color_node->field_flag)
- {
- shadow_color_node->color = GL_COLOR_SHADOW_MERGE_DEFAULT;
- }
- shadow_opacity = gl_label_object_get_shadow_opacity (GL_LABEL_OBJECT (object));
- shadow_color = gl_color_shadow (shadow_color_node->color,
- shadow_opacity,
- color_node->color);
-
- /* remove previous items from group. */
- for (li = view_text->priv->object_item_list; li != NULL; li = li->next) {
- gl_debug (DEBUG_VIEW, "in loop");
- gtk_object_destroy (GTK_OBJECT (li->data));
- }
- for (li = view_text->priv->shadow_item_list; li != NULL; li = li->next) {
- gl_debug (DEBUG_VIEW, "in loop");
- gtk_object_destroy (GTK_OBJECT (li->data));
- }
- gl_debug (DEBUG_VIEW, "1");
- g_list_free (view_text->priv->object_item_list);
- g_list_free (view_text->priv->shadow_item_list);
- view_text->priv->object_item_list = NULL;
- view_text->priv->shadow_item_list = NULL;
- gl_debug (DEBUG_VIEW, "2");
-
- /* get Gnome Font */
- font = gnome_font_find_closest_from_weight_slant ((guchar *)font_family,
- font_weight,
- font_italic_flag,
- font_size);
- art_affine_identity (affine);
-
- if (shadow_state)
- {
- /* render to group, one item per line. */
- for (i = 0; line[i] != NULL; i++) {
-
- glyphlist = gnome_glyphlist_from_text_dumb (font,
- shadow_color,
- 0.0, 0.0,
- (guchar *)line[i]);
-
- gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
- w = bbox.x1;
-
- switch (align) {
- case PANGO_ALIGN_LEFT:
- x_offset = GL_LABEL_TEXT_MARGIN;
- break;
- case PANGO_ALIGN_CENTER:
- x_offset = (object_w - GL_LABEL_TEXT_MARGIN - w) / 2.0;
- break;
- case PANGO_ALIGN_RIGHT:
- x_offset = object_w - GL_LABEL_TEXT_MARGIN - w;
- break;
- default:
- x_offset = 0.0;
- break; /* shouldn't happen */
- }
-
- /* Work out the y position to the BOTTOM of the first line */
- y_offset = GL_LABEL_TEXT_MARGIN +
- + gnome_font_get_descender (font)
- + (i + 1) * font_size * text_line_spacing;
-
- /* Remove any text line spacing from the first row. */
- y_offset -= font_size * (text_line_spacing - 1);
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_text),
- gl_canvas_hacktext_get_type (),
- "x", x_offset + shadow_x,
- "y", y_offset + shadow_y,
- "glyphlist", glyphlist, NULL);
-
- gnome_glyphlist_unref (glyphlist);
-
- view_text->priv->shadow_item_list =
- g_list_prepend (view_text->priv->shadow_item_list, item);
-
- }
- }
-
- /* render to group, one item per line. */
- for (i = 0; line[i] != NULL; i++) {
-
- glyphlist = gnome_glyphlist_from_text_dumb (font, color_node->color,
- 0.0, 0.0,
- (guchar *)line[i]);
-
- gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
- w = bbox.x1;
-
- switch (align) {
- case PANGO_ALIGN_LEFT:
- x_offset = GL_LABEL_TEXT_MARGIN;
- break;
- case PANGO_ALIGN_CENTER:
- x_offset = (object_w - GL_LABEL_TEXT_MARGIN - w) / 2.0;
- break;
- case PANGO_ALIGN_RIGHT:
- x_offset = object_w - GL_LABEL_TEXT_MARGIN - w;
- break;
- default:
- x_offset = 0.0;
- break; /* shouldn't happen */
- }
-
- /* Work out the y position to the BOTTOM of the first line */
- y_offset = GL_LABEL_TEXT_MARGIN +
- + gnome_font_get_descender (font)
- + (i + 1) * font_size * text_line_spacing;
-
- /* Remove any text line spacing from the first row. */
- y_offset -= font_size * (text_line_spacing - 1);
-
- item = gl_view_object_item_new (GL_VIEW_OBJECT(view_text),
- gl_canvas_hacktext_get_type (),
- "x", x_offset,
- "y", y_offset,
- "glyphlist", glyphlist, NULL);
-
- gnome_glyphlist_unref (glyphlist);
-
- view_text->priv->object_item_list =
- g_list_prepend (view_text->priv->object_item_list, item);
-
- }
-
- /* clean up */
- g_free (font_family);
- gl_color_node_free (&color_node);
- g_strfreev (line);
- g_free (text);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-#ifdef EDIT_TEXT_IN_PLACE
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Draw cursor to item (group). */
-/*--------------------------------------------------------------------------*/
-static void
-draw_cursor (glViewText *view_text)
-{
- glLabelObject *object;
- GnomeCanvasItem *item;
- GtkTextBuffer *buffer;
- GtkTextIter start, end;
- gchar *text;
- gchar *font_family;
- GnomeFontWeight font_weight;
- gboolean font_italic_flag;
- gdouble font_size;
- glColorNode *color_node;
- PangoAlignment align;
- GnomeFont *font;
- GnomeGlyphList *glyphlist;
- ArtDRect bbox;
- gdouble affine[6];
- gdouble x_offset, w, object_w, object_h;
- gint i;
- gchar **line;
- GList *li;
- GtkTextMark *cursor_mark, *bound_mark;
- GtkTextIter cursor_iter, bound_iter;
- gint cursor_line, cursor_char, bound_line, bound_char;
- gboolean selection_flag;
-
- gl_debug (DEBUG_VIEW, "START");
-
- /* Query label object and properties */
- object = gl_view_object_get_object (GL_VIEW_OBJECT(view_text));
- gl_label_object_get_size (object, &object_w, &object_h);
- font_family = gl_label_object_get_font_family (object);
- font_size = gl_label_object_get_font_size (object);
- font_weight = gl_label_object_get_font_weight (object);
- font_italic_flag = gl_label_object_get_font_italic_flag (object);
- color_node = gl_label_object_get_text_color (object);
- align = gl_label_object_get_text_alignment (object);
- buffer = gl_label_text_get_buffer(GL_LABEL_TEXT(object));
- gtk_text_buffer_get_bounds (buffer, &start, &end);
- text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
- line = g_strsplit (text, "\n", -1);
-
- /* Get cursor and selection information. */
- cursor_mark = gtk_text_buffer_get_insert (buffer);
- bound_mark = gtk_text_buffer_get_selection_bound (buffer);
- gtk_text_buffer_get_iter_at_mark (buffer, &cursor_iter, cursor_mark);
- gtk_text_buffer_get_iter_at_mark (buffer, &bound_iter, bound_mark);
- cursor_line = gtk_text_iter_get_line (&cursor_iter);
- cursor_char = gtk_text_iter_get_visible_line_index (&cursor_iter);
- bound_line = gtk_text_iter_get_line (&bound_iter);
- bound_char = gtk_text_iter_get_visible_line_index (&bound_iter);
- selection_flag = !gtk_text_iter_equal (&cursor_iter, &bound_iter);
-
- /* get Gnome Font */
- font = gnome_font_find_closest_from_weight_slant ((guchar *)font_family,
- font_weight,
- font_italic_flag,
- font_size);
- art_affine_identity (affine);
-
- for (i = 0; line[i] != NULL; i++) {
-
- if ( i == cursor_line ) {
- GnomeCanvasPoints *points;
-
- glyphlist = gnome_glyphlist_from_text_dumb (font, color_node->color,
- 0.0, 0.0,
- (guchar *)line[i]);
-
- gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
- gnome_glyphlist_unref (glyphlist);
- w = bbox.x1;
-
- switch (align) {
- case PANGO_ALIGN_LEFT:
- x_offset = GL_LABEL_TEXT_MARGIN;
- break;
- case PANGO_ALIGN_CENTER:
- x_offset = (object_w - GL_LABEL_TEXT_MARGIN - w) / 2.0;
- break;
- case PANGO_ALIGN_RIGHT:
- x_offset = object_w - GL_LABEL_TEXT_MARGIN - w;
- break;
- default:
- x_offset = 0.0;
- break; /* shouldn't happen */
- }
-
- glyphlist = gnome_glyphlist_from_text_sized_dumb (font, color_node->color,
- 0.0, 0.0,
- (guchar *)line[i],
- cursor_char);
- gnome_glyphlist_bbox (glyphlist, affine, 0, &bbox);
- gnome_glyphlist_unref (glyphlist);
- x_offset += bbox.x1;
-
- points = gnome_canvas_points_new (2);
- points->coords[0] = x_offset;
- points->coords[1] = GL_LABEL_TEXT_MARGIN + i*font_size;
- points->coords[2] = x_offset;
- points->coords[3] = GL_LABEL_TEXT_MARGIN + (i+1)*font_size;
-
- if (view_text->priv->cursor) {
- gtk_object_destroy (GTK_OBJECT (view_text->priv->cursor));
- }
- view_text->priv->cursor =
- gl_view_object_item_new (GL_VIEW_OBJECT(view_text),
- gnome_canvas_line_get_type (),
- "points", points,
- "fill_color_rgba", CURSOR_COLOR,
- "width_pixels", 2,
- NULL);
- gnome_canvas_points_free (points);
-
- if ( !view_text->priv->cursor_visible ) {
- gnome_canvas_item_hide (view_text->priv->cursor);
- }
-
- }
-
- }
-
- /* clean up */
- gl_color_node_free (&color_node);
- g_strfreev (line);
- g_free (text);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Text buffer "mark-set" callback. Tracks cursor position. */
-/*--------------------------------------------------------------------------*/
-static void
-mark_set_cb (GtkTextBuffer *textbuffer,
- GtkTextIter *iter,
- GtkTextMark *mark,
- glViewText *view_text)
-{
- const gchar *mark_name;
-
- mark_name = gtk_text_mark_get_name (mark);
-
- if ( mark_name && !strcmp (mark_name, "insert") ) {
- draw_cursor (view_text);
- }
-}
-
-
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Start the cursor blinking. */
-/*--------------------------------------------------------------------------*/
-static void
-blink_start (glViewText *view_text)
-{
- if ( !view_text->priv->cursor_visible ) return;
-
- view_text->priv->cursor_state = TRUE;
- gnome_canvas_item_show (view_text->priv->cursor);
- view_text->priv->cursor_timeout =
- gtk_timeout_add (CURSOR_ON_TIME, (GtkFunction)blink_cb, view_text);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Stop the cursor blinking. */
-/*--------------------------------------------------------------------------*/
-static void
-blink_stop (glViewText *view_text)
+/*****************************************************************************/
+/* Object creation handler: motion event. */
+/*****************************************************************************/
+void
+gl_view_text_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- if ( view_text->priv->cursor_timeout ) {
- gtk_timeout_remove (view_text->priv->cursor_timeout);
- view_text->priv->cursor_timeout = 0;
- }
-
- gnome_canvas_item_hide (view_text->priv->cursor);
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
}
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Blink cursor timeout callback. */
-/*--------------------------------------------------------------------------*/
-static gboolean
-blink_cb (glViewText *view_text)
+/*****************************************************************************/
+/* Object creation handler: button relesase event. */
+/*****************************************************************************/
+void
+gl_view_text_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y)
{
- if ( view_text->priv->cursor_visible ) {
-
- view_text->priv->cursor_state =
- !view_text->priv->cursor_state;
-
-
- if ( view_text->priv->cursor_state ) {
- gnome_canvas_item_show (view_text->priv->cursor);
- view_text->priv->cursor_timeout =
- gtk_timeout_add (CURSOR_ON_TIME,
- (GtkFunction)blink_cb, view_text);
- } else {
- gnome_canvas_item_hide (view_text->priv->cursor);
- view_text->priv->cursor_timeout =
- gtk_timeout_add (CURSOR_OFF_TIME,
- (GtkFunction)blink_cb, view_text);
- }
-
- }
+ glColorNode *color_node;
- return FALSE;
+ color_node = gl_color_node_new_default ();
+ gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
+ color_node->color = gl_view_get_default_text_color(view);
+ gl_label_object_set_text_color (GL_LABEL_OBJECT(view->create_object), color_node);
+ gl_color_node_free (&color_node);
}
-#endif /* EDIT_TEXT_IN_PLACE */
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Item event callback. */
-/*--------------------------------------------------------------------------*/
-static gint
-item_event_cb (GnomeCanvasItem *item,
- GdkEvent *event,
- glViewObject *view_object)
-{
- gl_debug (DEBUG_VIEW, "");
-}
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
- * view_text.h: GLabels canvas item wrapper widget
+ * view_text.h: GLabels label text object view
*
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
typedef struct _glViewTextPrivate glViewTextPrivate;
struct _glViewText {
- glViewObject parent_object;
+ glViewObject parent_object;
- glViewTextPrivate *priv;
+ glViewTextPrivate *priv;
};
struct _glViewTextClass {
- glViewObjectClass parent_class;
+ glViewObjectClass parent_class;
};
GType gl_view_text_get_type (void) G_GNUC_CONST;
glViewObject *gl_view_text_new (glLabelText *object,
- glView *view);
+ glView *view);
/* cursor for creating text objects */
GdkCursor *gl_view_text_get_create_cursor (void);
-/* event handler for creating text objects */
-gint gl_view_text_create_event_handler (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+/* Object creation handlers. */
+void gl_view_text_create_button_press_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_text_create_motion_event (glView *view,
+ gdouble x,
+ gdouble y);
+
+void gl_view_text_create_button_release_event (glView *view,
+ gdouble x,
+ gdouble y);
+
G_END_DECLS
*
* view.c: GLabels View module
*
- * Copyright (C) 2001-2005 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <glib/gi18n.h>
#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtklayout.h>
#include <gtk/gtkselection.h>
#include <gtk/gtkinvisible.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <math.h>
+#include "label.h"
+#include "cairo-label-path.h"
+#include "cairo-markup-path.h"
#include "view-object.h"
#include "view-box.h"
#include "view-ellipse.h"
/* Local function prototypes */
/*==========================================================================*/
-static void gl_view_finalize (GObject *object);
+static void gl_view_finalize (GObject *object);
-static void gl_view_construct (glView *view);
-static GtkWidget *gl_view_construct_canvas (glView *view);
-static void gl_view_construct_selection (glView *view);
+static void gl_view_construct (glView *view,
+ glLabel *label);
-static gdouble get_home_scale (glView *view);
+static gdouble get_home_scale (glView *view);
-static void draw_layers (glView *view);
+static gboolean expose_cb (glView *view,
+ GdkEventExpose *event);
-static void label_resized_cb (glLabel *label,
- glView *view);
+static void realize_cb (glView *view);
-static void draw_label_layer (glView *view);
+static void size_allocate_cb (glView *view,
+ GtkAllocation *allocation);
-static void draw_highlight_layer (glView *view);
+static void screen_changed_cb (glView *view);
-static void draw_bg_fg_layers (glView *view);
-static void draw_bg_fg_rect (glView *view);
-static void draw_bg_fg_rounded_rect (glView *view);
-static void draw_bg_fg_round (glView *view);
-static void draw_bg_fg_cd (glView *view);
-static void draw_bg_fg_cd_bc (glView *view);
+static void label_changed_cb (glView *view);
-static void draw_grid_layer (glView *view);
+static void label_resized_cb (glView *view);
-static void draw_markup_layer (glView *view);
+static void draw_layers (glView *view,
+ cairo_t *cr);
-static void draw_markup_margin (glView *view,
- glTemplateMarkup *margin);
-static void draw_markup_margin_rect (glView *view,
- glTemplateMarkup *margin);
-static void draw_markup_margin_rounded_rect (glView *view,
- glTemplateMarkup *margin);
-static void draw_markup_margin_round (glView *view,
- glTemplateMarkup *margin);
-static void draw_markup_margin_cd (glView *view,
- glTemplateMarkup *margin);
-static void draw_markup_margin_cd_bc (glView *view,
- glTemplateMarkup *margin);
+static void draw_bg_layer (glView *view,
+ cairo_t *cr);
+static void draw_grid_layer (glView *view,
+ cairo_t *cr);
+static void draw_markup_layer (glView *view,
+ cairo_t *cr);
+static void draw_objects_layer (glView *view,
+ cairo_t *cr);
+static void draw_fg_layer (glView *view,
+ cairo_t *cr);
+static void draw_highlight_layer (glView *view,
+ cairo_t *cr);
+static void draw_select_region_layer (glView *view,
+ cairo_t *cr);
-static void draw_markup_line (glView *view,
- glTemplateMarkup *line);
+static void select_object_real (glView *view,
+ glViewObject *view_object);
+static void unselect_object_real (glView *view,
+ glViewObject *view_object);
-static void draw_markup_circle (glView *view,
- glTemplateMarkup *circle);
+static glViewObject *view_view_object_at (glView *view,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y);
+static void set_zoom_real (glView *view,
+ gdouble zoom,
+ gboolean scale_to_fit_flag);
-static void select_object_real (glView *view,
- glViewObject *view_object);
-static void unselect_object_real (glView *view,
- glViewObject *view_object);
+static void selection_clear_cb (GtkWidget *widget,
+ GdkEventSelection *event,
+ glView *view);
-static gboolean object_at (glView *view,
- gdouble x, gdouble y);
+static void selection_get_cb (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ glView *view);
-static gboolean is_item_member_of_group (glView *view,
- GnomeCanvasItem *item,
- GnomeCanvasItem *group);
+static void selection_received_cb (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint time,
+ glView *view);
-static void set_zoom_real (glView *view,
- gdouble zoom,
- gboolean scale_to_fit_flag);
+static gboolean focus_in_event_cb (glView *view,
+ GdkEventFocus *event);
-static void size_allocate_cb (glView *view);
+static gboolean focus_out_event_cb (glView *view,
+ GdkEventFocus *event);
-static void screen_changed_cb (glView *view);
+static gboolean enter_notify_event_cb (glView *view,
+ GdkEventCrossing *event);
-static int canvas_event (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
-static int canvas_event_arrow_mode (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view);
+static gboolean leave_notify_event_cb (glView *view,
+ GdkEventCrossing *event);
-static void selection_clear_cb (GtkWidget *widget,
- GdkEventSelection *event,
- glView *view);
+static gboolean motion_notify_event_cb (glView *view,
+ GdkEventMotion *event);
-static void selection_get_cb (GtkWidget *widget,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- glView *view);
+static gboolean button_press_event_cb (glView *view,
+ GdkEventButton *event);
+
+static gboolean button_release_event_cb (glView *view,
+ GdkEventButton *event);
+
+static gboolean key_press_event_cb (glView *view,
+ GdkEventKey *event);
-static void selection_received_cb (GtkWidget *widget,
- GtkSelectionData *selection_data,
- guint time,
- glView *view);
\f
/****************************************************************************/
/* Boilerplate Object stuff. */
static void
gl_view_init (glView *view)
{
+ GtkWidget *wscroll;
+ GdkColor *bg_color;
+
gl_debug (DEBUG_VIEW, "START");
- view->label = NULL;
+ view->label = NULL;
+ view->grid_visible = TRUE;
+ view->grid_spacing = 9;
+ view->markup_visible = TRUE;
+ view->default_font_family = NULL;
+ view->mode = GL_VIEW_MODE_ARROW;
+ view->object_list = NULL;
+ view->selected_object_list = NULL;
+ view->zoom = 1.0;
+ view->home_scale = get_home_scale (view);
+
+ /*
+ * Canvas
+ */
+ view->canvas = gtk_layout_new (NULL, NULL);
+ wscroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wscroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (view), wscroll, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (wscroll), view->canvas);
+
+ bg_color = gl_color_to_gdk_color (BG_COLOR);
+ gtk_widget_modify_bg (GTK_WIDGET (view->canvas), GTK_STATE_NORMAL, bg_color);
+ g_free (bg_color);
- view->grid_spacing = 9;
+ GTK_WIDGET_SET_FLAGS (GTK_WIDGET (view->canvas), GTK_CAN_FOCUS);
+
+ gtk_widget_add_events (GTK_WIDGET (view->canvas),
+ (GDK_FOCUS_CHANGE_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_KEY_PRESS_MASK));
+
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "expose-event",
+ G_CALLBACK (expose_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "realize",
+ G_CALLBACK (realize_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "size-allocate",
+ G_CALLBACK (size_allocate_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "screen-changed",
+ G_CALLBACK (screen_changed_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "focus-in-event",
+ G_CALLBACK (focus_in_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "focus-out-event",
+ G_CALLBACK (focus_out_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "enter-notify-event",
+ G_CALLBACK (enter_notify_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "leave-notify-event",
+ G_CALLBACK (leave_notify_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "motion-notify-event",
+ G_CALLBACK (motion_notify_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "button-press-event",
+ G_CALLBACK (button_press_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "button-release-event",
+ G_CALLBACK (button_release_event_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->canvas), "key-press-event",
+ G_CALLBACK (key_press_event_cb), view);
+
+ /*
+ * Clipboard
+ */
+ view->have_selection = FALSE;
+ view->selection_data = NULL;
+ view->invisible = gtk_invisible_new ();
+ if (!clipboard_atom) {
+ clipboard_atom = gdk_atom_intern ("GLABELS_CLIPBOARD", FALSE);
+ }
+ gtk_selection_add_target (view->invisible,
+ clipboard_atom, GDK_SELECTION_TYPE_STRING, 1);
+ g_signal_connect (G_OBJECT (view->invisible),
+ "selection_clear_event",
+ G_CALLBACK (selection_clear_cb), view);
+ g_signal_connect (G_OBJECT (view->invisible), "selection_get",
+ G_CALLBACK (selection_get_cb), view);
+ g_signal_connect (G_OBJECT (view->invisible),
+ "selection_received",
+ G_CALLBACK (selection_received_cb), view);
- view->default_font_family = NULL;
+ /*
+ * Defaults from preferences
+ */
+ gl_view_set_default_font_family (view, gl_prefs->default_font_family);
+ gl_view_set_default_font_size (view, gl_prefs->default_font_size);
+ gl_view_set_default_font_weight (view, gl_prefs->default_font_weight);
+ gl_view_set_default_font_italic_flag (view, gl_prefs->default_font_italic_flag);
+ gl_view_set_default_text_color (view, gl_prefs->default_text_color);
+ gl_view_set_default_text_alignment (view, gl_prefs->default_text_alignment);
+ gl_view_set_default_text_line_spacing (view, gl_prefs->default_text_line_spacing);
+ gl_view_set_default_line_width (view, gl_prefs->default_line_width);
+ gl_view_set_default_line_color (view, gl_prefs->default_line_color);
+ gl_view_set_default_fill_color (view, gl_prefs->default_fill_color);
gl_debug (DEBUG_VIEW, "END");
}
g_return_val_if_fail (label && GL_IS_LABEL (label), NULL);
view = g_object_new (GL_TYPE_VIEW, NULL);
- view->label = label;
- gl_view_construct (view);
+ gl_view_construct (view, label);
gl_debug (DEBUG_VIEW, "END");
/* PRIVATE. Construct composite widget. */
/*---------------------------------------------------------------------------*/
static void
-gl_view_construct (glView *view)
+gl_view_construct (glView *view,
+ glLabel *label)
{
- GtkWidget *wvbox;
- GtkWidget *wscroll;
+ GList *p_obj;
+ glLabelObject *object;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (GL_IS_VIEW (view));
- wvbox = GTK_WIDGET (view);
-
- view->state = GL_VIEW_STATE_ARROW;
- view->object_list = NULL;
-
- gl_view_construct_canvas (view);
- wscroll = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wscroll),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start (GTK_BOX (wvbox), wscroll, TRUE, TRUE, 0);
- gtk_container_add (GTK_CONTAINER (wscroll), view->canvas);
-
- gl_view_construct_selection (view);
-
- gl_view_set_default_font_family (view, gl_prefs->default_font_family);
- gl_view_set_default_font_size (view, gl_prefs->default_font_size);
- gl_view_set_default_font_weight (view, gl_prefs->default_font_weight);
- gl_view_set_default_font_italic_flag (view, gl_prefs->default_font_italic_flag);
- gl_view_set_default_text_color (view, gl_prefs->default_text_color);
- gl_view_set_default_text_alignment (view, gl_prefs->default_text_alignment);
- gl_view_set_default_text_line_spacing (view, gl_prefs->default_text_line_spacing);
- gl_view_set_default_line_width (view, gl_prefs->default_line_width);
- gl_view_set_default_line_color (view, gl_prefs->default_line_color);
- gl_view_set_default_fill_color (view, gl_prefs->default_fill_color);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create canvas w/ a background in the shape of the label/card. */
-/*---------------------------------------------------------------------------*/
-static GtkWidget *
-gl_view_construct_canvas (glView *view)
-{
- glLabel *label;
- gdouble label_width;
- gdouble label_height;
- GdkColor *bg_color;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
- g_return_val_if_fail (view->label && GL_IS_LABEL (view->label), NULL);
-
- label = view->label;
-
- gtk_widget_push_colormap (gdk_rgb_get_colormap ());
- view->canvas = gnome_canvas_new_aa ();
- gtk_widget_pop_colormap ();
-
- bg_color = gl_color_to_gdk_color (BG_COLOR);
- gtk_widget_modify_bg (GTK_WIDGET(view->canvas), GTK_STATE_NORMAL, bg_color);
- g_free (bg_color);
-
- gl_label_get_size (label, &label_width, &label_height);
- gl_debug (DEBUG_VIEW, "Label size: w=%lf, h=%lf",
- label_width, label_height);
-
- view->zoom = 1.0;
- view->home_scale = get_home_scale (view);
- gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (view->canvas), view->home_scale);
-
- gnome_canvas_set_scroll_region (GNOME_CANVAS (view->canvas),
- 0.0, 0.0, label_width, label_height);
-
- draw_layers (view);
+ view->label = label;
- g_signal_connect (G_OBJECT (view->canvas), "event",
- G_CALLBACK (canvas_event), view);
+ for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next)
+ {
+ object = GL_LABEL_OBJECT (p_obj->data);
- g_signal_connect_swapped (G_OBJECT (view->canvas), "size-allocate",
- G_CALLBACK (size_allocate_cb), view);
+ if (GL_IS_LABEL_BOX (object)) {
+ gl_view_box_new (GL_LABEL_BOX(object), view);
+ } else if (GL_IS_LABEL_ELLIPSE (object)) {
+ gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), view);
+ } else if (GL_IS_LABEL_LINE (object)) {
+ gl_view_line_new (GL_LABEL_LINE(object), view);
+ } else if (GL_IS_LABEL_IMAGE (object)) {
+ gl_view_image_new (GL_LABEL_IMAGE(object), view);
+ } else if (GL_IS_LABEL_TEXT (object)) {
+ gl_view_text_new (GL_LABEL_TEXT(object), view);
+ } else if (GL_IS_LABEL_BARCODE (object)) {
+ gl_view_barcode_new (GL_LABEL_BARCODE(object), view);
+ } else {
+ /* Should not happen! */
+ g_message ("Invalid label object type.");
+ }
+ }
- g_signal_connect_swapped (G_OBJECT (view->canvas), "screen-changed",
- G_CALLBACK (screen_changed_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->label), "changed",
+ G_CALLBACK (label_changed_cb), view);
+ g_signal_connect_swapped (G_OBJECT (view->label), "size_changed",
+ G_CALLBACK (label_resized_cb), view);
gl_debug (DEBUG_VIEW, "END");
-
- return view->canvas;
}
/*---------------------------------------------------------------------------*/
gdouble y_pixels_per_mm;
gdouble scale;
+ if (view->canvas == NULL) return 1.0;
+
if (!gtk_widget_has_screen (GTK_WIDGET (view->canvas))) return 1.0;
screen = gtk_widget_get_screen (GTK_WIDGET (view->canvas));
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create clipboard selection targets. */
-/*---------------------------------------------------------------------------*/
-static void
-gl_view_construct_selection (glView *view)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (GL_IS_VIEW (view));
-
- view->have_selection = FALSE;
- view->selection_data = NULL;
- view->invisible = gtk_invisible_new ();
-
- view->selected_object_list = NULL;
-
- if (!clipboard_atom) {
- clipboard_atom = gdk_atom_intern ("GLABELS_CLIPBOARD", FALSE);
- }
-
- gtk_selection_add_target (view->invisible,
- clipboard_atom, GDK_SELECTION_TYPE_STRING, 1);
-
- g_signal_connect (G_OBJECT (view->invisible),
- "selection_clear_event",
- G_CALLBACK (selection_clear_cb), view);
-
- g_signal_connect (G_OBJECT (view->invisible), "selection_get",
- G_CALLBACK (selection_get_cb), view);
-
- g_signal_connect (G_OBJECT (view->invisible),
- "selection_received",
- G_CALLBACK (selection_received_cb), view);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create, draw and order layers. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_layers (glView *view)
-{
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- draw_bg_fg_layers (view);
- draw_grid_layer (view);
- draw_markup_layer (view);
- draw_highlight_layer (view); /* Must be done before label layer */
- draw_label_layer (view);
-
- gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group));
- gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->highlight_group));
-
- g_signal_connect (G_OBJECT (view->label), "size_changed",
- G_CALLBACK (label_resized_cb), view);
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Handle label resize event. . */
-/*---------------------------------------------------------------------------*/
-static void
-label_resized_cb (glLabel *label,
- glView *view)
-{
- gdouble label_width;
- gdouble label_height;
-
- g_return_if_fail (label && GL_IS_LABEL (label));
- g_return_if_fail (view && GL_IS_VIEW (view));
-
- gl_label_get_size (label, &label_width, &label_height);
- gnome_canvas_set_scroll_region (GNOME_CANVAS (view->canvas),
- 0.0, 0.0, label_width, label_height);
-
- gtk_object_destroy (GTK_OBJECT (view->bg_group));
- gtk_object_destroy (GTK_OBJECT (view->grid_group));
- gtk_object_destroy (GTK_OBJECT (view->markup_group));
- gtk_object_destroy (GTK_OBJECT (view->fg_group));
-
- draw_bg_fg_layers (view);
- draw_grid_layer (view);
- draw_markup_layer (view);
-
- gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->label_group));
- gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group));
- gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->highlight_group));
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw label layer. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_label_layer (glView *view)
-{
- GnomeCanvasGroup *group;
- glLabel *label;
- GList *p_obj;
- glLabelObject *object;
- glViewObject *view_object;
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- group = gnome_canvas_root (GNOME_CANVAS (view->canvas));
- view->label_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
-
- label = view->label;
-
- for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) {
- object = (glLabelObject *) p_obj->data;
-
- if (GL_IS_LABEL_BOX (object)) {
- view_object = gl_view_box_new (GL_LABEL_BOX(object),
- view);
- } else if (GL_IS_LABEL_ELLIPSE (object)) {
- view_object = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object),
- view);
- } else if (GL_IS_LABEL_LINE (object)) {
- view_object = gl_view_line_new (GL_LABEL_LINE(object),
- view);
- } else if (GL_IS_LABEL_IMAGE (object)) {
- view_object = gl_view_image_new (GL_LABEL_IMAGE(object),
- view);
- } else if (GL_IS_LABEL_TEXT (object)) {
- view_object = gl_view_text_new (GL_LABEL_TEXT(object),
- view);
- } else if (GL_IS_LABEL_BARCODE (object)) {
- view_object = gl_view_barcode_new (GL_LABEL_BARCODE(object),
- view);
- } else {
- /* Should not happen! */
- view_object = NULL;
- g_message ("Invalid label object type.");
- }
- }
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Create highlight layer. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_highlight_layer (glView *view)
-{
- GnomeCanvasGroup *group;
-
- g_return_if_fail (view && GL_IS_VIEW (view));
-
- group = gnome_canvas_root (GNOME_CANVAS (view->canvas));
- view->highlight_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw background and foreground outlines. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_bg_fg_layers (glView *view)
-{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- GnomeCanvasGroup *group;
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- group = gnome_canvas_root (GNOME_CANVAS (view->canvas));
- view->bg_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
- view->fg_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- switch (label_type->shape) {
-
- case GL_TEMPLATE_SHAPE_RECT:
- if (label_type->size.rect.r == 0.0) {
- /* Square corners. */
- draw_bg_fg_rect (view);
- } else {
- /* Rounded corners. */
- draw_bg_fg_rounded_rect (view);
- }
- break;
-
- case GL_TEMPLATE_SHAPE_ROUND:
- draw_bg_fg_round (view);
- break;
-
- case GL_TEMPLATE_SHAPE_CD:
- if ((label_type->size.cd.w == 0.0) && (label_type->size.cd.h == 0.0) ) {
- draw_bg_fg_cd (view);
- } else {
- draw_bg_fg_cd_bc (view);
- }
- break;
-
- default:
- g_message ("Unknown template label style");
- break;
- }
-
- gl_template_free (template);
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw simple recangular background. */
+/* PRIVATE. Update canvas. */
/*---------------------------------------------------------------------------*/
-static void
-draw_bg_fg_rect (glView *view)
+void
+gl_view_update (glView *view)
{
- glLabel *label;
- gdouble w;
- gdouble h;
- GnomeCanvasItem *item;
-
+ GtkWidget *widget;
+ GdkRegion *region;
+
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
+ widget = GTK_WIDGET (view->canvas);
- gl_label_get_size (label, &w, &h);
+ if (!widget->window) return;
- /* Background */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", w,
- "y2", h,
- "fill_color_rgba", PAPER_COLOR,
- NULL);
+ region = gdk_drawable_get_clip_region (widget->window);
+ /* redraw the cairo canvas completely by exposing it */
+ gdk_window_invalidate_region (widget->window, region, TRUE);
- /* Foreground */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_rect_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", w,
- "y2", h,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
+ gdk_region_destroy (region);
gl_debug (DEBUG_VIEW, "END");
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw rounded recangular background. */
+/* PRIVATE. Expose handler. */
/*---------------------------------------------------------------------------*/
-static void
-draw_bg_fg_rounded_rect (glView *view)
+static gboolean
+expose_cb (glView *view,
+ GdkEventExpose *event)
{
- glLabel *label;
- GnomeCanvasPoints *points;
- gint i_coords;
- gint i_theta;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble r;
- gdouble w;
- gdouble h;
- GnomeCanvasItem *item;
+ cairo_t *cr;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- gl_label_get_size (label, &w, &h);
- r = label_type->size.rect.r;
-
- points = gnome_canvas_points_new (4 * (1 + 90 / ARC_COURSE));
- i_coords = 0;
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- r - r * sin (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- r - r * cos (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- r - r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- (h - r) + r * sin (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- (w - r) + r * sin (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- (h - r) + r * cos (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- (w - r) + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- r - r * sin (i_theta * G_PI / 180.0);
- }
-
- /* Background */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "fill_color_rgba", PAPER_COLOR,
- NULL);
+ /* get a cairo_t */
+ cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window);
- /* Foreground */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
+ cairo_rectangle (cr,
+ event->area.x, event->area.y,
+ event->area.width, event->area.height);
+ cairo_clip (cr);
+
+ draw_layers (view, cr);
- gnome_canvas_points_free (points);
- gl_template_free (template);
+ cairo_destroy (cr);
gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw round background. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_bg_fg_round (glView *view)
-{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble r;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL(view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- r = label_type->size.round.r;
-
- /* Background */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 2.0*r,
- "y2", 2.0*r,
- "fill_color_rgba", PAPER_COLOR,
- NULL);
-
- /* Foreground */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 2.0*r,
- "y2", 2.0*r,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
- gl_template_free (template);
-
- gl_debug (DEBUG_VIEW, "END");
+ return FALSE;
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw CD style background, circular w/ concentric hole. */
+/* PRIVATE. Realize handler. */
/*---------------------------------------------------------------------------*/
static void
-draw_bg_fg_cd (glView *view)
+realize_cb (glView *view)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble r1;
- gdouble r2;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
-
g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
-
- /* Background */
- /* outer circle */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 2.0*r1,
- "y2", 2.0*r1,
- "fill_color_rgba", PAPER_COLOR,
- NULL);
- /* hole */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", r1 - r2,
- "y1", r1 - r2,
- "x2", r1 + r2,
- "y2", r1 + r2,
- "fill_color_rgba", GRID_COLOR,
- NULL);
-
- /* Foreground */
- /* outer circle */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", 0.0,
- "y1", 0.0,
- "x2", 2.0*r1,
- "y2", 2.0*r1,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
- /* hole */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", r1 - r2,
- "y1", r1 - r2,
- "x2", r1 + r2,
- "y2", r1 + r2,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
-
- gl_template_free (template);
-
- gl_debug (DEBUG_VIEW, "END");
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw Business Card CD style background, CD w/ chopped ends. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_bg_fg_cd_bc (glView *view)
-{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- GnomeCanvasPoints *points;
- gint i_coords;
- gint i_theta;
- gdouble theta1;
- gdouble theta2;
- gdouble x0, y0;
- gdouble w, h;
- gdouble r1, r2;
- GnomeCanvasItem *item;
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- gl_label_get_size (label, &w, &h);
- x0 = w/2.0;
- y0 = h/2.0;
-
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
-
- theta1 = (180.0/G_PI) * acos (w / (2.0*r1));
- theta2 = (180.0/G_PI) * asin (h / (2.0*r1));
-
- points = gnome_canvas_points_new (360/ARC_FINE + 1);
- i_coords = 0;
-
- points->coords[i_coords++] = x0 + r1 * cos (theta1 * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (theta1 * G_PI / 180.0);
-
- for ( i_theta = theta1 + ARC_FINE; i_theta < theta2; i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r1 * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (i_theta * G_PI / 180.0);
- }
-
- points->coords[i_coords++] = x0 + r1 * cos (theta2 * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (theta2 * G_PI / 180.0);
-
-
- if ( fabs (theta2 - 90.0) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r1 * cos ((180-theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((180-theta2) * G_PI / 180.0);
- }
-
- for ( i_theta = 180-theta2+ARC_FINE; i_theta < (180-theta1); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r1 * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (i_theta * G_PI / 180.0);
- }
-
- points->coords[i_coords++] = x0 + r1 * cos ((180-theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((180-theta1) * G_PI / 180.0);
-
- if ( fabs (theta1) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r1 * cos ((180+theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((180+theta1) * G_PI / 180.0);
- }
-
- for ( i_theta = 180+theta1+ARC_FINE; i_theta < (180+theta2); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r1 * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (i_theta * G_PI / 180.0);
- }
-
- points->coords[i_coords++] = x0 + r1 * cos ((180+theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((180+theta2) * G_PI / 180.0);
-
- if ( fabs (theta2 - 90.0) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r1 * cos ((360-theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((360-theta2) * G_PI / 180.0);
- }
-
- for ( i_theta = 360-theta2+ARC_FINE; i_theta < (360-theta1); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r1 * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin (i_theta * G_PI / 180.0);
- }
-
- if ( fabs (theta1) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r1 * cos ((360-theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r1 * sin ((360-theta1) * G_PI / 180.0);
- }
-
- points->num_points = i_coords / 2;
-
- /* Background */
- /* outer circle */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "fill_color_rgba", PAPER_COLOR,
- NULL);
- /* hole */
- item = gnome_canvas_item_new (view->bg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", x0 - r2,
- "y1", y0 - r2,
- "x2", x0 + r2,
- "y2", y0 + r2,
- "fill_color_rgba", GRID_COLOR,
- NULL);
-
- /* Foreground */
- /* outer circle */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
- /* hole */
- item = gnome_canvas_item_new (view->fg_group,
- gnome_canvas_ellipse_get_type (),
- "x1", x0 - r2,
- "y1", y0 - r2,
- "x2", x0 + r2,
- "y2", y0 + r2,
- "width_pixels", 2,
- "outline_color_rgba", OUTLINE_COLOR,
- NULL);
-
- gnome_canvas_points_free (points);
- gl_template_free (template);
-
gl_debug (DEBUG_VIEW, "END");
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw grid lines. */
+/* PRIVATE. Size allocation changed callback. */
/*---------------------------------------------------------------------------*/
static void
-draw_grid_layer (glView *view)
+size_allocate_cb (glView *view,
+ GtkAllocation *allocation)
{
- gdouble w, h;
- gdouble x, y;
- gdouble x0, y0;
- GnomeCanvasPoints *points;
- GnomeCanvasItem *item;
- GnomeCanvasGroup *group;
- glTemplate *template;
- const glTemplateLabelType *template_type;
-
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL(view->label));
+ GTK_LAYOUT (view->canvas)->hadjustment->page_size = allocation->width;
+ GTK_LAYOUT (view->canvas)->hadjustment->page_increment = allocation->width / 2;
+
+ GTK_LAYOUT (view->canvas)->vadjustment->page_size = allocation->height;
+ GTK_LAYOUT (view->canvas)->vadjustment->page_increment = allocation->height / 2;
- gl_label_get_size (view->label, &w, &h);
- template = gl_label_get_template (view->label);
- template_type = gl_template_get_first_label_type (template);
-
- if (template_type->shape == GL_TEMPLATE_SHAPE_RECT) {
- x0 = 0.0;
- y0 = 0.0;
- } else {
- /* for round labels, adjust grid to line up with center of label. */
- x0 = fmod (w/2.0, view->grid_spacing);
- y0 = fmod (h/2.0, view->grid_spacing);
- }
-
- group = gnome_canvas_root (GNOME_CANVAS (view->canvas));
- view->grid_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
- points = gnome_canvas_points_new (2);
+ g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->hadjustment, "changed");
+ g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->vadjustment, "changed");
- points->coords[1] = 0.0;
- points->coords[3] = h;
- for ( x=x0+view->grid_spacing; x < w; x += view->grid_spacing ) {
- points->coords[0] = points->coords[2] = x;
- item = gnome_canvas_item_new (view->grid_group,
- gnome_canvas_line_get_type (),
- "points", points,
- "width_pixels", 1,
- "fill_color_rgba", GRID_COLOR,
- NULL);
- }
-
- points->coords[0] = 0.0;
- points->coords[2] = w;
- for ( y=y0+view->grid_spacing; y < h; y += view->grid_spacing ) {
- points->coords[1] = points->coords[3] = y;
- item = gnome_canvas_item_new (view->grid_group,
- gnome_canvas_line_get_type (),
- "points", points,
- "width_pixels", 1,
- "fill_color_rgba", GRID_COLOR,
- NULL);
+ if (view->zoom_to_fit_flag) {
+ /* Maintain best fit zoom */
+ gl_view_zoom_to_fit (view);
}
- gnome_canvas_points_free (points);
- gl_template_free (template);
-
gl_debug (DEBUG_VIEW, "END");
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw markup lines. */
-/*---------------------------------------------------------------------------*/
-static void
-draw_markup_layer (glView *view)
-{
- GnomeCanvasGroup *group;
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- GList *p;
- glTemplateMarkup *markup;
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- group = gnome_canvas_root (GNOME_CANVAS (view->canvas));
- view->markup_group = GNOME_CANVAS_GROUP(
- gnome_canvas_item_new (group,
- gnome_canvas_group_get_type (),
- "x", 0.0,
- "y", 0.0,
- NULL));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- for ( p=label_type->markups; p != NULL; p=p->next ) {
- markup = (glTemplateMarkup *)p->data;
-
- switch (markup->type) {
- case GL_TEMPLATE_MARKUP_MARGIN:
- draw_markup_margin (view, markup);
- break;
- case GL_TEMPLATE_MARKUP_LINE:
- draw_markup_line (view, markup);
- break;
- case GL_TEMPLATE_MARKUP_CIRCLE:
- draw_markup_circle (view, markup);
- break;
- default:
- g_message ("Unknown template markup type");
- break;
- }
- }
-
- gl_template_free (template);
-
-}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw margin markup. */
+/* PRIVATE. Screen changed callback. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin (glView *view,
- glTemplateMarkup *markup)
+screen_changed_cb (glView *view)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- switch (label_type->shape) {
+ gl_debug (DEBUG_VIEW, "START");
- case GL_TEMPLATE_SHAPE_RECT:
- if (label_type->size.rect.r == 0.0) {
- /* Square corners. */
- draw_markup_margin_rect (view, markup);
- } else {
- if ( markup->data.margin.size < label_type->size.rect.r) {
- /* Rounded corners. */
- draw_markup_margin_rounded_rect (view, markup);
- } else {
- /* Square corners. */
- draw_markup_margin_rect (view, markup);
- }
- }
- break;
+ if (gtk_widget_has_screen (GTK_WIDGET (view->canvas))) {
- case GL_TEMPLATE_SHAPE_ROUND:
- draw_markup_margin_round (view, markup);
- break;
+ view->home_scale = get_home_scale (view);
- case GL_TEMPLATE_SHAPE_CD:
- if ((label_type->size.cd.w == 0.0) && (label_type->size.cd.h == 0.0) ) {
- draw_markup_margin_cd (view, markup);
- } else {
- draw_markup_margin_cd_bc (view, markup);
+ if (view->zoom_to_fit_flag) {
+ /* Maintain best fit zoom */
+ gl_view_zoom_to_fit (view);
}
- break;
-
- default:
- g_message ("Unknown template label style");
- break;
}
- gl_template_free (template);
+ gl_debug (DEBUG_VIEW, "END");
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw simple recangular margin. */
+/* PRIVATE. Handle label changed event. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin_rect (glView *view,
- glTemplateMarkup *markup)
+label_changed_cb (glView *view)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble w, h, m;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
-
- g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- gl_label_get_size (label, &w, &h);
- m = markup->data.margin.size;
+ g_return_if_fail (view && GL_IS_VIEW (view));
- /* Bounding box @ margin */
- gnome_canvas_item_new (view->markup_group,
- gnome_canvas_rect_get_type (),
- "x1", m,
- "y1", m,
- "x2", w - m,
- "y2", h - m,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
+ gl_debug (DEBUG_VIEW, "START");
- gl_template_free (template);
+ gl_view_update (view);
gl_debug (DEBUG_VIEW, "END");
}
+
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw rounded recangular markup. */
+/* PRIVATE. Handle label resize event. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin_rounded_rect (glView *view,
- glTemplateMarkup *markup)
+label_resized_cb (glView *view)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- GnomeCanvasPoints *points;
- gint i_coords;
- gint i_theta;
- gdouble r, w, h, m;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
-
g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
-
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
- gl_label_get_size (label, &w, &h);
- r = label_type->size.rect.r;
- m = markup->data.margin.size;
+ gl_debug (DEBUG_VIEW, "START");
- r = r - m;
- w = w - 2 * m;
- h = h - 2 * m;
+ g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->hadjustment, "changed");
+ g_signal_emit_by_name (GTK_LAYOUT (view->canvas)->vadjustment, "changed");
- /* rectangle with rounded corners */
- points = gnome_canvas_points_new (4 * (1 + 90 / ARC_COURSE));
- i_coords = 0;
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- m + r - r * sin (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- m + r - r * cos (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- m + r - r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- m + (h - r) + r * sin (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- m + (w - r) + r * sin (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- m + (h - r) + r * cos (i_theta * G_PI / 180.0);
- }
- for (i_theta = 0; i_theta <= 90; i_theta += ARC_COURSE) {
- points->coords[i_coords++] =
- m + (w - r) + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] =
- m + r - r * sin (i_theta * G_PI / 180.0);
- }
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
- gnome_canvas_points_free (points);
- gl_template_free (template);
+ gl_view_update (view);
gl_debug (DEBUG_VIEW, "END");
}
+
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw round margin. */
+/* PRIVATE. Create, draw and order layers. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin_round (glView *view,
- glTemplateMarkup *markup)
+draw_layers (glView *view,
+ cairo_t *cr)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble r, m;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
+ gdouble scale;
+ gdouble w, h;
+ gint canvas_w, canvas_h;
g_return_if_fail (view && GL_IS_VIEW (view));
g_return_if_fail (view->label && GL_IS_LABEL (view->label));
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
+ gl_debug (DEBUG_VIEW, "START");
+
+ scale = view->zoom * view->home_scale;
- r = label_type->size.round.r;
- m = markup->data.margin.size;
+ gl_label_get_size (view->label, &w, &h);
- /* Margin outline */
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_ellipse_get_type (),
- "x1", m,
- "y1", m,
- "x2", 2.0*r - m,
- "y2", 2.0*r - m,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
+ scale = view->home_scale * view->zoom;
+ gtk_layout_set_size (GTK_LAYOUT (view->canvas), w*scale+8, h*scale+8);
- gl_template_free (template);
+ gdk_drawable_get_size (GTK_LAYOUT (view->canvas)->bin_window, &canvas_w, &canvas_h);
+
+ view->x0 = (canvas_w/scale - w) / 2.0;
+ view->y0 = (canvas_h/scale - h) / 2.0;
+ view->w = w;
+ view->h = h;
+
+ cairo_save (cr);
+
+ cairo_scale (cr, scale, scale);
+ cairo_translate (cr, view->x0, view->y0);
+
+ draw_bg_layer (view, cr);
+ draw_grid_layer (view, cr);
+ draw_markup_layer (view, cr);
+ draw_objects_layer (view, cr);
+ draw_fg_layer (view, cr);
+ draw_highlight_layer (view, cr);
+ draw_select_region_layer (view, cr);
+
+ cairo_restore (cr);
gl_debug (DEBUG_VIEW, "END");
+
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw CD margins. */
+/* PRIVATE. Draw background */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin_cd (glView *view,
- glTemplateMarkup *markup)
+draw_bg_layer (glView *view,
+ cairo_t *cr)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble m, r1, r2;
- GnomeCanvasItem *item;
-
- gl_debug (DEBUG_VIEW, "START");
-
g_return_if_fail (view && GL_IS_VIEW (view));
g_return_if_fail (view->label && GL_IS_LABEL (view->label));
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
-
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
- m = markup->data.margin.size;
+ gl_cairo_label_path (cr, view->label, FALSE);
- /* outer margin */
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_ellipse_get_type (),
- "x1", m,
- "y1", m,
- "x2", 2.0*r1 - m,
- "y2", 2.0*r1 - m,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
- /* inner margin */
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_ellipse_get_type (),
- "x1", r1 - r2 - m,
- "y1", r1 - r2 - m,
- "x2", r1 + r2 + m,
- "y2", r1 + r2 + m,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
-
- gl_template_free (template);
-
- gl_debug (DEBUG_VIEW, "END");
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+ cairo_fill (cr);
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw Business Card CD margins. */
+/* PRIVATE. Draw grid lines. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_margin_cd_bc (glView *view,
- glTemplateMarkup *markup)
+draw_grid_layer (glView *view,
+ cairo_t *cr)
{
- glLabel *label;
- glTemplate *template;
- const glTemplateLabelType *label_type;
- gdouble m, r1, r2;
- GnomeCanvasPoints *points;
- gint i_coords;
- gint i_theta;
- gdouble theta1, theta2;
+ gdouble w, h;
+ gdouble x, y;
gdouble x0, y0;
- gdouble w, h, r;
- GnomeCanvasItem *item;
+ const glTemplateLabelType *label_type;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail (view->label && GL_IS_LABEL (view->label));
+ g_return_if_fail (view->label && GL_IS_LABEL(view->label));
- label = view->label;
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
+ if (view->grid_visible)
+ {
- gl_label_get_size (label, &w, &h);
- x0 = w/2.0;
- y0 = h/2.0;
+ label_type = gl_template_get_first_label_type (view->label->template);
- r1 = label_type->size.cd.r1;
- r2 = label_type->size.cd.r2;
- m = markup->data.margin.size;
+ gl_label_get_size (view->label, &w, &h);
+
+ if (label_type->shape == GL_TEMPLATE_SHAPE_RECT) {
+ x0 = 0.0;
+ y0 = 0.0;
+ } else {
+ /* round labels, adjust grid to line up with center of label. */
+ x0 = fmod (w/2.0, view->grid_spacing);
+ y0 = fmod (h/2.0, view->grid_spacing);
+ }
- /* outer margin */
- r = r1 - m;
- theta1 = (180.0/G_PI) * acos (w / (2.0*r1));
- theta2 = (180.0/G_PI) * asin (h / (2.0*r1));
- points = gnome_canvas_points_new (360/ARC_FINE + 1);
- i_coords = 0;
+ cairo_save (cr);
- points->coords[i_coords++] = x0 + r * cos (theta1 * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (theta1 * G_PI / 180.0);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+ cairo_set_line_width (cr, 1.0/(view->home_scale * view->zoom));
+ cairo_set_source_rgb (cr, 0.753, 0.753, 0.753);
- for ( i_theta = theta1 + ARC_FINE; i_theta < theta2; i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (i_theta * G_PI / 180.0);
- }
+ for ( x=x0+view->grid_spacing; x < w; x += view->grid_spacing )
+ {
+ cairo_move_to (cr, x, 0);
+ cairo_line_to (cr, x, h);
+ cairo_stroke (cr);
+ }
- points->coords[i_coords++] = x0 + r * cos (theta2 * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (theta2 * G_PI / 180.0);
+ for ( y=y0+view->grid_spacing; y < h; y += view->grid_spacing )
+ {
+ cairo_move_to (cr, 0, y);
+ cairo_line_to (cr, w, y);
+ cairo_stroke (cr);
+ }
+ cairo_restore (cr);
- if ( fabs (theta2 - 90.0) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r * cos ((180-theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((180-theta2) * G_PI / 180.0);
- }
+ }
- for ( i_theta = 180-theta2+ARC_FINE; i_theta < (180-theta1); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (i_theta * G_PI / 180.0);
- }
+ gl_debug (DEBUG_VIEW, "END");
+}
- points->coords[i_coords++] = x0 + r * cos ((180-theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((180-theta1) * G_PI / 180.0);
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw markup layer. */
+/*---------------------------------------------------------------------------*/
+static void
+draw_markup_layer (glView *view,
+ cairo_t *cr)
+{
+ glLabel *label;
+ const glTemplateLabelType *label_type;
+ GList *p;
+ glTemplateMarkup *markup;
- if ( fabs (theta1) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r * cos ((180+theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((180+theta1) * G_PI / 180.0);
- }
+ g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_if_fail (view->label && GL_IS_LABEL (view->label));
- for ( i_theta = 180+theta1+ARC_FINE; i_theta < (180+theta2); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (i_theta * G_PI / 180.0);
- }
+ if (view->markup_visible)
+ {
- points->coords[i_coords++] = x0 + r * cos ((180+theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((180+theta2) * G_PI / 180.0);
+ label = view->label;
+ label_type = gl_template_get_first_label_type (label->template);
- if ( fabs (theta2 - 90.0) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r * cos ((360-theta2) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((360-theta2) * G_PI / 180.0);
- }
+ cairo_save (cr);
- for ( i_theta = 360-theta2+ARC_FINE; i_theta < (360-theta1); i_theta +=ARC_FINE ) {
- points->coords[i_coords++] = x0 + r * cos (i_theta * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin (i_theta * G_PI / 180.0);
- }
+ cairo_set_line_width (cr, 1.0/(view->home_scale * view->zoom));
+ cairo_set_source_rgb (cr, 0.94, 0.39, 0.39);
- if ( fabs (theta1) > GNOME_CANVAS_EPSILON ) {
- points->coords[i_coords++] = x0 + r * cos ((360-theta1) * G_PI / 180.0);
- points->coords[i_coords++] = y0 + r * sin ((360-theta1) * G_PI / 180.0);
- }
+ for ( p=label_type->markups; p != NULL; p=p->next )
+ {
+ markup = (glTemplateMarkup *)p->data;
- points->num_points = i_coords / 2;
+ gl_cairo_markup_path (cr, markup, label);
+ }
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_polygon_get_type (),
- "points", points,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
+ cairo_stroke (cr);
- gnome_canvas_points_free (points);
+ cairo_restore (cr);
+ }
- /* inner margin */
- item = gnome_canvas_item_new (view->markup_group,
- gnome_canvas_ellipse_get_type (),
- "x1", x0 - r2 - m,
- "y1", y0 - r2 - m,
- "x2", x0 + r2 + m,
- "y2", y0 + r2 + m,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw objects layer. */
+/*---------------------------------------------------------------------------*/
+static void
+draw_objects_layer (glView *view,
+ cairo_t *cr)
+{
+ gl_label_draw (view->label, cr, TRUE, NULL);
+}
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Draw foreground */
+/*---------------------------------------------------------------------------*/
+static void
+draw_fg_layer (glView *view,
+ cairo_t *cr)
+{
+ g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_if_fail (view->label && GL_IS_LABEL (view->label));
- gl_template_free (template);
+ gl_cairo_label_path (cr, view->label, FALSE);
- gl_debug (DEBUG_VIEW, "END");
+ cairo_set_line_width (cr, 3.0/(view->home_scale * view->zoom));
+ cairo_set_source_rgb (cr, 0.68, 0.85, 0.90);
+ cairo_stroke (cr);
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw line markup. */
+/* PRIVATE. Create highlight layer. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_line (glView *view,
- glTemplateMarkup *markup)
+draw_highlight_layer (glView *view,
+ cairo_t *cr)
{
- GnomeCanvasPoints *points;
-
- gl_debug (DEBUG_VIEW, "START");
+ GList *p_obj;
+ glViewObject *view_object;
g_return_if_fail (view && GL_IS_VIEW (view));
- points = gnome_canvas_points_new (2);
- points->coords[0] = markup->data.line.x1;
- points->coords[1] = markup->data.line.y1;
- points->coords[2] = markup->data.line.x2;
- points->coords[3] = markup->data.line.y2;
+ cairo_save (cr);
- gnome_canvas_item_new (view->markup_group,
- gnome_canvas_line_get_type (),
- "points", points,
- "width_pixels", 1,
- "fill_color_rgba", MARKUP_COLOR,
- NULL);
+ cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
- gnome_canvas_points_free (points);
+ for (p_obj = view->selected_object_list; p_obj != NULL; p_obj = p_obj->next)
+ {
+ view_object = GL_VIEW_OBJECT (p_obj->data);
- gl_debug (DEBUG_VIEW, "END");
+ gl_view_object_draw_handles (view_object, cr);
+ }
+
+ cairo_restore (cr);
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Draw circle markup. */
+/* PRIVATE. Draw select region layer. */
/*---------------------------------------------------------------------------*/
static void
-draw_markup_circle (glView *view,
- glTemplateMarkup *markup)
+draw_select_region_layer (glView *view,
+ cairo_t *cr)
{
- gl_debug (DEBUG_VIEW, "START");
+ gdouble x1, y1;
+ gdouble w, h;
g_return_if_fail (view && GL_IS_VIEW (view));
- /* Circle outline */
- gnome_canvas_item_new (view->markup_group,
- gnome_canvas_ellipse_get_type (),
- "x1", markup->data.circle.x0 - markup->data.circle.r,
- "y1", markup->data.circle.y0 - markup->data.circle.r,
- "x2", markup->data.circle.x0 + markup->data.circle.r,
- "y2", markup->data.circle.y0 + markup->data.circle.r,
- "width_pixels", 1,
- "outline_color_rgba", MARKUP_COLOR,
- NULL);
+ if (view->select_region_visible)
+ {
+ x1 = MIN (view->select_region_x1, view->select_region_x2);
+ y1 = MIN (view->select_region_y1, view->select_region_y2);
+ w = fabs (view->select_region_x2 - view->select_region_x1);
+ h = fabs (view->select_region_y2 - view->select_region_y1);
- gl_debug (DEBUG_VIEW, "END");
+ cairo_rectangle (cr, x1, y1, w, h);
+
+ cairo_set_source_rgba (cr, 0.75, 0.75, 1.0, 0.5);
+ cairo_fill_preserve (cr);
+
+ cairo_set_line_width (cr, 3.0/(view->home_scale * view->zoom));
+ cairo_set_source_rgba (cr, 0, 0, 1.0, 0.5);
+ cairo_stroke (cr);
+ }
}
/*****************************************************************************/
{
g_return_if_fail (view && GL_IS_VIEW (view));
- gnome_canvas_item_show (GNOME_CANVAS_ITEM(view->grid_group));
+ view->grid_visible = TRUE;
+ gl_view_update (view);
}
/*****************************************************************************/
{
g_return_if_fail (view && GL_IS_VIEW (view));
- gnome_canvas_item_hide (GNOME_CANVAS_ITEM(view->grid_group));
+ view->grid_visible = FALSE;
+ gl_view_update (view);
}
/*****************************************************************************/
g_return_if_fail (view && GL_IS_VIEW (view));
view->grid_spacing = spacing;
-
- gtk_object_destroy (GTK_OBJECT(view->grid_group));
- draw_grid_layer (view);
+ gl_view_update (view);
}
/*****************************************************************************/
{
g_return_if_fail (view && GL_IS_VIEW (view));
- gnome_canvas_item_show (GNOME_CANVAS_ITEM(view->markup_group));
+ view->markup_visible = TRUE;
+ gl_view_update (view);
}
/*****************************************************************************/
{
g_return_if_fail (view && GL_IS_VIEW (view));
- gnome_canvas_item_hide (GNOME_CANVAS_ITEM(view->markup_group));
+ view->markup_visible = FALSE;
+ gl_view_update (view);
}
/*****************************************************************************/
void
gl_view_arrow_mode (glView *view)
{
- static GdkCursor *cursor = NULL;
+ GdkCursor *cursor;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (view && GL_IS_VIEW (view));
- if (!cursor) {
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- }
-
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
gdk_window_set_cursor (view->canvas->window, cursor);
+ gdk_cursor_unref (cursor);
- view->state = GL_VIEW_STATE_ARROW;
+ view->mode = GL_VIEW_MODE_ARROW;
+ view->state = GL_VIEW_IDLE;
gl_debug (DEBUG_VIEW, "END");
}
gl_view_object_create_mode (glView *view,
glLabelObjectType type)
{
- GdkCursor *cursor;
+ GdkCursor *cursor = NULL;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (view && GL_IS_VIEW (view));
- switch (type) {
+ switch (type)
+ {
case GL_LABEL_OBJECT_BOX:
cursor = gl_view_box_get_create_cursor ();
break;
}
gdk_window_set_cursor (view->canvas->window, cursor);
+ gdk_cursor_unref (cursor);
- view->state = GL_VIEW_STATE_OBJECT_CREATE;
+ view->mode = GL_VIEW_MODE_OBJECT_CREATE;
+ view->state = GL_VIEW_IDLE;
view->create_type = type;
gl_debug (DEBUG_VIEW, "END");
GList *p;
glViewObject *view_object;
glLabelObject *object;
+ gdouble r_x1, r_y1;
+ gdouble r_x2, r_y2;
gdouble i_x1, i_y1;
gdouble i_x2, i_y2;
gl_debug (DEBUG_VIEW, "START");
g_return_if_fail (view && GL_IS_VIEW (view));
- g_return_if_fail ((x1 <= x2) && (y1 <= y2));
+
+ r_x1 = MIN (x1, x2);
+ r_y1 = MIN (y1, y2);
+ r_x2 = MAX (x1, x2);
+ r_y2 = MAX (y1, y2);
for (p = view->object_list; p != NULL; p = p->next) {
view_object = GL_VIEW_OBJECT(p->data);
object = gl_view_object_get_object (view_object);
gl_label_object_get_extent (object, &i_x1, &i_y1, &i_x2, &i_y2);
- if ((i_x1 >= x1) && (i_x2 <= x2) && (i_y1 >= y1)
- && (i_y2 <= y2)) {
+ if ((i_x1 >= r_x1) && (i_x2 <= r_x2) && (i_y1 >= r_y1)
+ && (i_y2 <= r_y2)) {
select_object_real (view, view_object);
}
if (!gl_view_is_object_selected (view, view_object)) {
view->selected_object_list =
- g_list_prepend (view->selected_object_list, view_object);
+ g_list_append (view->selected_object_list, view_object);
}
- gl_view_object_show_highlight (view_object);
gtk_widget_grab_focus (GTK_WIDGET (view->canvas));
+ gl_view_update (view);
+
gl_debug (DEBUG_VIEW, "END");
}
g_return_if_fail (view && GL_IS_VIEW (view));
g_return_if_fail (GL_IS_VIEW_OBJECT (view_object));
- gl_view_object_hide_highlight (view_object);
-
view->selected_object_list =
g_list_remove (view->selected_object_list, view_object);
+ gl_view_update (view);
+
gl_debug (DEBUG_VIEW, "END");
}
/*---------------------------------------------------------------------------*/
/* PRIVATE. Return object at (x,y). */
/*---------------------------------------------------------------------------*/
-static gboolean
-object_at (glView *view,
- gdouble x,
- gdouble y)
+static glViewObject *
+view_view_object_at (glView *view,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y)
{
- GnomeCanvasItem *item;
- GList *p;
+ GList *p_obj;
+ glViewObject *view_object;
- gl_debug (DEBUG_VIEW, "");
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
- g_return_val_if_fail (view && GL_IS_VIEW (view), FALSE);
+ for (p_obj = g_list_last (view->object_list); p_obj != NULL; p_obj = p_obj->prev)
+ {
- item = gnome_canvas_get_item_at (GNOME_CANVAS (view->canvas), x, y);
+ view_object = GL_VIEW_OBJECT (p_obj->data);
- /* No item is at x, y */
- if (item == NULL)
- return FALSE;
+ if (gl_view_object_at (view_object, cr, x, y))
+ {
+ return view_object;
+ }
- /* ignore items not in label or highlight layers, e.g. background items */
- if (!is_item_member_of_group(view, item, GNOME_CANVAS_ITEM(view->label_group)) &&
- !is_item_member_of_group(view, item, GNOME_CANVAS_ITEM(view->highlight_group)))
- return FALSE;
+ }
- return TRUE;
+ return NULL;
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Is the item a child (or grandchild, etc.) of group. */
+/* PRIVATE. Return object handle at (x,y). */
/*---------------------------------------------------------------------------*/
-static gboolean
-is_item_member_of_group (glView *view,
- GnomeCanvasItem *item,
- GnomeCanvasItem *group)
+static glViewObject *
+view_handle_at (glView *view,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ glViewObjectHandle *handle)
{
- GnomeCanvasItem *parent;
- GnomeCanvasItem *root_group;
+ GList *p_obj;
+ glViewObject *view_object;
- g_return_val_if_fail (view && GL_IS_VIEW (view), FALSE);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
+
+ for (p_obj = g_list_last (view->selected_object_list); p_obj != NULL; p_obj = p_obj->prev)
+ {
+
+ view_object = GL_VIEW_OBJECT (p_obj->data);
- root_group = GNOME_CANVAS_ITEM(gnome_canvas_root (GNOME_CANVAS (view->canvas)));
+ if ((*handle = gl_view_object_handle_at (view_object, cr, x, y)))
+ {
+ return view_object;
+ }
- for ( parent=item->parent; parent && (parent!=root_group); parent=parent->parent) {
- if (parent == group) return TRUE;
}
- return FALSE;
+
+ return NULL;
}
/*****************************************************************************/
gl_debug (DEBUG_VIEW, "START");
- g_return_if_fail (view && GL_IS_VIEW (view));
+ g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
if (!gl_view_is_selection_empty (view)) {
/* Set font weight for all text contained in selected objects. */
/*****************************************************************************/
void
-gl_view_set_selection_font_weight (glView *view,
- GnomeFontWeight font_weight)
+gl_view_set_selection_font_weight (glView *view,
+ PangoWeight font_weight)
{
GList *p;
glLabelObject *object;
GList *p;
glViewObject *view_object;
glLabelObject *object;
- glTemplate *template;
- gboolean rotate_flag;
gl_debug (DEBUG_VIEW, "START");
if ( view->selection_data ) {
g_object_unref (view->selection_data);
}
- template = gl_label_get_template (view->label);
- rotate_flag = gl_label_get_rotate_flag (view->label);
view->selection_data = GL_LABEL(gl_label_new ());
- gl_label_set_template (view->selection_data, template);
- gl_label_set_rotate_flag (view->selection_data, rotate_flag);
- gl_template_free (template);
+ gl_label_set_template (view->selection_data, view->label->template);
+ gl_label_set_rotate_flag (view->selection_data, view->label->rotate_flag);
for (p = view->selected_object_list; p != NULL; p = p->next) {
}
/*---------------------------------------------------------------------------*/
-/* PRIVATE. Set canvas scale. *
+/* PRIVATE. Set canvas scale. */
/*---------------------------------------------------------------------------*/
static void
set_zoom_real (glView *view,
view->zoom = zoom;
view->zoom_to_fit_flag = zoom_to_fit_flag;
- gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (view->canvas),
- zoom*view->home_scale);
-
- g_signal_emit (G_OBJECT(view), signals[ZOOM_CHANGED], 0, zoom);
-
- }
-
- gl_debug (DEBUG_VIEW, "END");
-
-}
+ gl_view_update (view);
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Size allocation changed callback. */
-/*---------------------------------------------------------------------------*/
-static void
-size_allocate_cb (glView *view)
-{
- gl_debug (DEBUG_VIEW, "START");
+ g_signal_emit (G_OBJECT(view), signals[ZOOM_CHANGED], 0, zoom);
- if (view->zoom_to_fit_flag) {
- /* Maintain best fit zoom */
- gl_view_zoom_to_fit (view);
}
gl_debug (DEBUG_VIEW, "END");
-}
-
-
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Screen changed callback. */
-/*---------------------------------------------------------------------------*/
-static void
-screen_changed_cb (glView *view)
-{
- gl_debug (DEBUG_VIEW, "START");
-
- if (gtk_widget_has_screen (GTK_WIDGET (view->canvas))) {
-
- view->home_scale = get_home_scale (view);
-
- gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (view->canvas),
- view->zoom * view->home_scale);
-
- if (view->zoom_to_fit_flag) {
- /* Maintain best fit zoom */
- gl_view_zoom_to_fit (view);
- }
-
- }
- gl_debug (DEBUG_VIEW, "END");
}
-
/*****************************************************************************/
/* Get current zoom factor. */
/*****************************************************************************/
return view->zoom <= zooms[N_ZOOMS-1];
}
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Canvas event handler. */
-/*---------------------------------------------------------------------------*/
-static int
-canvas_event (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
-{
- gdouble x, y;
-
- gl_debug (DEBUG_VIEW, "");
-
- g_return_val_if_fail (view && GL_IS_VIEW (view), FALSE);
-
- /* emit pointer signals regardless of state */
- switch (event->type) {
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- g_signal_emit (G_OBJECT(view), signals[POINTER_MOVED], 0, x, y);
- break; /* fall through */
-
- case GDK_LEAVE_NOTIFY:
- gl_debug (DEBUG_VIEW, "LEAVEW_NOTIFY");
- g_signal_emit (G_OBJECT(view), signals[POINTER_EXIT], 0);
- break; /* fall through */
-
- default:
- break; /* fall through */
- }
-
-
- switch (view->state) {
-
- case GL_VIEW_STATE_ARROW:
- return canvas_event_arrow_mode (canvas, event, view);
-
- case GL_VIEW_STATE_OBJECT_CREATE:
- switch (view->create_type) {
- case GL_LABEL_OBJECT_BOX:
- return gl_view_box_create_event_handler (canvas,
- event,
- view);
- break;
- case GL_LABEL_OBJECT_ELLIPSE:
- return gl_view_ellipse_create_event_handler (canvas,
- event,
- view);
- break;
- case GL_LABEL_OBJECT_LINE:
- return gl_view_line_create_event_handler (canvas,
- event,
- view);
- break;
- case GL_LABEL_OBJECT_IMAGE:
- return gl_view_image_create_event_handler (canvas,
- event,
- view);
- break;
- case GL_LABEL_OBJECT_TEXT:
- return gl_view_text_create_event_handler (canvas,
- event,
- view);
- break;
- case GL_LABEL_OBJECT_BARCODE:
- return gl_view_barcode_create_event_handler (canvas,
- event,
- view);
- break;
- default:
- /*Should not happen!*/
- g_message ("Invalid label object type.");
- return FALSE;
- }
-
- default:
- g_message ("Invalid view state."); /*Should not happen!*/
- return FALSE;
-
- }
-}
-
-/*---------------------------------------------------------------------------*/
-/* PRIVATE. Canvas event handler (arrow mode) */
-/*---------------------------------------------------------------------------*/
-static int
-canvas_event_arrow_mode (GnomeCanvas *canvas,
- GdkEvent *event,
- glView *view)
-{
- static gdouble x0, y0;
- static gboolean dragging = FALSE;
- static GnomeCanvasItem *item;
- gdouble x, y;
- gdouble x1, y1;
- gdouble x2, y2;
- GnomeCanvasGroup *group;
- GdkCursor *cursor;
-
- gl_debug (DEBUG_VIEW, "");
-
- g_return_val_if_fail (view && GL_IS_VIEW (view), FALSE);
-
- switch (event->type) {
-
- case GDK_BUTTON_PRESS:
- gl_debug (DEBUG_VIEW, "BUTTON_PRESS");
- gtk_widget_grab_focus (GTK_WIDGET(canvas));
- switch (event->button.button) {
- case 1:
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y, &x, &y);
-
- if (!object_at (view, x, y)) {
- if (!(event->button.state & GDK_CONTROL_MASK)) {
- gl_view_unselect_all (view);
- }
-
- dragging = TRUE;
- gnome_canvas_item_grab (canvas->root,
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- group =
- gnome_canvas_root (GNOME_CANVAS
- (view->canvas));
- item =
- gnome_canvas_item_new (group,
- gnome_canvas_rect_get_type (),
- "x1", x-DELTA,
- "y1", y-DELTA,
- "x2", x+DELTA,
- "y2", y+DELTA,
- "width_pixels", 2,
- "outline_color_rgba",
- SEL_LINE_COLOR,
- "fill_color_rgba",
- SEL_FILL_COLOR,
- NULL);
- x0 = x;
- y0 = y;
-
- }
- return FALSE;
- case 3:
- /* activate context menu. */
- g_signal_emit (G_OBJECT (view),
- signals[CONTEXT_MENU_ACTIVATE], 0,
- event->button.button, event->button.time);
- return FALSE;
- default:
- return FALSE;
- }
-
- case GDK_BUTTON_RELEASE:
- gl_debug (DEBUG_VIEW, "BUTTON_RELEASE");
- switch (event->button.button) {
- case 1:
- if (dragging) {
- dragging = FALSE;
- gnome_canvas_item_ungrab (canvas->root,
- event->button.time);
- gnome_canvas_window_to_world (canvas,
- event->button.x,
- event->button.y,
- &x, &y);
- x1 = MIN (x, x0);
- y1 = MIN (y, y0);
- x2 = MAX (x, x0);
- y2 = MAX (y, y0);
- gl_view_select_region (view, x1, y1, x2, y2);
- gtk_object_destroy (GTK_OBJECT (item));
- return TRUE;
- }
- return FALSE;
-
- default:
- return FALSE;
- }
-
- case GDK_MOTION_NOTIFY:
- gl_debug (DEBUG_VIEW, "MOTION_NOTIFY");
- gnome_canvas_window_to_world (canvas,
- event->motion.x,
- event->motion.y, &x, &y);
- if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) {
- gl_debug (DEBUG_VIEW,
- "Dragging: (x0=%g, y0=%g), (x=%g, y=%g)", x0, y0, x, y);
- gnome_canvas_item_set (item,
- "x1", MIN (x, x0) - DELTA,
- "y1", MIN (y, y0) - DELTA,
- "x2", MAX (x, x0) + DELTA,
- "y2", MAX (y, y0) + DELTA,
- NULL);
- return TRUE;
- } else {
- return FALSE;
- }
-
- case GDK_KEY_PRESS:
- gl_debug (DEBUG_VIEW, "KEY_PRESS");
- if (!dragging) {
- switch (event->key.keyval) {
- case GDK_Left:
- case GDK_KP_Left:
- gl_view_move_selection (view,
- -1.0 / (view->zoom), 0.0);
- break;
- case GDK_Up:
- case GDK_KP_Up:
- gl_view_move_selection (view,
- 0.0, -1.0 / (view->zoom));
- break;
- case GDK_Right:
- case GDK_KP_Right:
- gl_view_move_selection (view,
- 1.0 / (view->zoom), 0.0);
- break;
- case GDK_Down:
- case GDK_KP_Down:
- gl_view_move_selection (view,
- 0.0, 1.0 / (view->zoom));
- break;
- case GDK_Delete:
- case GDK_KP_Delete:
- gl_view_delete_selection (view);
- cursor = gdk_cursor_new (GDK_LEFT_PTR);
- gdk_window_set_cursor (view->canvas->window,
- cursor);
- gdk_cursor_unref (cursor);
- break;
- default:
- return FALSE;
- }
- }
- return TRUE; /* We handled this or we were dragging. */
-
- default:
- gl_debug (DEBUG_VIEW, "default");
- return FALSE;
- }
-
-}
-
/*---------------------------------------------------------------------------*/
/* PRIVATE. Handle "selection-clear" signal. */
/*---------------------------------------------------------------------------*/
/* Set default font weight. */
/****************************************************************************/
void
-gl_view_set_default_font_weight (glView *view,
- GnomeFontWeight font_weight)
+gl_view_set_default_font_weight (glView *view,
+ PangoWeight font_weight)
{
gl_debug (DEBUG_VIEW, "START");
/****************************************************************************/
/* Get default font weight. */
/****************************************************************************/
-GnomeFontWeight
+PangoWeight
gl_view_get_default_font_weight (glView *view)
{
gl_debug (DEBUG_VIEW, "START");
- g_return_val_if_fail (view && GL_IS_VIEW (view), GNOME_FONT_BOOK);
+ g_return_val_if_fail (view && GL_IS_VIEW (view), PANGO_WEIGHT_NORMAL);
gl_debug (DEBUG_VIEW, "END");
return view->default_fill_color;
}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Focus in event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+focus_in_event_cb (glView *view,
+ GdkEventFocus *event)
+{
+ GTK_WIDGET_SET_FLAGS (GTK_WIDGET (view->canvas), GTK_HAS_FOCUS);
+
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Focus out event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+focus_out_event_cb (glView *view,
+ GdkEventFocus *event)
+{
+ GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (view->canvas), GTK_HAS_FOCUS);
+
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Enter notify event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+enter_notify_event_cb (glView *view,
+ GdkEventCrossing *event)
+{
+ gtk_widget_grab_focus(GTK_WIDGET (view->canvas));
+
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Leave notify event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+leave_notify_event_cb (glView *view,
+ GdkEventCrossing *event)
+{
+
+ g_signal_emit (G_OBJECT(view), signals[POINTER_EXIT], 0);
+
+ return FALSE;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Motion notify event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+motion_notify_event_cb (glView *view,
+ GdkEventMotion *event)
+{
+ gboolean return_value = FALSE;
+ cairo_t *cr;
+ gdouble scale;
+ gdouble x, y;
+ GdkCursor *cursor;
+ glViewObjectHandle handle;
+
+ cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window);
+
+ /*
+ * Translate to label coordinates
+ */
+ scale = view->zoom * view->home_scale;
+ cairo_scale (cr, scale, scale);
+ cairo_translate (cr, view->x0, view->y0);
+
+ x = event->x;
+ y = event->y;
+ cairo_device_to_user (cr, &x, &y);
+
+ /*
+ * Emit signal regardless of mode
+ */
+ g_signal_emit (G_OBJECT(view), signals[POINTER_MOVED], 0, x, y);
+
+ /*
+ * Handle event as appropriate for mode
+ */
+ switch (view->mode)
+ {
+
+ case GL_VIEW_MODE_ARROW:
+ switch (view->state)
+ {
+
+ case GL_VIEW_IDLE:
+ if (view_handle_at (view, cr, event->x, event->y, &handle))
+ {
+ cursor = gdk_cursor_new (GDK_CROSSHAIR);
+ }
+ else if (view_view_object_at (view, cr, event->x, event->y))
+ {
+ cursor = gdk_cursor_new (GDK_FLEUR);
+ }
+ else
+ {
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ }
+ gdk_window_set_cursor (view->canvas->window, cursor);
+ gdk_cursor_unref (cursor);
+ break;
+
+ case GL_VIEW_ARROW_SELECT_REGION:
+ view->select_region_x2 = x;
+ view->select_region_y2 = y;
+ gl_view_update (view);
+ break;
+
+ case GL_VIEW_ARROW_MOVE:
+ gl_view_move_selection (view,
+ (x - view->move_last_x),
+ (y - view->move_last_y));
+ view->move_last_x = x;
+ view->move_last_y = y;
+ break;
+
+ case GL_VIEW_ARROW_RESIZE:
+ gl_view_object_resize_event (view->resize_object,
+ view->resize_handle,
+ view->resize_honor_aspect,
+ cr,
+ event->x,
+ event->y);
+ break;
+
+ default:
+ g_message ("Invalid arrow state."); /*Should not happen!*/
+ }
+ return_value = TRUE;
+ break;
+
+
+ case GL_VIEW_MODE_OBJECT_CREATE:
+ if (view->state != GL_VIEW_IDLE)
+ {
+ switch (view->create_type)
+ {
+ case GL_LABEL_OBJECT_BOX:
+ gl_view_box_create_motion_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_ELLIPSE:
+ gl_view_ellipse_create_motion_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_LINE:
+ gl_view_line_create_motion_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_IMAGE:
+ gl_view_image_create_motion_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_TEXT:
+ gl_view_text_create_motion_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_BARCODE:
+ gl_view_barcode_create_motion_event (view, x, y);
+ break;
+ default:
+ g_message ("Invalid create type."); /*Should not happen!*/
+ }
+ }
+ break;
+
+
+ default:
+ g_message ("Invalid view mode."); /*Should not happen!*/
+
+ }
+
+ cairo_destroy (cr);
+
+ return return_value;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Button press event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+button_press_event_cb (glView *view,
+ GdkEventButton *event)
+{
+ gboolean return_value = FALSE;
+ cairo_t *cr;
+ gdouble scale;
+ gdouble x, y;
+ glViewObject *view_object;
+ glViewObjectHandle handle;
+
+ cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window);
+
+ /*
+ * Translate to label coordinates
+ */
+ scale = view->zoom * view->home_scale;
+ cairo_scale (cr, scale, scale);
+ cairo_translate (cr, view->x0, view->y0);
+
+ x = event->x;
+ y = event->y;
+ cairo_device_to_user (cr, &x, &y);
+
+ switch (event->button)
+ {
+
+ case 1:
+ /*
+ * Handle event as appropriate for mode
+ */
+ switch (view->mode)
+ {
+ case GL_VIEW_MODE_ARROW:
+ if ((view_object = view_handle_at (view, cr, event->x, event->y, &handle)))
+ {
+ view->resize_object = view_object;
+ view->resize_handle = handle;
+ view->resize_honor_aspect = event->state & GDK_CONTROL_MASK;
+
+ view->state = GL_VIEW_ARROW_RESIZE;
+ }
+ else if ((view_object = view_view_object_at (view, cr, event->x, event->y)))
+ {
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ if (gl_view_is_object_selected (view, view_object))
+ {
+ /* Un-selecting a selected item */
+ gl_view_unselect_object (view, view_object);
+ } else {
+ /* Add to current selection */
+ gl_view_select_object (view, view_object);
+ }
+ }
+ else
+ {
+ if (!gl_view_is_object_selected (view, view_object))
+ {
+ /* remove any selections before adding */
+ gl_view_unselect_all (view);
+ /* Add to current selection */
+ gl_view_select_object (view, view_object);
+ }
+ }
+ view->move_last_x = x;
+ view->move_last_y = y;
+
+ view->state = GL_VIEW_ARROW_MOVE;
+ }
+ else
+ {
+ if (!(event->state & GDK_CONTROL_MASK))
+ {
+ gl_view_unselect_all (view);
+ }
+
+ view->select_region_visible = TRUE;
+ view->select_region_x1 = x;
+ view->select_region_y1 = y;
+ view->select_region_x2 = x;
+ view->select_region_y2 = y;
+ gl_view_update (view);
+
+ view->state = GL_VIEW_ARROW_SELECT_REGION;
+ }
+
+
+ return_value = TRUE;
+ break;
+
+ case GL_VIEW_MODE_OBJECT_CREATE:
+ switch (view->create_type)
+ {
+ case GL_LABEL_OBJECT_BOX:
+ gl_view_box_create_button_press_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_ELLIPSE:
+ gl_view_ellipse_create_button_press_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_LINE:
+ gl_view_line_create_button_press_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_IMAGE:
+ gl_view_image_create_button_press_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_TEXT:
+ gl_view_text_create_button_press_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_BARCODE:
+ gl_view_barcode_create_button_press_event (view, x, y);
+ break;
+ default:
+ g_message ("Invalid create type."); /*Should not happen!*/
+ }
+ view->state = GL_VIEW_CREATE_DRAG;
+ return_value = TRUE;
+ break;
+
+ default:
+ g_message ("Invalid view mode."); /*Should not happen!*/
+ }
+ break;
+
+ case 3:
+ g_signal_emit (G_OBJECT (view),
+ signals[CONTEXT_MENU_ACTIVATE], 0,
+ event->button, event->time);
+ return_value = TRUE;
+ break;
+
+ }
+
+ cairo_destroy (cr);
+
+ return return_value;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Button release event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+button_release_event_cb (glView *view,
+ GdkEventButton *event)
+{
+ gboolean return_value = FALSE;
+ cairo_t *cr;
+ gdouble scale;
+ gdouble x, y;
+ GdkCursor *cursor;
+
+ cr = gdk_cairo_create (GTK_LAYOUT (view->canvas)->bin_window);
+
+ /*
+ * Translate to label coordinates
+ */
+ scale = view->zoom * view->home_scale;
+ cairo_scale (cr, scale, scale);
+ cairo_translate (cr, view->x0, view->y0);
+
+ x = event->x;
+ y = event->y;
+ cairo_device_to_user (cr, &x, &y);
+
+ switch (event->button)
+ {
+
+ case 1:
+ /*
+ * Handle event as appropriate for mode
+ */
+ switch (view->mode)
+ {
+ case GL_VIEW_MODE_ARROW:
+ switch (view->state)
+ {
+ case GL_VIEW_ARROW_RESIZE:
+ view->resize_object = NULL;
+
+ view->state = GL_VIEW_IDLE;
+ break;
+
+ case GL_VIEW_ARROW_SELECT_REGION:
+ view->select_region_visible = FALSE;
+ view->select_region_x2 = x;
+ view->select_region_y2 = y;
+
+ gl_view_select_region (view,
+ view->select_region_x1,
+ view->select_region_y1,
+ view->select_region_x2,
+ view->select_region_y2);
+
+ gl_view_update (view);
+
+ view->state = GL_VIEW_IDLE;
+ break;
+
+ default:
+ view->state = GL_VIEW_IDLE;
+ break;
+
+ }
+
+ return_value = TRUE;
+ break;
+
+
+ case GL_VIEW_MODE_OBJECT_CREATE:
+ switch (view->create_type)
+ {
+ case GL_LABEL_OBJECT_BOX:
+ gl_view_box_create_button_release_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_ELLIPSE:
+ gl_view_ellipse_create_button_release_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_LINE:
+ gl_view_line_create_button_release_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_IMAGE:
+ gl_view_image_create_button_release_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_TEXT:
+ gl_view_text_create_button_release_event (view, x, y);
+ break;
+ case GL_LABEL_OBJECT_BARCODE:
+ gl_view_barcode_create_button_release_event (view, x, y);
+ break;
+ default:
+ g_message ("Invalid create type."); /*Should not happen!*/
+ }
+ view->mode = GL_VIEW_MODE_ARROW;
+ view->state = GL_VIEW_IDLE;
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ gdk_window_set_cursor (view->canvas->window, cursor);
+ gdk_cursor_unref (cursor);
+ break;
+
+
+ default:
+ g_message ("Invalid view mode."); /*Should not happen!*/
+ }
+
+ }
+
+ cairo_destroy (cr);
+
+ return return_value;
+}
+
+/*---------------------------------------------------------------------------*/
+/* PRIVATE. Key press event handler. */
+/*---------------------------------------------------------------------------*/
+static gboolean
+key_press_event_cb (glView *view,
+ GdkEventKey *event)
+{
+ GdkCursor *cursor;
+
+ gl_debug (DEBUG_VIEW, "");
+
+ if ( (view->mode == GL_VIEW_MODE_ARROW) &&
+ (view->state == GL_VIEW_IDLE) )
+ {
+ switch (event->keyval) {
+
+ case GDK_Left:
+ case GDK_KP_Left:
+ gl_view_move_selection (view, -1.0 / (view->zoom), 0.0);
+ break;
+ case GDK_Up:
+ case GDK_KP_Up:
+ gl_view_move_selection (view, 0.0, -1.0 / (view->zoom));
+ break;
+ case GDK_Right:
+ case GDK_KP_Right:
+ gl_view_move_selection (view, 1.0 / (view->zoom), 0.0);
+ break;
+ case GDK_Down:
+ case GDK_KP_Down:
+ gl_view_move_selection (view, 0.0, 1.0 / (view->zoom));
+ break;
+ case GDK_Delete:
+ case GDK_KP_Delete:
+ gl_view_delete_selection (view);
+ cursor = gdk_cursor_new (GDK_LEFT_PTR);
+ gdk_window_set_cursor (GTK_WIDGET (view->canvas)->window
+, cursor);
+ gdk_cursor_unref (cursor);
+ break;
+ default:
+ return FALSE;
+
+ }
+ }
+ return TRUE; /* We handled this or we were dragging. */
+}
+
*
* view.h: GLabels View module header file
*
- * Copyright (C) 2001-2005 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2001-2007 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define __VIEW_H__
#include <gtk/gtkvbox.h>
-#include <libgnomecanvas/libgnomecanvas.h>
-#include <libgnomeprint/gnome-font.h>
#include "label-object.h"
typedef enum {
- GL_VIEW_STATE_ARROW,
- GL_VIEW_STATE_OBJECT_CREATE
+ GL_VIEW_MODE_ARROW,
+ GL_VIEW_MODE_OBJECT_CREATE
+} glViewMode;
+
+typedef enum {
+ GL_VIEW_IDLE = 0,
+ GL_VIEW_ARROW_SELECT_REGION,
+ GL_VIEW_ARROW_MOVE,
+ GL_VIEW_ARROW_RESIZE,
+ GL_VIEW_CREATE_DRAG,
} glViewState;
#define GL_TYPE_VIEW (gl_view_get_type ())
#include "color.h"
struct _glView {
- GtkVBox parent_widget;
+ GtkVBox parent_widget;
+
+ glLabel *label;
+
+ GtkWidget *canvas;
+ gdouble zoom;
+ gboolean zoom_to_fit_flag;
+ gdouble home_scale;
+ gdouble x0, y0;
+ gdouble w, h;
- glLabel *label;
+ gboolean grid_visible;
+ gdouble grid_spacing;
- GtkWidget *canvas;
- gdouble zoom;
- gboolean zoom_to_fit_flag;
- gdouble home_scale;
+ gboolean markup_visible;
- GnomeCanvasGroup *bg_group; /* Background layer */
- GnomeCanvasGroup *grid_group; /* Grid layer */
- GnomeCanvasGroup *markup_group; /* Markup layer */
- GnomeCanvasGroup *label_group; /* Label layer (user objects) */
- GnomeCanvasGroup *fg_group; /* Foreground layer */
- GnomeCanvasGroup *highlight_group; /* Highlight layer */
+ glViewMode mode;
+ glLabelObjectType create_type;
+ glViewState state;
- gdouble grid_spacing;
+ /* GL_VIEW_ARROW_MOVE state */
+ gdouble move_last_x;
+ gdouble move_last_y;
- glViewState state;
- glLabelObjectType create_type;
+ /* GL_VIEW_ARROW_SELECT_REGION state */
+ gboolean select_region_visible;
+ gdouble select_region_x1;
+ gdouble select_region_y1;
+ gdouble select_region_x2;
+ gdouble select_region_y2;
+
+ /* GL_VIEW_ARROW_RESIZE state */
+ glViewObject *resize_object;
+ glViewObjectHandle resize_handle;
+ gboolean resize_honor_aspect;
+
+ /* GL_VIEW_CREATE_DRAG state */
+ glLabelObject *create_object;
+ gdouble create_x0;
+ gdouble create_y0;
GList *object_list; /* glViewObjects */
GList *selected_object_list; /* glViewObjects */
/* Clipboard selection stuff */
- gint have_selection;
+ gint have_selection;
glLabel *selection_data;
GtkWidget *invisible;
/* Default object text properties */
gchar *default_font_family;
gdouble default_font_size;
- GnomeFontWeight default_font_weight;
+ PangoWeight default_font_weight;
gboolean default_font_italic_flag;
guint default_text_color;
PangoAlignment default_text_alignment;
guint default_line_color;
/* Default object fill properties */
- guint default_fill_color;
+ guint default_fill_color;
+
};
struct _glViewClass {
GtkWidget *gl_view_new (glLabel *label);
+void gl_view_update (glView *view);
+
void gl_view_show_grid (glView *view);
void gl_view_hide_grid (glView *view);
gdouble font_size);
void gl_view_set_selection_font_weight (glView *view,
- GnomeFontWeight font_weight);
+ PangoWeight font_weight);
void gl_view_set_selection_text_line_spacing (glView *view,
gdouble text_line_spacing);
gdouble font_size);
void gl_view_set_default_font_weight (glView *view,
- GnomeFontWeight font_weight);
+ PangoWeight font_weight);
void gl_view_set_default_font_italic_flag (glView *view,
gboolean font_italic_flag);
gdouble gl_view_get_default_font_size (glView *view);
-GnomeFontWeight gl_view_get_default_font_weight (glView *view);
+PangoWeight gl_view_get_default_font_weight (glView *view);
gboolean gl_view_get_default_font_italic_flag (glView *view);
static void template_selection_changed_cb (GtkTreeSelection *selection,
gpointer user_data);
-static void details_update (glWdgtMediaSelect *media_select,
- gchar *name);
-
static gchar *get_layout_desc (const glTemplate *template);
static gchar *get_label_size_desc (const glTemplate *template);
static void load_list (GtkListStore *store,
gl_wdgt_media_select_construct (glWdgtMediaSelect *media_select)
{
GtkWidget *hbox;
- GtkWidget *preview_vbox;
GList *page_sizes = NULL;
GList *categories = NULL;
GList *template_names = NULL;
const gchar *page_size_id;
gchar *page_size_name;
- gchar *name;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
- GtkTreeIter iter;
- GtkTreeModel *model;
gl_debug (DEBUG_MEDIA_SELECT, "START");
gchar *category_name, *category_id;
GList *template_names;
GtkTreeSelection *selection;
- GtkTreeIter iter;
- GtkTreeModel *model;
gl_debug (DEBUG_MEDIA_SELECT, "START");
template_selection_changed_cb (GtkTreeSelection *selection,
gpointer user_data)
{
- glWdgtMediaSelect *media_select = GL_WDGT_MEDIA_SELECT (user_data);
-
gl_debug (DEBUG_MEDIA_SELECT, "START");
/* Emit our "changed" signal */
{
const glTemplateLabelType *label_type;
gint n_labels;
- glTemplateLayout *layout;
gchar *string;
label_type = gl_template_get_first_label_type (template);
size = get_label_size_desc (template);
layout = get_layout_desc (template);
description = g_strdup_printf ("<b>%s</b>\n%s\n%s",
- p->data,
+ (gchar *)p->data,
size,
layout);
g_free (size);
static void
gl_wdgt_print_copies_finalize (GObject * object)
{
- glWdgtPrintCopies *copies = GL_WDGT_PRINT_COPIES (object);
-
g_return_if_fail (object != NULL);
g_return_if_fail (GL_IS_WDGT_PRINT_COPIES (object));
gl_wdgt_print_copies_construct (glWdgtPrintCopies *copies,
glLabel *label)
{
- glTemplate *template;
const glTemplateLabelType *label_type;
GtkWidget *whbox, *wvbox, *whbox1;
GSList *radio_group = NULL;
whbox = GTK_WIDGET (copies);
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
+ label_type = gl_template_get_first_label_type (label->template);
copies->labels_per_sheet = gl_template_get_n_labels (label_type);
copies->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
WDGT_MINI_PREVIEW_WIDTH);
gl_wdgt_mini_preview_set_template (GL_WDGT_MINI_PREVIEW(copies->mini_preview),
- template);
+ label->template);
gtk_box_pack_start (GTK_BOX(whbox), copies->mini_preview, FALSE, FALSE, 0);
wvbox = gtk_vbox_new (FALSE, GL_HIG_PAD1);
G_CALLBACK (first_spin_cb), copies);
g_signal_connect (G_OBJECT (copies->last_spin), "changed",
G_CALLBACK (last_spin_cb), copies);
-
- gl_template_free (template);
}
/*--------------------------------------------------------------------------*/
static void
gl_wdgt_print_merge_finalize (GObject * object)
{
- glWdgtPrintMerge *merge = GL_WDGT_PRINT_MERGE (object);
-
g_return_if_fail (object != NULL);
g_return_if_fail (GL_IS_WDGT_PRINT_MERGE (object));
gl_wdgt_print_merge_construct (glWdgtPrintMerge * merge,
glLabel * label)
{
- glTemplate *template;
const glTemplateLabelType *label_type;
GtkWidget *whbox, *wvbox, *whbox1;
GtkObject *adjust;
whbox = GTK_WIDGET (merge);
- template = gl_label_get_template (label);
- label_type = gl_template_get_first_label_type (template);
+ label_type = gl_template_get_first_label_type (label->template);
merge->labels_per_sheet = gl_template_get_n_labels (label_type);
merge->mini_preview = gl_wdgt_mini_preview_new (WDGT_MINI_PREVIEW_HEIGHT,
WDGT_MINI_PREVIEW_WIDTH);
gl_wdgt_mini_preview_set_template( GL_WDGT_MINI_PREVIEW (merge->mini_preview),
- template );
+ label->template );
gtk_box_pack_start (GTK_BOX(whbox), merge->mini_preview, FALSE, FALSE, 0);
gl_wdgt_mini_preview_highlight_range (GL_WDGT_MINI_PREVIEW(merge->mini_preview),
1, 1);
G_CALLBACK (spin_cb), merge);
g_signal_connect (G_OBJECT (merge->first_spin), "changed",
G_CALLBACK (spin_cb), merge);
-
- gl_template_free (template);
}
/*--------------------------------------------------------------------------*/
static void
gl_window_finalize (GObject *object)
{
- glWindow *window = GL_WINDOW (object);
-
gl_debug (DEBUG_WINDOW, "START");
g_return_if_fail (object != NULL);
{
glLabel *label;
xmlNodePtr node;
- xmlNsPtr ns;
GObject *object;
gboolean rotate_flag;
font_family = xmlGetProp (object_node, (xmlChar *)"font_family");
font_size = gl_xml_get_prop_double (object_node, "font_size", 0);
string = xmlGetProp (object_node, (xmlChar *)"font_weight");
- font_weight = gl_util_string_to_weight (string);
+ font_weight = gl_util_string_to_weight ((gchar *)string);
xmlFree (string);
font_italic_flag = gl_xml_get_prop_boolean (object_node, "font_italic", FALSE);
string = xmlGetProp (object_node, (xmlChar *)"justify");
- align = gl_util_string_to_align (string);
+ align = gl_util_string_to_align ((gchar *)string);
xmlFree (string);
color_node = gl_color_node_new_default ();
glLabel *label)
{
glMerge *merge;
- xmlNodePtr child;
xmlChar *string;
gl_debug (DEBUG_XML, "START");
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * label.c: GLabels xml label 1.91 compat module
- *
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <config.h>
-
-#include "xml-label-191.h"
-
-#include <glib/gi18n.h>
-#include <libxml/tree.h>
-#include <libxml/parser.h>
-#include <gdk-pixbuf/gdk-pixdata.h>
-
-#include "label.h"
-#include "label-object.h"
-#include "label-text.h"
-#include "label-box.h"
-#include "label-line.h"
-#include "label-ellipse.h"
-#include "label-image.h"
-#include "label-barcode.h"
-#include "base64.h"
-#include "xml-label.h"
-#include <libglabels/paper.h>
-#include <libglabels/template.h>
-#include <libglabels/xml-template.h>
-#include <libglabels/xml.h>
-#include "util.h"
-
-#include "debug.h"
-
-/*========================================================*/
-/* Private macros and constants. */
-/*========================================================*/
-
-/*========================================================*/
-/* Private types. */
-/*========================================================*/
-
-/*========================================================*/
-/* Private globals. */
-/*========================================================*/
-
-/*========================================================*/
-/* Private function prototypes. */
-/*========================================================*/
-
-static void xml191_parse_objects (xmlNodePtr node,
- glLabel *label);
-
-static void xml191_parse_object (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_text_props (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_box_props (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_line_props (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_ellipse_props (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_image_props (xmlNodePtr node,
- glLabel *label);
-
-static glLabelObject *xml191_parse_barcode_props (xmlNodePtr node,
- glLabel *label);
-
-static void xml191_parse_merge_fields (xmlNodePtr node,
- glLabel *label);
-
-static void xml191_parse_data (xmlNodePtr node,
- glLabel *label);
-
-static void xml191_parse_pixdata (xmlNodePtr node,
- glLabel *label);
-
-static glTemplate *xml191_parse_sheet (xmlNodePtr node);
-
-static void xml191_parse_label (xmlNodePtr label_node,
- glTemplate *template);
-
-static void xml191_parse_layout (xmlNodePtr layout_node,
- glTemplateLabelType *label_type);
-
-static void xml191_parse_markup (xmlNodePtr markup_node,
- glTemplateLabelType *label_type);
-
-static void xml191_parse_alias (xmlNodePtr alias_node,
- glTemplate *template);
-
-
-
-/****************************************************************************/
-/* Parse xml root node and create label. */
-/****************************************************************************/
-glLabel *
-gl_xml_label_191_parse (xmlNodePtr root,
- glXMLLabelStatus *status)
-{
- xmlNodePtr node;
- glLabel *label;
- glTemplate *template;
-
- gl_debug (DEBUG_XML, "START");
-
- *status = XML_LABEL_OK;
-
- if (!xmlStrEqual (root->name, (xmlChar *)"Document")) {
- g_message (_("Bad root node = \"%s\""), root->name);
- *status = XML_LABEL_ERROR_OPEN_PARSE;
- return NULL;
- }
-
- label = GL_LABEL(gl_label_new ());
-
- /* Pass 1, extract data nodes to pre-load cache. */
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
- if (xmlStrEqual (node->name, (xmlChar *)"Data")) {
- xml191_parse_data (node, label);
- }
- }
-
- /* Pass 2, now extract everything else. */
- for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
-
- if (xmlStrEqual (node->name, (xmlChar *)"Sheet")) {
- template = xml191_parse_sheet (node);
- if (!template) {
- *status = XML_LABEL_UNKNOWN_MEDIA;
- return NULL;
- }
- gl_template_register (template);
- gl_label_set_template (label, template);
- gl_template_free (template);
- } else if (xmlStrEqual (node->name, (xmlChar *)"Objects")) {
- xml191_parse_objects (node, label);
- } else if (xmlStrEqual (node->name, (xmlChar *)"Merge_Fields")) {
- xml191_parse_merge_fields (node, label);
- } else if (xmlStrEqual (node->name, (xmlChar *)"Data")) {
- /* Handled in pass 1. */
- } else {
- if (!xmlNodeIsText (node)) {
- g_message (_("bad node in Document node = \"%s\""),
- node->name);
- }
- }
- }
-
- gl_debug (DEBUG_XML, "END");
-
- return label;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse Objects node. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_objects (xmlNodePtr objects_node,
- glLabel *label)
-{
- gboolean rotate_flag;
- xmlNodePtr node;
-
- gl_debug (DEBUG_XML, "START");
-
- rotate_flag = gl_xml_get_prop_boolean (objects_node, "rotate", FALSE);
- gl_label_set_rotate_flag (label, rotate_flag);
-
- for (node = objects_node->xmlChildrenNode; node != NULL; node = node->next) {
-
- if (xmlStrEqual (node->name, (xmlChar *)"Object")) {
- xml191_parse_object (node, label);
- } else {
- if (!xmlNodeIsText (node)) {
- g_message (_("bad node = \"%s\""), node->name);
- }
- }
- }
-
- gl_debug (DEBUG_XML, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Object Node */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_object (xmlNodePtr object_node,
- glLabel *label)
-{
- glLabelObject *object;
- gdouble x, y;
- xmlChar *string;
- gdouble affine[6];
-
- gl_debug (DEBUG_XML, "START");
-
- string = xmlGetProp (object_node, (xmlChar *)"type");
-
- if ( xmlStrEqual (string, (xmlChar *)"Text") ) {
- object = xml191_parse_text_props (object_node, label);
- } else if ( xmlStrEqual (string, (xmlChar *)"Box") ) {
- object = xml191_parse_box_props (object_node, label);
- } else if ( xmlStrEqual (string, (xmlChar *)"Line") ) {
- object = xml191_parse_line_props (object_node, label);
- } else if ( xmlStrEqual (string, (xmlChar *)"Ellipse") ) {
- object = xml191_parse_ellipse_props (object_node, label);
- } else if ( xmlStrEqual (string, (xmlChar *)"Image") ) {
- object = xml191_parse_image_props (object_node, label);
- } else if ( xmlStrEqual (string, (xmlChar *)"Barcode") ) {
- object = xml191_parse_barcode_props (object_node, label);
- } else {
- g_message ("Unknown label object type \"%s\"", string);
- xmlFree (string);
- return;
- }
- xmlFree (string);
-
-
- x = gl_xml_get_prop_length (object_node, "x", 0.0);
- y = gl_xml_get_prop_length (object_node, "y", 0.0);
-
- gl_label_object_set_position (object, x, y);
-
-
- affine[0] = gl_xml_get_prop_double (object_node, "a0", 0.0);
- affine[1] = gl_xml_get_prop_double (object_node, "a1", 0.0);
- affine[2] = gl_xml_get_prop_double (object_node, "a2", 0.0);
- affine[3] = gl_xml_get_prop_double (object_node, "a3", 0.0);
- affine[4] = gl_xml_get_prop_double (object_node, "a4", 0.0);
- affine[5] = gl_xml_get_prop_double (object_node, "a5", 0.0);
-
- gl_label_object_set_affine (object, affine);
-
-
- gl_debug (DEBUG_XML, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Text Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_text_props (xmlNodePtr object_node,
- glLabel *label)
-{
- GObject *object;
- GList *lines;
- gdouble w, h;
- xmlChar *font_family;
- gdouble font_size;
- PangoWeight font_weight;
- gboolean font_italic_flag;
- glColorNode *color_node;
- PangoAlignment align;
- xmlNodePtr line_node, text_node;
- glTextNode *node_text;
- GList *nodes;
- xmlChar *string;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_text_new (label);
-
- w = gl_xml_get_prop_length (object_node, "w", 0);
- h = gl_xml_get_prop_length (object_node, "h", 0);
-
- font_family = xmlGetProp (object_node, (xmlChar *)"font_family");
-
- font_size = gl_xml_get_prop_double (object_node, "font_size", 0.0);
-
- string = xmlGetProp (object_node, (xmlChar *)"font_weight");
- font_weight = gl_util_string_to_weight ((gchar *)string);
- xmlFree (string);
-
- font_italic_flag = gl_xml_get_prop_boolean (object_node, "font_italic", FALSE);
-
- string = xmlGetProp (object_node, (xmlChar *)"justify");
- align = gl_util_string_to_align ((gchar *)string);
- xmlFree (string);
-
- color_node = gl_color_node_new_default ();
- color_node->color = gl_xml_get_prop_uint (object_node, "color", 0);
-
- lines = NULL;
- for (line_node = object_node->xmlChildrenNode;
- line_node != NULL;
- line_node = line_node->next) {
-
- if (xmlStrEqual (line_node->name, (xmlChar *)"Line")) {
-
- nodes = NULL;
- for (text_node = line_node->xmlChildrenNode;
- text_node != NULL; text_node = text_node->next) {
-
- if (xmlStrEqual (text_node->name, (xmlChar *)"Field")) {
- node_text = g_new0 (glTextNode, 1);
- node_text->field_flag = TRUE;
- node_text->data = (gchar *)xmlGetProp (text_node, (xmlChar *)"name");
- nodes = g_list_append (nodes, node_text);
- } else if (xmlStrEqual (text_node->name, (xmlChar *)"Literal")) {
- node_text = g_new0 (glTextNode, 1);
- node_text->field_flag = FALSE;
- node_text->data =
- (gchar *)xmlNodeGetContent (text_node);
- nodes =
- g_list_append (nodes, node_text);
- } else if (!xmlNodeIsText (text_node)) {
- g_message ("Unexpected Text Line child: \"%s\"",
- text_node->name);
- }
-
- }
- lines = g_list_append (lines, nodes);
-
- } else if (!xmlNodeIsText (line_node)) {
- g_message ("Unexpected Text child: \"%s\"",
- line_node->name);
- }
-
- }
-
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
- gl_label_text_set_lines (GL_LABEL_TEXT(object), lines);
- gl_label_object_set_font_family (GL_LABEL_OBJECT(object), (gchar *)font_family);
- gl_label_object_set_font_size (GL_LABEL_OBJECT(object), font_size);
- gl_label_object_set_font_weight (GL_LABEL_OBJECT(object), font_weight);
- gl_label_object_set_font_italic_flag (GL_LABEL_OBJECT(object), font_italic_flag);
- gl_label_object_set_text_color (GL_LABEL_OBJECT(object), color_node);
- gl_label_object_set_text_alignment (GL_LABEL_OBJECT(object), align);
-
- gl_color_node_free (&color_node);
- gl_text_node_lines_free (&lines);
- xmlFree (font_family);
-
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Box Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_box_props (xmlNodePtr node,
- glLabel *label)
-{
- GObject *object;
- gdouble line_width;
- glColorNode *line_color_node;
- glColorNode *fill_color_node;
- gdouble w, h;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_box_new (label);
-
- w = gl_xml_get_prop_length (node, "w", 0);
- h = gl_xml_get_prop_length (node, "h", 0);
-
- line_width = gl_xml_get_prop_length (node, "line_width", 1.0);
-
- line_color_node = gl_color_node_new_default ();
- line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0);
-
- fill_color_node = gl_color_node_new_default ();
- fill_color_node->color = gl_xml_get_prop_uint (node, "fill_color", 0);
-
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), line_color_node);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object), fill_color_node);
-
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Line Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_line_props (xmlNodePtr node,
- glLabel *label)
-{
- GObject *object;
- gdouble line_width;
- glColorNode *line_color_node;
- gdouble w, h;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_line_new (label);
-
- w = gl_xml_get_prop_length (node, "dx", 0);
- h = gl_xml_get_prop_length (node, "dy", 0);
-
- line_width = gl_xml_get_prop_length (node, "line_width", 1.0);
-
- line_color_node = gl_color_node_new_default ();
- line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0);
-
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), line_color_node);
-
- gl_color_node_free (&line_color_node);
-
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Ellipse Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_ellipse_props (xmlNodePtr node,
- glLabel *label)
-{
- GObject *object;
- gdouble line_width;
- glColorNode *line_color_node;
- glColorNode *fill_color_node;
- gdouble w, h;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_ellipse_new (label);
-
- w = gl_xml_get_prop_length (node, "w", 0);
- h = gl_xml_get_prop_length (node, "h", 0);
-
- line_width = gl_xml_get_prop_length (node, "line_width", 1.0);
-
- line_color_node = gl_color_node_new_default ();
- line_color_node->color = gl_xml_get_prop_uint (node, "line_color", 0);
-
- fill_color_node = gl_color_node_new_default ();
- fill_color_node->color = gl_xml_get_prop_uint (node, "fill_color", 0);
-
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
- gl_label_object_set_line_width (GL_LABEL_OBJECT(object), line_width);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), line_color_node);
- gl_label_object_set_fill_color (GL_LABEL_OBJECT(object), fill_color_node);
-
- gl_color_node_free (&line_color_node);
- gl_color_node_free (&fill_color_node);
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Image Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_image_props (xmlNodePtr node,
- glLabel *label)
-{
- GObject *object;
- xmlNodePtr child;
- gdouble w, h;
- glTextNode *filename;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_image_new (label);
-
- w = gl_xml_get_prop_length (node, "w", 0);
- h = gl_xml_get_prop_length (node, "h", 0);
-
- filename = g_new0 (glTextNode, 1);
- for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
- if (xmlStrEqual (child->name, (xmlChar *)"Field")) {
- filename->field_flag = TRUE;
- filename->data = (gchar *)xmlGetProp (child, (xmlChar *)"name");
- } else if (xmlStrEqual (child->name, (xmlChar *)"File")) {
- filename->field_flag = FALSE;
- filename->data = (gchar *)xmlGetProp (child, (xmlChar *)"src");
- } else if (!xmlNodeIsText (child)) {
- g_message ("Unexpected Image child: \"%s\"", child->name);
- }
- }
-
- gl_label_image_set_filename (GL_LABEL_IMAGE(object), filename);
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
-
- gl_text_node_free (&filename);
-
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Label->Barcode Node Properties */
-/*--------------------------------------------------------------------------*/
-static glLabelObject *
-xml191_parse_barcode_props (xmlNodePtr node,
- glLabel *label)
-{
- GObject *object;
- xmlNodePtr child;
- gdouble w, h;
- glTextNode *text_node;
- xmlChar *id;
- gboolean text_flag;
- gboolean checksum_flag;
- glColorNode *color_node;
-
- gl_debug (DEBUG_XML, "START");
-
- object = gl_label_barcode_new (label);
-
- w = gl_xml_get_prop_length (node, "w", 0);
- h = gl_xml_get_prop_length (node, "h", 0);
-
- color_node = gl_color_node_new_default ();
- color_node->color = gl_xml_get_prop_uint (node, "color", 0);
-
- id = xmlGetProp (node, (xmlChar *)"style");
-
- text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
- checksum_flag = gl_xml_get_prop_boolean (node, "checksum", TRUE);
-
- text_node = g_new0 (glTextNode, 1);
- for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
- if (xmlStrEqual (child->name, (xmlChar *)"Field")) {
- text_node->field_flag = TRUE;
- text_node->data = (gchar *)xmlGetProp (child, (xmlChar *)"name");
- } else if (xmlStrEqual (child->name, (xmlChar *)"Literal")) {
- text_node->field_flag = FALSE;
- text_node->data = (gchar *)xmlNodeGetContent (child);
- } else if (!xmlNodeIsText (child)) {
- g_message ("Unexpected Barcode child: \"%s\"", child->name);
- }
- }
-
- gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
-
- gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
- gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
- (gchar *)id, text_flag, checksum_flag, 0);
- gl_label_object_set_line_color (GL_LABEL_OBJECT(object), color_node);
-
- gl_color_node_free (&color_node);
- gl_text_node_free (&text_node);
- xmlFree (id);
-
- gl_debug (DEBUG_XML, "END");
-
- return GL_LABEL_OBJECT(object);
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML merge fields tag. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_merge_fields (xmlNodePtr node,
- glLabel *label)
-{
- xmlNodePtr child;
- xmlChar *string;
- glMerge *merge;
-
- gl_debug (DEBUG_XML, "START");
-
- string = xmlGetProp (node, (xmlChar *)"type");
- merge = gl_merge_new ((gchar *)string);
- xmlFree (string);
-
- string = xmlGetProp (node, (xmlChar *)"src");
- gl_merge_set_src (merge, (gchar *)string);
- xmlFree (string);
-
- gl_label_set_merge (label, merge);
-
- g_object_unref (G_OBJECT(merge));
-
- gl_debug (DEBUG_XML, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML data tag. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_data (xmlNodePtr node,
- glLabel *label)
-{
- xmlNodePtr child;
-
- gl_debug (DEBUG_XML, "START");
-
- for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
-
- if (xmlStrEqual (child->name, (xmlChar *)"Pixdata")) {
- xml191_parse_pixdata (child, label);
- } else {
- if (!xmlNodeIsText (child)) {
- g_message (_("bad node in Data node = \"%s\""),
- child->name);
- }
- }
- }
-
- gl_debug (DEBUG_XML, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML pixbuf data tag. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_pixdata (xmlNodePtr node,
- glLabel *label)
-{
- xmlChar *name, *base64;
- guchar *stream;
- guint stream_length;
- gboolean ret;
- GdkPixdata *pixdata;
- GdkPixbuf *pixbuf;
- GHashTable *pixbuf_cache;
-
- gl_debug (DEBUG_XML, "START");
-
- name = xmlGetProp (node, (xmlChar *)"name");
- base64 = xmlNodeGetContent (node);
-
- stream = gl_base64_decode ((gchar *)base64, &stream_length);
- pixdata = g_new0 (GdkPixdata, 1);
- ret = gdk_pixdata_deserialize (pixdata, stream_length, stream, NULL);
-
- if (ret) {
- pixbuf = gdk_pixbuf_from_pixdata (pixdata, TRUE, NULL);
-
- pixbuf_cache = gl_label_get_pixbuf_cache (label);
- gl_pixbuf_cache_add_pixbuf (pixbuf_cache, (gchar *)name, pixbuf);
- }
-
- xmlFree (name);
- xmlFree (base64);
-
- g_free (stream);
- g_free (pixdata);
-
- gl_debug (DEBUG_XML, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML template Node. */
-/*--------------------------------------------------------------------------*/
-static glTemplate *
-xml191_parse_sheet (xmlNodePtr sheet_node)
-{
- xmlChar *name, *description, *page_size;
- gdouble page_width, page_height;
- glTemplate *template;
- xmlNodePtr node;
- glPaper *paper;
-
- gl_debug (DEBUG_TEMPLATE, "START");
-
- name = xmlGetProp (sheet_node, (xmlChar *)"name");
-
- page_size = xmlGetProp (sheet_node, (xmlChar *)"size");
- if (gl_paper_is_id_other ((gchar *)page_size)) {
-
- page_width = gl_xml_get_prop_length (sheet_node, "width", 0);
- page_height = gl_xml_get_prop_length (sheet_node, "height", 0);
-
- } else {
- paper = gl_paper_from_id (template->page_size);
- if (paper == NULL) {
- /* This should always be an id, but just in case a name
- slips by! */
- g_message (_("Unknown page size id \"%s\", trying as name"),
- template->page_size);
- paper = gl_paper_from_name (template->page_size);
- g_free (template->page_size);
- template->page_size = g_strdup (paper->id);
- }
- if (paper != NULL) {
- page_width = paper->width;
- page_height = paper->height;
- } else {
- g_message (_("Unknown page size id or name \"%s\""),
- page_size);
- }
- gl_paper_free (paper);
- }
-
- description = xmlGetProp (sheet_node, (xmlChar *)"_description");
- if (description != NULL) {
-
- xmlChar *tmp = (xmlChar *)gettext ((char *)description);
-
- if (tmp == description) {
- template->description = (gchar *)description;
- } else {
- template->description = g_strdup ((gchar *)tmp);
- }
-
-
- } else {
- template->description = (gchar *)xmlGetProp (sheet_node, (xmlChar *)"description");
- }
-
- template = gl_template_new ((gchar *)name, (gchar *)description,
- (gchar *)page_size, page_width, page_height);
-
- for (node = sheet_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (xmlStrEqual (node->name, (xmlChar *)"Label")) {
- xml191_parse_label (node, template);
- } else if (xmlStrEqual (node->name, (xmlChar *)"Alias")) {
- xml191_parse_alias (node, template);
- } else {
- if (!xmlNodeIsText (node)) {
- g_message ("bad node = \"%s\"", node->name);
- }
- }
- }
-
- xmlFree (name);
- xmlFree (description);
- xmlFree (page_size);
-
- gl_debug (DEBUG_TEMPLATE, "END");
-
- return template;
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Sheet->Label Node. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_label (xmlNodePtr label_node,
- glTemplate *template)
-{
- xmlChar *style;
- glTemplateLabelShape shape;
- gdouble w, h, r, r1, r2;
- glTemplateLabelType *label_type;
- xmlNodePtr node;
-
- gl_debug (DEBUG_TEMPLATE, "START");
-
- style = xmlGetProp (label_node, (xmlChar *)"style");
- if (xmlStrEqual (style, (xmlChar *)"rectangle")) {
- shape = GL_TEMPLATE_SHAPE_RECT;
- } else if (xmlStrEqual (style, (xmlChar *)"round")) {
- shape = GL_TEMPLATE_SHAPE_ROUND;
- } else if (xmlStrEqual (style, (xmlChar *)"cd")) {
- shape = GL_TEMPLATE_SHAPE_CD;
- } else {
- shape = GL_TEMPLATE_SHAPE_RECT;
- g_message ("Unknown label style in template");
- }
- xmlFree (style);
-
- switch (shape) {
-
- case GL_TEMPLATE_SHAPE_RECT:
- w = gl_xml_get_prop_length (label_node, "width", 0);
- h = gl_xml_get_prop_length (label_node, "height", 0);
- r = gl_xml_get_prop_length (label_node, "round", 0);
- label_type =
- gl_template_rect_label_type_new ("0", w, h, r, 0.0, 0.0);
- break;
-
- case GL_TEMPLATE_SHAPE_ROUND:
- r = gl_xml_get_prop_length (label_node, "round", 0);
- label_type =
- gl_template_round_label_type_new ("0", r, 0.0);
- break;
-
- case GL_TEMPLATE_SHAPE_CD:
- r1 = gl_xml_get_prop_length (label_node, "radius", 0);
- r2 = gl_xml_get_prop_length (label_node, "hole", 0);
- w = gl_xml_get_prop_length (label_node, "width", 0);
- h = gl_xml_get_prop_length (label_node, "height", 0);
- label_type =
- gl_template_cd_label_type_new ("0", r1, r2, w, h, 0.0);
- break;
-
- default:
- break;
-
- }
-
- gl_template_add_label_type (template, label_type);
-
- for (node = label_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (xmlStrEqual (node->name, (xmlChar *)"Layout")) {
- xml191_parse_layout (node, label_type);
- } else if (xmlStrEqual (node->name, (xmlChar *)"Markup")) {
- xml191_parse_markup (node, label_type);
- } else if (!xmlNodeIsText (node)) {
- g_message ("bad node = \"%s\"", node->name);
- }
- }
-
- gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Sheet->Label->Layout Node. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_layout (xmlNodePtr layout_node,
- glTemplateLabelType *label_type)
-{
- gint nx, ny;
- gdouble x0, y0, dx, dy;
- xmlNodePtr node;
-
- gl_debug (DEBUG_TEMPLATE, "START");
-
- nx = gl_xml_get_prop_int (layout_node, "nx", 1);
- ny = gl_xml_get_prop_int (layout_node, "ny", 1);
-
- x0 = gl_xml_get_prop_length (layout_node, "x0", 0);
- y0 = gl_xml_get_prop_length (layout_node, "y0", 0);
-
- dx = gl_xml_get_prop_length (layout_node, "dx", 0);
- dy = gl_xml_get_prop_length (layout_node, "dy", 0);
-
- for (node = layout_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- g_message ("bad node = \"%s\"", node->name);
- }
- }
-
- gl_template_add_layout (label_type,
- gl_template_layout_new (nx, ny, x0, y0, dx, dy));
-
- gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Sheet->Label->Markup Node. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_markup (xmlNodePtr markup_node,
- glTemplateLabelType *label_type)
-{
- xmlChar *type;
- gdouble size;
- gdouble x1, y1, x2, y2;
- xmlNodePtr node;
-
- gl_debug (DEBUG_TEMPLATE, "START");
-
- type = xmlGetProp (markup_node, (xmlChar *)"type");
- if (xmlStrEqual (type, (xmlChar *)"margin")) {
-
- size = gl_xml_get_prop_length (markup_node, "size", 0);
-
- gl_template_add_markup (label_type,
- gl_template_markup_margin_new (size));
-
- } else if (xmlStrEqual (type, (xmlChar *)"line")) {
-
- x1 = gl_xml_get_prop_length (markup_node, "x1", 0);
- y1 = gl_xml_get_prop_length (markup_node, "y1", 0);
- x2 = gl_xml_get_prop_length (markup_node, "x2", 0);
- y2 = gl_xml_get_prop_length (markup_node, "y2", 0);
-
- gl_template_add_markup (label_type,
- gl_template_markup_line_new (x1, y1, x2, y2));
- }
- xmlFree (type);
-
- for (node = markup_node->xmlChildrenNode; node != NULL;
- node = node->next) {
- if (!xmlNodeIsText (node)) {
- g_message ("bad node = \"%s\"", node->name);
- }
- }
-
- gl_debug (DEBUG_TEMPLATE, "END");
-}
-
-/*--------------------------------------------------------------------------*/
-/* PRIVATE. Parse XML Sheet->Alias Node. */
-/*--------------------------------------------------------------------------*/
-static void
-xml191_parse_alias (xmlNodePtr alias_node,
- glTemplate *template)
-{
- xmlChar *name;
-
- gl_debug (DEBUG_TEMPLATE, "START");
-
- name = xmlGetProp (alias_node, (xmlChar *)"name");
- gl_template_add_alias (template, (gchar *)name);
- xmlFree (name);
-
- gl_debug (DEBUG_TEMPLATE, "END");
-}
+++ /dev/null
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
-
-/*
- * (GLABELS) Label and Business Card Creation program for GNOME
- *
- * xml-label-191.h: GLabels xml label compat module header file
- *
- * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __XML_LABEL_191_H__
-#define __XML_LABEL_191_H__
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include "xml-label.h"
-
-G_BEGIN_DECLS
-
-glLabel *gl_xml_label_191_parse (xmlNodePtr root,
- glXMLLabelStatus *status);
-
-G_END_DECLS
-
-
-#endif /* __XML_LABEL_191_H__ */
#include <glib/gi18n.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
+#include <libxml/xinclude.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include "label.h"
#include "label-barcode.h"
#include "base64.h"
#include "xml-label-04.h"
-#include "xml-label-191.h"
#include <libglabels/template.h>
#include <libglabels/xml-template.h>
#include <libglabels/xml.h>
/*========================================================*/
#define COMPAT01_NAME_SPACE "http://snaught.com/glabels/0.1/"
#define COMPAT04_NAME_SPACE "http://snaught.com/glabels/0.4/"
-#define COMPAT191_NAME_SPACE "http://snaught.com/glabels/1.92/"
/*========================================================*/
/* Private types. */
xml_doc_to_label (xmlDocPtr doc,
glXMLLabelStatus *status)
{
- xmlNodePtr root, node;
+ xmlNodePtr root;
xmlNsPtr ns;
glLabel *label;
g_message (_("Importing from glabels 0.4 format"));
label = gl_xml_label_04_parse (root, status);
} else {
- /* Try compatability mode 1.91 */
- ns = xmlSearchNsByHref (doc, root,
- (xmlChar *)COMPAT191_NAME_SPACE);
- if (ns != NULL) {
- g_message (_("Importing from glabels 1.91 format"));
- label = gl_xml_label_191_parse (root, status);
- } else {
- g_message (_("bad document, unknown glabels Namespace"));
- *status = XML_LABEL_ERROR_OPEN_PARSE;
- return NULL;
- }
+ g_message (_("bad document, unknown glabels Namespace"));
+ *status = XML_LABEL_ERROR_OPEN_PARSE;
+ return NULL;
}
}
}
xml_parse_merge_fields (xmlNodePtr node,
glLabel *label)
{
- xmlNodePtr child;
gchar *string;
glMerge *merge;
xml_parse_affine_attrs (xmlNodePtr node,
glLabelObject *object)
{
- gdouble affine[6];
+ gdouble a[6];
+ cairo_matrix_t matrix;
+
+ a[0] = gl_xml_get_prop_double (node, "a0", 0.0);
+ a[1] = gl_xml_get_prop_double (node, "a1", 0.0);
+ a[2] = gl_xml_get_prop_double (node, "a2", 0.0);
+ a[3] = gl_xml_get_prop_double (node, "a3", 0.0);
+ a[4] = gl_xml_get_prop_double (node, "a4", 0.0);
+ a[5] = gl_xml_get_prop_double (node, "a5", 0.0);
- affine[0] = gl_xml_get_prop_double (node, "a0", 0.0);
- affine[1] = gl_xml_get_prop_double (node, "a1", 0.0);
- affine[2] = gl_xml_get_prop_double (node, "a2", 0.0);
- affine[3] = gl_xml_get_prop_double (node, "a3", 0.0);
- affine[4] = gl_xml_get_prop_double (node, "a4", 0.0);
- affine[5] = gl_xml_get_prop_double (node, "a5", 0.0);
+ cairo_matrix_init (&matrix, a[0], a[1], a[2], a[3], a[4], a[5]);
- gl_label_object_set_affine (object, affine);
+ gl_label_object_set_matrix (object, &matrix);
}
/*--------------------------------------------------------------------------*/
{
xmlDocPtr doc;
gint size;
- gchar *buffer;
+ guchar *buffer;
gl_debug (DEBUG_XML, "START");
doc = xml_label_to_doc (label, status);
- xmlDocDumpMemory (doc, (xmlChar **)&buffer, &size);
+ xmlDocDumpMemory (doc, &buffer, &size);
xmlFreeDoc (doc);
gl_label_clear_modified (label);
gl_debug (DEBUG_XML, "END");
- return buffer;
+ return (gchar *)buffer;
}
/*--------------------------------------------------------------------------*/
{
xmlDocPtr doc;
xmlNsPtr ns;
- glTemplate *template;
glMerge *merge;
gl_debug (DEBUG_XML, "START");
ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)GL_XML_NAME_SPACE, NULL);
xmlSetNs (doc->xmlRootNode, ns);
- template = gl_label_get_template (label);
- gl_xml_template_create_template_node (template, doc->xmlRootNode, ns);
+ gl_xml_template_create_template_node (label->template, doc->xmlRootNode, ns);
xml_create_objects (doc->xmlRootNode, ns, label);
glLabel *label)
{
xmlNodePtr node;
- gboolean rotate_flag;
GList *p;
glLabelObject *object;
gl_debug (DEBUG_XML, "START");
- rotate_flag = gl_label_get_rotate_flag (label);
-
node = xmlNewChild (root, ns, (xmlChar *)"Objects", NULL);
gl_xml_set_prop_string (node, "id", "0");
- gl_xml_set_prop_boolean (node, "rotate", rotate_flag);
+ gl_xml_set_prop_boolean (node, "rotate", label->rotate_flag);
for (p = label->objects; p != NULL; p = p->next) {
gl_xml_set_prop_length (node, "y", y);
/* size attrs */
- gl_label_text_get_box ( GL_LABEL_TEXT(object), &w, &h);
+ gl_label_object_get_raw_size ( object, &w, &h);
gl_xml_set_prop_length (node, "w", w);
gl_xml_set_prop_length (node, "h", h);
gl_xml_set_prop_length (node, "y", y);
/* size attrs */
- gl_label_object_get_size (object, &w, &h);
+ gl_label_object_get_raw_size (object, &w, &h);
gl_xml_set_prop_length (node, "w", w);
gl_xml_set_prop_length (node, "h", h);
xmlNsPtr ns,
glLabel *label)
{
- xmlNodePtr node, child;
+ xmlNodePtr node;
gchar *string;
- GList *p;
glMerge *merge;
gl_debug (DEBUG_XML, "START");
xml_create_affine_attrs (xmlNodePtr node,
glLabelObject *object)
{
- gdouble affine[6];
+ cairo_matrix_t matrix;
- gl_label_object_get_affine (object, affine);
+ gl_label_object_get_matrix (object, &matrix);
- gl_xml_set_prop_double (node, "a0", affine[0]);
- gl_xml_set_prop_double (node, "a1", affine[1]);
- gl_xml_set_prop_double (node, "a2", affine[2]);
- gl_xml_set_prop_double (node, "a3", affine[3]);
- gl_xml_set_prop_double (node, "a4", affine[4]);
- gl_xml_set_prop_double (node, "a5", affine[5]);
+ gl_xml_set_prop_double (node, "a0", matrix.xx);
+ gl_xml_set_prop_double (node, "a1", matrix.yx);
+ gl_xml_set_prop_double (node, "a2", matrix.xy);
+ gl_xml_set_prop_double (node, "a3", matrix.yy);
+ gl_xml_set_prop_double (node, "a4", matrix.x0);
+ gl_xml_set_prop_double (node, "a5", matrix.y0);
}
/*--------------------------------------------------------------------------*/