diff options
| author | Jacob Palecki <[email protected]> | 2020-07-29 21:03:02 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-29 21:03:02 -0700 |
| commit | 36abeecf953e0efcd1ec9dcafa4bd1c554e362f5 (patch) | |
| tree | 92683e3c6b6330df917b366d24c1dfa0452c70a4 /grapher | |
| parent | All single-value boxes use fields (diff) | |
| download | rawaccel-36abeecf953e0efcd1ec9dcafa4bd1c554e362f5.tar.xz rawaccel-36abeecf953e0efcd1ec9dcafa4bd1c554e362f5.zip | |
Add FieldXY
Diffstat (limited to 'grapher')
| -rw-r--r-- | grapher/Field.cs | 19 | ||||
| -rw-r--r-- | grapher/FieldXY.cs | 82 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 192 | ||||
| -rw-r--r-- | grapher/Form1.cs | 38 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 1 |
5 files changed, 242 insertions, 90 deletions
diff --git a/grapher/Field.cs b/grapher/Field.cs index 4be87ba..3f4b170 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -26,14 +26,15 @@ namespace grapher #region Constructors - public Field(string defaultText, TextBox box, Form containingForm, double defaultData) + public Field(TextBox box, Form containingForm, double defaultData) { - DefaultText = defaultText; + DefaultText = defaultData.ToString("N1"); Box = box; Data = defaultData; + DefaultData = defaultData; State = FieldState.Undefined; ContainingForm = containingForm; - box.KeyDown += KeyDown; + box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); SetToDefault(); } @@ -52,6 +53,8 @@ namespace grapher public FieldState State { get; private set; } + private double DefaultData { get; } + #endregion Properties #region Methods @@ -65,6 +68,7 @@ namespace grapher State = FieldState.Default; } + Data = DefaultData; Box.Text = DefaultText; ContainingForm.ActiveControl = null; } @@ -93,6 +97,14 @@ namespace grapher ContainingForm.ActiveControl = null; } + public void SetToEntered(double value) + { + SetToEntered(); + + Data = value; + Box.Text = Data.ToString("N2"); + } + public void SetToUnavailable() { if (State != FieldState.Unavailable) @@ -129,6 +141,7 @@ namespace grapher break; case FieldState.Unavailable: Box.Text = string.Empty; + ContainingForm.ActiveControl = null; break; default: break; diff --git a/grapher/FieldXY.cs b/grapher/FieldXY.cs new file mode 100644 index 0000000..f06cc4f --- /dev/null +++ b/grapher/FieldXY.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher +{ + public class FieldXY + { + public FieldXY(TextBox xBox, TextBox yBox, CheckBox lockCheckBox, Form containingForm, double defaultData) + { + XField = new Field(xBox, containingForm, defaultData); + YField = new Field(yBox, containingForm, defaultData); + LockCheckBox = lockCheckBox; + DefaultData = defaultData; + LockCheckBox.CheckedChanged += new System.EventHandler(CheckChanged); + SetLocked(); + } + public double X + { + get => XField.Data; + } + + public double Y + { + get + { + if (Locked) + { + return X; + } + else + { + return YField.Data; + } + } + } + + public CheckBox LockCheckBox { get; } + + private Field XField { get; } + + private Field YField { get; } + + private double DefaultData { get; } + + private bool Locked { get; set; } + + private void CheckChanged(object sender, EventArgs e) + { + if (LockCheckBox.CheckState == CheckState.Checked) + { + SetUnlocked(); + } + else + { + SetLocked(); + } + } + + private void SetLocked() + { + Locked = true; + YField.SetToUnavailable(); + } + + private void SetUnlocked() + { + Locked = false; + if (XField.State == Field.FieldState.Default) + { + YField.SetToDefault(); + } + else + { + YField.SetToEntered(XField.Data); + } + } + } +} diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index fcfa239..c7be8c7 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -28,18 +28,18 @@ /// </summary> private void InitializeComponent() { - 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(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = 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(); + this.sensitivityBoxX = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.rotationBox = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.accelerationBox = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); - this.capBox = new System.Windows.Forms.TextBox(); + this.capBoxX = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.weightBoxFirst = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); @@ -51,25 +51,31 @@ this.offsetBox = new System.Windows.Forms.TextBox(); this.label8 = 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(); + this.sensXYLock = new System.Windows.Forms.CheckBox(); + this.capXYLock = new System.Windows.Forms.CheckBox(); + this.weightXYLock = new System.Windows.Forms.CheckBox(); + this.LockXYLabel = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.AccelerationChart)).BeginInit(); this.SuspendLayout(); // // AccelerationChart // - 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); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); + this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - 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); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); + this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; // @@ -84,24 +90,23 @@ "Logarithmic", "Sigmoid", "Power"}); - this.accelTypeDrop.Location = new System.Drawing.Point(15, 86); + this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); this.accelTypeDrop.Name = "accelTypeDrop"; - this.accelTypeDrop.Size = new System.Drawing.Size(132, 21); + this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); this.accelTypeDrop.TabIndex = 2; this.accelTypeDrop.Text = "Acceleration Type"; // - // sensitivityBox + // sensitivityBoxX // - this.sensitivityBox.Location = new System.Drawing.Point(96, 15); - this.sensitivityBox.Name = "sensitivityBox"; - this.sensitivityBox.Size = new System.Drawing.Size(51, 20); - this.sensitivityBox.TabIndex = 3; - this.sensitivityBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.sensitivityBox_KeyDown); + this.sensitivityBoxX.Location = new System.Drawing.Point(95, 37); + this.sensitivityBoxX.Name = "sensitivityBoxX"; + this.sensitivityBoxX.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxX.TabIndex = 3; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(15, 18); + 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; @@ -109,15 +114,15 @@ // // rotationBox // - this.rotationBox.Location = new System.Drawing.Point(96, 45); + this.rotationBox.Location = new System.Drawing.Point(95, 63); this.rotationBox.Name = "rotationBox"; - this.rotationBox.Size = new System.Drawing.Size(51, 20); + this.rotationBox.Size = new System.Drawing.Size(70, 20); this.rotationBox.TabIndex = 5; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(22, 48); + 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; @@ -125,32 +130,31 @@ // // accelerationBox // - this.accelerationBox.Location = new System.Drawing.Point(96, 113); + this.accelerationBox.Location = new System.Drawing.Point(96, 116); this.accelerationBox.Name = "accelerationBox"; - this.accelerationBox.Size = new System.Drawing.Size(51, 20); + this.accelerationBox.Size = new System.Drawing.Size(70, 20); this.accelerationBox.TabIndex = 7; // // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(15, 116); + this.label4.Location = new System.Drawing.Point(14, 119); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(66, 13); this.label4.TabIndex = 9; this.label4.Text = "Acceleration"; // - // capBox + // capBoxX // - this.capBox.Location = new System.Drawing.Point(96, 140); - this.capBox.Name = "capBox"; - this.capBox.Size = new System.Drawing.Size(51, 20); - this.capBox.TabIndex = 10; - this.capBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.capBox_KeyDown); + this.capBoxX.Location = new System.Drawing.Point(95, 142); + this.capBoxX.Name = "capBoxX"; + this.capBoxX.Size = new System.Drawing.Size(32, 20); + this.capBoxX.TabIndex = 10; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(25, 143); + this.label3.Location = new System.Drawing.Point(30, 145); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(26, 13); this.label3.TabIndex = 11; @@ -158,15 +162,15 @@ // // weightBoxFirst // - this.weightBoxFirst.Location = new System.Drawing.Point(96, 167); + this.weightBoxFirst.Location = new System.Drawing.Point(95, 168); this.weightBoxFirst.Name = "weightBoxFirst"; - this.weightBoxFirst.Size = new System.Drawing.Size(24, 20); + this.weightBoxFirst.Size = new System.Drawing.Size(32, 20); this.weightBoxFirst.TabIndex = 12; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(25, 173); + 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; @@ -174,22 +178,22 @@ // // weightBoxSecond // - this.weightBoxSecond.Location = new System.Drawing.Point(126, 167); + this.weightBoxSecond.Location = new System.Drawing.Point(134, 168); this.weightBoxSecond.Name = "weightBoxSecond"; - this.weightBoxSecond.Size = new System.Drawing.Size(21, 20); + this.weightBoxSecond.Size = new System.Drawing.Size(32, 20); this.weightBoxSecond.TabIndex = 14; // // limitBox // - this.limitBox.Location = new System.Drawing.Point(96, 219); + this.limitBox.Location = new System.Drawing.Point(95, 220); this.limitBox.Name = "limitBox"; - this.limitBox.Size = new System.Drawing.Size(51, 20); + this.limitBox.Size = new System.Drawing.Size(70, 20); this.limitBox.TabIndex = 15; // // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(12, 222); + this.label6.Location = new System.Drawing.Point(14, 223); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(78, 13); this.label6.TabIndex = 16; @@ -197,15 +201,15 @@ // // midpointBox // - this.midpointBox.Location = new System.Drawing.Point(96, 245); + this.midpointBox.Location = new System.Drawing.Point(95, 246); this.midpointBox.Name = "midpointBox"; - this.midpointBox.Size = new System.Drawing.Size(51, 20); + this.midpointBox.Size = new System.Drawing.Size(70, 20); this.midpointBox.TabIndex = 17; // // label7 // this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(22, 248); + this.label7.Location = new System.Drawing.Point(21, 249); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(47, 13); this.label7.TabIndex = 18; @@ -213,15 +217,15 @@ // // offsetBox // - this.offsetBox.Location = new System.Drawing.Point(96, 193); + this.offsetBox.Location = new System.Drawing.Point(95, 194); this.offsetBox.Name = "offsetBox"; - this.offsetBox.Size = new System.Drawing.Size(51, 20); + this.offsetBox.Size = new System.Drawing.Size(70, 20); this.offsetBox.TabIndex = 19; // // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(25, 200); + this.label8.Location = new System.Drawing.Point(30, 197); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(35, 13); this.label8.TabIndex = 20; @@ -229,7 +233,7 @@ // // writeButton // - this.writeButton.Location = new System.Drawing.Point(28, 271); + this.writeButton.Location = new System.Drawing.Point(47, 272); this.writeButton.Name = "writeButton"; this.writeButton.Size = new System.Drawing.Size(102, 23); this.writeButton.TabIndex = 21; @@ -237,11 +241,73 @@ this.writeButton.UseVisualStyleBackColor = true; this.writeButton.Click += new System.EventHandler(this.writeButton_Click); // + // sensitivityBoxY + // + this.sensitivityBoxY.Location = new System.Drawing.Point(133, 37); + this.sensitivityBoxY.Name = "sensitivityBoxY"; + this.sensitivityBoxY.Size = new System.Drawing.Size(32, 20); + this.sensitivityBoxY.TabIndex = 22; + // + // capBoxY + // + this.capBoxY.Location = new System.Drawing.Point(135, 142); + this.capBoxY.Name = "capBoxY"; + this.capBoxY.Size = new System.Drawing.Size(31, 20); + this.capBoxY.TabIndex = 23; + // + // sensXYLock + // + this.sensXYLock.AutoSize = true; + this.sensXYLock.Checked = true; + this.sensXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.sensXYLock.Location = new System.Drawing.Point(188, 40); + this.sensXYLock.Name = "sensXYLock"; + this.sensXYLock.Size = new System.Drawing.Size(15, 14); + this.sensXYLock.TabIndex = 24; + this.sensXYLock.UseVisualStyleBackColor = true; + // + // capXYLock + // + this.capXYLock.AutoSize = true; + this.capXYLock.Checked = true; + this.capXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.capXYLock.Location = new System.Drawing.Point(188, 145); + this.capXYLock.Name = "capXYLock"; + this.capXYLock.Size = new System.Drawing.Size(15, 14); + this.capXYLock.TabIndex = 25; + this.capXYLock.UseVisualStyleBackColor = true; + // + // weightXYLock + // + this.weightXYLock.AutoSize = true; + this.weightXYLock.Checked = true; + this.weightXYLock.CheckState = System.Windows.Forms.CheckState.Checked; + this.weightXYLock.Location = new System.Drawing.Point(188, 171); + this.weightXYLock.Name = "weightXYLock"; + this.weightXYLock.Size = new System.Drawing.Size(15, 14); + this.weightXYLock.TabIndex = 26; + this.weightXYLock.UseVisualStyleBackColor = true; + // + // LockXYLabel + // + this.LockXYLabel.AutoSize = true; + this.LockXYLabel.Location = new System.Drawing.Point(165, 21); + this.LockXYLabel.Name = "LockXYLabel"; + this.LockXYLabel.Size = new System.Drawing.Size(60, 13); + this.LockXYLabel.TabIndex = 27; + this.LockXYLabel.Text = "Lock X && Y"; + // // RawAcceleration // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(963, 310); + this.ClientSize = new System.Drawing.Size(963, 312); + this.Controls.Add(this.LockXYLabel); + this.Controls.Add(this.weightXYLock); + this.Controls.Add(this.capXYLock); + this.Controls.Add(this.sensXYLock); + this.Controls.Add(this.capBoxY); + this.Controls.Add(this.sensitivityBoxY); this.Controls.Add(this.writeButton); this.Controls.Add(this.label8); this.Controls.Add(this.offsetBox); @@ -253,13 +319,13 @@ this.Controls.Add(this.label5); this.Controls.Add(this.weightBoxFirst); this.Controls.Add(this.label3); - this.Controls.Add(this.capBox); + this.Controls.Add(this.capBoxX); this.Controls.Add(this.label4); this.Controls.Add(this.accelerationBox); this.Controls.Add(this.label2); this.Controls.Add(this.rotationBox); this.Controls.Add(this.label1); - this.Controls.Add(this.sensitivityBox); + this.Controls.Add(this.sensitivityBoxX); this.Controls.Add(this.accelTypeDrop); this.Controls.Add(this.AccelerationChart); this.Name = "RawAcceleration"; @@ -275,13 +341,13 @@ private System.Windows.Forms.DataVisualization.Charting.Chart AccelerationChart; private System.Windows.Forms.ComboBox accelTypeDrop; - private System.Windows.Forms.TextBox sensitivityBox; + private System.Windows.Forms.TextBox sensitivityBoxX; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox rotationBox; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox accelerationBox; private System.Windows.Forms.Label label4; - private System.Windows.Forms.TextBox capBox; + private System.Windows.Forms.TextBox capBoxX; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox weightBoxFirst; private System.Windows.Forms.Label label5; @@ -293,6 +359,12 @@ private System.Windows.Forms.TextBox offsetBox; private System.Windows.Forms.Label label8; private System.Windows.Forms.Button writeButton; + private System.Windows.Forms.TextBox sensitivityBoxY; + private System.Windows.Forms.TextBox capBoxY; + private System.Windows.Forms.CheckBox sensXYLock; + private System.Windows.Forms.CheckBox capXYLock; + private System.Windows.Forms.CheckBox weightXYLock; + private System.Windows.Forms.Label LockXYLabel; } } diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ef0dd3a..2bc4da7 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -20,14 +20,14 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationType = 5; - Sensitivity = new VectorXY(1); - Rotation = new Field("0.0", rotationBox, this, 0); - Weight = new VectorXY(1); - Cap = new VectorXY(0); - Offset = new Field("0.0", offsetBox, this, 0); - Acceleration = new Field("0.0", accelerationBox, this, 0); - LimitOrExponent = new Field("2.0", limitBox, this, 2); - Midpoint = new Field("0.0", midpointBox, this, 0); + 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(); @@ -59,13 +59,13 @@ namespace grapher private int AccelerationType { get; set; } - private VectorXY Sensitivity { get; set; } + private FieldXY Sensitivity { get; set; } private Field Rotation { get; set; } - private VectorXY Weight { get; set; } + private FieldXY Weight { get; set; } - private VectorXY Cap { get; set; } + private FieldXY Cap { get; set; } private Field Offset { get; set; } @@ -165,22 +165,6 @@ namespace grapher UpdateGraph(); } - private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Sensitivity.SetBoth(data); - } - } - - private void capBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Cap.SetBoth(data); - } - } - #endregion Methods } } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 9c29da4..7b0849f 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -48,6 +48,7 @@ </ItemGroup> <ItemGroup> <Compile Include="Field.cs" /> + <Compile Include="FieldXY.cs" /> <Compile Include="Form1.cs"> <SubType>Form</SubType> </Compile> |