[goffice] GOArrow: move draw function from Gnumeric.



commit 65485ce6d5a01f91fa8b348d45ae958c5aae8bd9
Author: Morten Welinder <terra gnome org>
Date:   Wed Feb 11 07:55:05 2015 -0500

    GOArrow: move draw function from Gnumeric.

 ChangeLog               |    5 ++++
 goffice/utils/go-line.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 goffice/utils/go-line.h |    3 ++
 3 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 14cc21d..bc46a62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-11  Morten Welinder  <terra gnome org>
+
+       * goffice/utils/go-line.c (go_arrow_draw): New function extracted
+       from Gnumeric.
+
 2015-02-07 Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * graph/gog-chart-map.c: protect against missing data
diff --git a/goffice/utils/go-line.c b/goffice/utils/go-line.c
index 77736d1..8b20c47 100644
--- a/goffice/utils/go-line.c
+++ b/goffice/utils/go-line.c
@@ -509,3 +509,51 @@ go_arrow_dup (GOArrow *src)
 {
        return g_memdup (src, sizeof (*src));
 }
+
+/**
+ * go_arrow_draw:
+ * @arrow: arrow to draw
+ * @cr: cairo surface to draw on
+ * @dx: (out): suggested change of line end-point
+ * @dy: (out): suggested change of line end-point
+ * @phi: angle to draw at
+ *
+ **/
+void
+go_arrow_draw (const GOArrow *arrow, cairo_t *cr,
+              double *dx, double *dy, double phi)
+{
+       if (dx) *dx = 0;
+       if (dy) *dy = 0;
+
+       switch (arrow->typ) {
+       case GO_ARROW_NONE:
+               return;
+
+       case GO_ARROW_KITE:
+               cairo_rotate (cr, phi);
+               cairo_set_line_width (cr, 1.0);
+               cairo_new_path (cr);
+               cairo_move_to (cr, 0.0, 0.0);
+               cairo_line_to (cr, -arrow->c, -arrow->b);
+               cairo_line_to (cr, 0.0, -arrow->a);
+               cairo_line_to (cr, arrow->c, -arrow->b);
+               cairo_close_path (cr);
+               cairo_fill (cr);
+
+               /*
+                * Make the line shorter so that the arrow won't be on top
+                * of a (perhaps quite fat) line.
+                */
+               if (dx) *dx = +arrow->a * sin (phi);
+               if (dy) *dy = -arrow->a * cos (phi);
+               break;
+
+       case GO_ARROW_OVAL:
+               cairo_rotate (cr, phi);
+               cairo_scale (cr, arrow->a, arrow->b);
+               cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
+               cairo_fill (cr);
+               break;
+       }
+}
diff --git a/goffice/utils/go-line.h b/goffice/utils/go-line.h
index 96c1071..f4c116d 100644
--- a/goffice/utils/go-line.h
+++ b/goffice/utils/go-line.h
@@ -76,6 +76,9 @@ void go_arrow_clear (GOArrow *dst);
 void go_arrow_init_kite (GOArrow *dst, double a, double b, double c);
 void go_arrow_init_oval (GOArrow *dst, double ra, double rb);
 
+void go_arrow_draw (const GOArrow *arrow, cairo_t *cr,
+                   double *dx, double *dy, double phi);
+
 G_END_DECLS
 
 #endif /* GO_LINE_H */


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