summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-30 02:00:20 -0700
committerJacob Palecki <[email protected]>2020-07-30 02:00:20 -0700
commitf315e8160e984df93be6667929db34749aa25cfa (patch)
tree19684a4f515fc6185e750d7cca3424fa7d96937b
parentFully use acceloptions (diff)
downloadrawaccel-f315e8160e984df93be6667929db34749aa25cfa.tar.xz
rawaccel-f315e8160e984df93be6667929db34749aa25cfa.zip
Use class heirarchy for layout types
-rw-r--r--grapher/AccelOptions.cs156
-rw-r--r--grapher/Form1.cs9
-rw-r--r--grapher/Layouts/ClassicLayout.cs19
-rw-r--r--grapher/Layouts/DefaultLayout.cs20
-rw-r--r--grapher/Layouts/LayoutBase.cs52
-rw-r--r--grapher/Layouts/LinearLayout.cs19
-rw-r--r--grapher/Layouts/LogLayout.cs19
-rw-r--r--grapher/Layouts/NaturalLayout.cs19
-rw-r--r--grapher/Layouts/PowerLayout.cs19
-rw-r--r--grapher/Layouts/SigmoidLayout.cs19
-rw-r--r--grapher/Option.cs9
-rw-r--r--grapher/grapher.csproj8
12 files changed, 234 insertions, 134 deletions
diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs
index 093ebe7..0235bc7 100644
--- a/grapher/AccelOptions.cs
+++ b/grapher/AccelOptions.cs
@@ -1,4 +1,5 @@
-using System;
+using grapher.Layouts;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -9,155 +10,48 @@ namespace grapher
{
public class AccelOptions
{
- public const string Off = "Off";
- public const string Linear = "Linear";
- public const string Classic = "Classic";
- public const string Natural = "Natural";
- public const string Logarithmic = "Logarithmic";
- public const string Sigmoid = "Sigmoid";
- public const string Power = "Power";
+ public const int PossibleOptionsCount = 3;
- /// <summary>
- /// Holds mapping from acceleration type to identifying integer.
- /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.)
- /// </summary>
- public static readonly Dictionary<string, int> TypeToIndex = new Dictionary<string, int>
+ public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
{
- { Off, 0 },
- { Linear, 1 },
- { Classic, 2 },
- { Natural, 3 },
- { Logarithmic, 4 },
- { Sigmoid, 5 },
- { Power, 6 },
- };
+ new DefaultLayout(),
+ new LinearLayout(),
+ new ClassicLayout(),
+ new NaturalLayout(),
+ new LogLayout(),
+ new SigmoidLayout(),
+ new PowerLayout(),
+ }.ToDictionary(k => k.Name);
public AccelOptions(
ComboBox accelDropdown,
- Option constOptionOne,
- Option constOptionTwo,
- Option constOptionThree
- )
+ Option[] options)
{
AccelDropdown = accelDropdown;
AccelDropdown.Items.Clear();
- AccelDropdown.Items.AddRange(TypeToIndex.Keys.ToArray());
+ AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
- ConstOptionOne = constOptionOne;
- ConstOptionTwo = constOptionTwo;
- ConstOptionThree = constOptionThree;
- }
-
- public ComboBox AccelDropdown { get; }
-
- public int AccelerationIndex { get; private set; }
-
- public Option ConstOptionOne { get; }
-
- public Option ConstOptionTwo { get; }
-
- public Option ConstOptionThree { get; }
-
- private void OnIndexChanged(object sender, EventArgs e)
- {
- var AccelerationType = AccelDropdown.SelectedItem.ToString();
- AccelerationIndex = TypeToIndex[AccelerationType];
-
- switch (AccelerationType)
+ if (options.Length > PossibleOptionsCount)
{
- case Linear:
- LayoutLinear();
- break;
- case Classic:
- LayoutClassic();
- break;
- case Natural:
- LayoutNatural();
- break;
- case Logarithmic:
- LayoutLogarithmic();
- break;
- case Sigmoid:
- LayoutSigmoid();
- break;
- case Power:
- LayoutPower();
- break;
- default:
- LayoutDefault();
- break;
+ throw new Exception("Layout given too many options.");
}
- }
-
- private void LayoutDefault()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Show();
- ConstOptionThree.Hide();
-
- ConstOptionOne.SetName("Acceleration");
- ConstOptionTwo.SetName("Limit\\Exponent");
- }
-
- private void LayoutLinear()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Hide();
- ConstOptionThree.Hide();
- ConstOptionOne.SetName("Acceleration");
- }
-
- private void LayoutClassic()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Show();
- ConstOptionThree.Hide();
-
- ConstOptionOne.SetName("Acceleration");
- ConstOptionTwo.SetName("Exponent");
- }
-
- private void LayoutNatural()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Show();
- ConstOptionThree.Hide();
-
- ConstOptionOne.SetName("Acceleration");
- ConstOptionOne.SetName("Limit");
- }
-
- private void LayoutLogarithmic()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Hide();
- ConstOptionThree.Hide();
-
- ConstOptionOne.SetName("Acceleration");
+ Options = options;
}
+ public ComboBox AccelDropdown { get; }
- private void LayoutSigmoid()
- {
- ConstOptionOne.Show();
- ConstOptionTwo.Show();
- ConstOptionThree.Show();
+ public int AccelerationIndex { get; private set; }
- ConstOptionOne.SetName("Acceleration");
- ConstOptionTwo.SetName("Limit");
- ConstOptionThree.SetName("Midpoint");
- }
+ public Option[] Options { get; }
- private void LayoutPower()
+ private void OnIndexChanged(object sender, EventArgs e)
{
- ConstOptionOne.Show();
- ConstOptionTwo.Show();
- ConstOptionThree.Hide();
-
- ConstOptionOne.SetName("Scale");
- ConstOptionTwo.SetName("Exponent");
+ var AccelerationTypeString = AccelDropdown.SelectedItem.ToString();
+ var AccelerationType = AccelerationTypes[AccelerationTypeString];
+ AccelerationIndex = AccelerationType.Index;
+ AccelerationType.Layout(Options);
}
}
}
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index ecb6ead..93e0768 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -21,9 +21,12 @@ namespace grapher
ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15);
AccelerationOptions = new AccelOptions(
accelTypeDrop,
- new Option(accelerationBox, constantOneLabel),
- new Option(limitBox, constantTwoLabel),
- new Option(midpointBox, constantThreeLabel));
+ new Option[]
+ {
+ new Option(accelerationBox, constantOneLabel),
+ new Option(limitBox, constantTwoLabel),
+ new Option(midpointBox, constantThreeLabel)
+ });
Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1);
Rotation = new Field(rotationBox, this, 0);
Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1);
diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs
new file mode 100644
index 0000000..a8fc2bd
--- /dev/null
+++ b/grapher/Layouts/ClassicLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class ClassicLayout : LayoutBase
+ {
+ public ClassicLayout()
+ {
+ Name = "Classic";
+ Index = 2;
+ Show = new bool[] { true, true, false };
+ OptionNames = new string[] { Acceleration, Exponent, string.Empty };
+ }
+ }
+}
diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs
new file mode 100644
index 0000000..2ad3c0e
--- /dev/null
+++ b/grapher/Layouts/DefaultLayout.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace grapher.Layouts
+{
+ public class DefaultLayout : LayoutBase
+ {
+ public DefaultLayout()
+ {
+ Name = "Off";
+ Index = 0;
+ Show = new bool[] { true, true, true };
+ OptionNames = new string[] { Acceleration, $"{Limit}\\{Exponent}", Midpoint };
+ }
+ }
+}
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
new file mode 100644
index 0000000..9c60008
--- /dev/null
+++ b/grapher/Layouts/LayoutBase.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public abstract class LayoutBase
+ {
+ public const string Acceleration = "Acceleration";
+ public const string Scale = "Scale";
+ public const string Exponent = "Exponent";
+ public const string Limit = "Limit";
+ public const string Midpoint = "Midpoint";
+
+ public LayoutBase()
+ {
+ Show = new bool[] { false, false, false };
+ OptionNames = new string[] { string.Empty, string.Empty, string.Empty };
+ }
+
+ /// <summary>
+ /// Gets or sets mapping from acceleration type to identifying integer.
+ /// Must match order in tagged_union in rawaccel.hpp (which is 1-indexed, meaning 0 is off.)
+ /// </summary>
+ public int Index { get; internal set; }
+
+ public string Name { get; internal set; }
+
+ internal bool[] Show { get; set; }
+
+ internal string[] OptionNames { get; set; }
+
+ public void Layout(Option[] options)
+ {
+ // Relies on AccelOptions to keep lengths correct.
+ for (int i = 0; i< options.Length; i++)
+ {
+ if (Show[i])
+ {
+ options[i].Show(OptionNames[i]);
+ }
+ else
+ {
+ options[i].Hide();
+ }
+ }
+
+ }
+ }
+}
diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs
new file mode 100644
index 0000000..b500b6b
--- /dev/null
+++ b/grapher/Layouts/LinearLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class LinearLayout : LayoutBase
+ {
+ public LinearLayout()
+ {
+ Name = "Linear";
+ Index = 1;
+ Show = new bool[] { true, false, false };
+ OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ }
+ }
+}
diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs
new file mode 100644
index 0000000..7c7fd9e
--- /dev/null
+++ b/grapher/Layouts/LogLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class LogLayout : LayoutBase
+ {
+ public LogLayout()
+ {
+ Name = "Logarithmic";
+ Index = 4;
+ Show = new bool[] { true, false, false };
+ OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ }
+ }
+}
diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs
new file mode 100644
index 0000000..180a7c0
--- /dev/null
+++ b/grapher/Layouts/NaturalLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class NaturalLayout : LayoutBase
+ {
+ public NaturalLayout()
+ {
+ Name = "Natural";
+ Index = 3;
+ Show = new bool[] { true, true, false };
+ OptionNames = new string[] { Acceleration, Limit, string.Empty };
+ }
+ }
+}
diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs
new file mode 100644
index 0000000..6d4f5d7
--- /dev/null
+++ b/grapher/Layouts/PowerLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class PowerLayout : LayoutBase
+ {
+ public PowerLayout()
+ {
+ Name = "Power";
+ Index = 6;
+ Show = new bool[] { true, true, false };
+ OptionNames = new string[] { Scale, Exponent, string.Empty };
+ }
+ }
+}
diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs
new file mode 100644
index 0000000..88d6c61
--- /dev/null
+++ b/grapher/Layouts/SigmoidLayout.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class SigmoidLayout : LayoutBase
+ {
+ public SigmoidLayout()
+ {
+ Name = "Sigmoid";
+ Index = 5;
+ Show = new bool[] { true, true, true };
+ OptionNames = new string[] { Acceleration, Limit, Midpoint };
+ }
+ }
+}
diff --git a/grapher/Option.cs b/grapher/Option.cs
index 6c7bcda..17e624b 100644
--- a/grapher/Option.cs
+++ b/grapher/Option.cs
@@ -22,6 +22,7 @@ namespace grapher
public void SetName(string name)
{
Label.Text = name;
+ Label.Left = Convert.ToInt32((Box.Left / 2.0) - (Label.Width / 2.0));
}
public void Hide()
@@ -35,5 +36,13 @@ namespace grapher
Box.Show();
Label.Show();
}
+
+ public void Show(string name)
+ {
+ SetName(name);
+
+ Box.Show();
+ Label.Show();
+ }
}
}
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index 3d0f50a..91518ce 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -56,6 +56,14 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
+ <Compile Include="Layouts\ClassicLayout.cs" />
+ <Compile Include="Layouts\DefaultLayout.cs" />
+ <Compile Include="Layouts\LayoutBase.cs" />
+ <Compile Include="Layouts\LinearLayout.cs" />
+ <Compile Include="Layouts\LogLayout.cs" />
+ <Compile Include="Layouts\NaturalLayout.cs" />
+ <Compile Include="Layouts\PowerLayout.cs" />
+ <Compile Include="Layouts\SigmoidLayout.cs" />
<Compile Include="Option.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />