[goffice] GocLine: more arrow shapes.



commit ce63f6b2aa28169a64bdce1cb488d451be54d6e1
Author: Morten Welinder <terra gnome org>
Date:   Thu Oct 15 12:41:45 2009 -0400

    GocLine: more arrow shapes.

 goffice/canvas/goc-line.c |   65 +++++++++++++++++++++++++++++++-------------
 goffice/utils/go-line.c   |   37 +++++++++++++++++++++++++
 goffice/utils/go-line.h   |    7 +++-
 3 files changed, 88 insertions(+), 21 deletions(-)
---
diff --git a/goffice/canvas/goc-line.c b/goffice/canvas/goc-line.c
index 695d6bd..c9383c9 100644
--- a/goffice/canvas/goc-line.c
+++ b/goffice/canvas/goc-line.c
@@ -117,6 +117,38 @@ goc_line_get_property (GObject *gobject, guint param_id,
 }
 
 static void
+handle_arrow_bounds (GOArrow const *arrow, GocItem *item)
+{
+	/*
+	 * Do not calculate things precisely, just add enough room
+	 * in all directions.
+	 */
+
+	switch (arrow->typ) {
+	case GO_ARROW_NONE:
+		break;
+	case GO_ARROW_TRIANGLE: {
+		double d = hypot (arrow->b, arrow->c);
+		item->x0 -= d;
+		item->x1 += d;
+		item->y0 -= d;
+		item->y1 += d;
+		break;
+	}
+	case GO_ARROW_OVAL: {
+		double d = MAX (arrow->a, arrow->b);
+		item->x0 -= d;
+		item->x1 += d;
+		item->y0 -= d;
+		item->y1 += d;
+		break;
+	}
+	default:
+		g_assert_not_reached ();
+	}
+}
+
+static void
 goc_line_update_bounds (GocItem *item)
 {
 	GocLine *line = GOC_LINE (item);
@@ -140,25 +172,9 @@ goc_line_update_bounds (GocItem *item)
 		item->y0 = line->endy - extra_width;
 		item->y1 = line->starty + extra_width;
 	}
-	if (line->start_arrow.typ) {
-		/*
-		 * Do not calculate things precisely, just add enough room
-		 * in all directions.
-		 */
-		double d = hypot (line->start_arrow.b, line->start_arrow.c);
-		item->x0 -= d;
-		item->x1 += d;
-		item->y0 -= d;
-		item->y1 += d;
-	}
-	if (line->end_arrow.typ) {
-		/* See above.  */
-		double d = hypot (line->end_arrow.b, line->end_arrow.c);
-		item->x0 -= d;
-		item->x1 += d;
-		item->y0 -= d;
-		item->y1 += d;
-	}
+
+	handle_arrow_bounds (&line->start_arrow, item);
+	handle_arrow_bounds (&line->end_arrow, item);
 }
 
 static double
@@ -219,6 +235,17 @@ draw_arrow (GOArrow const *arrow, cairo_t *cr, GOStyle *style,
 			*endx = *endy = 0.;
 		break;
 
+	case GO_ARROW_OVAL:
+		cairo_save (cr);
+		cairo_translate (cr, *endx, *endy);
+		cairo_rotate (cr, phi);
+		cairo_scale (cr, arrow->a, arrow->b);
+		cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
+		cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color));
+		cairo_fill (cr);
+		cairo_restore (cr);
+		break;
+
 	default:
 		g_assert_not_reached ();
 	}
diff --git a/goffice/utils/go-line.c b/goffice/utils/go-line.c
index 368d6b7..13e2d4b 100644
--- a/goffice/utils/go-line.c
+++ b/goffice/utils/go-line.c
@@ -349,6 +349,43 @@ go_line_interpolation_auto_skip	(GOLineInterpolation type)
 
 /* ------------------------------------------------------------------------- */
 
+static struct {
+	GOArrowType typ;
+	char const *name;
+} arrow_types[] = {
+	{ GO_LINE_NONE, "none" },
+	{ GO_ARROW_TRIANGLE, "triangle" },
+	{ GO_ARROW_OVAL, "oval" }
+};
+
+char const *
+go_arrow_type_as_str (GOArrowType typ)
+{
+	unsigned ui;
+
+	for (ui = 0; ui < G_N_ELEMENTS (arrow_types); ui++)
+		if (typ == arrow_types[ui].typ)
+			return arrow_types[ui].name;
+
+	return NULL;
+}
+
+GOArrowType
+go_arrow_type_from_str (const char *name)
+{
+	unsigned ui;
+	GOArrowType ret = GO_ARROW_NONE;
+
+	for (ui = 0; ui < G_N_ELEMENTS (arrow_types); ui++) {
+		if (strcmp (arrow_types[ui].name, name) == 0) {
+			ret = arrow_types[ui].typ;
+			break;
+		}
+	}
+
+	return ret;
+}
+
 GType
 go_arrow_get_type (void)
 {
diff --git a/goffice/utils/go-line.h b/goffice/utils/go-line.h
index a159708..582bf93 100644
--- a/goffice/utils/go-line.h
+++ b/goffice/utils/go-line.h
@@ -48,10 +48,10 @@ gboolean		 go_line_interpolation_auto_skip	(GOLineInterpolation type);
 
 typedef enum {
 	GO_ARROW_NONE,
-	GO_ARROW_TRIANGLE
+	GO_ARROW_TRIANGLE,
+	GO_ARROW_OVAL
 	/* GO_ARROW_STEALTH */
 	/* GO_ARROW_DIAMOND */
-	/* GO_ARROW_OVAL */
 	/* GO_ARROW_OPEN */
 } GOArrowType;
 
@@ -64,6 +64,9 @@ typedef struct {
 GType go_arrow_get_type (void);
 #define GO_ARROW_TYPE (go_arrow_get_type())
 
+char const *go_arrow_type_as_str (GOArrowType typ);
+GOArrowType go_arrow_type_from_str (const char *name);
+
 GOArrow *go_arrow_dup (GOArrow *src);
 void go_arrow_clear (GOArrow *dst);
 void go_arrow_init (GOArrow *res,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]