From 8f156fce93d5cc64c4722893522ec1dbabba5513 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 20 Oct 2002 22:22:54 +0000 Subject: [PATCH] Added line markup to template. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@170 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/template.c | 76 ++++++++++++++++++++++++++++++++++++++++- glabels2/src/template.h | 8 +++++ glabels2/src/view.c | 39 +++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) diff --git a/glabels2/src/template.c b/glabels2/src/template.c index 0402afd6..4f70c654 100644 --- a/glabels2/src/template.c +++ b/glabels2/src/template.c @@ -79,6 +79,9 @@ static void xml_add_layout (glTemplateLayout *layout, static void xml_add_markup_margin (glTemplateMarkupMargin *margin, xmlNodePtr root, xmlNsPtr ns); +static void xml_add_markup_line (glTemplateMarkupLine *line, + xmlNodePtr root, + xmlNsPtr ns); static void xml_add_alias (gchar *name, xmlNodePtr root, xmlNsPtr ns); @@ -97,6 +100,10 @@ static glTemplateLayout *layout_dup (glTemplateLayout *orig_layout); static void layout_free (glTemplateLayout **layout); static glTemplateMarkup *markup_margin_new (gdouble size); +static glTemplateMarkup *markup_line_new (gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2); static glTemplateMarkup *markup_dup (glTemplateMarkup *orig_markup); static void markup_free (glTemplateMarkup **markup); @@ -677,6 +684,7 @@ xml_parse_markup (xmlNodePtr markup_node, { gchar *type; gdouble size; + gdouble x1, y1, x2, y2; xmlNodePtr node; gl_debug (DEBUG_TEMPLATE, "START"); @@ -687,6 +695,14 @@ xml_parse_markup (xmlNodePtr markup_node, template->label.any.markups = g_list_append (template->label.any.markups, markup_margin_new (size)); + } else if (g_strcasecmp (type, "line") == 0) { + x1 = g_strtod (xmlGetProp (markup_node, "x1"), NULL); + y1 = g_strtod (xmlGetProp (markup_node, "y1"), NULL); + x2 = g_strtod (xmlGetProp (markup_node, "x2"), NULL); + y2 = g_strtod (xmlGetProp (markup_node, "y2"), NULL); + template->label.any.markups = + g_list_append (template->label.any.markups, + markup_line_new (x1, y1, x2, y2)); } for (node = markup_node->xmlChildrenNode; node != NULL; @@ -802,6 +818,10 @@ xml_add_label (const glTemplate *template, xml_add_markup_margin ((glTemplateMarkupMargin *)markup, node, ns); break; + case GL_TEMPLATE_MARKUP_LINE: + xml_add_markup_line ((glTemplateMarkupLine *)markup, + node, ns); + break; default: g_warning ("Unknown markup type"); break; @@ -853,7 +873,7 @@ xml_add_layout (glTemplateLayout *layout, } /*--------------------------------------------------------------------------*/ -/* PRIVATE. Add XML Sheet->Label->Markup Node. */ +/* PRIVATE. Add XML Sheet->Label->Markup (margin) Node. */ /*--------------------------------------------------------------------------*/ static void xml_add_markup_margin (glTemplateMarkupMargin *margin, @@ -875,6 +895,38 @@ xml_add_markup_margin (glTemplateMarkupMargin *margin, gl_debug (DEBUG_TEMPLATE, "END"); } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Add XML Sheet->Label->Markup (line) Node. */ +/*--------------------------------------------------------------------------*/ +static void +xml_add_markup_line (glTemplateMarkupLine *line, + xmlNodePtr root, + xmlNsPtr ns) +{ + xmlNodePtr node; + gchar *string; + + gl_debug (DEBUG_TEMPLATE, "START"); + + node = xmlNewChild(root, ns, "Markup", NULL); + xmlSetProp (node, "type", "line"); + + string = g_strdup_printf ("%g", line->x1); + xmlSetProp (node, "x1", string); + g_free (string); + string = g_strdup_printf ("%g", line->y1); + xmlSetProp (node, "y1", string); + g_free (string); + string = g_strdup_printf ("%g", line->x2); + xmlSetProp (node, "x2", string); + g_free (string); + string = g_strdup_printf ("%g", line->y2); + xmlSetProp (node, "y2", string); + g_free (string); + + gl_debug (DEBUG_TEMPLATE, "END"); +} + /*--------------------------------------------------------------------------*/ /* PRIVATE. Add XML Sheet->Alias Node. */ /*--------------------------------------------------------------------------*/ @@ -1157,6 +1209,28 @@ markup_margin_new (gdouble size) return markup; } +/*--------------------------------------------------------------------------*/ +/* PRIVATE. Create new margin line structure. */ +/*--------------------------------------------------------------------------*/ +static glTemplateMarkup * +markup_line_new (gdouble x1, + gdouble y1, + gdouble x2, + gdouble y2) +{ + glTemplateMarkup *markup; + + markup = g_new0 (glTemplateMarkup, 1); + + markup->type = GL_TEMPLATE_MARKUP_LINE; + markup->line.x1 = x1; + markup->line.y1 = y1; + markup->line.x2 = x2; + markup->line.y2 = y2; + + return markup; +} + /*--------------------------------------------------------------------------*/ /* PRIVATE. Duplicate markup structure. */ /*--------------------------------------------------------------------------*/ diff --git a/glabels2/src/template.h b/glabels2/src/template.h index 3b0a5fa2..e124b936 100644 --- a/glabels2/src/template.h +++ b/glabels2/src/template.h @@ -75,6 +75,7 @@ typedef union { */ typedef enum { GL_TEMPLATE_MARKUP_MARGIN, + GL_TEMPLATE_MARKUP_LINE, } glTemplateMarkupType; typedef struct { @@ -88,10 +89,17 @@ typedef struct { gdouble size; } glTemplateMarkupMargin; +typedef struct { + glTemplateMarkupParent parent; + + gdouble x1, y1, x2, y2; +} glTemplateMarkupLine; + typedef union { glTemplateMarkupType type; glTemplateMarkupParent any; glTemplateMarkupMargin margin; + glTemplateMarkupLine line; } glTemplateMarkup; diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 59740993..1ba3e58f 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -126,6 +126,9 @@ static void draw_markup_margin_round (glView *view, static void draw_markup_margin_cd (glView *view, glTemplateMarkupMargin *margin); +static void draw_markup_line (glView *view, + glTemplateMarkupLine *line); + static void select_object_real (glView *view, glViewObject *view_object); @@ -903,6 +906,10 @@ draw_markup_layer (glView *view) draw_markup_margin (view, (glTemplateMarkupMargin *)markup); break; + case GL_TEMPLATE_MARKUP_LINE: + draw_markup_line (view, + (glTemplateMarkupLine *)markup); + break; default: g_warning ("Unknown template markup type"); break; @@ -1138,6 +1145,38 @@ draw_markup_margin_cd (glView *view, gl_debug (DEBUG_VIEW, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Draw line markup. */ +/*---------------------------------------------------------------------------*/ +static void +draw_markup_line (glView *view, + glTemplateMarkupLine *line) +{ + GnomeCanvasPoints *points; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (GL_IS_VIEW (view)); + + points = gnome_canvas_points_new (2); + points->coords[0] = line->x1; + points->coords[1] = line->y1; + points->coords[2] = line->x2; + points->coords[3] = line->y2; + + /* Bounding box @ margin */ + gnome_canvas_item_new (view->markup_group, + gnome_canvas_line_get_type (), + "points", points, + "width_pixels", 1, + "fill_color_rgba", MARKUP_COLOR, + NULL); + + gnome_canvas_points_free (points); + + gl_debug (DEBUG_VIEW, "END"); +} + /*****************************************************************************/ /* Raise foreground items to top. */ /*****************************************************************************/ -- 2.39.5