[chronojump] Encoder bars loss with arrow (at new method UtilGtk.DrawArrow)



commit 91f7ad45f268a39c65f359d0f516e03e0269f06e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jan 31 16:30:28 2020 +0100

    Encoder bars loss with arrow (at new method UtilGtk.DrawArrow)

 src/gui/encoderGraphObjects.cs | 31 +++++++++++++++++--------------
 src/utilGtk.cs                 | 27 +++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/src/gui/encoderGraphObjects.cs b/src/gui/encoderGraphObjects.cs
index 8a2d873d..479510de 100644
--- a/src/gui/encoderGraphObjects.cs
+++ b/src/gui/encoderGraphObjects.cs
@@ -729,21 +729,23 @@ public class EncoderGraphDoPlot
                                        100.0 * (maxThisSetValidAndCon - minThisSetValidAndCon) / 
maxThisSetValidAndCon, decimals) + "%";
                        LogB.Information(string.Format("Loss at plot: {0}", 100.0 * (maxThisSetValidAndCon - 
minThisSetValidAndCon) / maxThisSetValidAndCon));
 
-
-                       /*
-                        * at bucle dLeft is calculed using dWidth
-                        *      dLeft = left_margin + dWidth * count;
-                        * but then dWidth changes on c and on ec. On c:
-                        *      dWidth = dWidth - sep
-                        * so here, to calcule the needed dLeft, use: dWidth + sep
-                        */
                        if(maxThisSetValidAndConPos < minThisSetValidAndConPos)
-                               pixmap.DrawLine(pen_selected_encoder_capture,
-                                               left_margin + (dWidth + sep) * maxThisSetValidAndConPos + 
(dWidth/2), //dLeft +
-                                               dBottom - UtilAll.DivideSafeAndGetInt(graphHeightSafe * 
maxThisSetValidAndCon, maxAbsolute * 1.0),
-                                               left_margin + (dWidth + sep) * minThisSetValidAndConPos + 
(dWidth/2), //dLeft +
-                                               dBottom - UtilAll.DivideSafeAndGetInt(graphHeightSafe * 
minThisSetValidAndCon, maxAbsolute * 1.0));
-                       //TODO: draw an arc at end (arrow end)
+                       {
+                               /*
+                                * at bucle dLeft is calculed using dWidth
+                                *      dLeft = left_margin + dWidth * count;
+                                * but then dWidth changes on c and on ec. On c:
+                                *      dWidth = dWidth - sep
+                                * so here, to calcule the needed dLeft, use: dWidth + sep
+                                */
+                               int x0 = Convert.ToInt32(left_margin + (dWidth + sep) * 
maxThisSetValidAndConPos + (dWidth/2));
+                               int y0 = Convert.ToInt32(dBottom - 
UtilAll.DivideSafeAndGetInt(graphHeightSafe * maxThisSetValidAndCon, maxAbsolute * 1.0));
+                               int x1 = Convert.ToInt32(left_margin + (dWidth + sep) * 
minThisSetValidAndConPos + (dWidth/2));
+                               int y1 = Convert.ToInt32(dBottom - 
UtilAll.DivideSafeAndGetInt(graphHeightSafe * minThisSetValidAndCon, maxAbsolute * 1.0));
+
+                               pixmap.DrawLine(pen_selected_encoder_capture, x0, y0, x1, y1);
+                               UtilGtk.DrawArrow(pixmap, pen_selected_encoder_capture, x1, x0, y1, y0);
+                       }
                }
 
 
@@ -789,6 +791,7 @@ public class EncoderGraphDoPlot
                drawingarea.Visible = true;
        }
 
+
        public void Erase()
        {
                UtilGtk.ErasePaint(drawingarea, pixmap);
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index b7d39077..74620095 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -801,6 +801,33 @@ public class UtilGtk
                return pixbuf;
        }
 
+       // adapted from: https://stackoverflow.com/a/9295210/12366369
+       // thanks to renosis and Komplot
+       public static void DrawArrow (Pixmap pixmap, Gdk.GC pen, int tipX, int tailX, int tipY, int tailY)
+       {
+               int arrowLength = 10; //can be adjusted
+               int dx = tipX - tailX;
+               int 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);
+
+               Point [] points = new Point[3];
+               points[0].X = (int) x;
+               points[0].Y = (int) y;
+               points[1].X = tipX;
+               points[1].Y = tipY;
+               points[2].X = (int) x2;
+               points[2].Y = (int) y2;
+
+               pixmap.DrawPolygon(pen, true, points);
+       }
 
 }


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