[chronojump] RaceAnalyzer: Initial code for a realtime velocimeter using cairo
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] RaceAnalyzer: Initial code for a realtime velocimeter using cairo
- Date: Mon, 14 Dec 2020 18:21:56 +0000 (UTC)
commit 80c2b9908fb6c1be078b1aa6de632eded1f39df9
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Dec 14 19:21:25 2020 +0100
RaceAnalyzer: Initial code for a realtime velocimeter using cairo
glade/app1.glade | 89 +++++++++++++++++++++++----
src/Makefile.am | 1 +
src/gui/app1/runEncoder.cs | 12 ++++
src/gui/cairo/radial.cs | 148 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 238 insertions(+), 12 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index c8229eea..167e0fa6 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -11589,6 +11589,65 @@ EncoderInertialCapture</property>
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHBox" id="hbox443">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <widget class="GtkSpinButton"
id="spin_race_analyzer_capture_speed_test">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">•</property>
+ <property name="width_chars">2</property>
+ <property
name="primary_icon_activatable">False</property>
+ <property
name="secondary_icon_activatable">False</property>
+ <property
name="primary_icon_sensitive">True</property>
+ <property
name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">0 0 20 1 10
0</property>
+ <property name="numeric">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_race_analyzer_capture_speed_test">
+ <property name="label"
translatable="yes">button</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_race_analyzer_capture_speed_test_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkDrawingArea"
id="drawingarea_race_analyzer_capture">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="expose_event"
handler="on_drawingarea_race_analyzer_capture_expose_event" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="position">8</property>
@@ -23488,6 +23547,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -28309,18 +28371,6 @@ 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>
@@ -28357,6 +28407,18 @@ 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>
@@ -36576,6 +36638,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/Makefile.am b/src/Makefile.am
index d0e86e8e..896ee884 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,6 +39,7 @@ SOURCES = \
gui/cairo/jumpsProfile.cs\
gui/cairo/jumpsRjFatigue.cs\
gui/cairo/jumpsWeightFVProfile.cs\
+ gui/cairo/radial.cs\
gui/cairo/util.cs\
gui/cairo/xy.cs\
gui/chronojumpImporter.cs\
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index 47b6ee67..c0612000 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -48,6 +48,8 @@ public partial class ChronoJumpWindow
[Widget] Gtk.TreeView treeview_raceAnalyzer;
[Widget] Gtk.Button button_raceAnalyzer_table_save;
[Widget] Gtk.Label label_race_analyzer_capture_speed;
+ [Widget] Gtk.DrawingArea drawingarea_race_analyzer_capture;
+ [Widget] Gtk.SpinButton spin_race_analyzer_capture_speed_test;
int race_analyzer_distance;
int race_analyzer_temperature;
@@ -1673,4 +1675,14 @@ public partial class ChronoJumpWindow
}
// -------------------------------- end of exercise stuff --------------------
+ CairoRadial cairoRadial;
+ private void on_drawingarea_race_analyzer_capture_expose_event (object o, ExposeEventArgs args)
+ {
+ cairoRadial = new CairoRadial(drawingarea_race_analyzer_capture,
preferences.fontType.ToString());
+ }
+
+ private void on_button_race_analyzer_capture_speed_test_clicked (object o, EventArgs args)
+ {
+ cairoRadial.GraphSpeed(spin_race_analyzer_capture_speed_test.Value);
+ }
}
diff --git a/src/gui/cairo/radial.cs b/src/gui/cairo/radial.cs
new file mode 100644
index 00000000..c7c73a86
--- /dev/null
+++ b/src/gui/cairo/radial.cs
@@ -0,0 +1,148 @@
+
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * ChronoJump is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Copyright (C) 2020 Xavier de Blas <xaviblas gmail com>
+ */
+
+using System;
+using System.Collections.Generic; //List
+using Gtk;
+using Cairo;
+using Mono.Unix;
+
+public class CairoRadial
+{
+ private Cairo.Context g;
+ private const int textHeight = 12;
+ private int margin = 20;
+ private Gtk.DrawingArea area;
+ private string font;
+ private int graphWidth;
+ private int graphHeight;
+ private Cairo.Color black;
+ private Cairo.Color red;
+
+ public CairoRadial (Gtk.DrawingArea area, string font)
+ {
+ this.area = area;
+ this.font = font;
+
+ initGraph();
+ endGraphDisposing();
+ }
+
+ private void initGraph()
+ {
+ //1 create context
+ g = Gdk.CairoHelper.Create (area.GdkWindow);
+
+ //2 clear DrawingArea (white)
+ g.SetSourceRGB(1,1,1);
+ g.Paint();
+
+ //graphWidth = Convert.ToInt32(area.Allocation.Width *.8);
+ graphWidth = area.Allocation.Width;
+ graphHeight = area.Allocation.Height;
+
+ g.SetSourceRGB(0,0,0);
+ g.LineWidth = 2;
+
+ //4 prepare font
+ g.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
+ g.SetFontSize(textHeight);
+
+ black = colorFromRGB(0,0,0);
+ //gray99 = colorFromRGB(99,99,99);
+ //white = colorFromRGB(255,255,255);
+ red = colorFromRGB(200,0,0);
+ //blue = colorFromRGB(178, 223, 238); //lightblue
+ //bluePlots = colorFromRGB(0, 0, 200);
+
+ g.MoveTo(5,10);
+ g.LineTo(20,30);
+ g.Color = red;
+ g.Stroke();
+
+ g.Color = black;
+ //TODO: correctly operate with the margins
+ printText(graphWidth/2 -margin, margin, 0, textHeight, "0", g, alignTypes.CENTER);
+ printText(graphWidth -margin, graphHeight/2 -margin, 0, textHeight, "5", g,
alignTypes.CENTER);
+ printText(graphWidth/2 -margin, graphHeight-margin, 0, textHeight, "10", g,
alignTypes.CENTER);
+ printText(margin, graphHeight/2-margin, 0, textHeight, "15", g, alignTypes.CENTER);
+ }
+
+ //TODO: currently max is 20
+ //TODO: make this go from bottom left to bottom right like a car
+ int maxValue = 20;
+ public void GraphSpeed(double speed)
+ {
+ initGraph();
+
+ double speedArc = (2*Math.PI / maxValue) * speed;
+
+ g.SetSourceRGB(0.5, 0.5, 0.5);
+ g.MoveTo(graphWidth/2, graphHeight/2);
+
+ double minSide = graphWidth;
+ if(graphHeight < minSide)
+ minSide = graphHeight;
+
+ //thanks to: http://ralph-glass.homepage.t-online.de/clock/readme.html
+ g.LineTo(graphWidth/2 + (minSide/2 -2*margin) * 0.9 * Math.Cos(speedArc - Math.PI/2),
+ graphHeight/2 + (minSide/2 -2*margin) * 0.9 * Math.Sin(speedArc - Math.PI/2));
+ g.Color = red;
+ g.Stroke();
+
+ endGraphDisposing();
+ LogB.Information("Graph speed done!");
+ }
+
+ //TODO: all this methods have to be shared with xy.cs
+
+ protected void endGraphDisposing()
+ {
+ g.GetTarget().Dispose ();
+ g.Dispose ();
+ }
+
+ //0 - 255
+ private Cairo.Color colorFromRGB(int red, int green, int blue)
+ {
+ return new Cairo.Color(red/256.0, green/256.0, blue/256.0);
+ }
+
+ private enum alignTypes { LEFT, CENTER, RIGHT }
+ private void printText (int x, int y, int height, int textHeight, string text, Cairo.Context g,
alignTypes align)
+ {
+ int moveToLeft = 0;
+ if(align == alignTypes.CENTER || align == alignTypes.RIGHT)
+ {
+ Cairo.TextExtents te;
+ te = g.TextExtents(text);
+
+ if(align == alignTypes.CENTER)
+ moveToLeft = Convert.ToInt32(te.Width/2);
+ else
+ moveToLeft = Convert.ToInt32(te.Width);
+ }
+
+ g.MoveTo( x - moveToLeft, ((y+y+height)/2) + textHeight/2 );
+ g.ShowText(text);
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]