diff options
| author | Jacob Palecki <[email protected]> | 2020-07-30 00:32:48 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-30 00:32:48 -0700 |
| commit | 20ea6f85cb0af56c13dabbfc3f65383af8793c7c (patch) | |
| tree | cd1bc1f551a8d981a660c68ffae88057d3dd91c9 | |
| parent | Adde accel type switch (diff) | |
| download | rawaccel-20ea6f85cb0af56c13dabbfc3f65383af8793c7c.tar.xz rawaccel-20ea6f85cb0af56c13dabbfc3f65383af8793c7c.zip | |
Fix small bugs, add AccelOptions class
| -rw-r--r-- | grapher/AccelOptions.cs | 68 | ||||
| -rw-r--r-- | grapher/Field.cs | 40 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 13 | ||||
| -rw-r--r-- | grapher/Form1.cs | 3 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 1 | ||||
| -rw-r--r-- | wrapper/wrapper.cpp | 2 | ||||
| -rw-r--r-- | wrapper/wrapper.hpp | 1 |
7 files changed, 115 insertions, 13 deletions
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"; + + /// <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> + { + { 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() + { + + } + } +} diff --git a/grapher/Field.cs b/grapher/Field.cs index 0f65e3e..6e1c6d2 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -28,13 +28,14 @@ namespace grapher public Field(TextBox box, Form containingForm, double defaultData) { - DefaultText = defaultData.ToString("N1"); + DefaultText = DecimalString(defaultData); Box = box; Data = defaultData; DefaultData = defaultData; State = FieldState.Undefined; ContainingForm = containingForm; box.KeyDown += new System.Windows.Forms.KeyEventHandler(KeyDown); + box.Leave += new System.EventHandler(FocusLeave); SetToDefault(); } @@ -53,6 +54,8 @@ namespace grapher public FieldState State { get; private set; } + public FieldState PreviousState { get; private set; } + private double DefaultData { get; } #endregion Properties @@ -66,6 +69,7 @@ namespace grapher Box.BackColor = Color.White; Box.ForeColor = Color.Gray; State = FieldState.Default; + PreviousState = FieldState.Default; } Data = DefaultData; @@ -80,6 +84,7 @@ namespace grapher Box.BackColor = Color.White; Box.ForeColor = Color.Black; + PreviousState = State; State = FieldState.Typing; } @@ -93,6 +98,7 @@ namespace grapher Box.BackColor = Color.AntiqueWhite; Box.ForeColor = Color.DarkGray; + PreviousState = State; State = FieldState.Entered; } @@ -104,7 +110,7 @@ namespace grapher SetToEntered(); Data = value; - Box.Text = Data.ToString("N2"); + Box.Text = DecimalString(Data); } public void SetToUnavailable() @@ -115,6 +121,7 @@ namespace grapher Box.ForeColor = Color.LightGray; Box.Text = string.Empty; + PreviousState = State; State = FieldState.Unavailable; } } @@ -152,6 +159,22 @@ namespace grapher } } + private void FocusLeave(object sender, EventArgs e) + { + if (State == FieldState.Typing) + { + if (PreviousState == FieldState.Default) + { + SetToDefault(); + } + else if (PreviousState == FieldState.Entered) + { + SetToEntered(); + Box.Text = DecimalString(Data); + } + } + } + private void HandleTyping(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) @@ -164,12 +187,23 @@ namespace grapher { } - Box.Text = Data.ToString("N2"); + Box.Text = DecimalString(Data); e.Handled = true; e.SuppressKeyPress = true; SetToEntered(); } + else if (e.KeyCode == Keys.Escape) + { + ContainingForm.ActiveControl = null; + e.Handled = true; + e.SuppressKeyPress = true; + } + } + + private static string DecimalString(double value) + { + return value.ToString("N2"); } #endregion Methods diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 09a4da3..b2bc052 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -1,4 +1,6 @@ -namespace grapher +using System.Linq; + +namespace grapher { partial class RawAcceleration { @@ -82,14 +84,7 @@ // accelTypeDrop // this.accelTypeDrop.FormattingEnabled = true; - this.accelTypeDrop.Items.AddRange(new object[] { - "Off", - "Linear", - "Classic", - "Natural", - "Logarithmic", - "Sigmoid", - "Power"}); + this.accelTypeDrop.Items.AddRange(AccelOptions.TypeToIndex.Keys.ToArray()); this.accelTypeDrop.Location = new System.Drawing.Point(14, 89); this.accelTypeDrop.Name = "accelTypeDrop"; this.accelTypeDrop.Size = new System.Drawing.Size(151, 21); diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 8dd4b8b..e35f097 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,7 +19,7 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - AccelerationType = 5; + AccelerationType = 0; Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); @@ -151,6 +151,7 @@ namespace grapher { ManagedAcceleration.UpdateAccel( AccelerationType, + Rotation.Data, Sensitivity.X, Sensitivity.Y, Weight.X, diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 7b0849f..d8ce5d3 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="AccelOptions.cs" /> <Compile Include="Field.cs" /> <Compile Include="FieldXY.cs" /> <Compile Include="Form1.cs"> diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp index e1aa35e..de2916c 100644 --- a/wrapper/wrapper.cpp +++ b/wrapper/wrapper.cpp @@ -14,6 +14,7 @@ Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time) void ManagedAccel::UpdateAccel( int mode, + double rotation, double sensitivityX, double sensitivityY, double weightX, @@ -29,6 +30,7 @@ void ManagedAccel::UpdateAccel( modifier_args args{}; args.acc_fn_args.accel_mode = mode; + args.degrees = rotation; args.sens.x = sensitivityX; args.sens.y = sensitivityY; args.acc_fn_args.weight.x = weightX; diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp index b8f0751..ff2720c 100644 --- a/wrapper/wrapper.hpp +++ b/wrapper/wrapper.hpp @@ -54,6 +54,7 @@ public: void UpdateAccel( int mode, + double rotation, double sensitivityX, double sensitivityY, double weightX, |