diff options
| author | Jacob Palecki <[email protected]> | 2020-07-30 20:15:12 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-30 20:15:12 -0700 |
| commit | 49bd00c71b223d12f1d85d5c1bae635d450403fd (patch) | |
| tree | b8984dcaa28c13c6b5f065cd0e540c1faca55c17 | |
| parent | Use class heirarchy for layout types (diff) | |
| download | rawaccel-49bd00c71b223d12f1d85d5c1bae635d450403fd.tar.xz rawaccel-49bd00c71b223d12f1d85d5c1bae635d450403fd.zip | |
Use options instead of fields
| -rw-r--r-- | grapher/Field.cs | 2 | ||||
| -rw-r--r-- | grapher/FieldXY.cs | 7 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 136 | ||||
| -rw-r--r-- | grapher/Form1.cs | 94 | ||||
| -rw-r--r-- | grapher/Option.cs | 14 | ||||
| -rw-r--r-- | grapher/OptionXY.cs | 51 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 1 |
7 files changed, 170 insertions, 135 deletions
diff --git a/grapher/Field.cs b/grapher/Field.cs index 6e1c6d2..7ce4c6e 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -44,7 +44,7 @@ namespace grapher #region Properties - TextBox Box { get; } + public TextBox Box { get; } Form ContainingForm { get; } diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs index 60da3a4..23c5de1 100644 --- a/grapher/FieldXY.cs +++ b/grapher/FieldXY.cs @@ -14,7 +14,6 @@ namespace grapher XField = new Field(xBox, containingForm, defaultData); YField = new Field(yBox, containingForm, defaultData); LockCheckBox = lockCheckBox; - DefaultData = defaultData; LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); SetLocked(); } @@ -40,11 +39,9 @@ namespace grapher public CheckBox LockCheckBox { get; } - private Field XField { get; } + public Field XField { get; } - private Field YField { get; } - - private double DefaultData { get; } + public Field YField { get; } private bool Locked { get; set; } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index ac936d3..decdeeb 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,28 +30,28 @@ namespace grapher /// </summary> private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea3 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend3 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); + this.sensitivityLabel = new System.Windows.Forms.Label(); this.rotationBox = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); + this.rotationLabel = new System.Windows.Forms.Label(); this.accelerationBox = new System.Windows.Forms.TextBox(); this.constantOneLabel = new System.Windows.Forms.Label(); this.capBoxX = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); + this.capLabel = new System.Windows.Forms.Label(); this.weightBoxFirst = new System.Windows.Forms.TextBox(); - this.label5 = new System.Windows.Forms.Label(); + this.weightLabel = new System.Windows.Forms.Label(); this.weightBoxSecond = new System.Windows.Forms.TextBox(); this.limitBox = new System.Windows.Forms.TextBox(); this.constantTwoLabel = new System.Windows.Forms.Label(); this.midpointBox = new System.Windows.Forms.TextBox(); this.constantThreeLabel = new System.Windows.Forms.Label(); this.offsetBox = new System.Windows.Forms.TextBox(); - this.label8 = new System.Windows.Forms.Label(); + this.offsetLabel = new System.Windows.Forms.Label(); this.writeButton = new System.Windows.Forms.Button(); this.sensitivityBoxY = new System.Windows.Forms.TextBox(); this.capBoxY = new System.Windows.Forms.TextBox(); @@ -64,19 +64,19 @@ namespace grapher // // AccelerationChart // - chartArea3.AxisX.Title = "Speed (counts/ms)"; - chartArea3.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea3.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea3); - legend3.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend3); + chartArea1.AxisX.Title = "Speed (counts/ms)"; + chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea1.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend1); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series3.ChartArea = "ChartArea1"; - series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series3.Legend = "Legend1"; - series3.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series3); + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series1); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; @@ -97,14 +97,14 @@ namespace grapher this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); this.sensitivityBoxX.TabIndex = 3; // - // label1 + // sensitivityLabel // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(14, 40); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(54, 13); - this.label1.TabIndex = 4; - this.label1.Text = "Sensitivity"; + this.sensitivityLabel.AutoSize = true; + this.sensitivityLabel.Location = new System.Drawing.Point(14, 40); + this.sensitivityLabel.Name = "sensitivityLabel"; + this.sensitivityLabel.Size = new System.Drawing.Size(54, 13); + this.sensitivityLabel.TabIndex = 4; + this.sensitivityLabel.Text = "Sensitivity"; // // rotationBox // @@ -113,14 +113,14 @@ namespace grapher this.rotationBox.Size = new System.Drawing.Size(70, 20); this.rotationBox.TabIndex = 5; // - // label2 + // rotationLabel // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(24, 66); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(47, 13); - this.label2.TabIndex = 6; - this.label2.Text = "Rotation"; + this.rotationLabel.AutoSize = true; + this.rotationLabel.Location = new System.Drawing.Point(24, 66); + this.rotationLabel.Name = "rotationLabel"; + this.rotationLabel.Size = new System.Drawing.Size(47, 13); + this.rotationLabel.TabIndex = 6; + this.rotationLabel.Text = "Rotation"; // // accelerationBox // @@ -146,16 +146,16 @@ namespace grapher this.capBoxX.Size = new System.Drawing.Size(32, 20); this.capBoxX.TabIndex = 10; // - // label3 + // capLabel // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(24, 146); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(26, 13); - this.label3.TabIndex = 11; - this.label3.Text = "Cap"; - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.label3.Click += new System.EventHandler(this.label3_Click); + this.capLabel.AutoSize = true; + this.capLabel.Location = new System.Drawing.Point(24, 146); + this.capLabel.Name = "capLabel"; + this.capLabel.Size = new System.Drawing.Size(26, 13); + this.capLabel.TabIndex = 11; + this.capLabel.Text = "Cap"; + this.capLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.capLabel.Click += new System.EventHandler(this.label3_Click); // // weightBoxFirst // @@ -164,15 +164,15 @@ namespace grapher this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); this.weightBoxFirst.TabIndex = 12; // - // label5 + // weightLabel // - this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(24, 171); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(41, 13); - this.label5.TabIndex = 13; - this.label5.Text = "Weight"; - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.weightLabel.AutoSize = true; + this.weightLabel.Location = new System.Drawing.Point(24, 171); + this.weightLabel.Name = "weightLabel"; + this.weightLabel.Size = new System.Drawing.Size(41, 13); + this.weightLabel.TabIndex = 13; + this.weightLabel.Text = "Weight"; + this.weightLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // weightBoxSecond // @@ -222,15 +222,15 @@ namespace grapher this.offsetBox.Size = new System.Drawing.Size(70, 20); this.offsetBox.TabIndex = 19; // - // label8 + // offsetLabel // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(24, 197); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(35, 13); - this.label8.TabIndex = 20; - this.label8.Text = "Offset"; - this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.offsetLabel.AutoSize = true; + this.offsetLabel.Location = new System.Drawing.Point(24, 197); + this.offsetLabel.Name = "offsetLabel"; + this.offsetLabel.Size = new System.Drawing.Size(35, 13); + this.offsetLabel.TabIndex = 20; + this.offsetLabel.Text = "Offset"; + this.offsetLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // writeButton // @@ -310,22 +310,22 @@ namespace grapher this.Controls.Add(this.capBoxY); this.Controls.Add(this.sensitivityBoxY); this.Controls.Add(this.writeButton); - this.Controls.Add(this.label8); + this.Controls.Add(this.offsetLabel); this.Controls.Add(this.offsetBox); this.Controls.Add(this.constantThreeLabel); this.Controls.Add(this.midpointBox); this.Controls.Add(this.constantTwoLabel); this.Controls.Add(this.limitBox); this.Controls.Add(this.weightBoxSecond); - this.Controls.Add(this.label5); + this.Controls.Add(this.weightLabel); this.Controls.Add(this.weightBoxFirst); - this.Controls.Add(this.label3); + this.Controls.Add(this.capLabel); this.Controls.Add(this.capBoxX); this.Controls.Add(this.constantOneLabel); this.Controls.Add(this.accelerationBox); - this.Controls.Add(this.label2); + this.Controls.Add(this.rotationLabel); this.Controls.Add(this.rotationBox); - this.Controls.Add(this.label1); + this.Controls.Add(this.sensitivityLabel); this.Controls.Add(this.sensitivityBoxX); this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); @@ -343,22 +343,22 @@ namespace grapher private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ComboBox accelTypeDrop; private System.Windows.Forms.TextBox sensitivityBoxX; - private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label sensitivityLabel; private System.Windows.Forms.TextBox rotationBox; - private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label rotationLabel; private System.Windows.Forms.TextBox accelerationBox; private System.Windows.Forms.Label constantOneLabel; private System.Windows.Forms.TextBox capBoxX; - private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label capLabel; private System.Windows.Forms.TextBox weightBoxFirst; - private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label weightLabel; private System.Windows.Forms.TextBox weightBoxSecond; private System.Windows.Forms.TextBox limitBox; private System.Windows.Forms.Label constantTwoLabel; private System.Windows.Forms.TextBox midpointBox; private System.Windows.Forms.Label constantThreeLabel; private System.Windows.Forms.TextBox offsetBox; - private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label offsetLabel; private System.Windows.Forms.Button writeButton; private System.Windows.Forms.TextBox sensitivityBoxY; private System.Windows.Forms.TextBox capBoxY; diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 93e0768..b1ab2fa 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,22 +19,31 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + Sensitivity = new OptionXY(new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1), sensitivityLabel); + Rotation = new Option(new Field(rotationBox, this, 0), rotationLabel); + Weight = new OptionXY(new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1), weightLabel); + Cap = new OptionXY(new FieldXY(capBoxX, capBoxY, capXYLock, this, 0), capLabel); + Offset = new Option(new Field(offsetBox, this, 0), offsetLabel); + + Sensitivity.SetName("Sensitivity"); + Rotation.SetName("Rotation"); + Weight.SetName("Weight"); + Cap.SetName("Cap"); + Offset.SetName("Offset"); + + // The name and layout of these options is handled by AccelerationOptions object. + Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + AccelerationOptions = new AccelOptions( accelTypeDrop, new Option[] { - new Option(accelerationBox, constantOneLabel), - new Option(limitBox, constantTwoLabel), - new Option(midpointBox, constantThreeLabel) + Acceleration, + LimitOrExponent, + Midpoint, }); - Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); - Rotation = new Field(rotationBox, this, 0); - Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); - Cap = new FieldXY(capBoxX, capBoxY, capXYLock, this, 0); - Offset = new Field(offsetBox, this, 0); - Acceleration = new Field(accelerationBox, this, 0); - LimitOrExponent = new Field(limitBox, this, 2); - Midpoint = new Field(midpointBox, this, 0); UpdateGraph(); @@ -66,21 +75,21 @@ namespace grapher private AccelOptions AccelerationOptions { get; set; } - private FieldXY Sensitivity { get; set; } + private OptionXY Sensitivity { get; set; } - private Field Rotation { get; set; } + private Option Rotation { get; set; } - private FieldXY Weight { get; set; } + private OptionXY Weight { get; set; } - private FieldXY Cap { get; set; } + private OptionXY Cap { get; set; } - private Field Offset { get; set; } + private Option Offset { get; set; } - private Field Acceleration { get; set; } + private Option Acceleration { get; set; } - private Field LimitOrExponent { get; set; } + private Option LimitOrExponent { get; set; } - private Field Midpoint { get; set; } + private Option Midpoint { get; set; } #endregion Properties @@ -113,7 +122,7 @@ namespace grapher var inMagnitude = Magnitude(i,j); var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X; + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.Fields.X; if (!orderedPoints.ContainsKey(inMagnitude)) { @@ -131,44 +140,21 @@ namespace grapher } } - 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; - } - private void writeButton_Click(object sender, EventArgs e) { ManagedAcceleration.UpdateAccel( AccelerationOptions.AccelerationIndex, - Rotation.Data, - Sensitivity.X, - Sensitivity.Y, - Weight.X, - Weight.Y, - Cap.X, - Cap.Y, - Offset.Data, - Acceleration.Data, - LimitOrExponent.Data, - Midpoint.Data); + Rotation.Field.Data, + Sensitivity.Fields.X, + Sensitivity.Fields.Y, + Weight.Fields.X, + Weight.Fields.Y, + Cap.Fields.X, + Cap.Fields.Y, + Offset.Field.Data, + Acceleration.Field.Data, + LimitOrExponent.Field.Data, + Midpoint.Field.Data); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } diff --git a/grapher/Option.cs b/grapher/Option.cs index 17e624b..a2a4f89 100644 --- a/grapher/Option.cs +++ b/grapher/Option.cs @@ -9,31 +9,31 @@ namespace grapher { public class Option { - public Option(TextBox box, Label label) + public Option(Field field, Label label) { - Box = box; + Field = field; Label = label; } - public TextBox Box { get; } + public Field Field { get; } public Label Label { get; } public void SetName(string name) { Label.Text = name; - Label.Left = Convert.ToInt32((Box.Left / 2.0) - (Label.Width / 2.0)); + Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); } public void Hide() { - Box.Hide(); + Field.Box.Hide(); Label.Hide(); } public void Show() { - Box.Show(); + Field.Box.Show(); Label.Show(); } @@ -41,7 +41,7 @@ namespace grapher { SetName(name); - Box.Show(); + Field.Box.Show(); Label.Show(); } } diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs new file mode 100644 index 0000000..c65d1cf --- /dev/null +++ b/grapher/OptionXY.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class OptionXY + { public OptionXY(FieldXY fields, Label label) + { + Fields = fields; + Label = label; + } + + public FieldXY Fields { get; } + + public Label Label { get; } + + public void SetName(string name) + { + Label.Text = name; + Label.Left = Convert.ToInt32((Fields.XField.Box.Left / 2.0) - (Label.Width / 2.0)); + } + + public void Hide() + { + Fields.XField.Box.Hide(); + Fields.YField.Box.Hide(); + Label.Hide(); + } + + public void Show() + { + Fields.XField.Box.Show(); + Fields.YField.Box.Show(); + Label.Show(); + } + + public void Show(string name) + { + SetName(name); + + Fields.XField.Box.Show(); + Fields.YField.Box.Show(); + Label.Show(); + } + + } +} diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 91518ce..04d2eaa 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -65,6 +65,7 @@ <Compile Include="Layouts\PowerLayout.cs" /> <Compile Include="Layouts\SigmoidLayout.cs" /> <Compile Include="Option.cs" /> + <Compile Include="OptionXY.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="VectorXY.cs" /> |