summaryrefslogtreecommitdiff
path: root/grapher
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
committerJacob Palecki <[email protected]>2020-07-31 12:20:11 -0700
commit6537db04f7e717eda2f21e007cdba7e13b7f559e (patch)
treeefb65bf3f305f376ea75f4f687b08bf8998c020f /grapher
parentAdd class for storing settings from file (diff)
parentMerge pull request #6 from a1xd/st-refactor (diff)
downloadrawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.tar.xz
rawaccel-6537db04f7e717eda2f21e007cdba7e13b7f559e.zip
Show no settings for off, remove unused class for PR
Diffstat (limited to 'grapher')
-rw-r--r--grapher/AccelOptions.cs36
-rw-r--r--grapher/AccelerationSettings.cs35
-rw-r--r--grapher/Form1.cs76
-rw-r--r--grapher/Layouts/ClassicLayout.cs5
-rw-r--r--grapher/Layouts/DefaultLayout.cs8
-rw-r--r--grapher/Layouts/LayoutBase.cs32
-rw-r--r--grapher/Layouts/LinearLayout.cs5
-rw-r--r--grapher/Layouts/LogLayout.cs5
-rw-r--r--grapher/Layouts/NaturalLayout.cs5
-rw-r--r--grapher/Layouts/OffLayout.cs22
-rw-r--r--grapher/Layouts/PowerLayout.cs5
-rw-r--r--grapher/Layouts/SigmoidLayout.cs5
-rw-r--r--grapher/Option.cs3
-rw-r--r--grapher/OptionXY.cs6
-rw-r--r--grapher/grapher.csproj2
15 files changed, 180 insertions, 70 deletions
diff --git a/grapher/AccelOptions.cs b/grapher/AccelOptions.cs
index 0235bc7..b233552 100644
--- a/grapher/AccelOptions.cs
+++ b/grapher/AccelOptions.cs
@@ -10,7 +10,8 @@ namespace grapher
{
public class AccelOptions
{
- public const int PossibleOptionsCount = 3;
+ public const int PossibleOptionsCount = 4;
+ public const int PossibleOptionsXYCount = 2;
public static readonly Dictionary<string, LayoutBase> AccelerationTypes = new List<LayoutBase>
{
@@ -21,15 +22,18 @@ namespace grapher
new LogLayout(),
new SigmoidLayout(),
new PowerLayout(),
+ new OffLayout()
}.ToDictionary(k => k.Name);
public AccelOptions(
ComboBox accelDropdown,
- Option[] options)
+ Option[] options,
+ OptionXY[] optionsXY,
+ Button writeButton)
{
AccelDropdown = accelDropdown;
AccelDropdown.Items.Clear();
- AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray());
+ AccelDropdown.Items.AddRange(AccelerationTypes.Keys.Skip(1).ToArray());
AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged);
if (options.Length > PossibleOptionsCount)
@@ -37,21 +41,39 @@ namespace grapher
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;
+
+ Layout("Default");
}
+ public Button WriteButton { get; }
+
public ComboBox AccelDropdown { get; }
public int AccelerationIndex { get; private set; }
public Option[] Options { get; }
+ public OptionXY[] OptionsXY { get; }
+
private void OnIndexChanged(object sender, EventArgs e)
{
- var AccelerationTypeString = AccelDropdown.SelectedItem.ToString();
- var AccelerationType = AccelerationTypes[AccelerationTypeString];
- AccelerationIndex = AccelerationType.Index;
- AccelerationType.Layout(Options);
+ 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/AccelerationSettings.cs b/grapher/AccelerationSettings.cs
deleted file mode 100644
index dd026e8..0000000
--- a/grapher/AccelerationSettings.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace grapher
-{
- public class AccelerationSettings
- {
- public double SensitivityX { get; }
-
- public double SensitivityY { get; }
-
- public double Rotation { get; }
-
- public double Offset { get; }
-
- public double WeightX { get; }
-
- public double WeightY { get; }
-
- public double CapX { get; }
-
- public double CapY { get; }
-
- public int AccelerationType { get; }
-
- public double Acceleration { get; }
-
- public double LimitOrExponent { get; }
-
- public double Midpoint { get; }
- }
-}
diff --git a/grapher/Form1.cs b/grapher/Form1.cs
index e0953eb..3807d2a 100644
--- a/grapher/Form1.cs
+++ b/grapher/Form1.cs
@@ -8,9 +8,51 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using System.Runtime.InteropServices;
namespace grapher
{
+ public enum accel_mode
+ {
+ linear=1, classic, natural, logarithmic, sigmoid, power, noaccel
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct vec2d
+ {
+ public double x;
+ public double y;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct accel_args
+ {
+ public double offset;
+ public double accel;
+ public double limit;
+ public double exponent;
+ public double midpoint;
+ public double power_scale;
+ public vec2d weight;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct accel_fn_args
+ {
+ public accel_args acc_args;
+ public int accel_mode;
+ public double time_min;
+ public vec2d cap;
+ }
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct modifier_args
+ {
+ public double degrees;
+ public vec2d sens;
+ public accel_fn_args acc_fn_args;
+ }
+
public partial class RawAcceleration : Form
{
public struct MagnitudeData
@@ -27,8 +69,31 @@ namespace grapher
public RawAcceleration()
{
InitializeComponent();
+ modifier_args args;
+
+ args.degrees = 0;
+ args.sens.x = 1;
+ args.sens.y = 1;
+ args.acc_fn_args.acc_args.offset = 0;
+ args.acc_fn_args.acc_args.accel = 0.01;
+ args.acc_fn_args.acc_args.limit = 2;
+ args.acc_fn_args.acc_args.exponent = 1;
+ args.acc_fn_args.acc_args.midpoint = 0;
+ args.acc_fn_args.acc_args.power_scale = 1;
+ args.acc_fn_args.acc_args.weight.x = 1;
+ args.acc_fn_args.acc_args.weight.y = 1;
+ args.acc_fn_args.accel_mode = (int)accel_mode.natural;
+ args.acc_fn_args.time_min = 0.4;
+ args.acc_fn_args.cap.x = 0;
+ args.acc_fn_args.cap.y = 0;
+
+ IntPtr args_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(args));
+ Marshal.StructureToPtr(args, args_ptr, false);
+
+ ManagedAcceleration = new ManagedAccel(args_ptr);
+
+ Marshal.FreeHGlobal(args_ptr);
- ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15);
Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity");
Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation");
Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight");
@@ -44,10 +109,17 @@ namespace grapher
accelTypeDrop,
new Option[]
{
+ Offset,
Acceleration,
LimitOrExponent,
Midpoint,
- });
+ },
+ new OptionXY[]
+ {
+ Weight,
+ Cap,
+ },
+ writeButton);
UpdateGraph();
diff --git a/grapher/Layouts/ClassicLayout.cs b/grapher/Layouts/ClassicLayout.cs
index a8fc2bd..093f7fa 100644
--- a/grapher/Layouts/ClassicLayout.cs
+++ b/grapher/Layouts/ClassicLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class ClassicLayout : LayoutBase
{
public ClassicLayout()
+ : base()
{
Name = "Classic";
Index = 2;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Acceleration, Exponent, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Acceleration, Exponent, string.Empty };
}
}
}
diff --git a/grapher/Layouts/DefaultLayout.cs b/grapher/Layouts/DefaultLayout.cs
index 2ad3c0e..095afdf 100644
--- a/grapher/Layouts/DefaultLayout.cs
+++ b/grapher/Layouts/DefaultLayout.cs
@@ -10,11 +10,13 @@ namespace grapher.Layouts
public class DefaultLayout : LayoutBase
{
public DefaultLayout()
+ : base()
{
- Name = "Off";
+ Name = "Default";
Index = 0;
- Show = new bool[] { true, true, true };
- OptionNames = new string[] { Acceleration, $"{Limit}\\{Exponent}", Midpoint };
+ ShowOptions = new bool[] { true, true, true, true };
+ OptionNames = new string[] { Offset, Acceleration, $"{Limit}\\{Exponent}", Midpoint };
+ ButtonEnabled = false;
}
}
}
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
index 9c60008..a4d0827 100644
--- a/grapher/Layouts/LayoutBase.cs
+++ b/grapher/Layouts/LayoutBase.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Forms;
namespace grapher.Layouts
{
@@ -13,11 +14,14 @@ namespace grapher.Layouts
public const string Exponent = "Exponent";
public const string Limit = "Limit";
public const string Midpoint = "Midpoint";
+ public const string Offset = "Offset";
public LayoutBase()
{
- Show = new bool[] { false, false, false };
- OptionNames = new string[] { string.Empty, string.Empty, string.Empty };
+ ShowOptions = new bool[] { false, false, false, false };
+ ShowOptionsXY = new bool[] { true, true };
+ OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };
+ ButtonEnabled = true;
}
/// <summary>
@@ -28,16 +32,20 @@ namespace grapher.Layouts
public string Name { get; internal set; }
- internal bool[] Show { get; set; }
+ internal bool[] ShowOptions { get; set; }
+
+ internal bool[] ShowOptionsXY { get; set; }
internal string[] OptionNames { get; set; }
- public void Layout(Option[] options)
+ internal bool ButtonEnabled { get; set; }
+
+ public void Layout(Option[] options, OptionXY[] optionsXY, Button button)
{
// Relies on AccelOptions to keep lengths correct.
for (int i = 0; i< options.Length; i++)
{
- if (Show[i])
+ if (ShowOptions[i])
{
options[i].Show(OptionNames[i]);
}
@@ -47,6 +55,20 @@ namespace grapher.Layouts
}
}
+ // Relies on AccelOptions to keep lengths correct.
+ for (int i = 0; i< optionsXY.Length; i++)
+ {
+ if (ShowOptionsXY[i])
+ {
+ optionsXY[i].Show();
+ }
+ else
+ {
+ optionsXY[i].Hide();
+ }
+ }
+
+ button.Enabled = ButtonEnabled;
}
}
}
diff --git a/grapher/Layouts/LinearLayout.cs b/grapher/Layouts/LinearLayout.cs
index b500b6b..2a0358e 100644
--- a/grapher/Layouts/LinearLayout.cs
+++ b/grapher/Layouts/LinearLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class LinearLayout : LayoutBase
{
public LinearLayout()
+ : base()
{
Name = "Linear";
Index = 1;
- Show = new bool[] { true, false, false };
- OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ ShowOptions = new bool[] { true, true, false, false };
+ OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty };
}
}
}
diff --git a/grapher/Layouts/LogLayout.cs b/grapher/Layouts/LogLayout.cs
index 7c7fd9e..ae1a8f5 100644
--- a/grapher/Layouts/LogLayout.cs
+++ b/grapher/Layouts/LogLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class LogLayout : LayoutBase
{
public LogLayout()
+ : base()
{
Name = "Logarithmic";
Index = 4;
- Show = new bool[] { true, false, false };
- OptionNames = new string[] { Acceleration, string.Empty, string.Empty };
+ ShowOptions = new bool[] { true, true, false, false };
+ OptionNames = new string[] { Offset, Acceleration, string.Empty, string.Empty };
}
}
}
diff --git a/grapher/Layouts/NaturalLayout.cs b/grapher/Layouts/NaturalLayout.cs
index 180a7c0..743135c 100644
--- a/grapher/Layouts/NaturalLayout.cs
+++ b/grapher/Layouts/NaturalLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class NaturalLayout : LayoutBase
{
public NaturalLayout()
+ : base()
{
Name = "Natural";
Index = 3;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Acceleration, Limit, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Acceleration, Limit, string.Empty };
}
}
}
diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs
new file mode 100644
index 0000000..cecba05
--- /dev/null
+++ b/grapher/Layouts/OffLayout.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class OffLayout : LayoutBase
+ {
+ public OffLayout()
+ : base()
+ {
+ Name = "Off";
+ Index = 7;
+ ShowOptions = new bool[] { false, false, false, false };
+ OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };
+ ShowOptionsXY = new bool[] { false, false };
+ ButtonEnabled = true;
+ }
+ }
+}
diff --git a/grapher/Layouts/PowerLayout.cs b/grapher/Layouts/PowerLayout.cs
index 6d4f5d7..da02cf5 100644
--- a/grapher/Layouts/PowerLayout.cs
+++ b/grapher/Layouts/PowerLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class PowerLayout : LayoutBase
{
public PowerLayout()
+ : base()
{
Name = "Power";
Index = 6;
- Show = new bool[] { true, true, false };
- OptionNames = new string[] { Scale, Exponent, string.Empty };
+ ShowOptions = new bool[] { true, true, true, false };
+ OptionNames = new string[] { Offset, Scale, Exponent, string.Empty };
}
}
}
diff --git a/grapher/Layouts/SigmoidLayout.cs b/grapher/Layouts/SigmoidLayout.cs
index 88d6c61..0dec3bf 100644
--- a/grapher/Layouts/SigmoidLayout.cs
+++ b/grapher/Layouts/SigmoidLayout.cs
@@ -9,11 +9,12 @@ namespace grapher.Layouts
public class SigmoidLayout : LayoutBase
{
public SigmoidLayout()
+ : base()
{
Name = "Sigmoid";
Index = 5;
- Show = new bool[] { true, true, true };
- OptionNames = new string[] { Acceleration, Limit, Midpoint };
+ ShowOptions = new bool[] { true, true, true, true };
+ OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint };
}
}
}
diff --git a/grapher/Option.cs b/grapher/Option.cs
index 8e3ecdf..eb5105e 100644
--- a/grapher/Option.cs
+++ b/grapher/Option.cs
@@ -52,8 +52,7 @@ namespace grapher
{
SetName(name);
- Field.Box.Show();
- Label.Show();
+ Show();
}
}
}
diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs
index de7fad9..1fdf244 100644
--- a/grapher/OptionXY.cs
+++ b/grapher/OptionXY.cs
@@ -59,6 +59,7 @@ namespace grapher
{
Fields.XField.Box.Hide();
Fields.YField.Box.Hide();
+ Fields.LockCheckBox.Hide();
Label.Hide();
}
@@ -66,6 +67,7 @@ namespace grapher
{
Fields.XField.Box.Show();
Fields.YField.Box.Show();
+ Fields.LockCheckBox.Show();
Label.Show();
}
@@ -73,9 +75,7 @@ namespace grapher
{
SetName(name);
- Fields.XField.Box.Show();
- Fields.YField.Box.Show();
- Label.Show();
+ Show();
}
}
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index 207de79..bd86a0c 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -47,7 +47,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="AccelerationSettings.cs" />
<Compile Include="AccelOptions.cs" />
<Compile Include="Field.cs" />
<Compile Include="FieldXY.cs" />
@@ -63,6 +62,7 @@
<Compile Include="Layouts\LinearLayout.cs" />
<Compile Include="Layouts\LogLayout.cs" />
<Compile Include="Layouts\NaturalLayout.cs" />
+ <Compile Include="Layouts\OffLayout.cs" />
<Compile Include="Layouts\PowerLayout.cs" />
<Compile Include="Layouts\SigmoidLayout.cs" />
<Compile Include="Option.cs" />