diff options
| author | Jacob Palecki <[email protected]> | 2020-07-30 02:00:20 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-30 02:00:20 -0700 |
| commit | f315e8160e984df93be6667929db34749aa25cfa (patch) | |
| tree | 19684a4f515fc6185e750d7cca3424fa7d96937b /grapher/AccelOptions.cs | |
| parent | Fully use acceloptions (diff) | |
| download | rawaccel-f315e8160e984df93be6667929db34749aa25cfa.tar.xz rawaccel-f315e8160e984df93be6667929db34749aa25cfa.zip | |
Use class heirarchy for layout types
Diffstat (limited to 'grapher/AccelOptions.cs')
| -rw-r--r-- | grapher/AccelOptions.cs | 156 |
1 files changed, 25 insertions, 131 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); } } } |