summaryrefslogtreecommitdiff
path: root/grapher/Models/Options
diff options
context:
space:
mode:
authorJacobPalecki <[email protected]>2020-09-08 16:00:05 -0700
committerGitHub <[email protected]>2020-09-08 16:00:05 -0700
commite5461fa84e65d78823d0022339fa2d8864f7e63c (patch)
treeb486ef524c93bfeb29a86403114b6805bf9decf1 /grapher/Models/Options
parentMerge pull request #19 from JacobPalecki/gainOffset (diff)
parentSave show last mouse value (diff)
downloadrawaccel-e5461fa84e65d78823d0022339fa2d8864f7e63c.tar.xz
rawaccel-e5461fa84e65d78823d0022339fa2d8864f7e63c.zip
Merge pull request #20 from JacobPalecki/GUI
GUI: Add By Component & Anisotropy; Remove Logarithm and Sigmoid; Delete Console; Some Refactoring
Diffstat (limited to 'grapher/Models/Options')
-rw-r--r--grapher/Models/Options/AccelOptionSet.cs117
-rw-r--r--grapher/Models/Options/AccelOptions.cs91
-rw-r--r--grapher/Models/Options/AccelTypeOptions.cs281
-rw-r--r--grapher/Models/Options/ActiveValueLabel.cs71
-rw-r--r--grapher/Models/Options/ActiveValueLabelXY.cs95
-rw-r--r--grapher/Models/Options/ApplyOptions.cs255
-rw-r--r--grapher/Models/Options/CapOptions.cs146
-rw-r--r--grapher/Models/Options/IOption.cs23
-rw-r--r--grapher/Models/Options/OffsetOptions.cs78
-rw-r--r--grapher/Models/Options/Option.cs99
-rw-r--r--grapher/Models/Options/OptionBase.cs33
-rw-r--r--grapher/Models/Options/OptionXY.cs84
12 files changed, 1185 insertions, 188 deletions
diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs
new file mode 100644
index 0000000..bc0d368
--- /dev/null
+++ b/grapher/Models/Options/AccelOptionSet.cs
@@ -0,0 +1,117 @@
+using grapher.Models.Serialized;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace grapher.Models.Options
+{
+ public class AccelOptionSet
+ {
+ public AccelOptionSet(
+ Label title,
+ Label activeValuesTitle,
+ int topAnchor,
+ AccelTypeOptions accelTypeOptions)
+ {
+ OptionsTitle = title;
+ ActiveValuesTitle = activeValuesTitle;
+ TopAnchor = topAnchor;
+ Options = accelTypeOptions;
+
+ ActiveValuesTitle.AutoSize = false;
+ ActiveValuesTitle.TextAlign = ContentAlignment.MiddleCenter;
+
+ Options.ShowFull();
+
+ OptionsTitle.Top = TopAnchor;
+ IsTitleMode = true;
+ SetRegularMode();
+ }
+
+ public int TopAnchor { get; }
+
+ public Label OptionsTitle { get; }
+
+ public Label ActiveValuesTitle { get; }
+
+ public AccelTypeOptions Options { get; }
+
+
+ public bool IsTitleMode { get; private set; }
+
+ public void SetRegularMode()
+ {
+ if (IsTitleMode)
+ {
+ IsTitleMode = false;
+
+ HideTitle();
+ Options.ShowFull();
+ }
+ }
+
+ public void SetTitleMode(string title)
+ {
+ OptionsTitle.Text = title;
+
+ if (!IsTitleMode)
+ {
+ IsTitleMode = true;
+
+ Options.ShowShortened();
+ DisplayTitle();
+ }
+ }
+
+ public void Hide()
+ {
+ OptionsTitle.Hide();
+ ActiveValuesTitle.Hide();
+ Options.Hide();
+ }
+
+ public void Show()
+ {
+ if (IsTitleMode)
+ {
+ OptionsTitle.Show();
+ }
+
+ ActiveValuesTitle.Show();
+ Options.Show();
+ }
+
+ public void DisplayTitle()
+ {
+ OptionsTitle.Show();
+
+ Options.Top = OptionsTitle.Top + OptionsTitle.Height + Constants.OptionVerticalSeperation;
+ }
+
+ public void HideTitle()
+ {
+ OptionsTitle.Hide();
+
+ Options.Top = TopAnchor;
+ }
+
+ public void SetArgs(ref AccelArgs args)
+ {
+ Options.SetArgs(ref args);
+ }
+
+ public AccelArgs GenerateArgs()
+ {
+ return Options.GenerateArgs();
+ }
+
+ public void SetActiveValues(int mode, AccelArgs args)
+ {
+ Options.SetActiveValues(mode, args);
+ }
+
+ public void AlignActiveValues()
+ {
+ Options.AlignActiveValues();
+ }
+ }
+}
diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs
deleted file mode 100644
index 6b98274..0000000
--- a/grapher/Models/Options/AccelOptions.cs
+++ /dev/null
@@ -1,91 +0,0 @@
-using grapher.Layouts;
-using grapher.Models.Options;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace grapher
-{
- public class AccelOptions
- {
- public const int PossibleOptionsCount = 4;
- public const int PossibleOptionsXYCount = 2;
-
- public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
- {
- new LinearLayout(),
- new ClassicLayout(),
- new NaturalLayout(),
- new LogLayout(),
- new SigmoidLayout(),
- new PowerLayout(),
- new NaturalGainLayout(),
- new SigmoidGainLayout(),
- new OffLayout()
- }.ToDictionary(k => k.Name);
-
- public AccelOptions(
- ComboBox accelDropdown,
- Option[] options,
- OptionXY[] optionsXY,
- Button writeButton,
- ActiveValueLabel activeValueLabel)
- {
- AccelDropdown = accelDropdown;
- AccelDropdown.Items.Clear();
- AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
- AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
-
- if (options.Length > PossibleOptionsCount)
- {
- throw new Exception("Layout given too many options.");
- }
-
- if (optionsXY.Length > PossibleOptionsXYCount)
- {
- throw new Exception("Layout given too many options.");
- }
-
- Options = options;
- OptionsXY = optionsXY;
- WriteButton = writeButton;
- ActiveValueLabel = activeValueLabel;
-
- Layout("Off");
- }
-
- public Button WriteButton { get; }
-
- public ComboBox AccelDropdown { get; }
-
- public int AccelerationIndex { get; private set; }
-
- public ActiveValueLabel ActiveValueLabel { get; }
-
- public Option[] Options { get; }
-
- public OptionXY[] OptionsXY { get; }
-
- public void SetActiveValue(int index)
- {
- var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name;
- ActiveValueLabel.SetValue(name);
- }
-
- private void OnIndexChanged(object sender, EventArgs e)
- {
- var accelerationTypeString = AccelDropdown.SelectedItem.ToString();
- Layout(accelerationTypeString);
- }
-
- private void Layout(string type)
- {
- var accelerationType = AccelerationTypes[type];
- AccelerationIndex = accelerationType.Index;
- accelerationType.Layout(Options, OptionsXY, WriteButton);
- }
- }
-}
diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs
new file mode 100644
index 0000000..14c2019
--- /dev/null
+++ b/grapher/Models/Options/AccelTypeOptions.cs
@@ -0,0 +1,281 @@
+using grapher.Layouts;
+using grapher.Models.Options;
+using grapher.Models.Serialized;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace grapher
+{
+ public class AccelTypeOptions : OptionBase
+ {
+ #region Fields
+
+ public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
+ {
+ new LinearLayout(),
+ new ClassicLayout(),
+ new NaturalLayout(),
+ new PowerLayout(),
+ new NaturalGainLayout(),
+ new SigmoidGainLayout(),
+ new OffLayout()
+ }.ToDictionary(k => k.Name);
+
+ #endregion Fields
+
+ #region Constructors
+
+ public AccelTypeOptions(
+ ComboBox accelDropdown,
+ Option acceleration,
+ CapOptions cap,
+ Option weight,
+ OffsetOptions offset,
+ Option limitOrExponent,
+ Option midpoint,
+ Button writeButton,
+ ActiveValueLabel accelTypeActiveValue)
+ {
+ AccelDropdown = accelDropdown;
+ AccelDropdown.Items.Clear();
+ AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
+ AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
+
+ Acceleration = acceleration;
+ Cap = cap;
+ Weight = weight;
+ Offset = offset;
+ LimitOrExponent = limitOrExponent;
+ Midpoint = midpoint;
+ WriteButton = writeButton;
+ AccelTypeActiveValue = accelTypeActiveValue;
+
+ AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width;
+ AccelTypeActiveValue.Height = AccelDropdown.Height;
+
+ Layout("Off");
+ ShowingDefault = true;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public Button WriteButton { get; }
+
+ public ComboBox AccelDropdown { get; }
+
+ public int AccelerationIndex
+ {
+ get
+ {
+ return AccelerationType.Index;
+ }
+ }
+
+ public LayoutBase AccelerationType { get; private set; }
+
+ public ActiveValueLabel AccelTypeActiveValue { get; }
+
+ public Option Acceleration { get; }
+
+ public CapOptions Cap { get; }
+
+ public Option Weight { get; }
+
+ public OffsetOptions Offset { get; }
+
+ public Option LimitOrExponent { get; }
+
+ public Option Midpoint { get; }
+
+ public override int Top
+ {
+ get
+ {
+ return AccelDropdown.Top;
+ }
+ set
+ {
+ AccelDropdown.Top = value;
+ AccelTypeActiveValue.Top = value;
+ Layout(value + AccelDropdown.Height + Constants.OptionVerticalSeperation);
+ }
+ }
+
+ public override int Height
+ {
+ get
+ {
+ return AccelDropdown.Height;
+ }
+ }
+
+ public override int Left
+ {
+ get
+ {
+ return AccelDropdown.Left;
+ }
+ set
+ {
+ AccelDropdown.Left = value;
+ }
+ }
+
+ public override int Width
+ {
+ get
+ {
+ return AccelDropdown.Width;
+ }
+ set
+ {
+ AccelDropdown.Width = value;
+ }
+ }
+
+ public override bool Visible
+ {
+ get
+ {
+ return AccelDropdown.Visible;
+ }
+ }
+
+ private bool ShowingDefault { get; set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public override void Hide()
+ {
+ AccelDropdown.Hide();
+ AccelTypeActiveValue.Hide();
+
+ Acceleration.Hide();
+ Cap.Hide();
+ Weight.Hide();
+ Offset.Hide();
+ LimitOrExponent.Hide();
+ Midpoint.Hide();
+ }
+
+ public void Show()
+ {
+ AccelDropdown.Show();
+ AccelTypeActiveValue.Show();
+ Layout();
+ }
+
+ public override void Show(string name)
+ {
+ Show();
+ }
+
+ public void SetActiveValues(int index, AccelArgs args)
+ {
+ var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name;
+ AccelTypeActiveValue.SetValue(name);
+
+ Weight.SetActiveValue(args.weight);
+ Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0);
+ Offset.SetActiveValue(args.offset, args.legacy_offset);
+ Acceleration.SetActiveValue(args.accel);
+ LimitOrExponent.SetActiveValue(args.exponent);
+ Midpoint.SetActiveValue(args.midpoint);
+ }
+
+ public void ShowFull()
+ {
+ if (ShowingDefault)
+ {
+ AccelDropdown.Text = Constants.AccelDropDownDefaultFullText;
+ }
+
+ Left = Acceleration.Left + Constants.DropDownLeftSeparation;
+ Width = Acceleration.Width - Constants.DropDownLeftSeparation;
+ }
+
+ public void ShowShortened()
+ {
+ if (ShowingDefault)
+ {
+ AccelDropdown.Text = Constants.AccelDropDownDefaultShortText;
+ }
+
+ Left = Acceleration.Field.Left;
+ Width = Acceleration.Field.Width;
+ }
+
+ public void SetArgs(ref AccelArgs args)
+ {
+ args.accel = Acceleration.Field.Data;
+ args.rate = Acceleration.Field.Data;
+ args.powerScale = Acceleration.Field.Data;
+ args.gainCap = Cap.VelocityGainCap;
+ args.scaleCap = Cap.SensitivityCap;
+ args.limit = LimitOrExponent.Field.Data;
+ args.exponent = LimitOrExponent.Field.Data;
+ args.powerExponent = LimitOrExponent.Field.Data;
+ args.offset = Offset.Offset;
+ args.legacy_offset = Offset.LegacyOffset;
+ args.midpoint = Midpoint.Field.Data;
+ args.weight = Weight.Field.Data;
+ }
+
+ public AccelArgs GenerateArgs()
+ {
+ AccelArgs args = new AccelArgs();
+ SetArgs(ref args);
+ return args;
+ }
+
+ public override void AlignActiveValues()
+ {
+ AccelTypeActiveValue.Align();
+ Acceleration.AlignActiveValues();
+ Cap.AlignActiveValues();
+ Offset.AlignActiveValues();
+ Weight.AlignActiveValues();
+ LimitOrExponent.AlignActiveValues();
+ Midpoint.AlignActiveValues();
+ }
+
+ private void OnIndexChanged(object sender, EventArgs e)
+ {
+ var accelerationTypeString = AccelDropdown.SelectedItem.ToString();
+ Layout(accelerationTypeString, Beneath);
+ ShowingDefault = false;
+ }
+
+ private void Layout(string type, int top = -1)
+ {
+ AccelerationType = AccelerationTypes[type];
+ Layout(top);
+ }
+
+ private void Layout(int top = -1)
+ {
+ if (top < 0)
+ {
+ top = Acceleration.Top;
+ }
+
+ AccelerationType.Layout(
+ Acceleration,
+ Cap,
+ Weight,
+ Offset,
+ LimitOrExponent,
+ Midpoint,
+ WriteButton,
+ top);
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Options/ActiveValueLabel.cs b/grapher/Models/Options/ActiveValueLabel.cs
index 138775a..18a4400 100644
--- a/grapher/Models/Options/ActiveValueLabel.cs
+++ b/grapher/Models/Options/ActiveValueLabel.cs
@@ -1,34 +1,42 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Drawing;
using System.Windows.Forms;
namespace grapher.Models.Options
{
public class ActiveValueLabel
{
- public const string DefaultFormatString = "0.######";
- public static readonly Color ActiveValueFontColor = Color.FromArgb(255, 65, 65, 65);
+ #region Constants
+
+
+ #endregion Constants
+
+ #region Fields
private string _prefix;
private string _value;
+ #endregion Fields
+
+ #region Constructors
+
public ActiveValueLabel(Label valueLabel, Label centeringLabel)
{
ValueLabel = valueLabel;
- ValueLabel.ForeColor = ActiveValueFontColor;
- Left = centeringLabel.Left;
- Width = centeringLabel.Width;
ValueLabel.AutoSize = false;
ValueLabel.TextAlign = ContentAlignment.MiddleCenter;
+ ValueLabel.ForeColor = Constants.ActiveValueFontColor;
- FormatString = DefaultFormatString;
+ CenteringLabel = centeringLabel;
+ Align();
+
+ FormatString = Constants.DefaultActiveValueFormatString;
Prefix = string.Empty;
}
+ #endregion Constructors
+
+ #region Properties
+
public Label ValueLabel { get; }
public string FormatString { get; set; }
@@ -79,6 +87,37 @@ namespace grapher.Models.Options
}
}
+ public int Top
+ {
+ get
+ {
+ return ValueLabel.Top;
+ }
+ set
+ {
+ ValueLabel.Top = value;
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return ValueLabel.Height;
+ }
+
+ set
+ {
+ ValueLabel.Height = value;
+ }
+ }
+
+ public Label CenteringLabel { get; }
+
+ #endregion Properties
+
+ #region Methods
+
public void Hide()
{
ValueLabel.Hide();
@@ -103,5 +142,13 @@ namespace grapher.Models.Options
{
ValueLabel.Text = string.IsNullOrWhiteSpace(Prefix) ? Value: $"{Prefix}: {Value}";
}
+
+ public void Align()
+ {
+ Left = CenteringLabel.Left;
+ Width = CenteringLabel.Width;
+ }
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs
index 12506e9..9498c66 100644
--- a/grapher/Models/Options/ActiveValueLabelXY.cs
+++ b/grapher/Models/Options/ActiveValueLabelXY.cs
@@ -1,15 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace grapher.Models.Options
+namespace grapher.Models.Options
{
public class ActiveValueLabelXY
{
- public const int ActiveLabelXYSeparation = 2;
- public const string ShortenedFormatString = "0.###";
+ #region Constants
+
+
+ #endregion Constants
+
+ #region Constructors
public ActiveValueLabelXY(
ActiveValueLabel x,
@@ -18,26 +16,57 @@ namespace grapher.Models.Options
X = x;
Y = y;
- FullWidth = x.Width;
- ShortenedWidth = (FullWidth - ActiveLabelXYSeparation) / 2;
-
- Y.Left = X.Left + ShortenedWidth + ActiveLabelXYSeparation;
+ Align(x.Width);
Y.Width = ShortenedWidth;
- Y.FormatString = ShortenedFormatString;
+ Y.FormatString = Constants.ShortenedFormatString;
Combined = false;
SetCombined();
}
+ #endregion Constructors
+
+ #region Properties
+
public ActiveValueLabel X { get; }
public ActiveValueLabel Y { get; }
public bool Combined { get; private set; }
- private int FullWidth { get; }
+ public int Left
+ {
+ get
+ {
+ return X.Left;
+ }
+ set
+ {
+ X.Left = value;
+ SetYLeft();
+ }
+ }
+
+ public int Height
+ {
+ get
+ {
+ return X.Height;
+ }
+ set
+ {
+ X.Height = value;
+ Y.Height = value;
+ }
+ }
+
+ private int FullWidth { get; set; }
+
+ private int ShortenedWidth { get; set; }
- private int ShortenedWidth { get; }
+ #endregion Properties
+
+ #region Methods
public void SetValues(double x, double y)
{
@@ -58,7 +87,7 @@ namespace grapher.Models.Options
{
if (!Combined)
{
- X.FormatString = ActiveValueLabel.DefaultFormatString;
+ X.FormatString = Constants.DefaultActiveValueFormatString;
X.Width = FullWidth;
X.Prefix = string.Empty;
Y.Hide();
@@ -71,7 +100,7 @@ namespace grapher.Models.Options
{
if (Combined)
{
- X.FormatString = ShortenedFormatString;
+ X.FormatString = Constants.ShortenedFormatString;
X.Width = ShortenedWidth;
X.Prefix = "X";
Y.Prefix = "Y";
@@ -80,5 +109,35 @@ namespace grapher.Models.Options
Combined = false;
}
+
+ public void AlignActiveValues()
+ {
+ Align(X.CenteringLabel.Width);
+
+ if (Combined)
+ {
+ X.Width = FullWidth;
+ }
+ else
+ {
+ X.Width = ShortenedWidth;
+ }
+ }
+
+ private void Align (int width)
+ {
+ FullWidth = width;
+ ShortenedWidth = (FullWidth - Constants.ActiveLabelXYSeparation) / 2;
+
+ SetYLeft();
+ Y.Width = ShortenedWidth;
+ }
+
+ private void SetYLeft()
+ {
+ Y.Left = X.Left + ShortenedWidth + Constants.ActiveLabelXYSeparation;
+ }
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs
new file mode 100644
index 0000000..241fe50
--- /dev/null
+++ b/grapher/Models/Options/ApplyOptions.cs
@@ -0,0 +1,255 @@
+using grapher.Models.Serialized;
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace grapher.Models.Options
+{
+ public class ApplyOptions
+ {
+ #region Constructors
+
+ public ApplyOptions(
+ ToolStripMenuItem wholeVectorMenuItem,
+ ToolStripMenuItem byComponentMenuItem,
+ CheckBox byComponentVectorXYLock,
+ AccelOptionSet optionSetX,
+ AccelOptionSet optionSetY,
+ OptionXY sensitivity,
+ Option rotation,
+ Label lockXYLabel,
+ AccelCharts accelCharts)
+ {
+ WholeVectorMenuItem = wholeVectorMenuItem;
+ ByComponentVectorMenuItem = byComponentMenuItem;
+
+ WholeVectorMenuItem.Click += new System.EventHandler(OnWholeClicked);
+ ByComponentVectorMenuItem.Click += new System.EventHandler(OnByComponentClicked);
+
+ WholeVectorMenuItem.CheckedChanged += new System.EventHandler(OnWholeCheckedChange);
+ ByComponentVectorMenuItem.CheckedChanged += new System.EventHandler(OnByComponentCheckedChange);
+
+ ByComponentVectorXYLock = byComponentVectorXYLock;
+ OptionSetX = optionSetX;
+ OptionSetY = optionSetY;
+ Sensitivity = sensitivity;
+ Rotation = rotation;
+ LockXYLabel = lockXYLabel;
+ AccelCharts = accelCharts;
+
+ LockXYLabel.AutoSize = false;
+ LockXYLabel.TextAlign = ContentAlignment.MiddleCenter;
+
+ ByComponentVectorXYLock.CheckedChanged += new System.EventHandler(OnByComponentXYLockChecked);
+ ByComponentVectorXYLock.Checked = true;
+
+ Rotation.SnapTo(Sensitivity);
+
+ EnableWholeApplication();
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public ToolStripMenuItem WholeVectorMenuItem { get; }
+
+ public ToolStripMenuItem ByComponentVectorMenuItem { get; }
+
+ public CheckBox ByComponentVectorXYLock { get; }
+
+ public AccelOptionSet OptionSetX { get; }
+
+ public AccelOptionSet OptionSetY { get; }
+
+ public OptionXY Sensitivity { get; }
+
+ public Option Rotation { get; }
+
+ public AccelCharts AccelCharts { get; }
+
+ public Label ActiveValueTitleY { get; }
+
+ public Label LockXYLabel { get; }
+
+ public bool IsWhole { get; private set; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public Vec2<AccelMode> GetModes()
+ {
+ var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex;
+
+ return new Vec2<AccelMode>
+ {
+ x = xMode,
+ y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex
+ };
+ }
+
+ public Vec2<AccelArgs> GetArgs()
+ {
+ var xArgs = OptionSetX.GenerateArgs();
+
+ return new Vec2<AccelArgs>
+ {
+ x = xArgs,
+ y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs()
+ };
+
+ }
+
+ public void SetActiveValues(
+ double xSens,
+ double ySens,
+ double rotation,
+ int xMode,
+ int yMode,
+ AccelArgs xArgs,
+ AccelArgs yArgs,
+ bool isWhole)
+ {
+ Sensitivity.SetActiveValues(xSens, ySens);
+ Rotation.SetActiveValue(rotation);
+ OptionSetX.SetActiveValues(xMode, xArgs);
+ OptionSetY.SetActiveValues(yMode, yArgs);
+ WholeVectorMenuItem.Checked = isWhole;
+ ByComponentVectorMenuItem.Checked = !isWhole;
+ }
+
+ public void SetActiveValues(DriverSettings settings)
+ {
+ SetActiveValues(
+ settings.sensitivity.x,
+ settings.sensitivity.x,
+ settings.rotation,
+ (int)settings.modes.x,
+ (int)settings.modes.y,
+ settings.args.x,
+ settings.args.y,
+ settings.combineMagnitudes);
+ }
+
+ public void OnWholeClicked(object sender, EventArgs e)
+ {
+ if (!WholeVectorMenuItem.Checked)
+ {
+ WholeVectorMenuItem.Checked = true;
+ ByComponentVectorMenuItem.Checked = false;
+ }
+ }
+
+ public void OnByComponentClicked(object sender, EventArgs e)
+ {
+ if (!ByComponentVectorMenuItem.Checked)
+ {
+ WholeVectorMenuItem.Checked = false;
+ ByComponentVectorMenuItem.Checked = true;
+ }
+ }
+
+ public void OnWholeCheckedChange(object sender, EventArgs e)
+ {
+ if (WholeVectorMenuItem.Checked)
+ {
+ EnableWholeApplication();
+ }
+ }
+
+ public void OnByComponentCheckedChange(object sender, EventArgs e)
+ {
+ if (ByComponentVectorMenuItem.Checked)
+ {
+ EnableByComponentApplication();
+ }
+ }
+
+ public void ShowWholeSet()
+ {
+ OptionSetX.SetRegularMode();
+ OptionSetY.Hide();
+ AccelCharts.SetWidened();
+ SetActiveTitlesWhole();
+ }
+
+ public void ShowByComponentAsOneSet()
+ {
+ OptionSetX.SetTitleMode("X = Y");
+ OptionSetY.Hide();
+ AccelCharts.SetWidened();
+ SetActiveTitlesByComponents();
+ }
+
+ public void ShowByComponentAsTwoSets()
+ {
+ OptionSetX.SetTitleMode("X");
+ OptionSetY.SetTitleMode("Y");
+ OptionSetY.Show();
+ AccelCharts.SetNarrowed();
+ }
+
+ public void ShowByComponentSet()
+ {
+ if (ByComponentVectorXYLock.Checked)
+ {
+ ShowByComponentAsOneSet();
+ }
+ else
+ {
+ ShowByComponentAsTwoSets();
+ }
+ }
+
+ private void OnByComponentXYLockChecked(object sender, EventArgs e)
+ {
+ if (!IsWhole)
+ {
+ ShowByComponentSet();
+ }
+ }
+
+ public void EnableWholeApplication()
+ {
+ IsWhole = true;
+ ByComponentVectorXYLock.Hide();
+ ShowWholeSet();
+ }
+
+ public void EnableByComponentApplication()
+ {
+ IsWhole = false;
+ ByComponentVectorXYLock.Show();
+ ShowByComponentSet();
+ }
+
+ private void SetActiveTitlesWhole()
+ {
+ OptionSetX.ActiveValuesTitle.Left = OptionSetX.Options.Left + OptionSetX.Options.Width;
+ LockXYLabel.Width = (AccelCharts.SensitivityChart.Left - OptionSetX.ActiveValuesTitle.Left) / 2;
+ OptionSetX.ActiveValuesTitle.Width = LockXYLabel.Width;
+ LockXYLabel.Left = OptionSetX.ActiveValuesTitle.Left + OptionSetX.ActiveValuesTitle.Width;
+ Sensitivity.Fields.LockCheckBox.Left = LockXYLabel.Left + LockXYLabel.Width / 2 - Sensitivity.Fields.LockCheckBox.Width / 2;
+ ByComponentVectorXYLock.Left = Sensitivity.Fields.LockCheckBox.Left;
+ AlignActiveValues();
+ }
+
+ private void SetActiveTitlesByComponents()
+ {
+ OptionSetY.ActiveValuesTitle.Left = OptionSetY.Options.Left + OptionSetY.Options.Width;
+ OptionSetY.ActiveValuesTitle.Width = Constants.NarrowChartLeft - OptionSetY.ActiveValuesTitle.Left;
+ AlignActiveValues();
+ }
+
+ private void AlignActiveValues()
+ {
+ OptionSetX.AlignActiveValues();
+ OptionSetY.AlignActiveValues();
+ Sensitivity.AlignActiveValues();
+ Rotation.AlignActiveValues();
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs
index 87bac88..5e47d7b 100644
--- a/grapher/Models/Options/CapOptions.cs
+++ b/grapher/Models/Options/CapOptions.cs
@@ -1,29 +1,27 @@
using grapher.Models.Options;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Forms;
namespace grapher
{
- public class CapOptions
+ public class CapOptions : OptionBase
{
+ #region Constants
- public const string GainCapFormatString = "0.##";
+
+ #endregion Constants
+
+ #region Constructors
public CapOptions(
ToolStripMenuItem velocityGainCapCheck,
ToolStripMenuItem legacyCapCheck,
- OptionXY capOption,
- OptionXY weightOption)
+ Option capOption)
{
VelocityGainCapCheck = velocityGainCapCheck;
LegacyCapCheck = legacyCapCheck;
CapOption = capOption;
- WeightOption = weightOption;
LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick);
VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick);
@@ -34,20 +32,24 @@ namespace grapher
EnableVelocityGainCap();
}
+ #endregion Constructors
+
+ #region Properties
+
public ToolStripMenuItem LegacyCapCheck { get; }
public ToolStripMenuItem VelocityGainCapCheck { get; }
- public OptionXY CapOption { get; }
+ public Option CapOption { get; }
- public OptionXY WeightOption { get; }
+ public bool IsSensitivityGain { get; private set; }
- public double SensitivityCapX {
+ public double SensitivityCap {
get
{
if (IsSensitivityGain)
{
- return CapOption.Fields.X;
+ return CapOption.Field.Data;
}
else
{
@@ -56,52 +58,122 @@ namespace grapher
}
}
- public double SensitivityCapY {
+ public double VelocityGainCap {
get
{
if (IsSensitivityGain)
{
- return CapOption.Fields.Y;
+ return 0;
}
else
{
- return 0;
+ return CapOption.Field.Data;
}
}
}
- public double VelocityGainCap {
+ public override int Top
+ {
+ get
+ {
+ return CapOption.Top;
+ }
+ set
+ {
+ CapOption.Top = value;
+ }
+ }
+
+ public override int Height
+ {
get
{
- if (IsSensitivityGain)
- {
- return 0;
- }
- else
- {
- return CapOption.Fields.X;
- }
+ return CapOption.Height;
}
}
- public bool IsSensitivityGain { get; private set; }
+ public override int Left
+ {
+ get
+ {
+ return CapOption.Left;
+ }
+ set
+ {
+ CapOption.Left = value;
+ }
+ }
+
+ public override int Width
+ {
+ get
+ {
+ return CapOption.Width;
+ }
+ set
+ {
+ CapOption.Width = value;
+ }
+ }
- public void SetActiveValues(double gainCap, double sensCapX, double sensCapY, bool capGainEnabled)
+ public override bool Visible
+ {
+ get
+ {
+ return CapOption.Visible;
+ }
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public override void Hide()
+ {
+ CapOption.Hide();
+ }
+
+ public void Show()
+ {
+ CapOption.Show();
+ }
+
+ public override void Show(string name)
+ {
+ CapOption.Show(name);
+ }
+
+ public void SnapTo(Option option)
+ {
+ Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
+ }
+
+
+ public void SetActiveValues(double gainCap, double sensCap, bool capGainEnabled)
{
if (capGainEnabled)
{
- CapOption.ActiveValueLabels.X.FormatString = GainCapFormatString;
- CapOption.ActiveValueLabels.X.Prefix = "Gain";
- CapOption.SetActiveValues(gainCap, gainCap);
+ CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString;
+ CapOption.ActiveValueLabel.Prefix = "Gain";
+ CapOption.SetActiveValue(gainCap);
+ LegacyCapCheck.Checked = true;
+ VelocityGainCapCheck.Checked = false;
}
else
{
- CapOption.ActiveValueLabels.X.FormatString = ActiveValueLabel.DefaultFormatString;
- CapOption.ActiveValueLabels.X.Prefix = string.Empty;
- CapOption.SetActiveValues(sensCapX, sensCapY);
+ CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString;
+ CapOption.ActiveValueLabel.Prefix = string.Empty;
+ CapOption.SetActiveValue(sensCap);
+ LegacyCapCheck.Checked = false;
+ VelocityGainCapCheck.Checked = true;
}
}
+ public override void AlignActiveValues()
+ {
+ CapOption.AlignActiveValues();
+ }
+
void OnSensitivityCapCheckClick(object sender, EventArgs e)
{
if (!LegacyCapCheck.Checked)
@@ -139,19 +211,15 @@ namespace grapher
void EnableSensitivityCap()
{
IsSensitivityGain = true;
- CapOption.Fields.LockCheckBox.Enabled = true;
- WeightOption.Fields.LockCheckBox.Enabled = true;
CapOption.SetName("Sensitivity Cap");
}
void EnableVelocityGainCap()
{
IsSensitivityGain = false;
- CapOption.Fields.LockCheckBox.Checked = true;
- CapOption.Fields.LockCheckBox.Enabled = false;
- WeightOption.Fields.LockCheckBox.Checked = true;
- WeightOption.Fields.LockCheckBox.Enabled = false;
CapOption.SetName("Velocity Gain Cap");
}
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/IOption.cs b/grapher/Models/Options/IOption.cs
new file mode 100644
index 0000000..fff1623
--- /dev/null
+++ b/grapher/Models/Options/IOption.cs
@@ -0,0 +1,23 @@
+namespace grapher.Models.Options
+{
+ public interface IOption
+ {
+ int Top { get; set; }
+
+ int Height { get; }
+
+ int Left { get; }
+
+ int Width { get; }
+
+ int Beneath { get; }
+
+ bool Visible { get; }
+
+ void Show(string name);
+
+ void Hide();
+
+ void SnapTo(IOption option);
+ }
+}
diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs
index 0b01ab9..b351ab5 100644
--- a/grapher/Models/Options/OffsetOptions.cs
+++ b/grapher/Models/Options/OffsetOptions.cs
@@ -1,13 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Forms;
namespace grapher.Models.Options
{
- public class OffsetOptions
+ public class OffsetOptions : OptionBase
{
public OffsetOptions(
ToolStripMenuItem velocityGainOffsetCheck,
@@ -65,6 +61,73 @@ namespace grapher.Models.Options
}
}
+ public override int Top
+ {
+ get
+ {
+ return OffsetOption.Top;
+ }
+ set
+ {
+ OffsetOption.Top = value;
+ }
+ }
+
+ public override int Height
+ {
+ get
+ {
+ return OffsetOption.Height;
+ }
+ }
+
+ public override int Left
+ {
+ get
+ {
+ return OffsetOption.Left;
+ }
+ set
+ {
+ OffsetOption.Left = value;
+ }
+ }
+
+ public override int Width
+ {
+ get
+ {
+ return OffsetOption.Width;
+ }
+ set
+ {
+ OffsetOption.Width = value;
+ }
+ }
+
+ public override bool Visible
+ {
+ get
+ {
+ return OffsetOption.Visible;
+ }
+ }
+
+ public override void Hide()
+ {
+ OffsetOption.Hide();
+ }
+
+ public void Show()
+ {
+ OffsetOption.Show();
+ }
+
+ public override void Show(string name)
+ {
+ OffsetOption.Show(name);
+ }
+
public void SetActiveValue(double offset, double legacyOffset)
{
if (offset > 0)
@@ -77,6 +140,11 @@ namespace grapher.Models.Options
}
}
+ public override void AlignActiveValues()
+ {
+ OffsetOption.AlignActiveValues();
+ }
+
public void OnVelocityGainOffsetClick(object sender, EventArgs e)
{
if (!VelocityGainOffsetCheck.Checked)
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
index b0ef374..5dc022b 100644
--- a/grapher/Models/Options/Option.cs
+++ b/grapher/Models/Options/Option.cs
@@ -1,23 +1,30 @@
using grapher.Models.Options;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Forms;
namespace grapher
{
- public class Option
+ public class Option : OptionBase
{
+ #region Constructors
+
public Option(
Field field,
Label label,
- ActiveValueLabel activeValueLabel)
+ ActiveValueLabel activeValueLabel,
+ int left)
{
Field = field;
Label = label;
ActiveValueLabel = activeValueLabel;
+ Left = left;
+
+ label.AutoSize = false;
+ label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+ label.Width = Field.Left - left - Constants.OptionLabelBoxSeperation;
+ label.Height = Field.Height;
+
+ ActiveValueLabel.Left = Field.Left + Field.Width;
+ ActiveValueLabel.Height = Field.Height;
}
public Option(
@@ -25,11 +32,13 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
+ int left,
ActiveValueLabel activeValueLabel)
: this(
new Field(box, containingForm, defaultData),
label,
- activeValueLabel)
+ activeValueLabel,
+ left)
{
}
@@ -38,6 +47,7 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
+ int left,
ActiveValueLabel activeValueLabel,
string startingName)
: this(
@@ -45,22 +55,82 @@ namespace grapher
containingForm,
defaultData,
label,
+ left,
activeValueLabel)
{
SetName(startingName);
}
+ #endregion Constructors
+
+ #region Properties
+
public Field Field { get; }
public Label Label { get; }
public ActiveValueLabel ActiveValueLabel { get; }
+ public override int Top
+ {
+ get
+ {
+ return Field.Top;
+ }
+ set
+ {
+ Field.Top = value;
+ Label.Top = value;
+ ActiveValueLabel.Top = value;
+ }
+ }
+
+ public override int Height
+ {
+ get
+ {
+ return Field.Height;
+ }
+ }
+
+ public override int Left
+ {
+ get
+ {
+ return Label.Left;
+ }
+ set
+ {
+ Label.Left = value;
+ }
+ }
+ public override int Width
+ {
+ get
+ {
+ return Field.Left + Field.Width - Label.Left;
+ }
+ set
+ {
+ }
+ }
+
+ public override bool Visible
+ {
+ get
+ {
+ return Field.Box.Visible;
+ }
+ }
+
+ #endregion Properties
+
+ #region Methods
+
public void SetName(string name)
{
Label.Text = name;
//Label.Left = Convert.ToInt32((Field.Box.Left / 2.0) - (Label.Width / 2.0)); //Centered
- Label.Left = Convert.ToInt32(Field.Box.Left - Label.Width - 10); //Right-aligned
}
public void SetActiveValue(double value)
@@ -68,7 +138,7 @@ namespace grapher
ActiveValueLabel.SetValue(value);
}
- public void Hide()
+ public override void Hide()
{
Field.Box.Hide();
Label.Hide();
@@ -87,11 +157,18 @@ namespace grapher
ActiveValueLabel.SetValue(value);
}
- public void Show(string name)
+ public override void Show(string name)
{
SetName(name);
Show();
}
+
+ public override void AlignActiveValues()
+ {
+ ActiveValueLabel.Align();
+ }
+
+ #endregion Methods
}
}
diff --git a/grapher/Models/Options/OptionBase.cs b/grapher/Models/Options/OptionBase.cs
new file mode 100644
index 0000000..5f6dca1
--- /dev/null
+++ b/grapher/Models/Options/OptionBase.cs
@@ -0,0 +1,33 @@
+namespace grapher.Models.Options
+{
+ public abstract class OptionBase : IOption
+ {
+ public abstract int Top { get; set; }
+
+ public abstract int Height { get; }
+
+ public abstract int Left { get; set; }
+
+ public abstract int Width { get; set; }
+
+ public int Beneath {
+ get
+ {
+ return Top + Height + Constants.OptionVerticalSeperation;
+ }
+ }
+
+ public abstract bool Visible { get; }
+
+ public abstract void Show(string Name);
+
+ public abstract void Hide();
+
+ public abstract void AlignActiveValues();
+
+ public virtual void SnapTo(IOption option)
+ {
+ Top = option.Beneath;
+ }
+ }
+}
diff --git a/grapher/Models/Options/OptionXY.cs b/grapher/Models/Options/OptionXY.cs
index 8e22617..6d6129a 100644
--- a/grapher/Models/Options/OptionXY.cs
+++ b/grapher/Models/Options/OptionXY.cs
@@ -1,20 +1,18 @@
using grapher.Models.Options;
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 class OptionXY : OptionBase
{
+ #region Constructors
public OptionXY(FieldXY fields, Label label, ActiveValueLabelXY activeValueLabels)
{
Fields = fields;
Label = label;
ActiveValueLabels = activeValueLabels;
+ ActiveValueLabels.Left = fields.CombinedWidth + fields.Left;
}
public OptionXY(
@@ -24,9 +22,8 @@ namespace grapher
Form containingForm,
double defaultData,
Label label,
- AccelCharts accelCharts,
ActiveValueLabelXY activeValueLabels)
- : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData, accelCharts), label, activeValueLabels)
+ : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label, activeValueLabels)
{
}
@@ -38,8 +35,7 @@ namespace grapher
double defaultData,
Label label,
ActiveValueLabelXY activeValueLabels,
- string startingName,
- AccelCharts accelCharts):
+ string startingName):
this(
xBox,
yBox,
@@ -47,18 +43,76 @@ namespace grapher
containingForm,
defaultData,
label,
- accelCharts,
activeValueLabels)
{
SetName(startingName);
}
+ #endregion Constructors
+
+ #region Properties
+
public FieldXY Fields { get; }
public Label Label { get; }
public ActiveValueLabelXY ActiveValueLabels { get; }
+ public override int Top
+ {
+ get
+ {
+ return Fields.Top;
+ }
+ set
+ {
+ Fields.Top = value;
+ }
+ }
+
+ public override int Height
+ {
+ get
+ {
+ return Fields.Height;
+ }
+ }
+
+ public override int Left
+ {
+ get
+ {
+ return Fields.Left;
+ }
+ set
+ {
+ Fields.Left = value;
+ }
+ }
+
+ public override int Width
+ {
+ get
+ {
+ return Fields.Width;
+ }
+ set
+ {
+ Fields.Width = value;
+ }
+ }
+
+ public override bool Visible
+ {
+ get
+ {
+ return Fields.Visible;
+ }
+ }
+ #endregion Properties
+
+ #region Methods
+
public void SetName(string name)
{
Label.Text = name;
@@ -71,7 +125,12 @@ namespace grapher
ActiveValueLabels.SetValues(x, y);
}
- public void Hide()
+ public override void AlignActiveValues()
+ {
+ ActiveValueLabels.AlignActiveValues();
+ }
+
+ public override void Hide()
{
Fields.Hide();
Fields.LockCheckBox.Hide();
@@ -85,12 +144,13 @@ namespace grapher
Label.Show();
}
- public void Show(string name)
+ public override void Show(string name)
{
SetName(name);
Show();
}
+ #endregion Methods
}
}