From 20ea6f85cb0af56c13dabbfc3f65383af8793c7c Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 00:32:48 -0700 Subject: Fix small bugs, add AccelOptions class --- grapher/AccelOptions.cs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 grapher/AccelOptions.cs (limited to 'grapher/AccelOptions.cs') diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs new file mode 100644 index 0000000..3aa6ef6 --- /dev/null +++ b/grapher/AccelOptions.cs @@ -0,0 +1,68 @@ +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 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"; + + /// + /// 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.) + /// + public static readonly Dictionary TypeToIndex = new Dictionary + { + { Off, 0 }, + { Linear, 1 }, + { Classic, 2 }, + { Natural, 3 }, + { Logarithmic, 4 }, + { Sigmoid, 5 }, + { Power, 6 }, + }; + + public AccelOptions(ComboBox accelDropdown) + { + AccelDropdown = accelDropdown; + AccelDropdown.Items.Clear(); + AccelDropdown.Items.AddRange(TypeToIndex.Keys.ToArray()); + } + + public ComboBox AccelDropdown { get; } + + public int AccelerationIndex { get; private set; } + + private void OnIndexChanged(object sender, EventArgs e) + { + var AccelerationType = AccelDropdown.SelectedItem.ToString(); + AccelerationIndex = TypeToIndex[AccelerationType]; + + /* + switch (AccelerationType) + { + case Linear: + LayoutLinear(); + default: + LayoutDefault(); + break; + } + */ + } + + private void LayoutDefault() + { + + } + } +} -- cgit v1.2.3 From 3cbec32cfa91bad661bc126b517faf78458a27a6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 01:13:24 -0700 Subject: Fully use acceloptions --- grapher/AccelOptions.cs | 101 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) (limited to 'grapher/AccelOptions.cs') diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs index 3aa6ef6..093ebe7 100644 --- a/grapher/AccelOptions.cs +++ b/grapher/AccelOptions.cs @@ -32,37 +32,132 @@ namespace grapher { Power, 6 }, }; - public AccelOptions(ComboBox accelDropdown) + public AccelOptions( + ComboBox accelDropdown, + Option constOptionOne, + Option constOptionTwo, + Option constOptionThree + ) { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); AccelDropdown.Items.AddRange(TypeToIndex.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) { 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; } - */ } 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"); + } + + + private void LayoutSigmoid() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Show(); + + ConstOptionOne.SetName("Acceleration"); + ConstOptionTwo.SetName("Limit"); + ConstOptionThree.SetName("Midpoint"); + } + + private void LayoutPower() + { + ConstOptionOne.Show(); + ConstOptionTwo.Show(); + ConstOptionThree.Hide(); + ConstOptionOne.SetName("Scale"); + ConstOptionTwo.SetName("Exponent"); } } } -- cgit v1.2.3 From f315e8160e984df93be6667929db34749aa25cfa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 02:00:20 -0700 Subject: Use class heirarchy for layout types --- grapher/AccelOptions.cs | 156 ++++++++---------------------------------------- 1 file changed, 25 insertions(+), 131 deletions(-) (limited to 'grapher/AccelOptions.cs') 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; - /// - /// 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.) - /// - public static readonly Dictionary TypeToIndex = new Dictionary + public static readonly Dictionary AccelerationTypes = new List { - { 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); } } } -- cgit v1.2.3