From 814a682c9362f01d7a3847153b0a37e103d83b17 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 14 Oct 2002 01:57:46 +0000 Subject: [PATCH] Initial flipping support -- still has some problems. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@163 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/marshal.list | 1 + glabels2/src/print.c | 113 +++++++++++++++--------- glabels2/src/tools.c | 36 ++++++++ glabels2/src/tools.h | 96 +++++++++++--------- glabels2/src/view-barcode.c | 41 ++++----- glabels2/src/view-box.c | 22 +++-- glabels2/src/view-ellipse.c | 22 +++-- glabels2/src/view-image.c | 22 +++-- glabels2/src/view-line.c | 15 ++-- glabels2/src/view-object.c | 170 ++++++++++++++++++++++++++++++++---- glabels2/src/view-object.h | 5 ++ glabels2/src/view-text.c | 19 ++-- glabels2/src/view.c | 46 ++++++++++ glabels2/src/view.h | 76 ++++++++-------- glabels2/src/xml-label.c | 33 ++++++- 15 files changed, 498 insertions(+), 219 deletions(-) diff --git a/glabels2/src/marshal.list b/glabels2/src/marshal.list index 333c5af4..44979604 100644 --- a/glabels2/src/marshal.list +++ b/glabels2/src/marshal.list @@ -2,6 +2,7 @@ VOID:VOID VOID:BOOLEAN VOID:INT VOID:INT,INT +VOID:INT,DOUBLE VOID:DOUBLE VOID:DOUBLE,DOUBLE VOID:STRING diff --git a/glabels2/src/print.c b/glabels2/src/print.c index d978ee7c..b248b841 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -95,6 +95,10 @@ static void draw_label (PrintInfo *pi, glMergeRecord *record); +static void draw_object (PrintInfo *pi, + glLabelObject *object, + glMergeRecord *record); + static void draw_text_object (PrintInfo *pi, glLabelText *object, glMergeRecord *record); @@ -532,23 +536,59 @@ draw_label (PrintInfo *pi, for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) { object = (glLabelObject *) p_obj->data; - 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)); - } else if (GL_IS_LABEL_LINE(object)) { - draw_line_object (pi, GL_LABEL_LINE(object)); - } else if (GL_IS_LABEL_ELLIPSE(object)) { - draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object)); - } else if (GL_IS_LABEL_IMAGE(object)) { - draw_image_object (pi, GL_LABEL_IMAGE(object)); - } else if (GL_IS_LABEL_BARCODE(object)) { - draw_barcode_object (pi, GL_LABEL_BARCODE(object), - record); - } + 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, w, h; + glLabelObjectFlip flip; + + gl_debug (DEBUG_PRINT, "START"); + + gl_label_object_get_position (object, &x0, &y0); + gl_label_object_get_size (object, &w, &h); + flip = gl_label_object_get_flip (object); + + gnome_print_gsave (pi->pc); + gnome_print_translate (pi->pc, x0, y0); + + if ( flip & GL_LABEL_OBJECT_FLIP_HORIZ ) { + gnome_print_translate (pi->pc, w, 0.0); + gnome_print_scale (pi->pc, -1.0, 1.0); + } + if ( flip & GL_LABEL_OBJECT_FLIP_VERT ) { + gnome_print_translate (pi->pc, 0.0, h); + gnome_print_scale (pi->pc, 1.0, -1.0); + } + + 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)); + } else if (GL_IS_LABEL_LINE(object)) { + draw_line_object (pi, GL_LABEL_LINE(object)); + } else if (GL_IS_LABEL_ELLIPSE(object)) { + draw_ellipse_object (pi, GL_LABEL_ELLIPSE(object)); + } else if (GL_IS_LABEL_IMAGE(object)) { + draw_image_object (pi, GL_LABEL_IMAGE(object)); + } else if (GL_IS_LABEL_BARCODE(object)) { + draw_barcode_object (pi, GL_LABEL_BARCODE(object), + record); } + gnome_print_grestore (pi->pc); + gl_debug (DEBUG_PRINT, "END"); } @@ -564,8 +604,6 @@ draw_text_object (PrintInfo *pi, gchar **line; gint i; gdouble x_offset, y_offset, w, object_w, object_h; - gdouble x, y; - gdouble x0, y0; gchar *text; GList *lines; gchar *font_family; @@ -581,7 +619,6 @@ draw_text_object (PrintInfo *pi, gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x0, &y0); gl_label_object_get_size (GL_LABEL_OBJECT(object), &object_w, &object_h); lines = gl_label_text_get_lines (object); gl_label_text_get_props (object, @@ -635,9 +672,7 @@ draw_text_object (PrintInfo *pi, y_offset = (i + 1) * font_size + gnome_font_get_descender (font); - x = x0 + x_offset; - y = y0 + y_offset; - gnome_print_moveto (pi->pc, x, y); + gnome_print_moveto (pi->pc, x_offset, y_offset); gnome_print_gsave (pi->pc); gnome_print_scale (pi->pc, 1.0, -1.0); @@ -660,20 +695,19 @@ static void draw_box_object (PrintInfo *pi, glLabelBox *object) { - gdouble x, y, w, h; + gdouble w, h; gdouble line_width; guint line_color, fill_color; gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); line_width = gl_label_box_get_line_width (object); line_color = gl_label_box_get_line_color (object); fill_color = gl_label_box_get_fill_color (object); /* Paint fill color */ - create_rectangle_path (pi->pc, x, y, w, h); + create_rectangle_path (pi->pc, 0.0, 0.0, w, h); gnome_print_setrgbcolor (pi->pc, GL_COLOR_F_RED (fill_color), GL_COLOR_F_GREEN (fill_color), @@ -682,7 +716,7 @@ draw_box_object (PrintInfo *pi, gnome_print_fill (pi->pc); /* Draw outline */ - create_rectangle_path (pi->pc, x, y, w, h); + create_rectangle_path (pi->pc, 0.0, 0.0, w, h); gnome_print_setrgbcolor (pi->pc, GL_COLOR_F_RED (line_color), GL_COLOR_F_GREEN (line_color), @@ -701,19 +735,18 @@ static void draw_line_object (PrintInfo *pi, glLabelLine *object) { - gdouble x, y, w, h; + gdouble w, h; gdouble line_width; guint line_color; gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); line_width = gl_label_line_get_line_width (object); line_color = gl_label_line_get_line_color (object); - gnome_print_moveto (pi->pc, x, y); - gnome_print_lineto (pi->pc, x + w, y + h); + gnome_print_moveto (pi->pc, 0.0, 0.0); + gnome_print_lineto (pi->pc, w, h); gnome_print_setrgbcolor (pi->pc, GL_COLOR_F_RED (line_color), GL_COLOR_F_GREEN (line_color), @@ -732,13 +765,12 @@ static void draw_ellipse_object (PrintInfo *pi, glLabelEllipse *object) { - gdouble x, y, x0, y0, rx, ry, w, h; + gdouble x0, y0, rx, ry, w, h; gdouble line_width; guint line_color, fill_color; gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); line_width = gl_label_ellipse_get_line_width (object); line_color = gl_label_ellipse_get_line_color (object); @@ -746,8 +778,8 @@ draw_ellipse_object (PrintInfo *pi, rx = w / 2.0; ry = h / 2.0; - x0 = x + rx; - y0 = y + ry; + x0 = rx; + y0 = ry; /* Paint fill color */ create_ellipse_path (pi->pc, x0, y0, rx, ry); @@ -778,7 +810,7 @@ static void draw_image_object (PrintInfo *pi, glLabelImage *object) { - gdouble x, y, w, h; + gdouble w, h; const GdkPixbuf *pixbuf; guchar *image_data; gint image_w, image_h, image_stride; @@ -787,7 +819,6 @@ draw_image_object (PrintInfo *pi, gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); pixbuf = gl_label_image_get_pixbuf (object); @@ -798,7 +829,7 @@ draw_image_object (PrintInfo *pi, image_alpha_flag = gdk_pixbuf_get_has_alpha(pixbuf); gnome_print_gsave (pi->pc); - gnome_print_translate (pi->pc, x, y+h); + gnome_print_translate (pi->pc, 0.0, h); gnome_print_scale (pi->pc, w, -h); if (image_alpha_flag) { ret = gnome_print_rgbaimage (pi->pc, image_data, @@ -826,7 +857,7 @@ draw_barcode_object (PrintInfo *pi, glBarcodeLine *line; glBarcodeChar *bchar; GList *li; - gdouble x, y, y_offset; + gdouble y_offset; GnomeFont *font; gchar *text, *cstring; glTextNode *text_node; @@ -837,7 +868,6 @@ draw_barcode_object (PrintInfo *pi, gl_debug (DEBUG_PRINT, "START"); - gl_label_object_get_position (GL_LABEL_OBJECT(object), &x, &y); text_node = gl_label_barcode_get_data (object); gl_label_barcode_get_props (object, &style, &text_flag, &color, &scale); @@ -863,7 +893,7 @@ draw_barcode_object (PrintInfo *pi, GL_COLOR_F_ALPHA (color)); y_offset = 12.0 - gnome_font_get_descender (font); - gnome_print_moveto (pi->pc, x, y + y_offset); + gnome_print_moveto (pi->pc, 0.0, y_offset); gnome_print_gsave (pi->pc); gnome_print_scale (pi->pc, 1.0, -1.0); @@ -875,9 +905,8 @@ draw_barcode_object (PrintInfo *pi, for (li = gbc->lines; li != NULL; li = li->next) { line = (glBarcodeLine *) li->data; - gnome_print_moveto (pi->pc, x + line->x, y + line->y); - gnome_print_lineto (pi->pc, x + line->x, - y + line->y + line->length); + gnome_print_moveto (pi->pc, line->x, line->y); + gnome_print_lineto (pi->pc, line->x, line->y + line->length); gnome_print_setrgbcolor (pi->pc, GL_COLOR_F_RED (color), GL_COLOR_F_GREEN (color), @@ -907,7 +936,7 @@ draw_barcode_object (PrintInfo *pi, y_offset = bchar->y + bchar->fsize - gnome_font_get_descender (font); - gnome_print_moveto (pi->pc, x + bchar->x, y + y_offset); + gnome_print_moveto (pi->pc, bchar->x, y_offset); cstring = g_strdup_printf ("%c", bchar->c); gnome_print_gsave (pi->pc); diff --git a/glabels2/src/tools.c b/glabels2/src/tools.c index a57e0623..e61f4db4 100644 --- a/glabels2/src/tools.c +++ b/glabels2/src/tools.c @@ -297,3 +297,39 @@ gl_tools_lower_objects (BonoboUIComponent *uic, } } +/*****************************************************************************/ +/* Flip objects horizontally callback. */ +/*****************************************************************************/ +void +gl_tools_flip_objects_horiz (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_flip_selection_horiz (GL_VIEW(window->view)); + } +} + +/*****************************************************************************/ +/* Flip objects vertically callback. */ +/*****************************************************************************/ +void +gl_tools_flip_objects_vert (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname) + +{ + glWindow *window; + + window = GL_WINDOW (user_data); + + if (window->view != NULL) { + gl_view_flip_selection_vert (GL_VIEW(window->view)); + } +} + diff --git a/glabels2/src/tools.h b/glabels2/src/tools.h index 62c3c4ae..17945417 100644 --- a/glabels2/src/tools.h +++ b/glabels2/src/tools.h @@ -24,60 +24,72 @@ #include -extern void gl_tools_arrow (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +G_BEGIN_DECLS -extern void gl_tools_text (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_arrow (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_box (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_text (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_line (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_box (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_ellipse (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_line (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_image (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_ellipse (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_barcode (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_image (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_zoomin (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_barcode (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_zoomout (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_zoomin (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_zoom1to1 (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_zoomout (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_merge_properties (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_zoom1to1 (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_object_properties (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_merge_properties (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_raise_objects (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_object_properties (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); -extern void gl_tools_lower_objects (BonoboUIComponent *uic, - gpointer user_data, - const gchar* verbname); +void gl_tools_raise_objects (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_lower_objects (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_flip_objects_horiz (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +void gl_tools_flip_objects_vert (BonoboUIComponent *uic, + gpointer user_data, + const gchar *verbname); + +G_END_DECLS #endif diff --git a/glabels2/src/view-barcode.c b/glabels2/src/view-barcode.c index 14e2964b..d25af344 100644 --- a/glabels2/src/view-barcode.c +++ b/glabels2/src/view-barcode.c @@ -745,7 +745,7 @@ static void draw_barcode (glViewBarcode *view_barcode) { glLabelObject *object; - GnomeCanvasItem *group, *item; + GnomeCanvasItem *item; glTextNode *text_node; glBarcodeStyle style; gboolean text_flag; @@ -775,9 +775,6 @@ draw_barcode (glViewBarcode *view_barcode) digits = gl_text_node_expand (text_node, NULL); } - /* get parent item/group to render to. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_barcode)); - /* remove previous items from group. */ for (li = view_barcode->private->item_list; li!=NULL; li = li->next) { gl_debug (DEBUG_VIEW, "in loop"); @@ -805,11 +802,11 @@ draw_barcode (glViewBarcode *view_barcode) strlen (cstring)); y_offset = 10.0 - gnome_font_get_descender (font); - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gl_canvas_hacktext_get_type (), - "x", 0.0, - "y", y_offset, - "glyphlist", glyphlist, NULL); + item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode), + gl_canvas_hacktext_get_type (), + "x", 0.0, + "y", y_offset, + "glyphlist", glyphlist, NULL); view_barcode->private->item_list = g_list_prepend (view_barcode->private->item_list, item); @@ -824,13 +821,12 @@ draw_barcode (glViewBarcode *view_barcode) points->coords[2] = line->x; points->coords[3] = line->y + line->length; - item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gnome_canvas_line_get_type - (), "points", points, - "width_units", line->width, - "fill_color_rgba", color, - NULL); + 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, + NULL); view_barcode->private->item_list = g_list_prepend (view_barcode->private->item_list, item); } @@ -853,13 +849,12 @@ draw_barcode (glViewBarcode *view_barcode) 1); y_offset = bchar->fsize - gnome_font_get_descender (font); - item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gnome_canvas_hacktext_get_type - (), "x", bchar->x, "y", - bchar->y + y_offset, - "glyphlist", glyphlist, - NULL); + item = gl_view_object_item_new (GL_VIEW_OBJECT(view_barcode), + gnome_canvas_hacktext_get_type (), + "x", bchar->x, + "y", bchar->y + y_offset, + "glyphlist", glyphlist, + NULL); view_barcode->private->item_list = g_list_prepend (view_barcode->private->item_list, item); diff --git a/glabels2/src/view-box.c b/glabels2/src/view-box.c index 3617fdfa..d45729ad 100644 --- a/glabels2/src/view-box.c +++ b/glabels2/src/view-box.c @@ -179,7 +179,6 @@ gl_view_box_new (glLabelBox *object, glView *view) { glViewBox *view_box; - GnomeCanvasItem *group; gdouble line_width; guint line_color, fill_color; gdouble w, h; @@ -203,18 +202,17 @@ gl_view_box_new (glLabelBox *object, fill_color = gl_label_box_get_fill_color(object); /* Create analogous canvas item. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_box)); view_box->private->item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_rect_get_type (), - "x1", 0.0, - "y1", 0.0, - "x2", w + DELTA, - "y2", h + DELTA, - "width_units", line_width, - "outline_color_rgba", line_color, - "fill_color_rgba", fill_color, - NULL); + gl_view_object_item_new (GL_VIEW_OBJECT(view_box), + gnome_canvas_rect_get_type (), + "x1", 0.0, + "y1", 0.0, + "x2", w + DELTA, + "y2", h + DELTA, + "width_units", line_width, + "outline_color_rgba", line_color, + "fill_color_rgba", fill_color, + NULL); g_signal_connect (G_OBJECT (object), "changed", G_CALLBACK (update_view_box_cb), view_box); diff --git a/glabels2/src/view-ellipse.c b/glabels2/src/view-ellipse.c index 55ae8080..cc3efaa8 100644 --- a/glabels2/src/view-ellipse.c +++ b/glabels2/src/view-ellipse.c @@ -179,7 +179,6 @@ gl_view_ellipse_new (glLabelEllipse *object, glView *view) { glViewEllipse *view_ellipse; - GnomeCanvasItem *group; gdouble line_width; guint line_color, fill_color; gdouble w, h; @@ -203,18 +202,17 @@ gl_view_ellipse_new (glLabelEllipse *object, fill_color = gl_label_ellipse_get_fill_color(object); /* Create analogous canvas item. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_ellipse)); view_ellipse->private->item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_ellipse_get_type (), - "x1", 0.0, - "y1", 0.0, - "x2", w + DELTA, - "y2", h + DELTA, - "width_units", line_width, - "outline_color_rgba", line_color, - "fill_color_rgba", fill_color, - NULL); + gl_view_object_item_new (GL_VIEW_OBJECT(view_ellipse), + gnome_canvas_ellipse_get_type (), + "x1", 0.0, + "y1", 0.0, + "x2", w + DELTA, + "y2", h + DELTA, + "width_units", line_width, + "outline_color_rgba", line_color, + "fill_color_rgba", fill_color, + NULL); g_signal_connect (G_OBJECT (object), "changed", G_CALLBACK (update_view_ellipse_cb), view_ellipse); diff --git a/glabels2/src/view-image.c b/glabels2/src/view-image.c index 77cd8a32..de318266 100644 --- a/glabels2/src/view-image.c +++ b/glabels2/src/view-image.c @@ -179,7 +179,6 @@ gl_view_image_new (glLabelImage *object, glView *view) { glViewImage *view_image; - GnomeCanvasItem *group; const GdkPixbuf *pixbuf; gdouble w, h; GtkMenu *menu; @@ -200,18 +199,17 @@ gl_view_image_new (glLabelImage *object, pixbuf = gl_label_image_get_pixbuf(object); /* Create analogous canvas item. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_image)); view_image->private->item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_pixbuf_get_type (), - "x", 0.0, - "y", 0.0, - "width_set", TRUE, - "height_set", TRUE, - "width", w, - "height", h, - "pixbuf", pixbuf, - NULL); + 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_view_image_cb), view_image); diff --git a/glabels2/src/view-line.c b/glabels2/src/view-line.c index 18e13765..bfdbdbc3 100644 --- a/glabels2/src/view-line.c +++ b/glabels2/src/view-line.c @@ -172,7 +172,6 @@ gl_view_line_new (glLabelLine *object, glView *view) { glViewLine *view_line; - GnomeCanvasItem *group; gdouble line_width; guint line_color; gdouble w, h; @@ -196,20 +195,18 @@ gl_view_line_new (glLabelLine *object, line_color = gl_label_line_get_line_color(object); /* Create analogous canvas item. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_line)); - points = gnome_canvas_points_new (2); points->coords[0] = 0.0; points->coords[1] = 0.0; points->coords[2] = w; points->coords[3] = h; view_line->private->item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_line_get_type (), - "points", points, - "width_units", line_width, - "fill_color_rgba", line_color, - NULL); + gl_view_object_item_new (GL_VIEW_OBJECT(view_line), + gnome_canvas_line_get_type (), + "points", points, + "width_units", line_width, + "fill_color_rgba", line_color, + NULL); gnome_canvas_points_free (points); g_signal_connect (G_OBJECT (object), "changed", diff --git a/glabels2/src/view-object.c b/glabels2/src/view-object.c index 2982f1d0..fc24d46f 100644 --- a/glabels2/src/view-object.c +++ b/glabels2/src/view-object.c @@ -23,6 +23,7 @@ #include #include "view-object.h" +#include "libart_lgpl/libart.h" #include "debug.h" @@ -38,6 +39,8 @@ struct _glViewObjectPrivate { GnomeCanvasItem *group; GnomeCanvasItem *highlight; + gdouble affine[6]; + GtkWidget *menu; GtkWidget *property_dialog; @@ -55,17 +58,28 @@ static GObjectClass *parent_class = NULL; /* Private function prototypes. */ /*========================================================*/ -static void gl_view_object_class_init (glViewObjectClass *klass); -static void gl_view_object_instance_init (glViewObject *view_object); -static void gl_view_object_finalize (GObject *object); +static void gl_view_object_class_init (glViewObjectClass *klass); +static void gl_view_object_instance_init (glViewObject *view_object); +static void gl_view_object_finalize (GObject *object); + +static GtkMenu *new_menu (glViewObject *view_object); + +static void object_moved_cb (glLabelObject *object, + gdouble x, + gdouble y, + glViewObject *view_object); -static GtkMenu *new_menu (glViewObject *view_object); +static void raise_object_cb (GtkWidget *widget, + glViewObject *view_object); + +static void lower_object_cb (GtkWidget *widget, + glViewObject *view_object); + +static void flip_rotate_object_cb (GtkWidget *widget, + glLabelObjectFlip flip, + gdouble rotate_degs, + glViewObject *view_object); -static void object_moved_cb (glLabelObject *object, - gdouble x, gdouble y, - glViewObject *view_object); -static void raise_object_cb (GtkWidget * widget, glViewObject *view_object); -static void lower_object_cb (GtkWidget * widget, glViewObject *view_object); /*****************************************************************************/ @@ -192,7 +206,9 @@ gl_view_object_set_object (glViewObject *view_object, { GnomeCanvas *canvas; GnomeCanvasGroup *root; - gdouble x, y; + gdouble x, y, w, h; + glLabelObjectFlip flip; + gdouble a[6]; gl_debug (DEBUG_VIEW, "START"); @@ -202,6 +218,7 @@ gl_view_object_set_object (glViewObject *view_object, view_object->private->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 */ canvas = GNOME_CANVAS (view_object->private->view->canvas); @@ -212,6 +229,30 @@ gl_view_object_set_object (glViewObject *view_object, "y", y, NULL); + /* create affine to handle flipping and rotation transformations */ + art_affine_identity (view_object->private->affine); +#if 1 + /* Apply appropriate flipping */ + flip = gl_label_object_get_flip (object); + g_print ("Flip = %d\n", flip); + if ( flip & GL_LABEL_OBJECT_FLIP_HORIZ ) { + art_affine_translate (a, -w, 0.0); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + art_affine_scale (a, -1.0, 1.0); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + } + if ( flip & GL_LABEL_OBJECT_FLIP_VERT ) { + art_affine_translate (a, 0.0, -h); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + art_affine_scale (a, 1.0, -1.0); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + } +#endif + /* Create appropriate selection highlight canvas item. */ view_object->private->highlight = gl_view_highlight_new (view_object, style); @@ -232,6 +273,10 @@ gl_view_object_set_object (glViewObject *view_object, 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->private->group), "event", G_CALLBACK (gl_view_item_event_handler), view_object); @@ -301,6 +346,46 @@ gl_view_object_get_group (glViewObject *view_object) return view_object->private->group; } +/*****************************************************************************/ +/* Create canvas item for this object. */ +/*****************************************************************************/ +GnomeCanvasItem * +gl_view_object_item_new (glViewObject *view_object, + GType type, + const gchar *first_arg_name, + ...) +{ + GnomeCanvasItem *item; + va_list args; + + 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->private->group), + type, NULL); + + va_start (args, first_arg_name); + gnome_canvas_item_set_valist (item, first_arg_name, args); + va_end (args); + + g_print ("Affine = {%f, %f, %f, %f, %f, %f}\n", + view_object->private->affine[0], + view_object->private->affine[1], + view_object->private->affine[2], + view_object->private->affine[3], + view_object->private->affine[4], + view_object->private->affine[5]); + +#if 0 + gnome_canvas_item_affine_absolute (item, view_object->private->affine); +#endif + + gl_debug (DEBUG_VIEW, "END"); + + return item; +} + /*****************************************************************************/ /* Return dialog for controlling/viewing object properties. */ /*****************************************************************************/ @@ -309,7 +394,7 @@ gl_view_object_get_dialog (glViewObject *view_object) { 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"); @@ -324,7 +409,7 @@ gl_view_object_get_menu (glViewObject *view_object) { 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"); @@ -472,9 +557,9 @@ gl_view_object_show_dialog (glViewObject *view_object) /*---------------------------------------------------------------------------*/ static void object_moved_cb (glLabelObject *object, - gdouble dx, - gdouble dy, - glViewObject *view_object) + gdouble dx, + gdouble dy, + glViewObject *view_object) { GnomeCanvasItem *item, *highlight; @@ -493,7 +578,7 @@ object_moved_cb (glLabelObject *object, /* PRIVATE. raise item to front callback. */ /*---------------------------------------------------------------------------*/ static void -raise_object_cb (GtkWidget * widget, +raise_object_cb (GtkWidget *widget, glViewObject *view_object) { glLabelObject *object; @@ -515,7 +600,7 @@ raise_object_cb (GtkWidget * widget, /* PRIVATE. lower item to back callback. */ /*---------------------------------------------------------------------------*/ static void -lower_object_cb (GtkWidget * widget, +lower_object_cb (GtkWidget *widget, glViewObject *view_object) { glLabelObject *object; @@ -533,6 +618,57 @@ lower_object_cb (GtkWidget * widget, gl_debug (DEBUG_VIEW, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Flip/rotate object callback. */ +/*---------------------------------------------------------------------------*/ +static void +flip_rotate_object_cb (GtkWidget *widget, + glLabelObjectFlip flip, + gdouble rotate_degs, + glViewObject *view_object) +{ + glLabelObject *object; + gdouble a[6]; + gdouble w, h; + GList *p, *item_list; + GnomeCanvasItem *item; + + gl_debug (DEBUG_VIEW, "START"); + + gl_label_object_get_size (view_object->private->object, &w, &h); + + /* Reset to identity affine */ + art_affine_identity (view_object->private->affine); + + /* Apply appropriate flipping */ + if ( flip & GL_LABEL_OBJECT_FLIP_HORIZ ) { + art_affine_translate (a, -w, 0.0); + art_affine_multiply (view_object->private->affine, view_object->private->affine, a); + art_affine_scale (a, -1.0, 1.0); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + } + if ( flip & GL_LABEL_OBJECT_FLIP_VERT ) { + art_affine_translate (a, 0.0, -h); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + art_affine_scale (a, 1.0, -1.0); + art_affine_multiply (view_object->private->affine, + view_object->private->affine, a); + } + +#if 0 + /* Apply newly constructed affine */ + item_list = GNOME_CANVAS_GROUP(view_object->private->group)->item_list; + for ( p=item_list; p != NULL; p=p->next) { + item = GNOME_CANVAS_ITEM(p->data); + gnome_canvas_item_affine_absolute (item, view_object->private->affine); + } +#endif + + gl_debug (DEBUG_VIEW, "END"); +} + /*****************************************************************************/ /* Select object. */ /*****************************************************************************/ diff --git a/glabels2/src/view-object.h b/glabels2/src/view-object.h index 4798fff0..e9723997 100644 --- a/glabels2/src/view-object.h +++ b/glabels2/src/view-object.h @@ -79,6 +79,11 @@ glLabelObject *gl_view_object_get_object (glViewObject *view_ob GnomeCanvasItem *gl_view_object_get_group (glViewObject *view_object); +GnomeCanvasItem *gl_view_object_item_new (glViewObject *view_object, + GType type, + const gchar *first_arg_name, + ...); + GtkMenu *gl_view_object_get_menu (glViewObject *view_object); void gl_view_object_update_highlight (glViewObject *view_object); diff --git a/glabels2/src/view-text.c b/glabels2/src/view-text.c index 308abec6..2feac3a2 100644 --- a/glabels2/src/view-text.c +++ b/glabels2/src/view-text.c @@ -214,12 +214,8 @@ static void update_view_text_cb (glLabelObject *object, glViewText *view_text) { - glView *view; - gl_debug (DEBUG_VIEW, "START"); - view = gl_view_object_get_view (GL_VIEW_OBJECT(view_text)); - /* Adjust appearance of analogous canvas item. */ draw_hacktext (view_text); @@ -700,7 +696,7 @@ static void draw_hacktext (glViewText *view_text) { glLabelObject *object; - GnomeCanvasItem *group, *item; + GnomeCanvasItem *item; GList *lines; gchar *text; gchar *font_family; @@ -731,9 +727,6 @@ draw_hacktext (glViewText *view_text) text = gl_text_node_lines_expand (lines, NULL); line = g_strsplit (text, "\n", -1); - /* get parent item/group to render to. */ - group = gl_view_object_get_group (GL_VIEW_OBJECT(view_text)); - /* remove previous items from group. */ for (li = view_text->private->item_list; li != NULL; li = li->next) { gl_debug (DEBUG_VIEW, "in loop"); @@ -779,11 +772,11 @@ draw_hacktext (glViewText *view_text) y_offset = (i + 1) * font_size + gnome_font_get_descender (font); - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gl_canvas_hacktext_get_type (), - "x", x_offset, - "y", y_offset, - "glyphlist", glyphlist, NULL); + 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); view_text->private->item_list = g_list_prepend (view_text->private->item_list, item); diff --git a/glabels2/src/view.c b/glabels2/src/view.c index ea52ad48..230dea8f 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -1484,6 +1484,52 @@ gl_view_lower_selection (glView *view) gl_debug (DEBUG_VIEW, "END"); } +/*****************************************************************************/ +/* Flip selected objects horizontally. */ +/*****************************************************************************/ +void +gl_view_flip_selection_horiz (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *label_object; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + for (p = view->selected_object_list; p != NULL; p = p->next) { + view_object = GL_VIEW_OBJECT (p->data); + label_object = gl_view_object_get_object (view_object); + gl_label_object_flip_horiz (label_object); + } + + gl_debug (DEBUG_VIEW, "END"); +} + +/*****************************************************************************/ +/* Flip selected objects vertically. */ +/*****************************************************************************/ +void +gl_view_flip_selection_vert (glView *view) +{ + GList *p; + glViewObject *view_object; + glLabelObject *label_object; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + for (p = view->selected_object_list; p != NULL; p = p->next) { + view_object = GL_VIEW_OBJECT (p->data); + label_object = gl_view_object_get_object (view_object); + gl_label_object_flip_vert (label_object); + } + + gl_debug (DEBUG_VIEW, "END"); +} + /*****************************************************************************/ /* "Cut" selected items and place in clipboard selections. */ /*****************************************************************************/ diff --git a/glabels2/src/view.h b/glabels2/src/view.h index 8012245d..b46fb9e1 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -88,72 +88,76 @@ struct _glViewClass { G_BEGIN_DECLS -guint gl_view_get_type (void); +guint gl_view_get_type (void); -GtkWidget *gl_view_new (glLabel *label); +GtkWidget *gl_view_new (glLabel *label); -void gl_view_raise_fg (glView *view); +void gl_view_raise_fg (glView *view); -void gl_view_arrow_mode (glView *view); +void gl_view_arrow_mode (glView *view); -void gl_view_object_create_mode (glView *view, - glLabelObjectType type); +void gl_view_object_create_mode (glView *view, + glLabelObjectType type); -void gl_view_select_object (glView *view, - glViewObject *view_object); +void gl_view_select_object (glView *view, + glViewObject *view_object); -void gl_view_unselect_object (glView *view, - glViewObject *view_object); +void gl_view_unselect_object (glView *view, + glViewObject *view_object); -void gl_view_select_all (glView *view); +void gl_view_select_all (glView *view); -void gl_view_unselect_all (glView *view); +void gl_view_unselect_all (glView *view); -void gl_view_select_region (glView *view, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2); +void gl_view_select_region (glView *view, + gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2); -gboolean gl_view_is_selection_empty (glView *view); +gboolean gl_view_is_selection_empty (glView *view); -gboolean gl_view_is_selection_atomic(glView *view); +gboolean gl_view_is_selection_atomic (glView *view); -void gl_view_delete_selection (glView *view); +void gl_view_delete_selection (glView *view); -void gl_view_edit_object_props (glView *view); +void gl_view_edit_object_props (glView *view); -void gl_view_raise_selection (glView *view); +void gl_view_raise_selection (glView *view); -void gl_view_lower_selection (glView *view); +void gl_view_lower_selection (glView *view); -void gl_view_cut (glView *view); +void gl_view_flip_selection_horiz (glView *view); -void gl_view_copy (glView *view); +void gl_view_flip_selection_vert (glView *view); -void gl_view_paste (glView *view); +void gl_view_cut (glView *view); +void gl_view_copy (glView *view); -void gl_view_zoom_in (glView *view); +void gl_view_paste (glView *view); -void gl_view_zoom_out (glView *view); -void gl_view_set_zoom (glView *view, - gdouble scale); +void gl_view_zoom_in (glView *view); -gdouble gl_view_get_zoom (glView *view); +void gl_view_zoom_out (glView *view); -gboolean gl_view_is_zoom_max (glView *view); +void gl_view_set_zoom (glView *view, + gdouble scale); -gboolean gl_view_is_zoom_min (glView *view); +gdouble gl_view_get_zoom (glView *view); +gboolean gl_view_is_zoom_max (glView *view); -int gl_view_item_event_handler (GnomeCanvasItem *item, - GdkEvent *event, - glViewObject *view_object); +gboolean gl_view_is_zoom_min (glView *view); + + +int gl_view_item_event_handler (GnomeCanvasItem *item, + GdkEvent *event, + glViewObject *view_object); G_END_DECLS diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index 62ab9981..16c23732 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -296,6 +296,7 @@ xml_parse_object (xmlNodePtr object_node, glLabelObject *object; gdouble x, y; gchar *type_string; + gchar *flip_string; gl_debug (DEBUG_XML, "START"); @@ -323,6 +324,20 @@ xml_parse_object (xmlNodePtr object_node, gl_label_object_set_position (object, x, y); + flip_string = xmlGetProp (object_node, "flip"); + if ( g_strcasecmp (flip_string, "None") == 0 ) { + gl_label_object_set_flip (object, GL_LABEL_OBJECT_FLIP_NONE); + } else if ( g_strcasecmp (flip_string, "Horiz") == 0 ) { + gl_label_object_set_flip (object, GL_LABEL_OBJECT_FLIP_HORIZ); + } else if ( g_strcasecmp (flip_string, "Vert") == 0 ) { + gl_label_object_set_flip (object, GL_LABEL_OBJECT_FLIP_VERT); + } else if ( g_strcasecmp (flip_string, "Both") == 0 ) { + gl_label_object_set_flip (object, GL_LABEL_OBJECT_FLIP_BOTH); + } else { + g_warning ("Unknown flip type \"%s\"", flip_string); + return; + } + gl_debug (DEBUG_XML, "END"); } @@ -784,7 +799,23 @@ xml_create_object (xmlNodePtr root, g_free (string); xmlSetProp (object_node, "rotate", "0"); - xmlSetProp (object_node, "flip", "None"); + + switch (gl_label_object_get_flip (object)) { + case GL_LABEL_OBJECT_FLIP_NONE: + xmlSetProp (object_node, "flip", "None"); + break; + case GL_LABEL_OBJECT_FLIP_HORIZ: + xmlSetProp (object_node, "flip", "Horiz"); + break; + case GL_LABEL_OBJECT_FLIP_VERT: + xmlSetProp (object_node, "flip", "Vert"); + break; + case GL_LABEL_OBJECT_FLIP_BOTH: + xmlSetProp (object_node, "flip", "Both"); + break; + default: + g_assert_not_reached (); + } if ( GL_IS_LABEL_TEXT(object) ) { xml_create_text_props (object_node, ns, object); -- 2.39.5