[chronojump] plotArrowFree() for drawing free arrows on Cairo
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] plotArrowFree() for drawing free arrows on Cairo
- Date: Fri, 25 Mar 2022 13:10:57 +0000 (UTC)
commit 685801733130c37f54f87ee94ebc58cc0b679df8
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Mar 25 14:08:32 2022 +0100
plotArrowFree() for drawing free arrows on Cairo
src/gui/cairo/generic.cs | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
---
diff --git a/src/gui/cairo/generic.cs b/src/gui/cairo/generic.cs
index b70987977..9ac572c0b 100644
--- a/src/gui/cairo/generic.cs
+++ b/src/gui/cairo/generic.cs
@@ -20,6 +20,7 @@
*/
using System;
+using System.Collections.Generic; //List
using Gtk;
using Cairo;
@@ -253,6 +254,51 @@ public abstract class CairoGeneric
g.SetSourceColor(black);
}
+ /*
+ not horizontal, not vertical. Adapted from UtilGtk.DrawArrow()
+ tip is the point where the arrow will be drawn
+ */
+ protected void plotArrowFree (Cairo.Context g, Cairo.Color color, int lineWidth, int arrowLength,
+ double tailX, double tailY, double tipX, double tipY)
+ {
+ g.Save();
+ g.LineWidth = lineWidth;
+ g.SetSourceColor(color);
+
+ // 1) draw the line
+ g.MoveTo (tailX, tailY);
+ g.LineTo (tipX, tipY);
+ g.Stroke ();
+
+ // 2) draw the tip
+ g.LineWidth = 1;
+ double dx = tipX - tailX;
+ double dy = tipY - tailY;
+
+ double theta = Math.Atan2(dy, dx);
+
+ double rad = MathCJ.ToRadians(35); //35 angle, can be adjusted
+ double x = tipX - arrowLength * Math.Cos(theta + rad);
+ double y = tipY - arrowLength * Math.Sin(theta + rad);
+
+ double phi2 = MathCJ.ToRadians(-35);//-35 angle, can be adjusted
+ double x2 = tipX - arrowLength * Math.Cos(theta + phi2);
+ double y2 = tipY - arrowLength * Math.Sin(theta + phi2);
+
+ List<PointF> points_l = new List<PointF>();
+ points_l.Add(new PointF(x, y));
+ points_l.Add(new PointF(tipX, tipY));
+ points_l.Add(new PointF(x2, y2));
+
+ g.MoveTo(points_l[0].X, points_l[0].Y);
+ g.LineTo(points_l[1].X, points_l[1].Y);
+ g.LineTo(points_l[2].X, points_l[2].Y);
+ g.FillPreserve ();
+ g.Stroke();
+
+ g.Restore();
+ }
+
//horiz or vertical to manage spacement of arrow points and tip draw
protected void plotArrowPassingRealPoints (Cairo.Context g, Cairo.Color color,
double ax, double ay, double bx, double by, bool horiz, bool doubleTip, int spacement)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]