summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-07 15:19:39 -0700
committerJacob Palecki <[email protected]>2020-09-07 15:19:39 -0700
commitaff3a066575f4bfa429f67a5104a1fcffc5f326e (patch)
tree975c8cf984e97d818ebf530b68a246f4a4b1aefb
parentPass args by ref for setting (diff)
downloadrawaccel-aff3a066575f4bfa429f67a5104a1fcffc5f326e.tar.xz
rawaccel-aff3a066575f4bfa429f67a5104a1fcffc5f326e.zip
Refactor type options
-rw-r--r--grapher/Layouts/ClassicLayout.cs9
-rw-r--r--grapher/Layouts/DefaultLayout.cs9
-rw-r--r--grapher/Layouts/LayoutBase.cs86
-rw-r--r--grapher/Layouts/LinearLayout.cs9
-rw-r--r--grapher/Layouts/NaturalGainLayout.cs9
-rw-r--r--grapher/Layouts/NaturalLayout.cs9
-rw-r--r--grapher/Layouts/OffLayout.cs9
-rw-r--r--grapher/Layouts/OptionLayout.cs41
-rw-r--r--grapher/Layouts/PowerLayout.cs9
-rw-r--r--grapher/Layouts/SigmoidGainLayout.cs9
-rw-r--r--grapher/Models/AccelGUIFactory.cs59
-rw-r--r--grapher/Models/Fields/Field.cs30
-rw-r--r--grapher/Models/Options/AccelOptionSet.cs83
-rw-r--r--grapher/Models/Options/AccelTypeOptions.cs116
-rw-r--r--grapher/Models/Options/ApplyOptions.cs4
-rw-r--r--grapher/Models/Options/CapOptions.cs40
-rw-r--r--grapher/Models/Options/IOption.cs27
-rw-r--r--grapher/Models/Options/OffsetOptions.cs65
-rw-r--r--grapher/Models/Options/Option.cs34
-rw-r--r--grapher/Models/Options/OptionBase.cs30
-rw-r--r--grapher/grapher.csproj3
21 files changed, 498 insertions, 192 deletions
diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs
index f7766f0..d02e11c 100644
--- a/grapher/Layouts/ClassicLayout.cs
+++ b/grapher/Layouts/ClassicLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "Classic";
Index = (int)AccelMode.classic;
- ShowOptions = new bool[] { true, true, true, false, true, true };
- OptionNames = new string[] { Offset, Acceleration, Exponent, string.Empty, Cap, Weight };
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(true, Cap);
+ WeightLayout = new OptionLayout(true, Weight);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, Exponent);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs
index cb1994f..d9e1413 100644
--- a/grapher/Layouts/DefaultLayout.cs
+++ b/grapher/Layouts/DefaultLayout.cs
@@ -16,9 +16,14 @@ namespace grapher.Layouts
{
Name = "Default";
Index = (int)AccelMode.noaccel;
- ShowOptions = new bool[] { true, true, true, true, true };
- OptionNames = new string[] { Offset, Acceleration, $"{Limit}\\{Exponent}", Midpoint, Cap, Weight };
ButtonEnabled = false;
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(true, Cap);
+ WeightLayout = new OptionLayout(true, Weight);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, $"{Limit}\\{Exponent}");
+ MidpointLayout = new OptionLayout(true, Midpoint);
}
}
}
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
index daac6f1..629b0a4 100644
--- a/grapher/Layouts/LayoutBase.cs
+++ b/grapher/Layouts/LayoutBase.cs
@@ -1,4 +1,5 @@
-using System;
+using grapher.Models.Options;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,9 +21,13 @@ namespace grapher.Layouts
public LayoutBase()
{
- ShowOptions = new bool[] { false, false, false, false, true, true };
- ShowOptionsXY = new bool[] { true, true };
- OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ AccelLayout = new OptionLayout(false, string.Empty);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(false, string.Empty);
+ LimExpLayout = new OptionLayout(false, string.Empty);
+ MidpointLayout = new OptionLayout(false, string.Empty);
+
ButtonEnabled = true;
}
@@ -34,30 +39,75 @@ namespace grapher.Layouts
public string Name { get; internal set; }
- internal bool[] ShowOptions { get; set; }
+ protected bool ButtonEnabled { get; set; }
+
+ protected OptionLayout AccelLayout { get; set; }
+
+ protected OptionLayout CapLayout { get; set; }
+
+ protected OptionLayout WeightLayout { get; set; }
- internal bool[] ShowOptionsXY { get; set; }
+ protected OptionLayout OffsetLayout { get; set; }
- internal string[] OptionNames { get; set; }
+ protected OptionLayout LimExpLayout { get; set; }
- internal bool ButtonEnabled { get; set; }
+ protected OptionLayout MidpointLayout { get; set; }
- public void Layout(Option[] options, Button button)
+ public void Layout(
+ IOption accelOption,
+ IOption capOption,
+ IOption weightOption,
+ IOption offsetOption,
+ IOption limExpOption,
+ IOption midpointOption,
+ Button button,
+ int top)
{
- // Relies on AccelOptions to keep lengths correct.
- for (int i = 0; i < options.Length; i++)
+ AccelLayout.Layout(accelOption);
+ CapLayout.Layout(capOption);
+ WeightLayout.Layout(weightOption);
+ OffsetLayout.Layout(offsetOption);
+ LimExpLayout.Layout(limExpOption);
+ MidpointLayout.Layout(midpointOption);
+
+ button.Enabled = ButtonEnabled;
+
+ IOption previous = null;
+ foreach (var option in new IOption[] { accelOption, capOption, weightOption, offsetOption, limExpOption, midpointOption})
{
- if (ShowOptions[i])
+ if (option.Visible)
{
- options[i].Show(OptionNames[i]);
- }
- else
- {
- options[i].Hide();
+ if (previous != null)
+ {
+ option.SnapTo(previous);
+ }
+ else
+ {
+ option.Top = top;
+ }
+
+ previous = option;
}
}
+ }
- button.Enabled = ButtonEnabled;
+ public void Layout(
+ IOption accelOption,
+ IOption capOption,
+ IOption weightOption,
+ IOption offsetOption,
+ IOption limExpOption,
+ IOption midpointOption,
+ Button button)
+ {
+ Layout(accelOption,
+ capOption,
+ weightOption,
+ offsetOption,
+ limExpOption,
+ midpointOption,
+ button,
+ accelOption.Top);
}
}
}
diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs
index 8b1d444..b5c6434 100644
--- a/grapher/Layouts/LinearLayout.cs
+++ b/grapher/Layouts/LinearLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "Linear";
Index = (int)AccelMode.linear;
- ShowOptions = new bool[] { true, true, false, false, true, true };
- OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty, Cap, Weight };
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(true, Cap);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(false, string.Empty);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/NaturalGainLayout.cs b/grapher/Layouts/NaturalGainLayout.cs
index 0f9caf0..ae73c80 100644
--- a/grapher/Layouts/NaturalGainLayout.cs
+++ b/grapher/Layouts/NaturalGainLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "NaturalGain";
Index = (int)AccelMode.naturalgain;
- ShowOptions = new bool[] { true, true, true, false, false, true };
- OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty, string.Empty, Weight};
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, Limit);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs
index caa77bd..0923e1d 100644
--- a/grapher/Layouts/NaturalLayout.cs
+++ b/grapher/Layouts/NaturalLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "Natural";
Index = (int)AccelMode.natural;
- ShowOptions = new bool[] { true, true, true, false, false, true };
- OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty, string.Empty, Weight };
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, Limit);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs
index 1c37026..2a2f414 100644
--- a/grapher/Layouts/OffLayout.cs
+++ b/grapher/Layouts/OffLayout.cs
@@ -14,9 +14,14 @@ namespace grapher.Layouts
{
Name = "Off";
Index = (int)AccelMode.noaccel;
- ShowOptions = new bool[] { false, false, false, false, false, false };
- OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
ButtonEnabled = true;
+
+ AccelLayout = new OptionLayout(false, string.Empty);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(false, string.Empty);
+ LimExpLayout = new OptionLayout(false, string.Empty);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/OptionLayout.cs b/grapher/Layouts/OptionLayout.cs
new file mode 100644
index 0000000..2f29706
--- /dev/null
+++ b/grapher/Layouts/OptionLayout.cs
@@ -0,0 +1,41 @@
+using grapher.Models.Options;
+
+namespace grapher.Layouts
+{
+ public class OptionLayout
+ {
+ #region Constructors
+
+ public OptionLayout(bool show, string name)
+ {
+ Show = show;
+ Name = name;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ private bool Show { get; }
+
+ private string Name { get; }
+
+ #endregion Properties
+
+ #region Methods
+
+ public void Layout(IOption option)
+ {
+ if (Show)
+ {
+ option.Show(Name);
+ }
+ else
+ {
+ option.Hide();
+ }
+ }
+
+ #endregion Methods
+ }
+}
diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs
index 699536f..4438c1a 100644
--- a/grapher/Layouts/PowerLayout.cs
+++ b/grapher/Layouts/PowerLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "Power";
Index = (int)AccelMode.power;
- ShowOptions = new bool[] { true, true, true, false, true, true };
- OptionNames = new string[] { Offset, Scale, Exponent, string.Empty, Cap, Weight };
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(true, Cap);
+ WeightLayout = new OptionLayout(true, Weight);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, Limit);
+ MidpointLayout = new OptionLayout(false, string.Empty);
}
}
}
diff --git a/grapher/Layouts/SigmoidGainLayout.cs b/grapher/Layouts/SigmoidGainLayout.cs
index 3897477..1704071 100644
--- a/grapher/Layouts/SigmoidGainLayout.cs
+++ b/grapher/Layouts/SigmoidGainLayout.cs
@@ -14,8 +14,13 @@ namespace grapher.Layouts
{
Name = "SigmoidGain";
Index = (int)AccelMode.sigmoidgain;
- ShowOptions = new bool[] { true, true, true, true, false, true };
- OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint, string.Empty, Weight };
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(false, string.Empty);
+ OffsetLayout = new OptionLayout(true, Offset);
+ LimExpLayout = new OptionLayout(true, Limit);
+ MidpointLayout = new OptionLayout(true, Midpoint);
}
}
}
diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs
index 230b64d..5d52f2e 100644
--- a/grapher/Models/AccelGUIFactory.cs
+++ b/grapher/Models/AccelGUIFactory.cs
@@ -185,7 +185,6 @@ namespace grapher.Models
legacyOffsetToolStripMenuItem,
offsetY);
- // The name and layout of these options is handled by AccelerationOptions object.
var accelerationX = new Option(
new Field(accelerationBoxX, form, 0),
constantOneLabelX,
@@ -222,34 +221,6 @@ namespace grapher.Models
new ActiveValueLabel(midpointActiveLabelY, activeValueTitle),
optionSetYLeft);
- var accelerationOptionsX = new AccelTypeOptions(
- accelTypeDropX,
- new Option[]
- {
- offsetX,
- accelerationX,
- limitOrExponentX,
- midpointX,
- capX,
- weightX
- },
- writeButton,
- new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitle));
-
- var accelerationOptionsY = new AccelTypeOptions(
- accelTypeDropY,
- new Option[]
- {
- offsetY,
- accelerationY,
- limitOrExponentY,
- midpointY,
- capY,
- weightY
- },
- writeButton,
- new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitle));
-
var capOptionsX = new CapOptions(
velocityGainCapToolStripMenuItem,
legacyCapToolStripMenuItem,
@@ -260,27 +231,37 @@ namespace grapher.Models
legacyCapToolStripMenuItem,
capY);
- var optionsSetX = new AccelOptionSet(
- optionSetXTitle,
- rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
- accelerationOptionsX,
+ var accelerationOptionsX = new AccelTypeOptions(
+ accelTypeDropX,
accelerationX,
capOptionsX,
weightX,
offsetOptionsX,
limitOrExponentX,
- midpointX);
+ midpointX,
+ writeButton,
+ new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitle));
- var optionsSetY = new AccelOptionSet(
- optionSetYTitle,
- rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
- accelerationOptionsY,
+ var accelerationOptionsY = new AccelTypeOptions(
+ accelTypeDropY,
accelerationY,
capOptionsY,
weightY,
offsetOptionsY,
limitOrExponentY,
- midpointY);
+ midpointY,
+ writeButton,
+ new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitle));
+
+ var optionsSetX = new AccelOptionSet(
+ optionSetXTitle,
+ rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
+ accelerationOptionsX);
+
+ var optionsSetY = new AccelOptionSet(
+ optionSetYTitle,
+ rotationBox.Top + rotationBox.Height + Constants.OptionVerticalSeperation,
+ accelerationOptionsY);
var applyOptions = new ApplyOptions(
wholeVectorToolStripMenuItem,
diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs
index 6f38314..f8a9c2d 100644
--- a/grapher/Models/Fields/Field.cs
+++ b/grapher/Models/Fields/Field.cs
@@ -23,13 +23,19 @@ namespace grapher
#endregion Enumerations
+ #region Fields
+
+ private double _data;
+
+ #endregion Fields
+
#region Constructors
public Field(TextBox box, Form containingForm, double defaultData)
{
DefaultText = DecimalString(defaultData);
Box = box;
- Data = defaultData;
+ _data = defaultData;
DefaultData = defaultData;
State = FieldState.Undefined;
ContainingForm = containingForm;
@@ -48,8 +54,6 @@ namespace grapher
private Form ContainingForm { get; }
- public double Data { get; private set; }
-
public string FormatString { get; set; }
public string DefaultText { get; }
@@ -58,6 +62,20 @@ namespace grapher
public FieldState PreviousState { get; private set; }
+ public double Data {
+ get
+ {
+ if (Box.Visible)
+ {
+ return _data;
+ }
+ else
+ {
+ return DefaultData;
+ }
+ }
+ }
+
public int Top
{
get
@@ -122,7 +140,7 @@ namespace grapher
PreviousState = FieldState.Default;
}
- Data = DefaultData;
+ _data = DefaultData;
Box.Text = DefaultText;
ContainingForm.ActiveControl = null;
}
@@ -159,7 +177,7 @@ namespace grapher
{
SetToEntered();
- Data = value;
+ _data = value;
Box.Text = DecimalString(Data);
}
@@ -238,7 +256,7 @@ namespace grapher
{
try
{
- Data = Convert.ToDouble(Box.Text);
+ _data = Convert.ToDouble(Box.Text);
}
catch
{
diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs
index 3b9b534..8c7b303 100644
--- a/grapher/Models/Options/AccelOptionSet.cs
+++ b/grapher/Models/Options/AccelOptionSet.cs
@@ -13,25 +13,13 @@ namespace grapher.Models.Options
public AccelOptionSet(
Label titleLabel,
int topAnchor,
- AccelTypeOptions accelTypeOptions,
- Option acceleration,
- CapOptions cap,
- Option weight,
- OffsetOptions offset,
- Option limitOrExp,
- Option midpoint)
+ AccelTypeOptions accelTypeOptions)
{
TitleLabel = titleLabel;
TopAnchor = topAnchor;
- AccelTypeOptions = accelTypeOptions;
- Acceleration = acceleration;
- Cap = cap;
- Weight = weight;
- Offset = offset;
- LimitOrExponent = limitOrExp;
- Midpoint = midpoint;
+ Options = accelTypeOptions;
- AccelTypeOptions.ShowFullText();
+ Options.ShowFull();
TitleLabel.Top = TopAnchor;
IsTitleMode = true;
@@ -42,19 +30,8 @@ namespace grapher.Models.Options
public Label TitleLabel { get; }
- public AccelTypeOptions AccelTypeOptions { get; }
+ public AccelTypeOptions Options { 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 bool IsTitleMode { get; private set; }
@@ -65,9 +42,7 @@ namespace grapher.Models.Options
IsTitleMode = false;
HideTitle();
- AccelTypeOptions.Left = Acceleration.Left;
- AccelTypeOptions.Width = Acceleration.Width;
- AccelTypeOptions.ShowFullText();
+ Options.ShowFull();
}
}
@@ -79,9 +54,7 @@ namespace grapher.Models.Options
{
IsTitleMode = true;
- AccelTypeOptions.Left = Acceleration.Field.Left;
- AccelTypeOptions.Width = Acceleration.Field.Width;
- AccelTypeOptions.ShowShortenedText();
+ Options.ShowShortened();
DisplayTitle();
}
}
@@ -89,7 +62,7 @@ namespace grapher.Models.Options
public void Hide()
{
TitleLabel.Hide();
- AccelTypeOptions.Hide();
+ Options.Hide();
}
public void Show()
@@ -99,66 +72,36 @@ namespace grapher.Models.Options
TitleLabel.Show();
}
- AccelTypeOptions.Show();
+ Options.Show();
}
public void DisplayTitle()
{
TitleLabel.Show();
- SetOptionsTop(TitleLabel.Top + TitleLabel.Height + Constants.OptionVerticalSeperation);
+ Options.Top = TitleLabel.Top + TitleLabel.Height + Constants.OptionVerticalSeperation;
}
public void HideTitle()
{
TitleLabel.Hide();
- SetOptionsTop(TopAnchor);
+ Options.Top = TopAnchor;
}
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;
+ Options.SetArgs(ref args);
}
public AccelArgs GenerateArgs()
{
- AccelArgs args = new AccelArgs();
- SetArgs(ref args);
- return args;
+ return Options.GenerateArgs();
}
public void SetActiveValues(int mode, AccelArgs args)
{
- AccelTypeOptions.SetActiveValue(mode);
- 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);
- }
-
- private void SetOptionsTop(int top)
- {
- AccelTypeOptions.Top = top;
- Acceleration.Top = AccelTypeOptions.Top + AccelTypeOptions.Height + Constants.OptionVerticalSeperation;
- Cap.SnapTo(Acceleration);
- Weight.SnapTo(Cap);
- Offset.OffsetOption.SnapTo(Weight);
- LimitOrExponent.SnapTo(Offset.OffsetOption);
- Midpoint.SnapTo(LimitOrExponent);
+ Options.SetActiveValues(mode, args);
}
}
}
diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs
index f05d617..878c955 100644
--- a/grapher/Models/Options/AccelTypeOptions.cs
+++ b/grapher/Models/Options/AccelTypeOptions.cs
@@ -1,5 +1,6 @@
using grapher.Layouts;
using grapher.Models.Options;
+using grapher.Models.Serialized;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -30,7 +31,12 @@ namespace grapher
public AccelTypeOptions(
ComboBox accelDropdown,
- Option[] options,
+ Option acceleration,
+ CapOptions cap,
+ Option weight,
+ OffsetOptions offset,
+ Option limitOrExponent,
+ Option midpoint,
Button writeButton,
ActiveValueLabel activeValueLabel)
{
@@ -39,15 +45,25 @@ namespace grapher
AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
- if (options.Length > Constants.PossibleOptionsCount)
- {
- throw new Exception("Layout given too many options.");
- }
-
- Options = options;
+ Acceleration = acceleration;
+ Cap = cap;
+ Weight = weight;
+ Offset = offset;
+ LimitOrExponent = limitOrExponent;
+ Midpoint = midpoint;
WriteButton = writeButton;
ActiveValueLabel = activeValueLabel;
+ Options = new List<OptionBase>
+ {
+ Acceleration,
+ Cap,
+ Offset,
+ Weight,
+ LimitOrExponent,
+ Midpoint,
+ };
+
Layout("Off");
ShowingDefault = true;
}
@@ -72,7 +88,19 @@ namespace grapher
public ActiveValueLabel ActiveValueLabel { get; }
- public Option[] Options { 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; }
+
+ private IEnumerable<OptionBase> Options { get; }
public int Top
{
@@ -83,6 +111,7 @@ namespace grapher
set
{
AccelDropdown.Top = value;
+ Layout(value + AccelDropdown.Height + Constants.OptionVerticalSeperation);
}
}
@@ -131,11 +160,13 @@ namespace grapher
public void Hide()
{
AccelDropdown.Hide();
-
- foreach(var option in Options)
- {
- option.Hide();
- }
+
+ Acceleration.Hide();
+ Cap.Hide();
+ Weight.Hide();
+ Offset.Hide();
+ LimitOrExponent.Hide();
+ Midpoint.Hide();
}
public void Show()
@@ -144,26 +175,62 @@ namespace grapher
Layout();
}
- public void SetActiveValue(int index)
+ public void SetActiveValues(int index, AccelArgs args)
{
var name = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value.Name;
ActiveValueLabel.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 ShowFullText()
+ public void ShowFull()
{
if (ShowingDefault)
{
AccelDropdown.Text = Constants.AccelDropDownDefaultFullText;
}
+
+ Left = Acceleration.Left;
+ Width = Acceleration.Width;
}
- public void ShowShortenedText()
+ 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;
}
private void OnIndexChanged(object sender, EventArgs e)
@@ -179,9 +246,22 @@ namespace grapher
Layout();
}
- private void Layout()
+ private void Layout(int top = -1)
{
- AccelerationType.Layout(Options, WriteButton);
+ if (top < 0)
+ {
+ top = Acceleration.Top;
+ }
+
+ AccelerationType.Layout(
+ Acceleration,
+ Cap,
+ Weight,
+ Offset,
+ LimitOrExponent,
+ Midpoint,
+ WriteButton,
+ top);
}
#endregion Methods
diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs
index bfbc1ef..68f06fb 100644
--- a/grapher/Models/Options/ApplyOptions.cs
+++ b/grapher/Models/Options/ApplyOptions.cs
@@ -61,12 +61,12 @@ namespace grapher.Models.Options
public Vec2<AccelMode> GetModes()
{
- var xMode = (AccelMode)OptionSetX.AccelTypeOptions.AccelerationIndex;
+ var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex;
return new Vec2<AccelMode>
{
x = xMode,
- y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.AccelTypeOptions.AccelerationIndex
+ y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex
};
}
diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs
index 6dc1116..cf587c7 100644
--- a/grapher/Models/Options/CapOptions.cs
+++ b/grapher/Models/Options/CapOptions.cs
@@ -8,7 +8,7 @@ using System.Windows.Forms;
namespace grapher
{
- public class CapOptions
+ public class CapOptions : OptionBase
{
#region Constants
@@ -76,7 +76,7 @@ namespace grapher
}
}
- public int Top
+ public override int Top
{
get
{
@@ -88,7 +88,7 @@ namespace grapher
}
}
- public int Height
+ public override int Height
{
get
{
@@ -96,12 +96,39 @@ namespace grapher
}
}
+ public override int Left
+ {
+ get
+ {
+ return CapOption.Left;
+ }
+ set
+ {
+ CapOption.Left = value;
+ }
+ }
+
+ public override int Width
+ {
+ get
+ {
+ return CapOption.Width;
+ }
+ }
+
+ public override bool Visible
+ {
+ get
+ {
+ return CapOption.Visible;
+ }
+ }
#endregion Properties
#region Methods
- public void Hide()
+ public override void Hide()
{
CapOption.Hide();
}
@@ -111,6 +138,11 @@ namespace grapher
CapOption.Show();
}
+ public override void Show(string name)
+ {
+ CapOption.Show(name);
+ }
+
public void SnapTo(Option option)
{
Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
diff --git a/grapher/Models/Options/IOption.cs b/grapher/Models/Options/IOption.cs
new file mode 100644
index 0000000..71ac5e4
--- /dev/null
+++ b/grapher/Models/Options/IOption.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Models.Options
+{
+ public interface IOption
+ {
+ int Top { get; set; }
+
+ int Height { get; }
+
+ int Left { get; }
+
+ int Width { 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..fbc6898 100644
--- a/grapher/Models/Options/OffsetOptions.cs
+++ b/grapher/Models/Options/OffsetOptions.cs
@@ -7,7 +7,7 @@ using System.Windows.Forms;
namespace grapher.Models.Options
{
- public class OffsetOptions
+ public class OffsetOptions : OptionBase
{
public OffsetOptions(
ToolStripMenuItem velocityGainOffsetCheck,
@@ -65,6 +65,69 @@ 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;
+ }
+ }
+
+ 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)
diff --git a/grapher/Models/Options/Option.cs b/grapher/Models/Options/Option.cs
index 22b78d4..68ecf66 100644
--- a/grapher/Models/Options/Option.cs
+++ b/grapher/Models/Options/Option.cs
@@ -8,7 +8,7 @@ using System.Windows.Forms;
namespace grapher
{
- public class Option
+ public class Option : OptionBase
{
#region Constructors
@@ -72,7 +72,7 @@ namespace grapher
public ActiveValueLabel ActiveValueLabel { get; }
- public int Top
+ public override int Top
{
get
{
@@ -85,7 +85,7 @@ namespace grapher
}
}
- public int Height
+ public override int Height
{
get
{
@@ -93,18 +93,18 @@ namespace grapher
}
}
- public int Left
+ public override int Left
{
get
{
return Label.Left;
}
- private set
+ set
{
Label.Left = value;
}
}
- public int Width
+ public override int Width
{
get
{
@@ -112,6 +112,14 @@ namespace grapher
}
}
+ public override bool Visible
+ {
+ get
+ {
+ return Field.Box.Visible;
+ }
+ }
+
#endregion Properties
#region Methods
@@ -127,7 +135,7 @@ namespace grapher
ActiveValueLabel.SetValue(value);
}
- public void Hide()
+ public override void Hide()
{
Field.Box.Hide();
Label.Hide();
@@ -146,23 +154,13 @@ namespace grapher
ActiveValueLabel.SetValue(value);
}
- public void Show(string name)
+ public override void Show(string name)
{
SetName(name);
Show();
}
- public void SnapTo(Option option)
- {
- Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
- }
-
- public void SnapTo(CapOptions option)
- {
- Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
- }
-
#endregion Methods
}
}
diff --git a/grapher/Models/Options/OptionBase.cs b/grapher/Models/Options/OptionBase.cs
new file mode 100644
index 0000000..9fba72f
--- /dev/null
+++ b/grapher/Models/Options/OptionBase.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+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; }
+
+ public abstract bool Visible { get; }
+
+ public abstract void Show(string Name);
+
+ public abstract void Hide();
+
+ public virtual void SnapTo(IOption option)
+ {
+ Top = option.Top + option.Height + Constants.OptionVerticalSeperation;
+ }
+ }
+}
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index b70bbb6..74e2959 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -87,8 +87,11 @@
<Compile Include="Layouts\NaturalLayout.cs" />
<Compile Include="Layouts\OffLayout.cs" />
<Compile Include="Layouts\PowerLayout.cs" />
+ <Compile Include="Models\Options\IOption.cs" />
<Compile Include="Models\Options\OffsetOptions.cs" />
<Compile Include="Models\Options\Option.cs" />
+ <Compile Include="Layouts\OptionLayout.cs" />
+ <Compile Include="Models\Options\OptionBase.cs" />
<Compile Include="Models\Options\OptionXY.cs" />
<Compile Include="Models\Serialized\GUISettings.cs" />
<Compile Include="Models\Serialized\DriverSettings.cs" />