[chronojump] RaceAnalyzer capture velocimeter much nicer



commit fefc483cc9eef581aec8ec4af17953ac44632331
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Dec 18 11:10:54 2020 +0100

    RaceAnalyzer capture velocimeter much nicer

 glade/app1.glade           | 67 +++++++++++++---------------------------------
 src/gui/app1/runEncoder.cs |  4 +--
 src/gui/cairo/radial.cs    | 47 +++++++++++++++++++++++++++-----
 3 files changed, 62 insertions(+), 56 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 99f82808..d7ce28cf 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -11568,41 +11568,6 @@ EncoderInertialCapture</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="border_width">8</property>
                                                             <child>
-                                                            <widget class="GtkHBox" id="hbox290">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="spacing">8</property>
-                                                            <child>
-                                                            <widget class="GtkLabel" id="label584">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label">Capture speed:</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
-                                                            <widget class="GtkLabel" 
id="label_race_analyzer_capture_speed">
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="position">1</property>
-                                                            </packing>
-                                                            </child>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkDrawingArea" 
id="drawingarea_race_analyzer_capture">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -11611,7 +11576,7 @@ EncoderInertialCapture</property>
                                                             <packing>
                                                             <property name="expand">True</property>
                                                             <property name="fill">True</property>
-                                                            <property name="position">1</property>
+                                                            <property name="position">0</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
@@ -23522,6 +23487,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -28343,6 +28311,18 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -28379,18 +28359,6 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -36619,6 +36587,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 944a36ce..b9e854cb 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -48,7 +48,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Viewport viewport_run_encoder_graph;
        [Widget] Gtk.TreeView treeview_raceAnalyzer;
        [Widget] Gtk.Button button_raceAnalyzer_table_save;
-       [Widget] Gtk.Label label_race_analyzer_capture_speed;
+       //[Widget] Gtk.Label label_race_analyzer_capture_speed;
        [Widget] Gtk.DrawingArea drawingarea_race_analyzer_capture;
 
        int race_analyzer_distance;
@@ -1321,8 +1321,8 @@ public partial class ChronoJumpWindow
                else
                {
                        event_execute_label_message.Text = runEncoderPulseMessage;
-                       label_race_analyzer_capture_speed.Text = Util.TrimDecimals(runEncoderCaptureSpeed,3) 
+ " m/s";
 
+                       //label_race_analyzer_capture_speed.Text = 
Util.TrimDecimals(runEncoderCaptureSpeed,3) + " m/s";
                        cairoRadial.GraphSpeed(runEncoderCaptureSpeed);
 
                        if(runEncoderPulseMessage == capturingMessage)
diff --git a/src/gui/cairo/radial.cs b/src/gui/cairo/radial.cs
index 8c8a36b1..25b0b43b 100644
--- a/src/gui/cairo/radial.cs
+++ b/src/gui/cairo/radial.cs
@@ -28,7 +28,7 @@ using Mono.Unix;
 public class CairoRadial
 {
        private Cairo.Context g;
-       private const int textHeight = 12;
+       private int textHeight = 12;
        private int margin = 20;
        private Gtk.DrawingArea area;
        private string font;
@@ -60,8 +60,11 @@ public class CairoRadial
                graphWidth = area.Allocation.Width - 2*margin;
                graphHeight = area.Allocation.Height - 2*margin;
 
+               if(graphWidth > 1200 || graphHeight > 1000)
+                       textHeight = 16;
+
                g.SetSourceRGB(0,0,0);
-               g.LineWidth = 2;
+               g.LineWidth = 1;
 
                //4 prepare font
                g.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
@@ -78,17 +81,43 @@ public class CairoRadial
                minSide = graphWidth;
                if(graphHeight < minSide)
                        minSide = graphHeight;
-               for(int i = 0; i < 20; i ++)
+
+               double tickLength = .1;
+               for(int i = 0; i <= 20; i ++)
                {
-                       double iArc = (2*Math.PI / maxPossibleValue) * i;
+                       double iArc = (2*Math.PI / (maxPossibleValue +7)) * (i+17); //+7 for have the 
maxvalue at bottom right, +17 to have 0 on the bottom left
+
+                       //numbers
                        printText(Convert.ToInt32(margin + graphWidth/2 + (minSide/2) * 1 * Math.Cos(iArc - 
Math.PI/2)),
                                        Convert.ToInt32(margin + graphHeight/2 + (minSide/2) * 1 * 
Math.Sin(iArc - Math.PI/2)),
                                        0, textHeight, i.ToString(), g, alignTypes.CENTER);
+
+                       //ticks
+                       g.MoveTo (
+                                       margin + graphWidth/2 + (minSide/2) * .9 * Math.Cos(iArc - Math.PI/2),
+                                       margin + graphHeight/2 + (minSide/2) * .9 * Math.Sin(iArc - 
Math.PI/2));
+                       g.LineTo (
+                                       margin + graphWidth/2 + (minSide/2) * (.9-tickLength) * Math.Cos(iArc 
- Math.PI/2),
+                                       margin + graphHeight/2 + (minSide/2) * (.9-tickLength) * 
Math.Sin(iArc - Math.PI/2));
+                       g.Stroke();
+
+                       if(tickLength == .1)
+                               tickLength = .05;
+                       else
+                               tickLength = .1;
                }
+
+               /*
+               //TEST:
+               g.LineWidth = 2;
+               graphLineFromCenter(3, red);
+               printText(Convert.ToInt32(margin + graphWidth/2),
+                               Convert.ToInt32(margin + (.66 * graphHeight)),
+                               0, textHeight, "Speed: 3 m/s", g, alignTypes.CENTER);
+               */
        }
 
        //TODO: currently max is 20
-       //TODO: make this go from bottom left to bottom right like a car
        int maxPossibleValue = 20;
        double speedMax = 0;
        public void ResetSpeedMax()
@@ -105,16 +134,22 @@ public class CairoRadial
 
                //g.SetSourceRGB(0.5, 0.5, 0.5);
 
+               g.LineWidth = 2;
                graphLineFromCenter(speed, red);
                if(speedMax > speed)
                        graphLineFromCenter(speedMax, gray);
 
+               printText(Convert.ToInt32(margin + graphWidth/2),
+                               Convert.ToInt32(margin + (.66 * graphHeight)),
+                               0, textHeight, "Speed: " + Util.TrimDecimals(speed, 1) + " m/s", g, 
alignTypes.CENTER);
+
                endGraphDisposing();
        }
 
        private void graphLineFromCenter(double toValue, Cairo.Color color)
        {
-               double arc = (2*Math.PI / maxPossibleValue) * toValue;
+               //double arc = (2*Math.PI / maxPossibleValue) * toValue;
+               double arc = (2*Math.PI / (maxPossibleValue +7)) * (toValue+17); //+7 for have the maxvalue 
at bottom right, +17 to have 0 on the bottom left
                g.MoveTo(margin + graphWidth/2, margin + graphHeight/2);
 
                //thanks to: http://ralph-glass.homepage.t-online.de/clock/readme.html


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