summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grapher/Field.cs130
-rw-r--r--grapher/Form1.Designer.cs29
-rw-r--r--grapher/Form1.cs39
-rw-r--r--grapher/VectorXY.cs33
-rw-r--r--grapher/grapher.csproj2
5 files changed, 182 insertions, 51 deletions
diff --git a/grapher/Field.cs b/grapher/Field.cs
new file mode 100644
index 0000000..641bb2a
--- /dev/null
+++ b/grapher/Field.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class Field
+ {
+ #region Enums
+
+ public enum FieldState
+ {
+ Undefined,
+ Default,
+ Typing,
+ Entered,
+ Unavailable,
+ }
+
+ #endregion Enums
+
+
+ #region Constructors
+
+ public Field(string defaultText, TextBox box, double defaultData)
+ {
+ DefaultText = defaultText;
+ Box = box;
+ Data = defaultData;
+ State = FieldState.Undefined;
+ box.KeyDown += KeyDown;
+
+ SetToDefault();
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ TextBox Box { get; }
+
+ public double Data { get; private set; }
+
+ public string DefaultText { get; }
+
+ public FieldState State { get; private set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public void SetToDefault()
+ {
+ if (State != FieldState.Default)
+ {
+ Box.BackColor = Color.AntiqueWhite;
+ Box.ForeColor = Color.Gray;
+ Box.Text = DefaultText;
+ State = FieldState.Default;
+ }
+ }
+
+ public void SetToTyping()
+ {
+ if (State != FieldState.Typing)
+ {
+ Box.BackColor = Color.White;
+ Box.ForeColor = Color.Black;
+ State = FieldState.Typing;
+ }
+ }
+
+ public void SetToEntered()
+ {
+ if (State != FieldState.Entered)
+ {
+ Box.BackColor = Color.White;
+ Box.ForeColor = Color.DarkGray;
+ State = FieldState.Entered;
+ }
+ }
+
+ public void SetToUnavailable()
+ {
+ if (State != FieldState.Unavailable)
+ {
+ Box.BackColor = Color.LightGray;
+ Box.ForeColor = Color.LightGray;
+ Box.Text = string.Empty;
+ }
+ }
+
+ public void KeyDown(object sender, KeyEventArgs e)
+ {
+ if (TryHandleWithEnter(e, sender, out double data))
+ {
+ Data = data;
+ }
+ }
+
+ private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data)
+ {
+ bool validEntry = false;
+ data = 0.0;
+
+ if (e.KeyCode == Keys.Enter)
+ {
+ try
+ {
+ data = Convert.ToDouble(((TextBox)sender).Text);
+ validEntry = true;
+ }
+ catch
+ {
+ }
+
+ e.Handled = true;
+ e.SuppressKeyPress = true;
+ }
+
+ return validEntry;
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs
index d2aae7d..978f3da 100644
--- a/grapher/Form1.Designer.cs
+++ b/grapher/Form1.Designer.cs
@@ -28,9 +28,9 @@
/// </summary>
private void InitializeComponent()
{
- System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea10 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
- System.Windows.Forms.DataVisualization.Charting.Legend legend10 = new System.Windows.Forms.DataVisualization.Charting.Legend();
- System.Windows.Forms.DataVisualization.Charting.Series series10 = new System.Windows.Forms.DataVisualization.Charting.Series();
+ System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea12 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
+ System.Windows.Forms.DataVisualization.Charting.Legend legend12 = new System.Windows.Forms.DataVisualization.Charting.Legend();
+ System.Windows.Forms.DataVisualization.Charting.Series series12 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.accelTypeDrop = new System.Windows.Forms.ComboBox();
this.sensitivityBox = new System.Windows.Forms.TextBox();
@@ -56,19 +56,19 @@
//
// AccelerationChart
//
- chartArea10.AxisX.Title = "Speed (counts/ms)";
- chartArea10.AxisY.Title = "Sensitivity (magnitude ratio)";
- chartArea10.Name = "ChartArea1";
- this.AccelerationChart.ChartAreas.Add(chartArea10);
- legend10.Name = "Legend1";
- this.AccelerationChart.Legends.Add(legend10);
+ chartArea12.AxisX.Title = "Speed (counts/ms)";
+ chartArea12.AxisY.Title = "Sensitivity (magnitude ratio)";
+ chartArea12.Name = "ChartArea1";
+ this.AccelerationChart.ChartAreas.Add(chartArea12);
+ legend12.Name = "Legend1";
+ this.AccelerationChart.Legends.Add(legend12);
this.AccelerationChart.Location = new System.Drawing.Point(162, 0);
this.AccelerationChart.Name = "AccelerationChart";
- series10.ChartArea = "ChartArea1";
- series10.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
- series10.Legend = "Legend1";
- series10.Name = "Accelerated Sensitivity";
- this.AccelerationChart.Series.Add(series10);
+ series12.ChartArea = "ChartArea1";
+ series12.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
+ series12.Legend = "Legend1";
+ series12.Name = "Accelerated Sensitivity";
+ this.AccelerationChart.Series.Add(series12);
this.AccelerationChart.Size = new System.Drawing.Size(801, 312);
this.AccelerationChart.TabIndex = 0;
this.AccelerationChart.Text = "chart1";
@@ -130,7 +130,6 @@
this.accelerationBox.Name = "accelerationBox";
this.accelerationBox.Size = new System.Drawing.Size(51, 20);
this.accelerationBox.TabIndex = 7;
- this.accelerationBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.accelerationBox_KeyDown);
//
// label4
//
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index d1244f3..fbf5dfb 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -25,7 +25,7 @@ namespace grapher
Weight = new VectorXY(1);
Cap = new VectorXY(0);
Offset = 0;
- Acceleration = 0;
+ Acceleration = new Field("0.0", this.accelerationBox, 0);
LimitOrExponent = 1.01;
Midpoint = 0;
@@ -69,7 +69,7 @@ namespace grapher
private double Offset { get; set; }
- private double Acceleration { get; set; }
+ private Field Acceleration { get; set; }
private double LimitOrExponent { get; set; }
@@ -158,7 +158,7 @@ namespace grapher
Cap.X,
Cap.Y,
Offset,
- Acceleration,
+ Acceleration.Data,
LimitOrExponent,
Midpoint);
ManagedAcceleration.WriteToDriver();
@@ -173,14 +173,6 @@ namespace grapher
}
}
- private void accelerationBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (TryHandleWithEnter(e, sender, out double data))
- {
- Acceleration = data;
- }
- }
-
private void rotationBox_KeyDown(object sender, KeyEventArgs e)
{
if (TryHandleWithEnter(e, sender, out double data))
@@ -222,30 +214,5 @@ namespace grapher
}
#endregion Methods
-
- public class VectorXY
- {
- public VectorXY(double x)
- {
- X = x;
- Y = x;
- }
-
- public VectorXY(double x, double y)
- {
- X = x;
- Y = y;
- }
-
- public double X { get; set; }
-
- public double Y { get; set; }
-
- public void SetBoth(double value)
- {
- X = value;
- Y = value;
- }
- }
}
}
diff --git a/grapher/VectorXY.cs b/grapher/VectorXY.cs
new file mode 100644
index 0000000..53c9e68
--- /dev/null
+++ b/grapher/VectorXY.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher
+{
+ public class VectorXY
+ {
+ public VectorXY(double x)
+ {
+ X = x;
+ Y = x;
+ }
+
+ public VectorXY(double x, double y)
+ {
+ X = x;
+ Y = y;
+ }
+
+ public double X { get; set; }
+
+ public double Y { get; set; }
+
+ public void SetBoth(double value)
+ {
+ X = value;
+ Y = value;
+ }
+ }
+}
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index f67ced1..9c29da4 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -47,6 +47,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Field.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
@@ -55,6 +56,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="VectorXY.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>