[chronojump] Cairo plotArrow moved to generic, and can have double tip and pass real/graph points



commit a0a8dfa29f75748e18cab8d8fd96d552f03a11ed
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Aug 28 10:33:15 2021 +0200

    Cairo plotArrow moved to generic, and can have double tip and pass real/graph points

 src/gui/cairo/generic.cs              | 66 +++++++++++++++++++++++++++++++++++
 src/gui/cairo/jumpsWeightFVProfile.cs |  6 ++--
 src/gui/cairo/raceAnalyzer.cs         |  3 +-
 src/gui/cairo/xy.cs                   | 51 ---------------------------
 4 files changed, 72 insertions(+), 54 deletions(-)
---
diff --git a/src/gui/cairo/generic.cs b/src/gui/cairo/generic.cs
index d29f4e0da..05b71a56d 100644
--- a/src/gui/cairo/generic.cs
+++ b/src/gui/cairo/generic.cs
@@ -168,6 +168,72 @@ public abstract class CairoGeneric
                LogB.Information("pvgl fontH: " + fontH.ToString());
        }
 
+       //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)
+       {
+               plotArrowPassingGraphPoints (g, color,
+                               calculatePaintX(ax), calculatePaintY(ay),
+                               calculatePaintX(bx), calculatePaintY(by),
+                               horiz, doubleTip, spacement);
+       }
+       protected void plotArrowPassingGraphPoints (Cairo.Context g, Cairo.Color color,
+                       double ax, double ay, double bx, double by, bool horiz, bool doubleTip, int spacement)
+       {
+               // 1) have spacements
+               if(horiz) {
+                       ax += spacement;
+                       bx -= spacement;
+               } else {
+                       ay -= spacement;
+                       by += spacement;
+               }
+               //g.SetSourceRGB(255,0,0);
+               g.Color = color;
+
+               // 2) write line (if it fits)
+               if(horiz && bx > ax || ! horiz && ay > by)
+               {
+                       g.MoveTo(ax, ay);
+                       g.LineTo(bx, by);
+               } else {
+                       //if it does not fit, move bx or by to have the arrow at the middle
+                       if(horiz)
+                               bx = Convert.ToInt32((ax + bx) / 2);
+                       else
+                               by = Convert.ToInt32((ay + by) / 2);
+                       g.MoveTo(bx, by);
+               }
+
+               // 3) write arrow tip(s)
+               int tip = 5;
+               if(horiz) {
+                       g.LineTo(bx - tip, by - tip);
+                       g.MoveTo(bx, by);
+                       g.LineTo(bx - tip, by + tip);
+                       if(doubleTip) {
+                               g.MoveTo(ax, ay);
+                               g.LineTo(ax + tip, ay - tip);
+                               g.MoveTo(ax, ay);
+                               g.LineTo(ax + tip, ay + tip);
+                       }
+               } else {
+                       g.LineTo(bx - tip, by + tip);
+                       g.MoveTo(bx, by);
+                       g.LineTo(bx + tip, by + tip);
+                       if(doubleTip) {
+                               g.MoveTo(ax, ay);
+                               g.LineTo(ax - tip, ay - tip);
+                               g.MoveTo(ax, ay);
+                               g.LineTo(ax + tip, ay - tip);
+                       }
+               }
+
+               // 4) end
+               g.Stroke ();
+               g.SetSourceRGB(0,0,0);
+       }
+
        /*
         * adapted to not used LinQ from:
         * https://stackoverflow.com/questions/237220/tickmark-algorithm-for-a-graph-axis
diff --git a/src/gui/cairo/jumpsWeightFVProfile.cs b/src/gui/cairo/jumpsWeightFVProfile.cs
index 7ce15838f..cad7908b7 100644
--- a/src/gui/cairo/jumpsWeightFVProfile.cs
+++ b/src/gui/cairo/jumpsWeightFVProfile.cs
@@ -155,9 +155,11 @@ public class JumpsWeightFVProfileGraph : CairoXY
                        if(showFullGraph)
                        {
                                if(f0Opt > f0Rel)
-                                       plotArrow (0, f0Rel, 0, f0Opt, false, 12);
+                                       plotArrowPassingRealPoints (g, colorFromRGB(255,0,0),
+                                                       0, f0Rel, 0, f0Opt, false, false, 12);
                                if(v0Opt > v0)
-                                       plotArrow (v0, 0, v0Opt, 0, true, 12);
+                                       plotArrowPassingRealPoints (g, colorFromRGB(255,0,0),
+                                                       v0, 0, v0Opt, 0, true, false, 12);
                        }
                }
 
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index a37a6afb3..212ac23a1 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -114,7 +114,8 @@ public class CairoGraphRaceAnalyzer : CairoXY
                                MovingAverage mAverage = new MovingAverage(points_list, 5);
                                mAverage.Calculate();
                                PointF pMaxY = mAverage.GetMaxY();
-                               plotArrow (pMaxY.X, pMaxY.Y, points_list[points_list.Count -1].X, pMaxY.Y, 
true, 0);
+                               plotArrowPassingRealPoints (g, colorFromRGB(255,0,0),
+                                               pMaxY.X, pMaxY.Y, points_list[points_list.Count -1].X, 
pMaxY.Y, true, false, 0);
                        }
                }
 
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index 0e291df39..8e88b82e4 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -247,57 +247,6 @@ public abstract class CairoXY : CairoGeneric
                g.SetSourceRGB(0,0,0);
        }
 
-       //horiz or vertical to manage spacement of arrow points and tip draw
-       protected void plotArrow (double ax, double ay, double bx, double by, bool horiz, int spacement)
-       {
-               // 1) convert to graph coordinates
-               ax = calculatePaintX(ax);
-               ay = calculatePaintY(ay);
-               bx = calculatePaintX(bx);
-               by = calculatePaintY(by);
-
-               // 2) have spacements
-               if(horiz) {
-                       ax += spacement;
-                       bx -= spacement;
-               } else {
-                       ay -= spacement;
-                       by += spacement;
-               }
-               g.SetSourceRGB(255,0,0);
-
-               // 3) write line (if it fits)
-               if(horiz && bx > ax || ! horiz && ay > by)
-               {
-                       g.MoveTo(ax, ay);
-                       g.LineTo(bx, by);
-               } else {
-                       //if it does not fit, move bx or by to have the arrow at the middle
-                       if(horiz)
-                               bx = Convert.ToInt32((ax + bx) / 2);
-                       else
-                               by = Convert.ToInt32((ay + by) / 2);
-                       g.MoveTo(bx, by);
-               }
-
-               // 4) write arrow tip
-
-               int tip = 5;
-               if(horiz) {
-                       g.LineTo(bx - tip, by - tip);
-                       g.MoveTo(bx, by);
-                       g.LineTo(bx - tip, by + tip);
-               } else {
-                       g.LineTo(bx - tip, by + tip);
-                       g.MoveTo(bx, by);
-                       g.LineTo(bx + tip, by + tip);
-               }
-
-               // 5) end
-               g.Stroke ();
-               g.SetSourceRGB(0,0,0);
-       }
-
        protected virtual void separateMinXMaxXIfNeeded()
        {
                if(minX == maxX)


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