From 70382da847f2a9f4353ea2f981199f832c600ca4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Apr 2021 21:01:41 -0700 Subject: Add lookuptable json --- grapher/Models/AccelGUI.cs | 4 +- grapher/Models/Serialized/LookupTable.cs | 67 ++++++++++++++++++++++++++++ grapher/Models/Serialized/SettingsManager.cs | 2 +- 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 grapher/Models/Serialized/LookupTable.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 3a30a9b..4c4b598 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -45,7 +45,7 @@ namespace grapher ToggleButton.Click += new System.EventHandler(OnToggleButtonClick); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); - ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs); + ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); @@ -62,7 +62,7 @@ namespace grapher } else { - DriverSettings active = DriverInterop.GetActiveSettings(); + DriverSettings active = ManagedAccel.GetActive().Settings; bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active); LastToggleChecked = activeNotDefault; diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs new file mode 100644 index 0000000..578c5bf --- /dev/null +++ b/grapher/Models/Serialized/LookupTable.cs @@ -0,0 +1,67 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Serialized +{ + [Serializable] + public class LookupTable + { + [Serializable] + public class Point + { + public Point(double x, double y) + { + X = x; + Y = y; + } + + double X { get; set; } + + double Y { get; set; } + } + + public LookupTable(Point[] points) + { + Points = points; + } + + public Point[] Points { get; } + + public bool InSensGraph { get; } + + public static LookupTable Deserialize(string lutFile) + { + if (!File.Exists(lutFile)) + { + throw new Exception($"LUT file does not exist at {lutFile}."); + } + + JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); + + var lut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); + + if (lut is null || lut.Points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } + + lut.Verify(); + + return lut; + } + + private void Verify() + { + if (Points.Length >= short.MaxValue) + { + throw new Exception($"LUT file with {Points.Length} points is too long. Max points: {short.MaxValue}"); + } + } + } +} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 40652dd..3773a9e 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -85,7 +85,7 @@ namespace grapher.Models.Serialized public static void SendToDriver(DriverSettings settings) { - new Thread(() => DriverInterop.Write(settings)).Start(); + new Thread(() => settings.ToFile()).Start(); } public static SettingsErrors SendToDriverSafe(DriverSettings settings) -- cgit v1.2.3 From ebfd5a8af07bc5fdf5b463714d8030e49eac53ba Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Apr 2021 22:08:01 -0700 Subject: Add differing table types --- grapher/Models/Serialized/LookupTable.cs | 57 +++++++++++--------------------- 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs index 578c5bf..d373461 100644 --- a/grapher/Models/Serialized/LookupTable.cs +++ b/grapher/Models/Serialized/LookupTable.cs @@ -10,32 +10,9 @@ using System.Threading.Tasks; namespace grapher.Models.Serialized { [Serializable] - public class LookupTable + public static class LookupTable { - [Serializable] - public class Point - { - public Point(double x, double y) - { - X = x; - Y = y; - } - - double X { get; set; } - - double Y { get; set; } - } - - public LookupTable(Point[] points) - { - Points = points; - } - - public Point[] Points { get; } - - public bool InSensGraph { get; } - - public static LookupTable Deserialize(string lutFile) + public static void Deserialize(string lutFile, ref DriverSettings settings) { if (!File.Exists(lutFile)) { @@ -44,23 +21,29 @@ namespace grapher.Models.Serialized JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); - var lut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); + var spacedLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - if (lut is null || lut.Points is null) + if (spacedLut is null) { - throw new Exception($"{lutFile} does not contain valid lookuptable json."); - } + var arbitraryLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - lut.Verify(); + if (arbitraryLut is null || arbitraryLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } - return lut; - } - - private void Verify() - { - if (Points.Length >= short.MaxValue) + settings.ArbitraryTable = arbitraryLut; + settings.args.x.lutArgs.type = TableType.arbitrary; + } + else { - throw new Exception($"LUT file with {Points.Length} points is too long. Max points: {short.MaxValue}"); + if (spacedLut.points is null) + { + throw new Exception($"{lutFile} does not contain valid lookuptable json."); + } + + settings.SpacedTable = spacedLut; + settings.args.x.lutArgs = spacedLut.args; } } } -- cgit v1.2.3 From 069bf5795fbf127d2a8c3233988a77aa7b2107d7 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 4 Apr 2021 23:14:39 -0700 Subject: Fix most errors from wrapper rewrite --- grapher/Models/AccelGUI.cs | 9 ++--- grapher/Models/Options/AccelOptionSet.cs | 4 +- grapher/Models/Options/AccelTypeOptions.cs | 55 +++++++++++++++++++++------ grapher/Models/Options/ApplyOptions.cs | 8 +--- grapher/Models/Options/CapOptions.cs | 12 ++---- grapher/Models/Options/OffsetOptions.cs | 5 +-- grapher/Models/Serialized/RawAccelSettings.cs | 4 +- grapher/Models/Serialized/SettingsManager.cs | 6 +-- 8 files changed, 62 insertions(+), 41 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 4c4b598..943360b 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -137,8 +137,6 @@ namespace grapher var driverSettings = Settings.RawAccelSettings.AccelerationSettings; var newArgs = ApplyOptions.GetArgs(); - newArgs.x.speedCap = driverSettings.args.x.speedCap; - newArgs.y.speedCap = driverSettings.args.y.speedCap; var settings = new DriverSettings { @@ -150,13 +148,14 @@ namespace grapher y = ApplyOptions.Sensitivity.Fields.Y }, combineMagnitudes = ApplyOptions.IsWhole, - modes = ApplyOptions.GetModes(), args = newArgs, minimumTime = driverSettings.minimumTime, directionalMultipliers = driverSettings.directionalMultipliers, domainArgs = ApplyOptions.Directionality.GetDomainArgs(), rangeXY = ApplyOptions.Directionality.GetRangeXY(), deviceID = DeviceIDManager.ID, + maximumSpeed = driverSettings.maximumSpeed, + minimumSpeed = driverSettings.minimumSpeed }; ButtonDelay(WriteButton); @@ -252,13 +251,13 @@ namespace grapher { var settings = ToggleButton.Checked ? Settings.RawAccelSettings.AccelerationSettings : - DriverInterop.DefaultSettings; + AccelTypeOptions.DefaultSettings; LastToggleChecked = ToggleButton.Checked; ButtonDelay(ToggleButton); SettingsManager.SendToDriver(settings); - Settings.ActiveAccel.UpdateFromSettings(settings); + Settings.ActiveAccel.Settings = settings; RefreshOnRead(settings); } diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 11a7f10..f4c08a1 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -108,11 +108,11 @@ namespace grapher.Models.Options return Options.GenerateArgs(); } - public void SetActiveValues(int mode, AccelArgs args) + public void SetActiveValues(AccelArgs args) { if (!Hidden) { - Options.SetActiveValues(mode, args); + Options.SetActiveValues(args); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 8d3fecb..0547164 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -17,12 +17,13 @@ namespace grapher new LinearLayout(), new ClassicLayout(), new NaturalLayout(), - new NaturalGainLayout(), new PowerLayout(), new MotivityLayout(), new OffLayout() }.ToDictionary(k => k.Name); + public static readonly DriverSettings DefaultSettings = new DriverSettings(); + #endregion Fields #region Constructors @@ -187,16 +188,16 @@ namespace grapher Show(); } - public void SetActiveValues(int index, AccelArgs args) + public void SetActiveValues(AccelArgs args) { - AccelerationType = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; + AccelerationType = AccelTypeFromSettings(args); AccelTypeActiveValue.SetValue(AccelerationType.Name); AccelDropdown.SelectedIndex = AccelerationType.Index; Weight.SetActiveValue(args.weight); - Cap.SetActiveValues(args.gainCap, args.scaleCap, args.gainCap > 0 || args.scaleCap <= 0); - Offset.SetActiveValue(args.offset, args.legacyOffset); - Acceleration.SetActiveValue(args.acceleration); + Cap.SetActiveValues(args.cap, args.legacy); + Offset.SetActiveValue(args.offset); + Acceleration.SetActiveValue(AccelerationParameterFromArgs(args)); Scale.SetActiveValue(args.scale); Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); @@ -227,15 +228,15 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - AccelArgs defaults = DriverInterop.DefaultSettings.args.x; - args.acceleration = Acceleration.Visible ? Acceleration.Field.Data : defaults.acceleration; + AccelArgs defaults = DefaultSettings.args.x; + args.accelClassic = defaults.accelClassic; + args.accelMotivity = defaults.accelMotivity; + args.accelNatural = defaults.accelClassic; args.scale = Scale.Visible ? Scale.Field.Data : defaults.scale; - args.gainCap = Cap.Visible ? Cap.VelocityGainCap : defaults.gainCap; - args.scaleCap = Cap.Visible ? Cap.SensitivityCap : defaults.scaleCap; + args.cap = Cap.Visible ? Cap.SensitivityCap : defaults.cap; args.limit = Limit.Visible ? Limit.Field.Data : defaults.limit; args.exponent = Exponent.Visible ? Exponent.Field.Data : defaults.exponent; args.offset = Offset.Visible ? Offset.Offset : defaults.offset; - args.legacyOffset = Offset.IsLegacy; args.midpoint = Midpoint.Visible ? Midpoint.Field.Data : defaults.midpoint; args.weight = Weight.Visible ? Weight.Field.Data : defaults.weight; } @@ -292,6 +293,38 @@ namespace grapher top); } + private LayoutBase AccelTypeFromSettings(AccelArgs args) + { + LayoutBase type; + if (args.mode == AccelMode.classic && args.exponent == 2) + { + type = AccelerationTypes.Values.Where(t => string.Equals(t.Name, LinearLayout.LinearName)).FirstOrDefault(); + } + else + { + int index = (int)args.mode; + type = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; + } + + return type; + } + + private double AccelerationParameterFromArgs(AccelArgs args) + { + if (args.mode == AccelMode.motivity) + { + return args.accelMotivity; + } + else if (args.mode == AccelMode.natural) + { + return args.accelNatural; + } + else + { + return args.accelClassic; + } + } + #endregion Methods } } diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index ffe430d..43a2da8 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -108,19 +108,17 @@ namespace grapher.Models.Options double xSens, double ySens, double rotation, - int xMode, - int yMode, AccelArgs xArgs, AccelArgs yArgs, bool isWhole) { Sensitivity.SetActiveValues(xSens, ySens); Rotation.SetActiveValue(rotation); - OptionSetX.SetActiveValues(xMode, xArgs); + OptionSetX.SetActiveValues(xArgs); WholeVectorCheckBox.Checked = isWhole; ByComponentVectorCheckBox.Checked = !isWhole; ByComponentVectorXYLock.Checked = xArgs.Equals(yArgs); - OptionSetY.SetActiveValues(yMode, yArgs); + OptionSetY.SetActiveValues(yArgs); } public void SetActiveValues(DriverSettings settings) @@ -129,8 +127,6 @@ namespace grapher.Models.Options settings.sensitivity.x, settings.sensitivity.y, settings.rotation, - (int)settings.modes.x, - (int)settings.modes.y, settings.args.x, settings.args.y, settings.combineMagnitudes); diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs index c459c50..b4afa5c 100644 --- a/grapher/Models/Options/CapOptions.cs +++ b/grapher/Models/Options/CapOptions.cs @@ -149,24 +149,20 @@ namespace grapher } - public void SetActiveValues(double gainCap, double sensCap, bool capGainEnabled) + public void SetActiveValues(double cap, bool legacyCap) { - if (capGainEnabled) + if (!legacyCap) { CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString; CapOption.ActiveValueLabel.Prefix = "Gain"; - CapOption.SetActiveValue(gainCap); - LegacyCapCheck.Checked = false; - VelocityGainCapCheck.Checked = true; } else { CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString; CapOption.ActiveValueLabel.Prefix = string.Empty; - CapOption.SetActiveValue(sensCap); - LegacyCapCheck.Checked = true; - VelocityGainCapCheck.Checked = false; } + + CapOption.SetActiveValue(cap); } public override void AlignActiveValues() diff --git a/grapher/Models/Options/OffsetOptions.cs b/grapher/Models/Options/OffsetOptions.cs index 6638ed7..42d2d92 100644 --- a/grapher/Models/Options/OffsetOptions.cs +++ b/grapher/Models/Options/OffsetOptions.cs @@ -106,12 +106,9 @@ namespace grapher.Models.Options OffsetOption.Show(name); } - public void SetActiveValue(double offset, bool legacy) + public void SetActiveValue(double offset) { OffsetOption.SetActiveValue(offset); - - VelocityGainOffsetCheck.Checked = !legacy; - LegacyOffsetCheck.Checked = legacy; } public override void AlignActiveValues() diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 17db910..dc4eb0a 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -123,7 +123,7 @@ namespace grapher.Models.Serialized public static bool IsDefaultEquivalent(DriverSettings accelSettings) { bool wholeOrNoY = accelSettings.combineMagnitudes || - accelSettings.modes.y == AccelMode.noaccel; + accelSettings.args.y.mode == AccelMode.noaccel; return string.IsNullOrEmpty(accelSettings.deviceID) && accelSettings.sensitivity.x == 1 && @@ -132,7 +132,7 @@ namespace grapher.Models.Serialized accelSettings.directionalMultipliers.y <= 0 && accelSettings.rotation == 0 && accelSettings.snap == 0 && - accelSettings.modes.x == AccelMode.noaccel && + accelSettings.args.x.mode == AccelMode.noaccel && wholeOrNoY; } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 3773a9e..1a57838 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -79,7 +79,7 @@ namespace grapher.Models.Serialized public SettingsErrors TryUpdateAccel(DriverSettings settings) { var errors = SendToDriverSafe(settings); - if (errors.Empty()) ActiveAccel.UpdateFromSettings(settings); + if (errors.Empty()) ActiveAccel.Settings = settings; return errors; } @@ -90,7 +90,7 @@ namespace grapher.Models.Serialized public static SettingsErrors SendToDriverSafe(DriverSettings settings) { - var errors = DriverInterop.GetSettingsErrors(settings); + var errors = new SettingsErrors(settings); if (errors.Empty()) SendToDriver(settings); return errors; } @@ -129,7 +129,7 @@ namespace grapher.Models.Serialized } RawAccelSettings = new RawAccelSettings( - DriverInterop.GetActiveSettings(), + ManagedAccel.GetActive().Settings, MakeGUISettingsFromFields()); RawAccelSettings.Save(); return true; -- cgit v1.2.3 From d948065a830dafe526e38868f23a4ca4a6ba63e4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 4 Apr 2021 23:31:14 -0700 Subject: Add textoption for lut text display --- grapher/Models/Options/TextOption.cs | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 grapher/Models/Options/TextOption.cs (limited to 'grapher/Models') diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs new file mode 100644 index 0000000..bbdedca --- /dev/null +++ b/grapher/Models/Options/TextOption.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class TextOption : OptionBase + { + #region Constructors + + public TextOption(Label label) + { + Label = label; + } + + #endregion Constructors + + #region Properties + + private Label Label { get; } + + public override bool Visible + { + get + { + return Label.Visible; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + Label.Top = value; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + Label.Width = value; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + } + } + + public override void Hide() + { + Label.Hide(); + } + + public override void Show(string Name) + { + Label.Show(); + Label.Text = Name; + } + + public override void AlignActiveValues() + { + // Nothing to do here + } + + #endregion Properties + } +} -- cgit v1.2.3 From 9864bc77331baf61a95f49dd2d96dbda51e841db Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 19:46:04 -0700 Subject: It builds --- grapher/Models/AccelGUI.cs | 10 +++++----- grapher/Models/Options/AccelTypeOptions.cs | 4 ++-- grapher/Models/Serialized/SettingsManager.cs | 17 +++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 943360b..5a04030 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -249,16 +249,16 @@ namespace grapher private void OnToggleButtonClick(object sender, EventArgs e) { - var settings = ToggleButton.Checked ? - Settings.RawAccelSettings.AccelerationSettings : + var accel = ToggleButton.Checked ? + new ManagedAccel(Settings.RawAccelSettings.AccelerationSettings) : AccelTypeOptions.DefaultSettings; LastToggleChecked = ToggleButton.Checked; ButtonDelay(ToggleButton); - SettingsManager.SendToDriver(settings); - Settings.ActiveAccel.Settings = settings; - RefreshOnRead(settings); + SettingsManager.SendToDriver(accel); + Settings.ActiveAccel = accel; + RefreshOnRead(accel.Settings); } private void OnButtonTimerTick(object sender, EventArgs e) diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 0547164..aeada3f 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -22,7 +22,7 @@ namespace grapher new OffLayout() }.ToDictionary(k => k.Name); - public static readonly DriverSettings DefaultSettings = new DriverSettings(); + public static readonly ManagedAccel DefaultSettings = new ManagedAccel(); #endregion Fields @@ -228,7 +228,7 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - AccelArgs defaults = DefaultSettings.args.x; + AccelArgs defaults = DefaultSettings.Settings.args.x; args.accelClassic = defaults.accelClassic; args.accelMotivity = defaults.accelMotivity; args.accelNatural = defaults.accelClassic; diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 1a57838..25aa534 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -34,7 +34,7 @@ namespace grapher.Models.Serialized #region Properties - public ManagedAccel ActiveAccel { get; } + public ManagedAccel ActiveAccel { get; set; } public RawAccelSettings RawAccelSettings { get; private set; } @@ -78,20 +78,21 @@ namespace grapher.Models.Serialized public SettingsErrors TryUpdateAccel(DriverSettings settings) { - var errors = SendToDriverSafe(settings); - if (errors.Empty()) ActiveAccel.Settings = settings; + var accel = new ManagedAccel(settings); + var errors = SendToDriverSafe(accel); + if (errors.Empty()) ActiveAccel= accel; return errors; } - public static void SendToDriver(DriverSettings settings) + public static void SendToDriver(ManagedAccel accel) { - new Thread(() => settings.ToFile()).Start(); + new Thread(() => accel.Activate()).Start(); } - public static SettingsErrors SendToDriverSafe(DriverSettings settings) + public static SettingsErrors SendToDriverSafe(ManagedAccel accel) { - var errors = new SettingsErrors(settings); - if (errors.Empty()) SendToDriver(settings); + var errors = new SettingsErrors(accel.Settings); + if (errors.Empty()) SendToDriver(accel); return errors; } -- cgit v1.2.3 From cf1fdf2e6cdba8c6ae8493eb744f223b6324594c Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 20:43:08 -0700 Subject: LUT text layout --- grapher/Models/AccelGUIFactory.cs | 5 +++++ grapher/Models/Options/AccelTypeOptions.cs | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 1c42c76..c8446f0 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -85,6 +85,7 @@ namespace grapher.Models Label limitLabelY, Label expLabelX, Label expLabelY, + Label lutTextLabel, Label constantThreeLabelX, Label constantThreeLabelY, Label activeValueTitleX, @@ -332,6 +333,8 @@ namespace grapher.Models legacyCapToolStripMenuItem, capY); + var lutText = new TextOption(lutTextLabel); + var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, accelerationX, @@ -342,6 +345,7 @@ namespace grapher.Models limitX, exponentX, midpointX, + lutText, writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -355,6 +359,7 @@ namespace grapher.Models limitY, exponentY, midpointY, + lutText, writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index aeada3f..7e2e3d7 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -19,7 +19,8 @@ namespace grapher new NaturalLayout(), new PowerLayout(), new MotivityLayout(), - new OffLayout() + new OffLayout(), + new LUTLayout(), }.ToDictionary(k => k.Name); public static readonly ManagedAccel DefaultSettings = new ManagedAccel(); @@ -38,6 +39,7 @@ namespace grapher Option limit, Option exponent, Option midpoint, + TextOption lutText, Button writeButton, ActiveValueLabel accelTypeActiveValue) { @@ -56,6 +58,7 @@ namespace grapher Midpoint = midpoint; WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; + LutText = lutText; AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; @@ -101,6 +104,8 @@ namespace grapher public Option Midpoint { get; } + public TextOption LutText { get; } + public override int Top { get @@ -290,6 +295,7 @@ namespace grapher Limit, Exponent, Midpoint, + LutText, top); } -- cgit v1.2.3 From 7c1f14845bc948e9ea25908e96099203d9433a69 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Apr 2021 01:21:42 -0400 Subject: update wrapper + writer to handle lut grapher is building but applying options still broken for the most part --- grapher/Models/AccelGUI.cs | 124 ++++++++-------------- grapher/Models/Mouse/MouseWatcher.cs | 4 +- grapher/Models/Options/AccelTypeOptions.cs | 23 ++--- grapher/Models/Serialized/GUISettings.cs | 27 +++++ grapher/Models/Serialized/LookupTable.cs | 50 --------- grapher/Models/Serialized/RawAccelSettings.cs | 141 -------------------------- grapher/Models/Serialized/SettingsManager.cs | 138 ++++++++++++++++--------- 7 files changed, 175 insertions(+), 332 deletions(-) delete mode 100644 grapher/Models/Serialized/LookupTable.cs delete mode 100644 grapher/Models/Serialized/RawAccelSettings.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 5a04030..9ed2cb9 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -32,7 +32,7 @@ namespace grapher AccelCharts = accelCharts; ApplyOptions = applyOptions; WriteButton = writeButton; - ToggleButton = (CheckBox)toggleButton; + DisableButton = (CheckBox)toggleButton; ScaleMenuItem = scaleMenuItem; Settings = settings; DefaultButtonFont = WriteButton.Font; @@ -42,7 +42,7 @@ namespace grapher ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); - ToggleButton.Click += new System.EventHandler(OnToggleButtonClick); + DisableButton.Click += new System.EventHandler(DisableDriverEventHandler); AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); ButtonTimerInterval = Convert.ToInt32(DriverSettings.WriteDelayMs); @@ -51,25 +51,8 @@ namespace grapher ChartRefresh = SetupChartTimer(); - bool settingsActive = Settings.Startup(); - SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); - - if (settingsActive) - { - LastToggleChecked = SettingsNotDefault; - ToggleButton.Enabled = LastToggleChecked; - RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); - } - else - { - DriverSettings active = ManagedAccel.GetActive().Settings; - bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active); - - LastToggleChecked = activeNotDefault; - ToggleButton.Enabled = SettingsNotDefault || activeNotDefault; - RefreshOnRead(active); - } - + RefreshUser(); + RefreshActive(); SetupButtons(); // TODO: The below removes an overlapping form from the anisotropy panel. @@ -94,7 +77,7 @@ namespace grapher public Button WriteButton { get; } - public CheckBox ToggleButton { get; } + public CheckBox DisableButton { get; } public Timer ButtonTimer { get; } @@ -104,8 +87,6 @@ namespace grapher public DeviceIDManager DeviceIDManager { get; } - public Action UpdateInputManagers { get; private set; } - private Timer ChartRefresh { get; } private Font SmallButtonFont { get; } @@ -125,46 +106,37 @@ namespace grapher private void SaveGUISettingsOnClose(Object sender, FormClosingEventArgs e) { var guiSettings = Settings.MakeGUISettingsFromFields(); - if (!Settings.RawAccelSettings.GUISettings.Equals(guiSettings)) + if (!Settings.GuiSettings.Equals(guiSettings)) { - Settings.RawAccelSettings.GUISettings = guiSettings; - Settings.RawAccelSettings.Save(); + guiSettings.Save(); } } public void UpdateActiveSettingsFromFields() { - var driverSettings = Settings.RawAccelSettings.AccelerationSettings; - - var newArgs = ApplyOptions.GetArgs(); - var settings = new DriverSettings { rotation = ApplyOptions.Rotation.Field.Data, - snap = driverSettings.snap, sensitivity = new Vec2 { x = ApplyOptions.Sensitivity.Fields.X, y = ApplyOptions.Sensitivity.Fields.Y }, combineMagnitudes = ApplyOptions.IsWhole, - args = newArgs, - minimumTime = driverSettings.minimumTime, - directionalMultipliers = driverSettings.directionalMultipliers, + args = ApplyOptions.GetArgs(), domainArgs = ApplyOptions.Directionality.GetDomainArgs(), rangeXY = ApplyOptions.Directionality.GetRangeXY(), deviceID = DeviceIDManager.ID, - maximumSpeed = driverSettings.maximumSpeed, - minimumSpeed = driverSettings.minimumSpeed }; + Settings.SetHiddenOptions(settings); + ButtonDelay(WriteButton); - SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); + + SettingsErrors errors = Settings.TryActivate(settings); if (errors.Empty()) { - SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); - LastToggleChecked = SettingsNotDefault; - RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); + RefreshActive(); } else { @@ -172,25 +144,28 @@ namespace grapher } } - public void RefreshOnRead(DriverSettings args) + public void UpdateInputManagers() { - UpdateShownActiveValues(args); - UpdateGraph(args); - - UpdateInputManagers = () => - { - MouseWatcher.UpdateHandles(args.deviceID); - DeviceIDManager.Update(args.deviceID); - }; + MouseWatcher.UpdateHandles(Settings.ActiveSettings.baseSettings.deviceID); + DeviceIDManager.Update(Settings.ActiveSettings.baseSettings.deviceID); + } + public void RefreshActive() + { + UpdateGraph(); UpdateInputManagers(); } - public void UpdateGraph(DriverSettings args) + public void RefreshUser() + { + UpdateShownActiveValues(Settings.UserSettings); + } + + public void UpdateGraph() { AccelCharts.Calculate( Settings.ActiveAccel, - args); + Settings.ActiveSettings.baseSettings); AccelCharts.Bind(); } @@ -214,32 +189,31 @@ namespace grapher { WriteButton.Top = Constants.SensitivityChartAloneHeight - Constants.ButtonVerticalOffset; - ToggleButton.Appearance = Appearance.Button; - ToggleButton.FlatStyle = FlatStyle.System; - ToggleButton.TextAlign = ContentAlignment.MiddleCenter; - ToggleButton.Size = WriteButton.Size; - ToggleButton.Top = WriteButton.Top; + DisableButton.Appearance = Appearance.Button; + DisableButton.FlatStyle = FlatStyle.System; + DisableButton.TextAlign = ContentAlignment.MiddleCenter; + DisableButton.Size = WriteButton.Size; + DisableButton.Top = WriteButton.Top; SetButtonDefaults(); } private void SetButtonDefaults() { - ToggleButton.Checked = LastToggleChecked; - - ToggleButton.Font = DefaultButtonFont; - ToggleButton.Text = ToggleButton.Checked ? "Disable" : "Enable"; - ToggleButton.Update(); + DisableButton.Font = DefaultButtonFont; + DisableButton.Text = "Disable"; + DisableButton.Enabled = true; + DisableButton.Update(); WriteButton.Font = DefaultButtonFont; WriteButton.Text = Constants.WriteButtonDefaultText; - WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled; + WriteButton.Enabled = true; WriteButton.Update(); } private void OnScaleMenuItemClick(object sender, EventArgs e) { - UpdateGraph(Settings.RawAccelSettings.AccelerationSettings); + UpdateGraph(); } private void OnWriteButtonClick(object sender, EventArgs e) @@ -247,24 +221,16 @@ namespace grapher UpdateActiveSettingsFromFields(); } - private void OnToggleButtonClick(object sender, EventArgs e) + private void DisableDriverEventHandler(object sender, EventArgs e) { - var accel = ToggleButton.Checked ? - new ManagedAccel(Settings.RawAccelSettings.AccelerationSettings) : - AccelTypeOptions.DefaultSettings; - - LastToggleChecked = ToggleButton.Checked; - ButtonDelay(ToggleButton); - - SettingsManager.SendToDriver(accel); - Settings.ActiveAccel = accel; - RefreshOnRead(accel.Settings); + ButtonDelay(DisableButton); + Settings.DisableDriver(); + RefreshActive(); } private void OnButtonTimerTick(object sender, EventArgs e) { ButtonTimer.Stop(); - ToggleButton.Enabled = SettingsNotDefault; SetButtonDefaults(); } @@ -276,15 +242,13 @@ namespace grapher private void ButtonDelay(ButtonBase btn) { - ToggleButton.Checked = false; - - ToggleButton.Enabled = false; + DisableButton.Enabled = false; WriteButton.Enabled = false; btn.Font = SmallButtonFont; btn.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; - ToggleButton.Update(); + DisableButton.Update(); WriteButton.Update(); StartButtonTimer(); diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 163829f..c5c2ae5 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -772,8 +772,8 @@ namespace grapher.Models.Mouse // strip negative directional multipliers, charts calculated from positive input - Vec2 dirMults = SettingsManager.RawAccelSettings - .AccelerationSettings.directionalMultipliers; + Vec2 dirMults = SettingsManager.ActiveSettings.baseSettings + .directionalMultipliers; if (dirMults.x > 0 && x < 0) { diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 7e2e3d7..556f969 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -17,13 +17,14 @@ namespace grapher new LinearLayout(), new ClassicLayout(), new NaturalLayout(), + new JumpLayout(), new PowerLayout(), new MotivityLayout(), new OffLayout(), new LUTLayout(), }.ToDictionary(k => k.Name); - public static readonly ManagedAccel DefaultSettings = new ManagedAccel(); + public static readonly AccelArgs DefaultArgs = new DriverSettings().args.x; #endregion Fields @@ -233,22 +234,18 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - AccelArgs defaults = DefaultSettings.Settings.args.x; - args.accelClassic = defaults.accelClassic; - args.accelMotivity = defaults.accelMotivity; - args.accelNatural = defaults.accelClassic; - args.scale = Scale.Visible ? Scale.Field.Data : defaults.scale; - args.cap = Cap.Visible ? Cap.SensitivityCap : defaults.cap; - args.limit = Limit.Visible ? Limit.Field.Data : defaults.limit; - args.exponent = Exponent.Visible ? Exponent.Field.Data : defaults.exponent; - args.offset = Offset.Visible ? Offset.Offset : defaults.offset; - args.midpoint = Midpoint.Visible ? Midpoint.Field.Data : defaults.midpoint; - args.weight = Weight.Visible ? Weight.Field.Data : defaults.weight; + if (Scale.Visible) args.scale = Scale.Field.Data; + if (Cap.Visible) args.cap = Cap.SensitivityCap; + if (Limit.Visible) args.limit = Limit.Field.Data; + if (Exponent.Visible) args.exponent = Exponent.Field.Data; + if (Offset.Visible) args.offset = Offset.Offset; + if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; + if (Weight.Visible) args.weight = Weight.Field.Data; } public AccelArgs GenerateArgs() { - AccelArgs args = new AccelArgs(); + AccelArgs args = new DriverSettings().args.x; SetArgs(ref args); return args; } diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index bb35055..93d56de 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.IO; namespace grapher.Models.Serialized { @@ -65,6 +66,32 @@ namespace grapher.Models.Serialized AutoWriteToDriverOnStartup.GetHashCode(); } + public void Save() + { + File.WriteAllText(Constants.GuiConfigFileName, JsonConvert.SerializeObject(this)); + } + + public static GUISettings MaybeLoad() + { + GUISettings settings = null; + + try + { + settings = JsonConvert.DeserializeObject( + File.ReadAllText(Constants.GuiConfigFileName)); + } + catch (Exception ex) + { + if (!(ex is JsonException || ex is FileNotFoundException)) + { + throw; + } + } + + return settings; + } + #endregion Methods + } } diff --git a/grapher/Models/Serialized/LookupTable.cs b/grapher/Models/Serialized/LookupTable.cs deleted file mode 100644 index d373461..0000000 --- a/grapher/Models/Serialized/LookupTable.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace grapher.Models.Serialized -{ - [Serializable] - public static class LookupTable - { - public static void Deserialize(string lutFile, ref DriverSettings settings) - { - if (!File.Exists(lutFile)) - { - throw new Exception($"LUT file does not exist at {lutFile}."); - } - - JObject lutJObject = JObject.Parse(File.ReadAllText(lutFile)); - - var spacedLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - - if (spacedLut is null) - { - var arbitraryLut = lutJObject.ToObject(JsonSerializer.Create(RawAccelSettings.SerializerSettings)); - - if (arbitraryLut is null || arbitraryLut.points is null) - { - throw new Exception($"{lutFile} does not contain valid lookuptable json."); - } - - settings.ArbitraryTable = arbitraryLut; - settings.args.x.lutArgs.type = TableType.arbitrary; - } - else - { - if (spacedLut.points is null) - { - throw new Exception($"{lutFile} does not contain valid lookuptable json."); - } - - settings.SpacedTable = spacedLut; - settings.args.x.lutArgs = spacedLut.args; - } - } - } -} diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs deleted file mode 100644 index dc4eb0a..0000000 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ /dev/null @@ -1,141 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.IO; -using System.Linq; - -namespace grapher.Models.Serialized -{ - [Serializable] - public class RawAccelSettings - { - #region Fields - - public static readonly string ExecutingDirectory = AppDomain.CurrentDomain.BaseDirectory; - public static readonly string DefaultSettingsFile = Path.Combine(ExecutingDirectory, Constants.DefaultSettingsFileName); - public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings - { - MissingMemberHandling = MissingMemberHandling.Ignore, - }; - #endregion Fields - - #region Constructors - - public RawAccelSettings() { } - - public RawAccelSettings( - DriverSettings accelSettings, - GUISettings guiSettings) - { - AccelerationSettings = accelSettings; - GUISettings = guiSettings; - } - - #endregion Constructors - - #region Properties - [JsonProperty(Required = Required.Always)] - public GUISettings GUISettings { get; set; } - - [JsonProperty(DriverSettings.Key, Required = Required.Always)] - public DriverSettings AccelerationSettings { get; set; } - - #endregion Properties - - #region Methods - - public static RawAccelSettings Load(Func DefaultGUISettingsSupplier) - { - return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); - } - - public static RawAccelSettings Load(string file, Func DefaultGUISettingsSupplier) - { - try - { - RawAccelSettings settings = null; - - JObject settingsJObject = JObject.Parse(File.ReadAllText(file)); - if (settingsJObject.ContainsKey(DriverSettings.Key)) - { - settings = settingsJObject.ToObject(JsonSerializer.Create(SerializerSettings)); - } - else - { - settings = new RawAccelSettings - { - AccelerationSettings = settingsJObject.ToObject(), - GUISettings = DefaultGUISettingsSupplier() - }; - } - - if (settings is null || settings.AccelerationSettings is null) - { - throw new JsonException($"{file} contains invalid JSON"); - } - - return settings; - } - catch (FileNotFoundException e) - { - throw new FileNotFoundException($"Settings file does not exist at {file}", e); - } - catch (JsonException e) - { - throw new JsonException($"Settings file at {file} does not contain valid Raw Accel Settings.", e); - } - } - - public static bool Exists() - { - return Exists(DefaultSettingsFile); - } - - public static bool Exists(string file) - { - return File.Exists(file); - } - - public void Save() - { - Save(DefaultSettingsFile); - } - - public void Save(string file) - { - JObject thisJO = JObject.FromObject(this); - AddComments(thisJO); - File.WriteAllText(file, thisJO.ToString(Formatting.Indented)); - } - - private void AddComments(JObject thisJO) - { - string modes = string.Join(" | ", Enum.GetNames(typeof(AccelMode))); - ((JObject)thisJO[DriverSettings.Key]) - .AddFirst(new JProperty("### Mode Types ###", modes)); - } - - public bool IsDefaultEquivalent() - { - return IsDefaultEquivalent(AccelerationSettings); - } - - public static bool IsDefaultEquivalent(DriverSettings accelSettings) - { - bool wholeOrNoY = accelSettings.combineMagnitudes || - accelSettings.args.y.mode == AccelMode.noaccel; - - return string.IsNullOrEmpty(accelSettings.deviceID) && - accelSettings.sensitivity.x == 1 && - accelSettings.sensitivity.y == 1 && - accelSettings.directionalMultipliers.x <= 0 && - accelSettings.directionalMultipliers.y <= 0 && - accelSettings.rotation == 0 && - accelSettings.snap == 0 && - accelSettings.args.x.mode == AccelMode.noaccel && - wholeOrNoY; - } - - #endregion Methods - } -} diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 25aa534..c0cc413 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.IO; using System.Windows.Forms; using System.Threading; using System.Text; @@ -21,22 +22,41 @@ namespace grapher.Models.Serialized ToolStripMenuItem showVelocityAndGain, DeviceIDManager deviceIDManager) { - ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; AutoWriteMenuItem = autoWrite; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; DeviceIDManager = deviceIDManager; + + SetActiveFields(activeAccel); + + GuiSettings = GUISettings.MaybeLoad(); + + if (GuiSettings is null) + { + GuiSettings = MakeGUISettingsFromFields(); + GuiSettings.Save(); + } + else + { + UpdateFieldsFromGUISettings(); + } + + UserSettings = InitUserSettings(); } #endregion Constructors #region Properties - public ManagedAccel ActiveAccel { get; set; } + public GUISettings GuiSettings { get; private set; } + + public ManagedAccel ActiveAccel { get; private set; } + + public ExtendedSettings ActiveSettings { get; private set; } - public RawAccelSettings RawAccelSettings { get; private set; } + public DriverSettings UserSettings { get; private set; } public Field DpiField { get; private set; } @@ -53,47 +73,54 @@ namespace grapher.Models.Serialized #endregion Properties #region Methods - public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) - { - var errors = TryUpdateAccel(settings); - - if (errors.Empty()) - { - RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = MakeGUISettingsFromFields(); - RawAccelSettings.Save(); - } - return errors; + public void DisableDriver() + { + var defaultSettings = new ExtendedSettings(); + ActiveSettings = defaultSettings; + ActiveAccel.Settings = defaultSettings; + new Thread(() => ActiveAccel.Activate()).Start(); } public void UpdateFieldsFromGUISettings() { - DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); - PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); - ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; - ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; - AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + DpiField.SetToEntered(GuiSettings.DPI); + PollRateField.SetToEntered(GuiSettings.PollRate); + ShowLastMouseMoveMenuItem.Checked = GuiSettings.ShowLastMouseMove; + ShowVelocityAndGainMoveMenuItem.Checked = GuiSettings.ShowVelocityAndGain; + AutoWriteMenuItem.Checked = GuiSettings.AutoWriteToDriverOnStartup; } - public SettingsErrors TryUpdateAccel(DriverSettings settings) + public SettingsErrors TryActivate(DriverSettings settings) { - var accel = new ManagedAccel(settings); - var errors = SendToDriverSafe(accel); - if (errors.Empty()) ActiveAccel= accel; - return errors; - } + var errors = new SettingsErrors(settings); - public static void SendToDriver(ManagedAccel accel) - { - new Thread(() => accel.Activate()).Start(); + if (errors.Empty()) + { + GuiSettings = MakeGUISettingsFromFields(); + GuiSettings.Save(); + + UserSettings = settings; + File.WriteAllText(Constants.DefaultSettingsFileName, RaConvert.Settings(settings)); + + ActiveSettings = new ExtendedSettings(settings); + ActiveAccel.Settings = ActiveSettings; + + new Thread(() => ActiveAccel.Activate()).Start(); + } + + return errors; } - public static SettingsErrors SendToDriverSafe(ManagedAccel accel) + public void SetHiddenOptions(DriverSettings settings) { - var errors = new SettingsErrors(accel.Settings); - if (errors.Empty()) SendToDriver(accel); - return errors; + settings.snap = UserSettings.snap; + settings.maximumSpeed = UserSettings.maximumSpeed; + settings.minimumSpeed = UserSettings.minimumSpeed; + settings.minimumTime = UserSettings.minimumTime; + settings.maximumTime = UserSettings.maximumTime; + settings.ignore = UserSettings.ignore; + settings.directionalMultipliers = UserSettings.directionalMultipliers; } public GUISettings MakeGUISettingsFromFields() @@ -108,32 +135,51 @@ namespace grapher.Models.Serialized }; } - // Returns true when file settings are active - public bool Startup() + public bool TableActive() + { + return ActiveSettings.tables.x != null || ActiveSettings.tables.y != null; + } + + public void SetActiveFields(ManagedAccel activeAccel) { - if (RawAccelSettings.Exists()) + ActiveAccel = activeAccel; + ActiveSettings = activeAccel.Settings; + } + + private DriverSettings InitUserSettings() + { + var path = Constants.DefaultSettingsFileName; + if (File.Exists(path)) { try { - RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); - UpdateFieldsFromGUISettings(); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) + DriverSettings settings = RaConvert.Settings(File.ReadAllText(path)); + + if (!GuiSettings.AutoWriteToDriverOnStartup || + TableActive() || + TryActivate(settings).Empty()) { - TryUpdateAccel(RawAccelSettings.AccelerationSettings); + return settings; } - return RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; + } catch (JsonException e) { - Console.WriteLine($"bad settings: {e}"); + System.Diagnostics.Debug.WriteLine($"bad settings: {e}"); } } - RawAccelSettings = new RawAccelSettings( - ManagedAccel.GetActive().Settings, - MakeGUISettingsFromFields()); - RawAccelSettings.Save(); - return true; + if (!TableActive()) + { + File.WriteAllText(path, RaConvert.Settings(ActiveSettings.baseSettings)); + return ActiveSettings.baseSettings; + } + else + { + var defaultSettings = new DriverSettings(); + File.WriteAllText(path, RaConvert.Settings(defaultSettings)); + return defaultSettings; + } } #endregion Methods -- cgit v1.2.3 From db593584edb93b053396259db4c4acbeee0ee9e6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 22:41:16 -0700 Subject: LUT GUI fixes --- grapher/Models/AccelGUIFactory.cs | 10 ++++++---- grapher/Models/Options/AccelTypeOptions.cs | 2 +- grapher/Models/Options/TextOption.cs | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index c8446f0..e3a16b6 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -85,7 +85,8 @@ namespace grapher.Models Label limitLabelY, Label expLabelX, Label expLabelY, - Label lutTextLabel, + Label lutTextLabelX, + Label lutTextLabelY, Label constantThreeLabelX, Label constantThreeLabelY, Label activeValueTitleX, @@ -333,7 +334,8 @@ namespace grapher.Models legacyCapToolStripMenuItem, capY); - var lutText = new TextOption(lutTextLabel); + var lutTextX = new TextOption(lutTextLabelX); + var lutTextY = new TextOption(lutTextLabelY); var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, @@ -345,7 +347,7 @@ namespace grapher.Models limitX, exponentX, midpointX, - lutText, + lutTextX, writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -359,7 +361,7 @@ namespace grapher.Models limitY, exponentY, midpointY, - lutText, + lutTextY, writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 556f969..68eccf5 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -20,8 +20,8 @@ namespace grapher new JumpLayout(), new PowerLayout(), new MotivityLayout(), - new OffLayout(), new LUTLayout(), + new OffLayout(), }.ToDictionary(k => k.Name); public static readonly AccelArgs DefaultArgs = new DriverSettings().args.x; diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs index bbdedca..292b805 100644 --- a/grapher/Models/Options/TextOption.cs +++ b/grapher/Models/Options/TextOption.cs @@ -14,6 +14,9 @@ namespace grapher.Models.Options public TextOption(Label label) { Label = label; + Label.AutoSize = false; + Label.Width = 150; + Label.Height = 100; } #endregion Constructors -- cgit v1.2.3 From 019665015ab30893209ab49fea352405b144f0f8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 23:36:26 -0700 Subject: Add gain switch --- grapher/Models/AccelGUIFactory.cs | 6 +++ grapher/Models/Options/AccelTypeOptions.cs | 28 +++++++++++ grapher/Models/Options/CheckBoxOption.cs | 81 ++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 grapher/Models/Options/CheckBoxOption.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index e3a16b6..6e03293 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -68,6 +68,8 @@ namespace grapher.Models CheckBox fakeBox, CheckBox wholeCheckBox, CheckBox byComponentCheckBox, + CheckBox gainSwitchX, + CheckBox gainSwitchY, Label lockXYLabel, Label sensitivityLabel, Label rotationLabel, @@ -336,9 +338,12 @@ namespace grapher.Models var lutTextX = new TextOption(lutTextLabelX); var lutTextY = new TextOption(lutTextLabelY); + var gainSwitchOptionX = new CheckBoxOption(gainSwitchX); + var gainSwitchOptionY = new CheckBoxOption(gainSwitchY); var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, + gainSwitchOptionX, accelerationX, scaleX, capOptionsX, @@ -353,6 +358,7 @@ namespace grapher.Models var accelerationOptionsY = new AccelTypeOptions( accelTypeDropY, + gainSwitchOptionY, accelerationY, scaleY, capOptionsY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 68eccf5..d29f6a8 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -32,6 +32,7 @@ namespace grapher public AccelTypeOptions( ComboBox accelDropdown, + CheckBoxOption gainSwitch, Option acceleration, Option scale, CapOptions cap, @@ -49,6 +50,7 @@ namespace grapher AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); + GainSwitch = gainSwitch; Acceleration = acceleration; Scale = scale; Cap = cap; @@ -107,6 +109,8 @@ namespace grapher public TextOption LutText { get; } + public CheckBoxOption GainSwitch { get; } + public override int Top { get @@ -172,6 +176,7 @@ namespace grapher AccelDropdown.Hide(); AccelTypeActiveValue.Hide(); + GainSwitch.Hide(); Acceleration.Hide(); Scale.Hide(); Cap.Hide(); @@ -180,6 +185,7 @@ namespace grapher Limit.Hide(); Exponent.Hide(); Midpoint.Hide(); + LutText.Hide(); } public void Show() @@ -234,6 +240,27 @@ namespace grapher public void SetArgs(ref AccelArgs args) { + args.mode = (AccelMode)AccelerationType.Index; + if (Acceleration.Visible) + { + if (args.mode == AccelMode.natural) + { + args.accelNatural = Acceleration.Field.Data; + } + else if (args.mode == AccelMode.motivity) + { + args.accelMotivity = Acceleration.Field.Data; + } + else + { + args.accelClassic = Acceleration.Field.Data; + } + + args.smooth = Acceleration.Field.Data; + } + + args.legacy = !GainSwitch.CheckBox.Checked; + if (Scale.Visible) args.scale = Scale.Field.Data; if (Cap.Visible) args.cap = Cap.SensitivityCap; if (Limit.Visible) args.limit = Limit.Field.Data; @@ -284,6 +311,7 @@ namespace grapher } AccelerationType.Layout( + GainSwitch, Acceleration, Scale, Cap, diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs new file mode 100644 index 0000000..43757b4 --- /dev/null +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -0,0 +1,81 @@ +using System.Windows.Forms; + +namespace grapher.Models.Options +{ + public class CheckBoxOption : OptionBase + { + public CheckBoxOption(CheckBox checkBox) + { + CheckBox = checkBox; + } + + public CheckBox CheckBox { get; } + + public override bool Visible + { + get + { + return CheckBox.Visible; + } + } + + public override int Left + { + get + { + return CheckBox.Left; + } + set + { + CheckBox.Left = value; + } + } + + public override int Height + { + get + { + return CheckBox.Height; + } + } + + public override int Top + { + get + { + return CheckBox.Top; + } + set + { + CheckBox.Top = value; + } + } + + public override int Width + { + get + { + return CheckBox.Width; + } + set + { + CheckBox.Width = value; + } + } + + public override void AlignActiveValues() + { + } + + public override void Hide() + { + CheckBox.Hide(); + } + + public override void Show(string Name) + { + CheckBox.Show(); + CheckBox.Name = Name; + } + } +} -- cgit v1.2.3 From ce0cf42d8b7b379a091fee586dd60db1cabf4ab9 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 23:41:23 -0700 Subject: Correctly align gain switch --- grapher/Models/Options/AccelTypeOptions.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index d29f6a8..ded9ac5 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -65,6 +65,7 @@ namespace grapher AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; + GainSwitch.Left = Acceleration.Field.Left; Layout("Off"); ShowingDefault = true; -- cgit v1.2.3 From aba8e7757da8d2a542415257ac845f40f28f78a0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 5 Apr 2021 23:52:46 -0700 Subject: Resize vertically for correctness --- grapher/Models/AccelGUIFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 6e03293..de2d99c 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -394,7 +394,7 @@ namespace grapher.Models range, wholeCheckBox, byComponentCheckBox, - 260); + Constants.DirectionalityVerticalOffset); var applyOptions = new ApplyOptions( byComponentXYLock, -- cgit v1.2.3 From 399aaf96f863029206fc672a1dc4b556ed456c58 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 00:42:58 -0700 Subject: Fix checkbox not snapping --- grapher/Models/Options/AccelTypeOptions.cs | 2 +- grapher/Models/Options/CheckBoxOption.cs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index ded9ac5..851c44d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -308,7 +308,7 @@ namespace grapher { if (top < 0) { - top = Acceleration.Top; + top = GainSwitch.Top; } AccelerationType.Layout( diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs index 43757b4..83b2d7a 100644 --- a/grapher/Models/Options/CheckBoxOption.cs +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -7,6 +7,7 @@ namespace grapher.Models.Options public CheckBoxOption(CheckBox checkBox) { CheckBox = checkBox; + Show(string.Empty); } public CheckBox CheckBox { get; } @@ -15,7 +16,7 @@ namespace grapher.Models.Options { get { - return CheckBox.Visible; + return CheckBox.Visible || ShouldShow; } } @@ -63,6 +64,13 @@ namespace grapher.Models.Options } } + /// + /// For some reason, setting CheckBox.Show() does not result in visible not being true on GUI startup. + /// This is inconsistent with the other options, which do. + /// Keep this bool for allowing Visible to still be the signal for option snapping. + /// + private bool ShouldShow { get; set; } + public override void AlignActiveValues() { } @@ -70,11 +78,15 @@ namespace grapher.Models.Options public override void Hide() { CheckBox.Hide(); + ShouldShow = false; + CheckBox.Enabled = false; } public override void Show(string Name) { CheckBox.Show(); + ShouldShow = true; + CheckBox.Enabled = true; CheckBox.Name = Name; } } -- cgit v1.2.3 From 5b519e7f8614953263d3c47690ecec0b8f07eb17 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 17:55:57 -0700 Subject: Remove cap and offset style switches --- grapher/Models/AccelGUIFactory.cs | 31 ++++-------------------------- grapher/Models/Options/AccelTypeOptions.cs | 14 +++++++------- 2 files changed, 11 insertions(+), 34 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index de2d99c..6bfc510 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -29,10 +29,6 @@ namespace grapher.Models ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, ToolStripMenuItem showLastMouseMoveMenuItem, - ToolStripMenuItem velocityGainCapToolStripMenuItem, - ToolStripMenuItem legacyCapToolStripMenuItem, - ToolStripMenuItem gainOffsetToolStripMenuItem, - ToolStripMenuItem legacyOffsetToolStripMenuItem, ToolStripMenuItem autoWriteMenuItem, ToolStripMenuItem useSpecificDeviceMenuItem, ToolStripMenuItem scaleMenuItem, @@ -226,16 +222,6 @@ namespace grapher.Models new ActiveValueLabel(offsetActiveLabelY, activeValueTitleY), "Offset"); - var offsetOptionsX = new OffsetOptions( - gainOffsetToolStripMenuItem, - legacyOffsetToolStripMenuItem, - offsetX); - - var offsetOptionsY = new OffsetOptions( - gainOffsetToolStripMenuItem, - legacyOffsetToolStripMenuItem, - offsetY); - var accelerationX = new Option( new Field(accelerationBoxX, form, 0), constantOneLabelX, @@ -326,15 +312,6 @@ namespace grapher.Models new ActiveValueLabel(rangeActiveValueY, direcionalityActiveValueTitle)), false); - var capOptionsX = new CapOptions( - velocityGainCapToolStripMenuItem, - legacyCapToolStripMenuItem, - capX); - - var capOptionsY = new CapOptions( - velocityGainCapToolStripMenuItem, - legacyCapToolStripMenuItem, - capY); var lutTextX = new TextOption(lutTextLabelX); var lutTextY = new TextOption(lutTextLabelY); @@ -346,9 +323,9 @@ namespace grapher.Models gainSwitchOptionX, accelerationX, scaleX, - capOptionsX, + capX, weightX, - offsetOptionsX, + offsetX, limitX, exponentX, midpointX, @@ -361,9 +338,9 @@ namespace grapher.Models gainSwitchOptionY, accelerationY, scaleY, - capOptionsY, + capY, weightY, - offsetOptionsY, + offsetY, limitY, exponentY, midpointY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 851c44d..60bb53d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -35,9 +35,9 @@ namespace grapher CheckBoxOption gainSwitch, Option acceleration, Option scale, - CapOptions cap, + Option cap, Option weight, - OffsetOptions offset, + Option offset, Option limit, Option exponent, Option midpoint, @@ -96,11 +96,11 @@ namespace grapher public Option Scale { get; } - public CapOptions Cap { get; } + public Option Cap { get; } public Option Weight { get; } - public OffsetOptions Offset { get; } + public Option Offset { get; } public Option Limit { get; } @@ -208,7 +208,7 @@ namespace grapher AccelDropdown.SelectedIndex = AccelerationType.Index; Weight.SetActiveValue(args.weight); - Cap.SetActiveValues(args.cap, args.legacy); + Cap.SetActiveValue(args.cap); Offset.SetActiveValue(args.offset); Acceleration.SetActiveValue(AccelerationParameterFromArgs(args)); Scale.SetActiveValue(args.scale); @@ -263,10 +263,10 @@ namespace grapher args.legacy = !GainSwitch.CheckBox.Checked; if (Scale.Visible) args.scale = Scale.Field.Data; - if (Cap.Visible) args.cap = Cap.SensitivityCap; + if (Cap.Visible) args.cap = Cap.Field.Data; if (Limit.Visible) args.limit = Limit.Field.Data; if (Exponent.Visible) args.exponent = Exponent.Field.Data; - if (Offset.Visible) args.offset = Offset.Offset; + if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; } -- cgit v1.2.3 From 758de1d236f591de1d8b2fba4c58bfd8d5bbd26e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 18:04:28 -0700 Subject: Rename accelMotivity to growthRate --- grapher/Models/Options/AccelTypeOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 60bb53d..768d17d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -250,7 +250,7 @@ namespace grapher } else if (args.mode == AccelMode.motivity) { - args.accelMotivity = Acceleration.Field.Data; + args.growthRate = Acceleration.Field.Data; } else { @@ -345,7 +345,7 @@ namespace grapher { if (args.mode == AccelMode.motivity) { - return args.accelMotivity; + return args.growthRate; } else if (args.mode == AccelMode.natural) { -- cgit v1.2.3 From 258fcd3bd236a787f07d7dac2049be524d86cb75 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Tue, 6 Apr 2021 23:11:20 -0700 Subject: Fix natural legacy algorithm, rename accelNatural to decayRate --- grapher/Models/Options/AccelTypeOptions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 768d17d..a271ea4 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -246,7 +246,7 @@ namespace grapher { if (args.mode == AccelMode.natural) { - args.accelNatural = Acceleration.Field.Data; + args.decayRate = Acceleration.Field.Data; } else if (args.mode == AccelMode.motivity) { @@ -349,7 +349,7 @@ namespace grapher } else if (args.mode == AccelMode.natural) { - return args.accelNatural; + return args.decayRate; } else { -- cgit v1.2.3 From 5e858b059436375ed1c17f7dc1b3e47a7e8e1d5d Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 7 Apr 2021 01:05:59 -0700 Subject: Add active value labels for gain switch --- grapher/Models/AccelGUI.cs | 1 + grapher/Models/AccelGUIFactory.cs | 10 ++++++++-- grapher/Models/Options/AccelTypeOptions.cs | 5 ++++- grapher/Models/Options/CheckBoxOption.cs | 18 +++++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 9ed2cb9..ec570d3 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -154,6 +154,7 @@ namespace grapher { UpdateGraph(); UpdateInputManagers(); + UpdateShownActiveValues(Settings.UserSettings); } public void RefreshUser() diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 6bfc510..73be939 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -110,6 +110,8 @@ namespace grapher.Models Label midpointActiveLabelY, Label accelTypeActiveLabelX, Label accelTypeActiveLabelY, + Label gainSwitchActiveLabelX, + Label gainSwitchActiveLabelY, Label optionSetXTitle, Label optionSetYTitle, Label mouseLabel, @@ -315,8 +317,12 @@ namespace grapher.Models var lutTextX = new TextOption(lutTextLabelX); var lutTextY = new TextOption(lutTextLabelY); - var gainSwitchOptionX = new CheckBoxOption(gainSwitchX); - var gainSwitchOptionY = new CheckBoxOption(gainSwitchY); + var gainSwitchOptionX = new CheckBoxOption( + gainSwitchX, + new ActiveValueLabel(gainSwitchActiveLabelX, activeValueTitleX)); + var gainSwitchOptionY = new CheckBoxOption( + gainSwitchY, + new ActiveValueLabel(gainSwitchActiveLabelY, activeValueTitleY)); var accelerationOptionsX = new AccelTypeOptions( accelTypeDropX, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index a271ea4..b12ad8a 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -205,8 +205,10 @@ namespace grapher { AccelerationType = AccelTypeFromSettings(args); AccelTypeActiveValue.SetValue(AccelerationType.Name); - AccelDropdown.SelectedIndex = AccelerationType.Index; + // Add one to include linear, which is not represented separately in the config + AccelDropdown.SelectedIndex = AccelerationType.Index + 1; + GainSwitch.SetActiveValue(args.legacy); Weight.SetActiveValue(args.weight); Cap.SetActiveValue(args.cap); Offset.SetActiveValue(args.offset); @@ -281,6 +283,7 @@ namespace grapher public override void AlignActiveValues() { AccelTypeActiveValue.Align(); + GainSwitch.AlignActiveValues(); Acceleration.AlignActiveValues(); Scale.AlignActiveValues(); Cap.AlignActiveValues(); diff --git a/grapher/Models/Options/CheckBoxOption.cs b/grapher/Models/Options/CheckBoxOption.cs index 83b2d7a..abf96d3 100644 --- a/grapher/Models/Options/CheckBoxOption.cs +++ b/grapher/Models/Options/CheckBoxOption.cs @@ -4,14 +4,19 @@ namespace grapher.Models.Options { public class CheckBoxOption : OptionBase { - public CheckBoxOption(CheckBox checkBox) + public CheckBoxOption( + CheckBox checkBox, + ActiveValueLabel activeValueLabel) { CheckBox = checkBox; + ActiveValueLabel = activeValueLabel; Show(string.Empty); } public CheckBox CheckBox { get; } + public ActiveValueLabel ActiveValueLabel { get; } + public override bool Visible { get @@ -49,6 +54,7 @@ namespace grapher.Models.Options set { CheckBox.Top = value; + ActiveValueLabel.Top = value; } } @@ -73,6 +79,7 @@ namespace grapher.Models.Options public override void AlignActiveValues() { + ActiveValueLabel.Align(); } public override void Hide() @@ -80,6 +87,7 @@ namespace grapher.Models.Options CheckBox.Hide(); ShouldShow = false; CheckBox.Enabled = false; + ActiveValueLabel.Hide(); } public override void Show(string Name) @@ -88,6 +96,14 @@ namespace grapher.Models.Options ShouldShow = true; CheckBox.Enabled = true; CheckBox.Name = Name; + ActiveValueLabel.Show(); + } + + public void SetActiveValue(bool legacy) + { + CheckBox.Checked = !legacy; + var activeValueString = legacy ? "Legacy" : "Gain"; + ActiveValueLabel.SetValue(activeValueString); } } } -- cgit v1.2.3 From a6926be0e911b7b7637861866f41c3bca31a87a3 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 13 Apr 2021 23:59:21 -0400 Subject: move arbitrary input into settings separate arbitrary mode from spaced modes, arbitrary now deserializes from default settings file --- grapher/Models/AccelGUI.cs | 23 +++--- grapher/Models/Options/AccelOptionSet.cs | 9 +-- grapher/Models/Options/AccelTypeOptions.cs | 121 +++++++++++++++-------------- grapher/Models/Options/ApplyOptions.cs | 57 ++++---------- 4 files changed, 92 insertions(+), 118 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index ec570d3..324dcb1 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -114,20 +114,19 @@ namespace grapher public void UpdateActiveSettingsFromFields() { - var settings = new DriverSettings + var settings = new DriverSettings(); + + settings.rotation = ApplyOptions.Rotation.Field.Data; + settings.sensitivity = new Vec2 { - rotation = ApplyOptions.Rotation.Field.Data, - sensitivity = new Vec2 - { - x = ApplyOptions.Sensitivity.Fields.X, - y = ApplyOptions.Sensitivity.Fields.Y - }, - combineMagnitudes = ApplyOptions.IsWhole, - args = ApplyOptions.GetArgs(), - domainArgs = ApplyOptions.Directionality.GetDomainArgs(), - rangeXY = ApplyOptions.Directionality.GetRangeXY(), - deviceID = DeviceIDManager.ID, + x = ApplyOptions.Sensitivity.Fields.X, + y = ApplyOptions.Sensitivity.Fields.Y }; + settings.combineMagnitudes = ApplyOptions.IsWhole; + ApplyOptions.SetArgs(ref settings.args); + settings.domainArgs = ApplyOptions.Directionality.GetDomainArgs(); + settings.rangeXY = ApplyOptions.Directionality.GetRangeXY(); + settings.deviceID = DeviceIDManager.ID; Settings.SetHiddenOptions(settings); diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index f4c08a1..8b957f1 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -103,16 +103,11 @@ namespace grapher.Models.Options Options.SetArgs(ref args); } - public AccelArgs GenerateArgs() - { - return Options.GenerateArgs(); - } - - public void SetActiveValues(AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { if (!Hidden) { - Options.SetActiveValues(args); + Options.SetActiveValues(ref args); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index b12ad8a..62a923d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -12,19 +12,15 @@ namespace grapher { #region Fields - public static readonly Dictionary AccelerationTypes = new List - { - new LinearLayout(), - new ClassicLayout(), - new NaturalLayout(), - new JumpLayout(), - new PowerLayout(), - new MotivityLayout(), - new LUTLayout(), - new OffLayout(), - }.ToDictionary(k => k.Name); - - public static readonly AccelArgs DefaultArgs = new DriverSettings().args.x; + public static readonly LayoutBase Linear = new LinearLayout(); + public static readonly LayoutBase Classic = new ClassicLayout(); + public static readonly LayoutBase Jump = new JumpLayout(); + public static readonly LayoutBase Natural = new NaturalLayout(); + public static readonly LayoutBase Motivity = new MotivityLayout(); + public static readonly LayoutBase Power = new PowerLayout(); + public static readonly LayoutBase LUT = new LUTLayout(); + public static readonly LayoutBase Off = new OffLayout(); + public static readonly LayoutBase Unsupported = new UnsupportedLayout(); #endregion Fields @@ -47,7 +43,19 @@ namespace grapher { AccelDropdown = accelDropdown; AccelDropdown.Items.Clear(); - AccelDropdown.Items.AddRange(AccelerationTypes.Keys.ToArray()); + AccelDropdown.Items.AddRange( + new LayoutBase[] + { + Linear, + Classic, + Jump, + Natural, + Motivity, + Power, + LUT, + Off + }); + AccelDropdown.SelectedIndexChanged += new System.EventHandler(OnIndexChanged); GainSwitch = gainSwitch; @@ -67,7 +75,8 @@ namespace grapher AccelTypeActiveValue.Height = AccelDropdown.Height; GainSwitch.Left = Acceleration.Field.Left; - Layout("Off"); + AccelerationType = Off; + Layout(); ShowingDefault = true; } @@ -80,16 +89,6 @@ namespace grapher public ComboBox AccelDropdown { get; } - public int AccelerationIndex - { - get - { - return AccelerationType.Index; - } - } - - public LayoutBase AccelerationType { get; private set; } - public ActiveValueLabel AccelTypeActiveValue { get; } public Option Acceleration { get; } @@ -112,6 +111,18 @@ namespace grapher public CheckBoxOption GainSwitch { get; } + public LayoutBase AccelerationType + { + get + { + return AccelDropdown.SelectedItem as LayoutBase; + } + private set + { + AccelDropdown.SelectedItem = value; + } + } + public override int Top { get @@ -201,18 +212,15 @@ namespace grapher Show(); } - public void SetActiveValues(AccelArgs args) + public void SetActiveValues(ref AccelArgs args) { - AccelerationType = AccelTypeFromSettings(args); + AccelerationType = AccelTypeFromSettings(ref args); AccelTypeActiveValue.SetValue(AccelerationType.Name); - // Add one to include linear, which is not represented separately in the config - AccelDropdown.SelectedIndex = AccelerationType.Index + 1; - GainSwitch.SetActiveValue(args.legacy); Weight.SetActiveValue(args.weight); Cap.SetActiveValue(args.cap); Offset.SetActiveValue(args.offset); - Acceleration.SetActiveValue(AccelerationParameterFromArgs(args)); + Acceleration.SetActiveValue(AccelerationParameterFromArgs(ref args)); Scale.SetActiveValue(args.scale); Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); @@ -243,7 +251,10 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - args.mode = (AccelMode)AccelerationType.Index; + if (AccelerationType == Unsupported) throw new NotImplementedException(); + + args.mode = AccelerationType.Mode; + if (Acceleration.Visible) { if (args.mode == AccelMode.natural) @@ -273,13 +284,6 @@ namespace grapher if (Weight.Visible) args.weight = Weight.Field.Data; } - public AccelArgs GenerateArgs() - { - AccelArgs args = new DriverSettings().args.x; - SetArgs(ref args); - return args; - } - public override void AlignActiveValues() { AccelTypeActiveValue.Align(); @@ -296,17 +300,10 @@ namespace grapher private void OnIndexChanged(object sender, EventArgs e) { - var accelerationTypeString = AccelDropdown.SelectedItem.ToString(); - Layout(accelerationTypeString, Beneath); + Layout(Beneath); ShowingDefault = false; } - private void Layout(string type, int top = -1) - { - AccelerationType = AccelerationTypes[type]; - Layout(top); - } - private void Layout(int top = -1) { if (top < 0) @@ -328,23 +325,31 @@ namespace grapher top); } - private LayoutBase AccelTypeFromSettings(AccelArgs args) - { - LayoutBase type; - if (args.mode == AccelMode.classic && args.exponent == 2) + private LayoutBase AccelTypeFromSettings(ref AccelArgs args) + { + if (args.spacedTableArgs.mode != SpacedTableMode.off) { - type = AccelerationTypes.Values.Where(t => string.Equals(t.Name, LinearLayout.LinearName)).FirstOrDefault(); + if (!AccelDropdown.Items.Contains(Unsupported)) + { + AccelDropdown.Items.Add(Unsupported); + } + + return Unsupported; } - else + + switch (args.mode) { - int index = (int)args.mode; - type = AccelerationTypes.Where(t => t.Value.Index == index).FirstOrDefault().Value; + case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.jump: return Jump; + case AccelMode.natural: return Natural; + case AccelMode.motivity: return Motivity; + case AccelMode.power: return Power; + case AccelMode.lut: return LUT; + default: return Off; } - - return type; } - private double AccelerationParameterFromArgs(AccelArgs args) + private double AccelerationParameterFromArgs(ref AccelArgs args) { if (args.mode == AccelMode.motivity) { diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 43a2da8..06854b8 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -81,55 +81,30 @@ namespace grapher.Models.Options #region Methods - public Vec2 GetModes() + public void SetArgs(ref Vec2 args) { - var xMode = (AccelMode)OptionSetX.Options.AccelerationIndex; + OptionSetX.SetArgs(ref args.x); - return new Vec2 + if (ByComponentVectorXYLock.Checked) { - x = xMode, - y = ByComponentVectorXYLock.Checked ? xMode : (AccelMode)OptionSetY.Options.AccelerationIndex - }; - } - - public Vec2 GetArgs() - { - var xArgs = OptionSetX.GenerateArgs(); - - return new Vec2 + OptionSetX.SetArgs(ref args.y); + } + else { - x = xArgs, - y = ByComponentVectorXYLock.Checked ? xArgs : OptionSetY.GenerateArgs() - }; - - } - - public void SetActiveValues( - double xSens, - double ySens, - double rotation, - AccelArgs xArgs, - AccelArgs yArgs, - bool isWhole) - { - Sensitivity.SetActiveValues(xSens, ySens); - Rotation.SetActiveValue(rotation); - OptionSetX.SetActiveValues(xArgs); - WholeVectorCheckBox.Checked = isWhole; - ByComponentVectorCheckBox.Checked = !isWhole; - ByComponentVectorXYLock.Checked = xArgs.Equals(yArgs); - OptionSetY.SetActiveValues(yArgs); + OptionSetY.SetArgs(ref args.y); + } } public void SetActiveValues(DriverSettings settings) { - SetActiveValues( - settings.sensitivity.x, - settings.sensitivity.y, - settings.rotation, - settings.args.x, - settings.args.y, - settings.combineMagnitudes); + Sensitivity.SetActiveValues(settings.sensitivity.x, settings.sensitivity.y); + Rotation.SetActiveValue(settings.rotation); + + WholeVectorCheckBox.Checked = settings.combineMagnitudes; + ByComponentVectorCheckBox.Checked = !settings.combineMagnitudes; + ByComponentVectorXYLock.Checked = settings.args.x.Equals(settings.args.y); + OptionSetX.SetActiveValues(ref settings.args.x); + OptionSetY.SetActiveValues(ref settings.args.y); Directionality.SetActiveValues(settings); -- cgit v1.2.3 From 0af5b1d23be9ecfb0134c957197cfd8f838b7998 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 25 Apr 2021 21:57:25 -0700 Subject: Fixed layout issues for LUT --- grapher/Models/Options/AccelTypeOptions.cs | 2 +- grapher/Models/Options/TextOption.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 62a923d..e79e767 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -215,7 +215,7 @@ namespace grapher public void SetActiveValues(ref AccelArgs args) { AccelerationType = AccelTypeFromSettings(ref args); - AccelTypeActiveValue.SetValue(AccelerationType.Name); + AccelTypeActiveValue.SetValue(AccelerationType.ActiveName); GainSwitch.SetActiveValue(args.legacy); Weight.SetActiveValue(args.weight); Cap.SetActiveValue(args.cap); diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs index 292b805..3c6f378 100644 --- a/grapher/Models/Options/TextOption.cs +++ b/grapher/Models/Options/TextOption.cs @@ -29,7 +29,7 @@ namespace grapher.Models.Options { get { - return Label.Visible; + return Label.Visible || ShouldShow; } } @@ -77,15 +77,22 @@ namespace grapher.Models.Options } } + private bool ShouldShow + { + get; set; + } + public override void Hide() { Label.Hide(); + ShouldShow = false; } public override void Show(string Name) { Label.Show(); Label.Text = Name; + ShouldShow = true; } public override void AlignActiveValues() -- cgit v1.2.3 From 0cf5ce3762926fa556418572e9661d79cbbaa240 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sun, 25 Apr 2021 23:05:44 -0700 Subject: Start of LUT points editing --- grapher/Models/AccelGUIFactory.cs | 5 + grapher/Models/Options/AccelTypeOptions.cs | 10 ++ grapher/Models/Options/LUT/LUTPanelOptions.cs | 136 ++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 grapher/Models/Options/LUT/LUTPanelOptions.cs (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 73be939..5035598 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -3,6 +3,7 @@ using grapher.Models.Devices; using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Options.Directionality; +using grapher.Models.Options.LUT; using grapher.Models.Serialized; using System; using System.Windows.Forms; @@ -66,6 +67,8 @@ namespace grapher.Models CheckBox byComponentCheckBox, CheckBox gainSwitchX, CheckBox gainSwitchY, + Panel lutPanelX, + Panel lutPanelY, Label lockXYLabel, Label sensitivityLabel, Label rotationLabel, @@ -336,6 +339,7 @@ namespace grapher.Models exponentX, midpointX, lutTextX, + new LUTPanelOptions(lutPanelX), writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -351,6 +355,7 @@ namespace grapher.Models exponentY, midpointY, lutTextY, + new LUTPanelOptions(lutPanelY), writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index e79e767..74e748a 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -1,5 +1,6 @@ using grapher.Layouts; using grapher.Models.Options; +using grapher.Models.Options.LUT; using grapher.Models.Serialized; using System; using System.Collections.Generic; @@ -38,6 +39,7 @@ namespace grapher Option exponent, Option midpoint, TextOption lutText, + LUTPanelOptions lutPanelOptions, Button writeButton, ActiveValueLabel accelTypeActiveValue) { @@ -70,11 +72,15 @@ namespace grapher WriteButton = writeButton; AccelTypeActiveValue = accelTypeActiveValue; LutText = lutText; + LutPanel = lutPanelOptions; AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; GainSwitch.Left = Acceleration.Field.Left; + LutPanel.Left = AccelDropdown.Left; + LutPanel.Width = AccelDropdown.Width + AccelTypeActiveValue.Width; + AccelerationType = Off; Layout(); ShowingDefault = true; @@ -111,6 +117,8 @@ namespace grapher public CheckBoxOption GainSwitch { get; } + public LUTPanelOptions LutPanel { get; } + public LayoutBase AccelerationType { get @@ -198,6 +206,7 @@ namespace grapher Exponent.Hide(); Midpoint.Hide(); LutText.Hide(); + LutPanel.Hide(); } public void Show() @@ -322,6 +331,7 @@ namespace grapher Exponent, Midpoint, LutText, + LutPanel, top); } diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs new file mode 100644 index 0000000..a6b894b --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPanelOptions : OptionBase + { + public const string LUTPanelTitle = "LookupTable Points"; + public const string ApplyAsSensTitle = "Apply as sensitivity"; + public const string ApplyAsVelocityTitle = "Apply as velocity"; + public const int TitlePadding = 5; + public const int PanelHeight = 40; + + public LUTPanelOptions(Panel panel) + { + Panel = panel; + Panel.Height = PanelHeight; + Panel.Paint += Panel_Paint; + + Title = new Label(); + Title.Text = LUTPanelTitle; + ApplyAsSens = new CheckBox(); + ApplyAsSens.Text = ApplyAsSensTitle; + ApplyAsVelocity = new CheckBox(); + ApplyAsVelocity.Text = ApplyAsVelocityTitle; + + Panel.Controls.Add(Title); + Title.Left = TitlePadding; + Title.Top = TitlePadding; + } + + public Panel Panel + { + get; + } + + public Label Title + { + get; + } + + public CheckBox ApplyAsSens + { + get; + } + + public CheckBox ApplyAsVelocity + { + get; + } + + public override bool Visible + { + get + { + return Panel.Visible || ShouldShow; + } + } + + public override int Top + { + get + { + return Panel.Top; + } + set + { + Panel.Top = value; + } + } + + public override int Height + { + get + { + return Panel.Height; + } + } + + public override int Left + { + get + { + return Panel.Left; + } + set + { + Panel.Left = value; + } + } + + public override int Width + { + get + { + return Panel.Width; + } + set + { + Panel.Width = value; + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + Panel.Hide(); + ShouldShow = false; + } + + public override void Show(string name) + { + Panel.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + // Nothing to do here. + } + + private void Panel_Paint(object sender, PaintEventArgs e) + { + Color col = Color.DarkGray; + ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; + int thickness = 2; + ControlPaint.DrawBorder(e.Graphics, Panel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); + } + } +} -- cgit v1.2.3 From ff478cda3d57457ddc205067779c335e39e9cf59 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 9 Jun 2021 16:11:18 -0700 Subject: added point option --- grapher/Models/Options/LUT/LUTPointOption.cs | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 grapher/Models/Options/LUT/LUTPointOption.cs (limited to 'grapher/Models') diff --git a/grapher/Models/Options/LUT/LUTPointOption.cs b/grapher/Models/Options/LUT/LUTPointOption.cs new file mode 100644 index 0000000..6afee4f --- /dev/null +++ b/grapher/Models/Options/LUT/LUTPointOption.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LUTPointOption + { + public LUTPointOption(Form form) + { + FieldX = new Field(new System.Windows.Forms.TextBox(), form, 0); + FieldY = new Field(new System.Windows.Forms.TextBox(), form, 0); + } + + public double X { get => FieldX.Data; } + + public double Y { get => FieldY.Data; } + + public int Top + { + get + { + return FieldX.Top; + } + set + { + FieldX.Top = value; + FieldY.Top = value; + } + } + + private Field FieldX { get; } + + private Field FieldY { get; } + } +} -- cgit v1.2.3 From 08e3b9e32b76bbd74b8878e8afed56ad4689e8c4 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Mon, 28 Jun 2021 23:26:49 -0700 Subject: Fix high DPI issue --- grapher/Models/Calculations/AccelCalculator.cs | 170 ++++++++++++++++++------- grapher/Models/Options/LUT/LUTPanelOptions.cs | 41 +++--- 2 files changed, 143 insertions(+), 68 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index d641873..574f55a 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -108,7 +108,7 @@ namespace grapher.Models.Calculations } var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); - var outMagnitude = Velocity(output.Item1, output.Item2, simulatedInputDatum.time); + var outMagnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(outMagnitude - lastOutputMagnitude, 5); @@ -133,8 +133,8 @@ namespace grapher.Models.Calculations logIndex++; } - var ratio = outMagnitude / simulatedInputDatum.velocity; - var slope = inDiff > 0 ? outDiff / inDiff : starter; + var ratio = DecimalCheck(outMagnitude / simulatedInputDatum.velocity); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : starter); if (slope < lastSlope) { @@ -200,9 +200,6 @@ namespace grapher.Models.Calculations double maxSlope = 0.0; double minSlope = Double.MaxValue; - - Sensitivity = GetSens(ref settings); - int angleIndex = 0; foreach (var simulatedInputDataAngle in simulatedInputData) @@ -223,7 +220,7 @@ namespace grapher.Models.Calculations } var output = accel.Accelerate(simulatedInputDatum.x, simulatedInputDatum.y, simulatedInputDatum.time); - var magnitude = Velocity(output.Item1, output.Item2, simulatedInputDatum.time); + var magnitude = DecimalCheck(Velocity(output.Item1, output.Item2, simulatedInputDatum.time)); var inDiff = Math.Round(simulatedInputDatum.velocity - lastInputMagnitude, 5); var outDiff = Math.Round(magnitude - lastOutputMagnitude, 5); @@ -248,10 +245,15 @@ namespace grapher.Models.Calculations logIndex++; } - var ratio = magnitude / simulatedInputDatum.velocity; - var slope = inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x; + var ratio = DecimalCheck(magnitude / simulatedInputDatum.velocity); + var slope = DecimalCheck(inDiff > 0 ? outDiff / inDiff : settings.sensitivity.x); bool indexToMeasureExtrema = (angleIndex == 0) || (angleIndex == (Constants.AngleDivisions - 1)); + + if (angleIndex == 0 && double.IsNaN(ratio)) + { + Console.WriteLine("oops"); + } if (indexToMeasureExtrema && (ratio > maxRatio)) { @@ -322,10 +324,9 @@ namespace grapher.Models.Calculations mouseInputData.x = ceilX; mouseInputData.y = ceilY; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceilX, ceilY, mouseInputData.time)); mouseInputData.angle = Math.Atan2(ceilY, ceilX); magnitudes.Add(mouseInputData); - } for (double i = 5; i < MaxVelocity; i+=Increment) @@ -336,7 +337,7 @@ namespace grapher.Models.Calculations mouseInputData.x = ceil; mouseInputData.y = 0; mouseInputData.time = MeasurementTime * timeFactor; - mouseInputData.velocity = Velocity(ceil, 0, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceil, 0, mouseInputData.time)); mouseInputData.angle = Math.Atan2(ceil, 0); magnitudes.Add(mouseInputData); } @@ -371,7 +372,7 @@ namespace grapher.Models.Calculations mouseInputData.x = ceil; mouseInputData.y = 0; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(ceil, 0, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(ceil, 0, mouseInputData.time)); mouseInputData.angle = 0; magnitudes.Add(mouseInputData); } @@ -391,7 +392,7 @@ namespace grapher.Models.Calculations mouseInputData.x = 0; mouseInputData.y = ceil; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(0, ceil, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(0, ceil, mouseInputData.time)); mouseInputData.angle = 0; magnitudes.Add(mouseInputData); } @@ -404,7 +405,7 @@ namespace grapher.Models.Calculations mouseInputData.x = 0; mouseInputData.y = ceil; mouseInputData.time = MeasurementTime*timeFactor; - mouseInputData.velocity = Velocity(0, ceil, mouseInputData.time); + mouseInputData.velocity = DecimalCheck(Velocity(0, ceil, mouseInputData.time)); mouseInputData.angle = Math.PI / 2; magnitudes.Add(mouseInputData); } @@ -422,39 +423,12 @@ namespace grapher.Models.Calculations foreach (var slowMoveMagnitude in SlowMovements) { - var slowMoveX = Math.Round(slowMoveMagnitude * Math.Cos(angle), 4); - var slowMoveY = Math.Round(slowMoveMagnitude * Math.Sin(angle), 4); - var ceilX = (int)Math.Round(slowMoveX*90); - var ceilY = (int)Math.Round(slowMoveY*90); - var ceilMagnitude = Magnitude(ceilX, ceilY); - var timeFactor = ceilMagnitude / slowMoveMagnitude; - - SimulatedMouseInput mouseInputData; - mouseInputData.x = ceilX; - mouseInputData.y = ceilY; - mouseInputData.time = timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, timeFactor); - mouseInputData.angle = angle; - magnitudes.Add(mouseInputData); + magnitudes.Add(SimulateAngledInput(angle, slowMoveMagnitude)); } for (double magnitude = 5; magnitude < MaxVelocity; magnitude+=Increment) { - var slowMoveX = Math.Round(magnitude * Math.Cos(angle), 4); - var slowMoveY = Math.Round(magnitude * Math.Sin(angle), 4); - var ratio = slowMoveX > 0.0 ? slowMoveY / slowMoveX : 90; - var ceilX = (int)Math.Round(slowMoveX*90); - var ceilY = (int)Math.Round(slowMoveY*ratio); - var ceilMagnitude = Magnitude(ceilX, ceilY); - var timeFactor = ceilMagnitude / magnitude; - - SimulatedMouseInput mouseInputData; - mouseInputData.x = ceilX; - mouseInputData.y = ceilY; - mouseInputData.time = timeFactor; - mouseInputData.velocity = Velocity(ceilX, ceilY, mouseInputData.time); - mouseInputData.angle = angle; - magnitudes.Add(mouseInputData); + magnitudes.Add(SimulateAngledInput(angle, magnitude)); } magnitudesByAngle.Add(magnitudes.AsReadOnly()); @@ -465,11 +439,31 @@ namespace grapher.Models.Calculations public static double Magnitude(int x, int y) { + if (x == 0) + { + return Math.Abs(y); + } + + if (y == 0) + { + return Math.Abs(x); + } + return Math.Sqrt(x * x + y * y); } public static double Magnitude(double x, double y) { + if (x == 0) + { + return Math.Abs(y); + } + + if (y == 0) + { + return Math.Abs(x); + } + return Math.Sqrt(x * x + y * y); } @@ -519,6 +513,94 @@ namespace grapher.Models.Calculations SimulatedDirectionalInput = GetSimulatedDirectionalInput(); } + private static readonly double MinChartAllowedValue = Convert.ToDouble(Decimal.MinValue) / 10; + private static readonly double MaxChartAllowedValue = Convert.ToDouble(Decimal.MaxValue) / 10; + + private double DecimalCheck(double value) + { + if (value < MinChartAllowedValue) + { + return MinChartAllowedValue; + } + + if (value > MaxChartAllowedValue) + { + return MaxChartAllowedValue; + } + + return value; + } + + private SimulatedMouseInput SimulateAngledInput(double angle, double magnitude) + { + SimulatedMouseInput mouseInputData; + + var moveX = Math.Round(magnitude * Math.Cos(angle), 4); + var moveY = Math.Round(magnitude * Math.Sin(angle), 4); + + if (moveX == 0) + { + mouseInputData.x = 0; + mouseInputData.y = (int)Math.Ceiling(moveY); + mouseInputData.time = mouseInputData.y / moveY; + } + else if (moveY == 0) + { + mouseInputData.x = (int)Math.Ceiling(moveX); + mouseInputData.y = 0; + mouseInputData.time = mouseInputData.x / moveX; + } + else + { + var ratio = moveY / moveX; + int ceilX = 0; + int ceilY = 0; + double biggerX = 0; + double biggerY = 0; + double roundedBiggerX = 0; + double roundedBiggerY = 0; + double roundedRatio = -1; + double factor = 10; + + while (Math.Abs(roundedRatio - ratio) > 0.01 && + biggerX < 25000 && + biggerY < 25000) + { + roundedBiggerX = Math.Floor(biggerX); + roundedBiggerY = Math.Floor(biggerY); + ceilX = Convert.ToInt32(roundedBiggerX); + ceilY = Convert.ToInt32(roundedBiggerY); + roundedRatio = ceilX > 0 ? ceilY / ceilX : -1; + biggerX = moveX * factor; + biggerY = moveY * factor; + factor *= 10; + } + + var ceilMagnitude = Magnitude(ceilX, ceilY); + var timeFactor = ceilMagnitude / magnitude; + + mouseInputData.x = ceilX; + mouseInputData.y = ceilY; + mouseInputData.time = timeFactor; + + if (mouseInputData.x == 1 && mouseInputData.time == 1) + { + Console.WriteLine("Oops"); + } + + } + + mouseInputData.velocity = DecimalCheck(Velocity(mouseInputData.x, mouseInputData.y, mouseInputData.time)); + + if (double.IsNaN(mouseInputData.velocity)) + { + Console.WriteLine("oopsie"); + } + + mouseInputData.angle = angle; + return mouseInputData; + } + #endregion Methods } } diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index a6b894b..e723dcd 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -10,31 +10,24 @@ namespace grapher.Models.Options.LUT { public class LUTPanelOptions : OptionBase { - public const string LUTPanelTitle = "LookupTable Points"; public const string ApplyAsSensTitle = "Apply as sensitivity"; public const string ApplyAsVelocityTitle = "Apply as velocity"; public const int TitlePadding = 5; - public const int PanelHeight = 40; + public const int PanelHeight = 100; - public LUTPanelOptions(Panel panel) + public LUTPanelOptions(Panel activePanel) { - Panel = panel; - Panel.Height = PanelHeight; - Panel.Paint += Panel_Paint; + ActivePanel = activePanel; + ActivePanel.Height = PanelHeight; + ActivePanel.Paint += Panel_Paint; - Title = new Label(); - Title.Text = LUTPanelTitle; ApplyAsSens = new CheckBox(); ApplyAsSens.Text = ApplyAsSensTitle; ApplyAsVelocity = new CheckBox(); ApplyAsVelocity.Text = ApplyAsVelocityTitle; - - Panel.Controls.Add(Title); - Title.Left = TitlePadding; - Title.Top = TitlePadding; } - public Panel Panel + public Panel ActivePanel { get; } @@ -58,7 +51,7 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Visible || ShouldShow; + return ActivePanel.Visible || ShouldShow; } } @@ -66,11 +59,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Top; + return ActivePanel.Top; } set { - Panel.Top = value; + ActivePanel.Top = value; } } @@ -78,7 +71,7 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Height; + return ActivePanel.Height; } } @@ -86,11 +79,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Left; + return ActivePanel.Left; } set { - Panel.Left = value; + ActivePanel.Left = value; } } @@ -98,11 +91,11 @@ namespace grapher.Models.Options.LUT { get { - return Panel.Width; + return ActivePanel.Width; } set { - Panel.Width = value; + ActivePanel.Width = value; } } @@ -110,13 +103,13 @@ namespace grapher.Models.Options.LUT public override void Hide() { - Panel.Hide(); + ActivePanel.Hide(); ShouldShow = false; } public override void Show(string name) { - Panel.Show(); + ActivePanel.Show(); ShouldShow = true; } @@ -130,7 +123,7 @@ namespace grapher.Models.Options.LUT Color col = Color.DarkGray; ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; int thickness = 2; - ControlPaint.DrawBorder(e.Graphics, Panel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); + ControlPaint.DrawBorder(e.Graphics, ActivePanel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); } } } -- cgit v1.2.3 From abbe20f63aded56c4714766ca1b93183eafa062a Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 30 Jun 2021 00:01:26 -0700 Subject: Add class for LUT apply type --- grapher/Models/Options/AccelTypeOptions.cs | 7 + grapher/Models/Options/CapOptions.cs | 221 -------------------------- grapher/Models/Options/LUT/LutApplyOptions.cs | 176 ++++++++++++++++++++ 3 files changed, 183 insertions(+), 221 deletions(-) delete mode 100644 grapher/Models/Options/CapOptions.cs create mode 100644 grapher/Models/Options/LUT/LutApplyOptions.cs (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 74e748a..cc2480c 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -119,6 +119,8 @@ namespace grapher public LUTPanelOptions LutPanel { get; } + public LutApplyOptions LutApply { get; } + public LayoutBase AccelerationType { get @@ -207,6 +209,7 @@ namespace grapher Midpoint.Hide(); LutText.Hide(); LutPanel.Hide(); + LutApply.Hide(); } public void Show() @@ -234,6 +237,7 @@ namespace grapher Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); Midpoint.SetActiveValue(args.midpoint); + LutApply.SetActiveValue(args.tableData.velocity); } public void ShowFull() @@ -291,6 +295,7 @@ namespace grapher if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; + if (LutApply.Visible) args.tableData.velocity = LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity; } public override void AlignActiveValues() @@ -305,6 +310,7 @@ namespace grapher Limit.AlignActiveValues(); Exponent.AlignActiveValues(); Midpoint.AlignActiveValues(); + LutApply.AlignActiveValues(); } private void OnIndexChanged(object sender, EventArgs e) @@ -332,6 +338,7 @@ namespace grapher Midpoint, LutText, LutPanel, + LutApply, top); } diff --git a/grapher/Models/Options/CapOptions.cs b/grapher/Models/Options/CapOptions.cs deleted file mode 100644 index b4afa5c..0000000 --- a/grapher/Models/Options/CapOptions.cs +++ /dev/null @@ -1,221 +0,0 @@ -using grapher.Models.Options; -using System; -using System.Windows.Forms; - -namespace grapher -{ - public class CapOptions : OptionBase - { - #region Constants - - - #endregion Constants - - #region Constructors - - public CapOptions( - ToolStripMenuItem velocityGainCapCheck, - ToolStripMenuItem legacyCapCheck, - Option capOption) - { - - VelocityGainCapCheck = velocityGainCapCheck; - LegacyCapCheck = legacyCapCheck; - CapOption = capOption; - - LegacyCapCheck.Click += new System.EventHandler(OnSensitivityCapCheckClick); - VelocityGainCapCheck.Click += new System.EventHandler(OnVelocityGainCapCheckClick); - - LegacyCapCheck.CheckedChanged += new System.EventHandler(OnSensitivityCapCheckedChange); - VelocityGainCapCheck.CheckedChanged += new System.EventHandler(OnVelocityGainCapCheckedChange); - - EnableVelocityGainCap(); - } - - #endregion Constructors - - #region Properties - - public ToolStripMenuItem LegacyCapCheck { get; } - - public ToolStripMenuItem VelocityGainCapCheck { get; } - - public Option CapOption { get; } - - public bool IsSensitivityGain { get; private set; } - - public double SensitivityCap { - get - { - if (IsSensitivityGain) - { - return CapOption.Field.Data; - } - else - { - return 0; - } - } - } - - public double VelocityGainCap { - get - { - if (IsSensitivityGain) - { - return 0; - } - else - { - return CapOption.Field.Data; - } - } - } - - public override int Top - { - get - { - return CapOption.Top; - } - set - { - CapOption.Top = value; - } - } - - public override int Height - { - get - { - return CapOption.Height; - } - } - - public override int Left - { - get - { - return CapOption.Left; - } - set - { - CapOption.Left = value; - } - } - - public override int Width - { - get - { - return CapOption.Width; - } - set - { - CapOption.Width = value; - } - } - - public override bool Visible - { - get - { - return CapOption.Visible; - } - } - - #endregion Properties - - #region Methods - - public override void Hide() - { - CapOption.Hide(); - } - - public void Show() - { - CapOption.Show(); - } - - public override void Show(string name) - { - CapOption.Show(name); - } - - public void SnapTo(Option option) - { - Top = option.Top + option.Height + Constants.OptionVerticalSeperation; - } - - - public void SetActiveValues(double cap, bool legacyCap) - { - if (!legacyCap) - { - CapOption.ActiveValueLabel.FormatString = Constants.GainCapFormatString; - CapOption.ActiveValueLabel.Prefix = "Gain"; - } - else - { - CapOption.ActiveValueLabel.FormatString = Constants.DefaultActiveValueFormatString; - CapOption.ActiveValueLabel.Prefix = string.Empty; - } - - CapOption.SetActiveValue(cap); - } - - public override void AlignActiveValues() - { - CapOption.AlignActiveValues(); - } - - void OnSensitivityCapCheckClick(object sender, EventArgs e) - { - if (!LegacyCapCheck.Checked) - { - VelocityGainCapCheck.Checked = false; - LegacyCapCheck.Checked = true; - } - } - - void OnVelocityGainCapCheckClick(object sender, EventArgs e) - { - if (!VelocityGainCapCheck.Checked) - { - VelocityGainCapCheck.Checked = true; - LegacyCapCheck.Checked = false; - } - } - - void OnSensitivityCapCheckedChange(object sender, EventArgs e) - { - if (LegacyCapCheck.Checked) - { - EnableSensitivityCap(); - } - } - - void OnVelocityGainCapCheckedChange(object sender, EventArgs e) - { - if (VelocityGainCapCheck.Checked) - { - EnableVelocityGainCap(); - } - } - - void EnableSensitivityCap() - { - IsSensitivityGain = true; - CapOption.SetName("Sensitivity Cap"); - } - - void EnableVelocityGainCap() - { - IsSensitivityGain = false; - CapOption.SetName("Velocity Gain Cap"); - } - - #endregion Methods - } -} diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs new file mode 100644 index 0000000..6ea7412 --- /dev/null +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace grapher.Models.Options.LUT +{ + public class LutApplyOptions : OptionBase + { + public const string LUTApplyOptionsLabelText = "Apply as:"; + + public enum LutApplyType + { + Sensitivity, + Velocity + } + + public class LutApplyOption + { + public LutApplyType Type { get; set; } + + public string Name => Type.ToString(); + } + + public static readonly LutApplyOption Sensitivity = new LutApplyOption + { + Type = LutApplyType.Sensitivity, + }; + + public static readonly LutApplyOption Velocity = new LutApplyOption + { + Type = LutApplyType.Velocity, + }; + + public LutApplyOptions( + Label label, + ComboBox applyOptionsDropdown, + ActiveValueLabel lutApplyActiveValue) + { + ApplyOptions = applyOptionsDropdown; + ApplyOptions.Items.Clear(); + ApplyOptions.Items.AddRange( + new LutApplyOption[] + { + Sensitivity, + Velocity, + }); + + Label = label; + Label.Text = LUTApplyOptionsLabelText; + + ActiveValueLabel = lutApplyActiveValue; + } + + public LutApplyType ApplyType { get => ApplyOption.Type; } + + public LutApplyOption ApplyOption { + get + { + return ApplyOptions.SelectedItem as LutApplyOption; + } + set + { + ApplyOptions.SelectedItem = value; + } + } + + public Label Label { get; } + + public ActiveValueLabel ActiveValueLabel { get; } + + public ComboBox ApplyOptions { get; } + + public override bool Visible + { + get + { + return Label.Visible || ShouldShow; + } + } + + public override int Left + { + get + { + return Label.Left; + } + set + { + Label.Left = value; + ApplyOptions.Left = Label.Left + Label.Width + Constants.OptionLabelBoxSeperation; + } + } + + public override int Height + { + get + { + return Label.Height; + } + } + + public override int Top + { + get + { + return Label.Top; + } + set + { + Label.Top = value; + ApplyOptions.Top = value; + ActiveValueLabel.Top = value; + } + } + + public override int Width + { + get + { + return Label.Width; + } + set + { + ApplyOptions.Width = value - Label.Width - Constants.OptionLabelBoxSeperation; + } + } + + private bool ShouldShow { get; set; } + + public override void Hide() + { + Label.Hide(); + ApplyOptions.Hide(); + ShouldShow = false; + } + + public override void Show(string labelText) + { + Label.Show(); + + if (!string.IsNullOrWhiteSpace(labelText)) + { + Label.Text = labelText; + } + + ApplyOptions.Show(); + ShouldShow = true; + } + + public override void AlignActiveValues() + { + ActiveValueLabel.Align(); + } + + public void SetActiveValue(bool applyAsVelocity) + { + ApplyOption = ApplyOptionFromSettings(applyAsVelocity); + ActiveValueLabel.SetValue(ApplyOption.Name); + } + + public LutApplyOption ApplyOptionFromSettings(bool applyAsVelocity) + { + if (applyAsVelocity) + { + return Velocity; + } + else + { + return Sensitivity; + } + } + } +} -- cgit v1.2.3 From dc76635349577f9dd95ab347fb79652dad2abb30 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 30 Jun 2021 23:52:31 -0700 Subject: Better-written LUT panels --- grapher/Models/AccelGUIFactory.cs | 22 +++- grapher/Models/Options/AccelTypeOptions.cs | 3 + grapher/Models/Options/LUT/LUTPanelOptions.cs | 149 ++++++++++++++++++++++---- 3 files changed, 148 insertions(+), 26 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 5035598..b82cf59 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -26,6 +26,8 @@ namespace grapher.Models Chart gainChartY, ComboBox accelTypeDropX, ComboBox accelTypeDropY, + ComboBox lutApplyDropdownX, + ComboBox lutApplyDropdownY, Button writeButton, ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, @@ -69,6 +71,8 @@ namespace grapher.Models CheckBox gainSwitchY, Panel lutPanelX, Panel lutPanelY, + RichTextBox xLutPointsBox, + RichTextBox yLutPointsBox, Label lockXYLabel, Label sensitivityLabel, Label rotationLabel, @@ -129,7 +133,11 @@ namespace grapher.Models Label domainActiveValueY, Label rangeLabel, Label rangeActiveValueX, - Label rangeActiveValueY) + Label rangeActiveValueY, + Label lutApplyLabelX, + Label lutApplyLabelY, + Label lutApplyActiveValueX, + Label lutApplyActiveValueY) { fakeBox.Checked = false; fakeBox.Hide(); @@ -339,7 +347,11 @@ namespace grapher.Models exponentX, midpointX, lutTextX, - new LUTPanelOptions(lutPanelX), + new LUTPanelOptions(lutPanelX, xLutPointsBox), + new LutApplyOptions( + lutApplyLabelX, + lutApplyDropdownX, + new ActiveValueLabel(lutApplyActiveValueX, activeValueTitleX)), writeButton, new ActiveValueLabel(accelTypeActiveLabelX, activeValueTitleX)); @@ -355,7 +367,11 @@ namespace grapher.Models exponentY, midpointY, lutTextY, - new LUTPanelOptions(lutPanelY), + new LUTPanelOptions(lutPanelY, yLutPointsBox), + new LutApplyOptions( + lutApplyLabelY, + lutApplyDropdownY, + new ActiveValueLabel(lutApplyActiveValueY, activeValueTitleY)), writeButton, new ActiveValueLabel(accelTypeActiveLabelY, activeValueTitleY)); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index cc2480c..08ab111 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -40,6 +40,7 @@ namespace grapher Option midpoint, TextOption lutText, LUTPanelOptions lutPanelOptions, + LutApplyOptions lutApplyOptions, Button writeButton, ActiveValueLabel accelTypeActiveValue) { @@ -73,6 +74,7 @@ namespace grapher AccelTypeActiveValue = accelTypeActiveValue; LutText = lutText; LutPanel = lutPanelOptions; + LutApply = lutApplyOptions; AccelTypeActiveValue.Left = AccelDropdown.Left + AccelDropdown.Width; AccelTypeActiveValue.Height = AccelDropdown.Height; @@ -237,6 +239,7 @@ namespace grapher Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); Midpoint.SetActiveValue(args.midpoint); + LutPanel.SetActiveValues(args.tableData.points); LutApply.SetActiveValue(args.tableData.velocity); } diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index e723dcd..6425d91 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -10,39 +10,33 @@ namespace grapher.Models.Options.LUT { public class LUTPanelOptions : OptionBase { - public const string ApplyAsSensTitle = "Apply as sensitivity"; - public const string ApplyAsVelocityTitle = "Apply as velocity"; - public const int TitlePadding = 5; + public const int PanelPadding = 5; public const int PanelHeight = 100; - public LUTPanelOptions(Panel activePanel) + public LUTPanelOptions(Panel activePanel, RichTextBox pointsTextBox) { + PointsTextBox = pointsTextBox; + ActivePanel = activePanel; ActivePanel.Height = PanelHeight; ActivePanel.Paint += Panel_Paint; - ApplyAsSens = new CheckBox(); - ApplyAsSens.Text = ApplyAsSensTitle; - ApplyAsVelocity = new CheckBox(); - ApplyAsVelocity.Text = ApplyAsVelocityTitle; - } - - public Panel ActivePanel - { - get; + ActiveValuesTextBox = new RichTextBox(); + ActiveValuesTextBox.ReadOnly = true; + ActivePanel.Controls.Add(ActiveValuesTextBox); } - public Label Title + public RichTextBox PointsTextBox { get; } - public CheckBox ApplyAsSens + public RichTextBox ActiveValuesTextBox { get; } - public CheckBox ApplyAsVelocity + public Panel ActivePanel { get; } @@ -51,7 +45,7 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Visible || ShouldShow; + return PointsTextBox.Visible || ShouldShow; } } @@ -59,10 +53,11 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Top; + return PointsTextBox.Top; } set { + PointsTextBox.Top = value; ActivePanel.Top = value; } } @@ -71,7 +66,7 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Height; + return PointsTextBox.Height; } } @@ -79,11 +74,12 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Left; + return PointsTextBox.Left; } set { - ActivePanel.Left = value; + PointsTextBox.Left = value; + AlignActivePanelToPointsTextBox(); } } @@ -91,11 +87,14 @@ namespace grapher.Models.Options.LUT { get { - return ActivePanel.Width; + return PointsTextBox.Width; } set { - ActivePanel.Width = value; + var panelWidth = value / 2 - PanelPadding; + PointsTextBox.Width = panelWidth; + ActivePanel.Width = panelWidth; + AlignActivePanelToPointsTextBox(); } } @@ -103,12 +102,14 @@ namespace grapher.Models.Options.LUT public override void Hide() { + PointsTextBox.Hide(); ActivePanel.Hide(); ShouldShow = false; } public override void Show(string name) { + PointsTextBox.Show(); ActivePanel.Show(); ShouldShow = true; } @@ -118,6 +119,108 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } + public void SetActiveValues(IEnumerable> activePoints) + { + if (activePoints.Any() && activePoints.First().x != 0) + { + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints); + } + else + { + ActiveValuesTextBox.Text = string.Empty; + } + } + + public Vec2[] GetPoints() + { + return UserTextToPoints(PointsTextBox.Text); + } + + private static Vec2[] UserTextToPoints(string userText) + { + if (string.IsNullOrWhiteSpace(userText)) + { + throw new Exception("Text must be entered in text box to fill Look Up Table."); + } + + Vec2[] points = new Vec2[256]; + + var userTextSplit = userText.Split(';'); + int index = 0; + float lastX = 0; + + foreach(var pointEntry in userTextSplit) + { + var pointSplit = pointEntry.Trim().Split(','); + + if (pointSplit.Length != 2) + { + throw new Exception($"Point at index {index} is malformed. Expected format: x,y; Given: {pointEntry.Trim()}"); + } + + float x; + float y; + + try + { + x = float.Parse(pointSplit[0]); + } + catch (Exception ex) + { + throw new Exception($"X-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[0]}", ex); + } + + if (x <= 0) + { + throw new Exception($"X-value for point at index {index} is less than or equal to 0. Point (0,0) is implied and should not be specified in points text."); + } + + if (x <= lastX) + { + throw new Exception($"X-value for point at index {index} is less than or equal to previous x-value. Value: {x} Previous: {lastX}"); + } + + lastX = x; + + try + { + y = float.Parse(pointSplit[1]); + } + catch (Exception ex) + { + throw new Exception($"Y-value for point at index {index} is malformed. Expected: float. Given: {pointSplit[1]}", ex); + } + + if (y <= 0) + { + throw new Exception($"Y-value for point at index {index} is less than or equal to 0. Value: {y}"); + } + + points[index] = new Vec2 { x = x, y = y }; + + index++; + } + + return points; + } + + private void AlignActivePanelToPointsTextBox() + { + ActivePanel.Left = PointsTextBox.Right + PanelPadding; + } + + private string PointsToActiveValuesText(IEnumerable> points) + { + StringBuilder builder = new StringBuilder(); + + foreach(var point in points) + { + builder.AppendLine($"{point.x},{point.y};"); + } + + return builder.ToString(); + } + private void Panel_Paint(object sender, PaintEventArgs e) { Color col = Color.DarkGray; -- cgit v1.2.3 From ac0a6eb86c8d783c21cb246d688a221913b15789 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Jul 2021 19:13:12 -0700 Subject: Mostly working --- grapher/Models/AccelGUIFactory.cs | 8 ++-- grapher/Models/Options/AccelTypeOptions.cs | 14 ++++++- grapher/Models/Options/LUT/LUTPanelOptions.cs | 53 ++++++++++----------------- grapher/Models/Options/LUT/LutApplyOptions.cs | 3 ++ grapher/Models/Options/TextOption.cs | 6 +-- 5 files changed, 41 insertions(+), 43 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index b82cf59..3bb5a49 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -69,8 +69,8 @@ namespace grapher.Models CheckBox byComponentCheckBox, CheckBox gainSwitchX, CheckBox gainSwitchY, - Panel lutPanelX, - Panel lutPanelY, + RichTextBox xLutActiveValuesBox, + RichTextBox yLutActiveValuesBox, RichTextBox xLutPointsBox, RichTextBox yLutPointsBox, Label lockXYLabel, @@ -347,7 +347,7 @@ namespace grapher.Models exponentX, midpointX, lutTextX, - new LUTPanelOptions(lutPanelX, xLutPointsBox), + new LUTPanelOptions(xLutPointsBox, xLutActiveValuesBox), new LutApplyOptions( lutApplyLabelX, lutApplyDropdownX, @@ -367,7 +367,7 @@ namespace grapher.Models exponentY, midpointY, lutTextY, - new LUTPanelOptions(lutPanelY, yLutPointsBox), + new LUTPanelOptions(yLutPointsBox, yLutActiveValuesBox), new LutApplyOptions( lutApplyLabelY, lutApplyDropdownY, diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 08ab111..f43d955 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -166,6 +166,9 @@ namespace grapher set { AccelDropdown.Left = value; + LutText.Left = value; + LutPanel.Left = value; + LutApply.Left = value; } } @@ -178,6 +181,9 @@ namespace grapher set { AccelDropdown.Width = value; + LutText.Width = value; + LutPanel.Width = value; + LutApply.Width = value; } } @@ -239,7 +245,7 @@ namespace grapher Limit.SetActiveValue(args.limit); Exponent.SetActiveValue(args.exponent); Midpoint.SetActiveValue(args.midpoint); - LutPanel.SetActiveValues(args.tableData.points); + LutPanel.SetActiveValues(args.tableData.points, args.tableData.length); LutApply.SetActiveValue(args.tableData.velocity); } @@ -298,6 +304,12 @@ namespace grapher if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; + if (LutPanel.Visible) + { + (var points, var length) = LutPanel.GetPoints(); + args.tableData.points = points; + args.tableData.length = length; + } if (LutApply.Visible) args.tableData.velocity = LutApply.ApplyType == LutApplyOptions.LutApplyType.Velocity; } diff --git a/grapher/Models/Options/LUT/LUTPanelOptions.cs b/grapher/Models/Options/LUT/LUTPanelOptions.cs index 6425d91..6b13cdc 100644 --- a/grapher/Models/Options/LUT/LUTPanelOptions.cs +++ b/grapher/Models/Options/LUT/LUTPanelOptions.cs @@ -13,17 +13,14 @@ namespace grapher.Models.Options.LUT public const int PanelPadding = 5; public const int PanelHeight = 100; - public LUTPanelOptions(Panel activePanel, RichTextBox pointsTextBox) + public LUTPanelOptions(RichTextBox pointsTextBox, RichTextBox activeValuesTextBox) { PointsTextBox = pointsTextBox; + PointsTextBox.Height = PanelHeight; - ActivePanel = activePanel; - ActivePanel.Height = PanelHeight; - ActivePanel.Paint += Panel_Paint; - - ActiveValuesTextBox = new RichTextBox(); + ActiveValuesTextBox = activeValuesTextBox; + ActiveValuesTextBox.Height = PanelHeight; ActiveValuesTextBox.ReadOnly = true; - ActivePanel.Controls.Add(ActiveValuesTextBox); } public RichTextBox PointsTextBox @@ -36,11 +33,6 @@ namespace grapher.Models.Options.LUT get; } - public Panel ActivePanel - { - get; - } - public override bool Visible { get @@ -58,7 +50,7 @@ namespace grapher.Models.Options.LUT set { PointsTextBox.Top = value; - ActivePanel.Top = value; + ActiveValuesTextBox.Top = value; } } @@ -93,7 +85,7 @@ namespace grapher.Models.Options.LUT { var panelWidth = value / 2 - PanelPadding; PointsTextBox.Width = panelWidth; - ActivePanel.Width = panelWidth; + ActiveValuesTextBox.Width = panelWidth; AlignActivePanelToPointsTextBox(); } } @@ -103,14 +95,14 @@ namespace grapher.Models.Options.LUT public override void Hide() { PointsTextBox.Hide(); - ActivePanel.Hide(); + ActiveValuesTextBox.Hide(); ShouldShow = false; } public override void Show(string name) { PointsTextBox.Show(); - ActivePanel.Show(); + ActiveValuesTextBox.Show(); ShouldShow = true; } @@ -119,11 +111,11 @@ namespace grapher.Models.Options.LUT // Nothing to do here. } - public void SetActiveValues(IEnumerable> activePoints) + public void SetActiveValues(IEnumerable> activePoints, int length) { - if (activePoints.Any() && activePoints.First().x != 0) + if (length > 0 && activePoints.First().x != 0) { - ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints); + ActiveValuesTextBox.Text = PointsToActiveValuesText(activePoints, length); } else { @@ -131,12 +123,12 @@ namespace grapher.Models.Options.LUT } } - public Vec2[] GetPoints() + public (Vec2[], int length) GetPoints() { return UserTextToPoints(PointsTextBox.Text); } - private static Vec2[] UserTextToPoints(string userText) + private static (Vec2[], int length) UserTextToPoints(string userText) { if (string.IsNullOrWhiteSpace(userText)) { @@ -145,7 +137,7 @@ namespace grapher.Models.Options.LUT Vec2[] points = new Vec2[256]; - var userTextSplit = userText.Split(';'); + var userTextSplit = userText.Trim().Trim(';').Split(';'); int index = 0; float lastX = 0; @@ -201,32 +193,25 @@ namespace grapher.Models.Options.LUT index++; } - return points; + return (points, userTextSplit.Length); } private void AlignActivePanelToPointsTextBox() { - ActivePanel.Left = PointsTextBox.Right + PanelPadding; + ActiveValuesTextBox.Left = PointsTextBox.Right + PanelPadding; } - private string PointsToActiveValuesText(IEnumerable> points) + private string PointsToActiveValuesText(IEnumerable> points, int length) { StringBuilder builder = new StringBuilder(); - foreach(var point in points) + for(int i = 0; i < length; i++) { + var point = points.ElementAt(i); builder.AppendLine($"{point.x},{point.y};"); } return builder.ToString(); } - - private void Panel_Paint(object sender, PaintEventArgs e) - { - Color col = Color.DarkGray; - ButtonBorderStyle bbs = ButtonBorderStyle.Dashed; - int thickness = 2; - ControlPaint.DrawBorder(e.Graphics, ActivePanel.ClientRectangle, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs, col, thickness, bbs); - } } } diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs index 6ea7412..f71c1e2 100644 --- a/grapher/Models/Options/LUT/LutApplyOptions.cs +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -22,6 +22,8 @@ namespace grapher.Models.Options.LUT public LutApplyType Type { get; set; } public string Name => Type.ToString(); + + public override string ToString() => Name; } public static readonly LutApplyOption Sensitivity = new LutApplyOption @@ -50,6 +52,7 @@ namespace grapher.Models.Options.LUT Label = label; Label.Text = LUTApplyOptionsLabelText; + Label.Width = 45; ActiveValueLabel = lutApplyActiveValue; } diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs index 3c6f378..83a72df 100644 --- a/grapher/Models/Options/TextOption.cs +++ b/grapher/Models/Options/TextOption.cs @@ -14,9 +14,7 @@ namespace grapher.Models.Options public TextOption(Label label) { Label = label; - Label.AutoSize = false; - Label.Width = 150; - Label.Height = 100; + Label.AutoSize = true; } #endregion Constructors @@ -61,7 +59,7 @@ namespace grapher.Models.Options } set { - Label.Width = value; + Label.MaximumSize = new System.Drawing.Size(value, 0); } } -- cgit v1.2.3 From 308eed9ce9ed48984323e6512546a2ffeb195b14 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Jul 2021 22:32:55 -0700 Subject: LUT Panel formatting --- grapher/Models/Options/AccelTypeOptions.cs | 6 +++++- grapher/Models/Options/LUT/LutApplyOptions.cs | 8 +++++--- grapher/Models/Options/TextOption.cs | 28 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index f43d955..4222d48 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -83,6 +83,8 @@ namespace grapher LutPanel.Left = AccelDropdown.Left; LutPanel.Width = AccelDropdown.Width + AccelTypeActiveValue.Width; + LutText.SetText(TextOption.LUTLayoutExpandedText, TextOption.LUTLayoutShortenedText); + AccelerationType = Off; Layout(); ShowingDefault = true; @@ -182,7 +184,7 @@ namespace grapher { AccelDropdown.Width = value; LutText.Width = value; - LutPanel.Width = value; + LutPanel.Width = AccelTypeActiveValue.CenteringLabel.Right - AccelDropdown.Left; LutApply.Width = value; } } @@ -258,6 +260,7 @@ namespace grapher Left = Acceleration.Left + Constants.DropDownLeftSeparation; Width = Acceleration.Width - Constants.DropDownLeftSeparation; + LutText.Expand(); } public void ShowShortened() @@ -269,6 +272,7 @@ namespace grapher Left = Acceleration.Field.Left; Width = Acceleration.Field.Width; + LutText.Shorten(); } public void SetArgs(ref AccelArgs args) diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs index f71c1e2..897460e 100644 --- a/grapher/Models/Options/LUT/LutApplyOptions.cs +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -10,6 +10,7 @@ namespace grapher.Models.Options.LUT public class LutApplyOptions : OptionBase { public const string LUTApplyOptionsLabelText = "Apply as:"; + public const int LUTApplyLabelDropdownSeparation = 4; public enum LutApplyType { @@ -52,7 +53,8 @@ namespace grapher.Models.Options.LUT Label = label; Label.Text = LUTApplyOptionsLabelText; - Label.Width = 45; + Label.AutoSize = false; + Label.Width = 50; ActiveValueLabel = lutApplyActiveValue; } @@ -93,7 +95,7 @@ namespace grapher.Models.Options.LUT set { Label.Left = value; - ApplyOptions.Left = Label.Left + Label.Width + Constants.OptionLabelBoxSeperation; + ApplyOptions.Left = Label.Left + Label.Width + LUTApplyLabelDropdownSeparation; } } @@ -113,8 +115,8 @@ namespace grapher.Models.Options.LUT } set { - Label.Top = value; ApplyOptions.Top = value; + Label.Top = (ApplyOptions.Height - Label.Height) / 2 + ApplyOptions.Top; ActiveValueLabel.Top = value; } } diff --git a/grapher/Models/Options/TextOption.cs b/grapher/Models/Options/TextOption.cs index 83a72df..1f8034d 100644 --- a/grapher/Models/Options/TextOption.cs +++ b/grapher/Models/Options/TextOption.cs @@ -9,6 +9,13 @@ namespace grapher.Models.Options { public class TextOption : OptionBase { + #region Constants + + public const string LUTLayoutExpandedText = "This mode is for experts only. Format: x1,y1;x2,y2;...xn,yn;"; + public const string LUTLayoutShortenedText = "Experts only."; + + #endregion Constants + #region Constructors public TextOption(Label label) @@ -23,6 +30,10 @@ namespace grapher.Models.Options private Label Label { get; } + private string ExpandedText { get; set; } + + private string ShortenedText { get; set; } + public override bool Visible { get @@ -89,10 +100,25 @@ namespace grapher.Models.Options public override void Show(string Name) { Label.Show(); - Label.Text = Name; ShouldShow = true; } + public void Expand() + { + Label.Text = ExpandedText; + } + + public void Shorten() + { + Label.Text = ShortenedText; + } + + public void SetText(string expandedText, string shortenedText) + { + ExpandedText = expandedText; + ShortenedText = shortenedText; + } + public override void AlignActiveValues() { // Nothing to do here -- cgit v1.2.3 From 526620d1cbc42d5cd1f6dc2b55484e1d7dbfdc38 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Jul 2021 23:11:18 -0700 Subject: Further formatting adjustments --- grapher/Models/Options/AccelOptionSet.cs | 2 +- grapher/Models/Options/AccelTypeOptions.cs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 8b957f1..8fb2ad5 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -46,8 +46,8 @@ namespace grapher.Models.Options { IsTitleMode = false; - HideTitle(); Options.ShowFull(); + HideTitle(); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 4222d48..75860f4 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -226,7 +226,7 @@ namespace grapher { AccelDropdown.Show(); AccelTypeActiveValue.Show(); - Layout(); + Layout(AccelDropdown.Bottom + Constants.OptionVerticalSeperation); } public override void Show(string name) @@ -253,6 +253,8 @@ namespace grapher public void ShowFull() { + LutText.Expand(); + if (ShowingDefault) { AccelDropdown.Text = Constants.AccelDropDownDefaultFullText; @@ -260,11 +262,12 @@ namespace grapher Left = Acceleration.Left + Constants.DropDownLeftSeparation; Width = Acceleration.Width - Constants.DropDownLeftSeparation; - LutText.Expand(); } public void ShowShortened() { + LutText.Shorten(); + if (ShowingDefault) { AccelDropdown.Text = Constants.AccelDropDownDefaultShortText; @@ -272,7 +275,6 @@ namespace grapher Left = Acceleration.Field.Left; Width = Acceleration.Field.Width; - LutText.Shorten(); } public void SetArgs(ref AccelArgs args) -- cgit v1.2.3 From a8eec2c939982010b760b1ae77b361d5f7a7a7f5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 1 Jul 2021 23:30:13 -0700 Subject: Format mostly correct --- grapher/Models/Options/AccelOptionSet.cs | 1 + grapher/Models/Options/AccelTypeOptions.cs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelOptionSet.cs b/grapher/Models/Options/AccelOptionSet.cs index 8fb2ad5..75eb017 100644 --- a/grapher/Models/Options/AccelOptionSet.cs +++ b/grapher/Models/Options/AccelOptionSet.cs @@ -61,6 +61,7 @@ namespace grapher.Models.Options Options.ShowShortened(); DisplayTitle(); + Options.HandleLUTOptionsOnResize(); } } diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 75860f4..30940ad 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -253,8 +253,6 @@ namespace grapher public void ShowFull() { - LutText.Expand(); - if (ShowingDefault) { AccelDropdown.Text = Constants.AccelDropDownDefaultFullText; @@ -262,12 +260,13 @@ namespace grapher Left = Acceleration.Left + Constants.DropDownLeftSeparation; Width = Acceleration.Width - Constants.DropDownLeftSeparation; + + LutText.Expand(); + HandleLUTOptionsOnResize(); } public void ShowShortened() { - LutText.Shorten(); - if (ShowingDefault) { AccelDropdown.Text = Constants.AccelDropDownDefaultShortText; @@ -275,6 +274,8 @@ namespace grapher Left = Acceleration.Field.Left; Width = Acceleration.Field.Width; + + LutText.Shorten(); } public void SetArgs(ref AccelArgs args) @@ -334,6 +335,15 @@ namespace grapher LutApply.AlignActiveValues(); } + public void HandleLUTOptionsOnResize() + { + LutText.Left = AccelDropdown.Left; + LutPanel.Left = GainSwitch.Left - 100; + LutPanel.Width = Acceleration.ActiveValueLabel.CenteringLabel.Right - LutPanel.Left; + LutApply.Left = LutPanel.Left; + LutApply.Width = AccelDropdown.Right - LutPanel.Left; + } + private void OnIndexChanged(object sender, EventArgs e) { Layout(Beneath); -- cgit v1.2.3 From 44c20e12d53434c47b08dbe855567316159d0469 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 3 Jul 2021 14:52:54 -0700 Subject: Small fixes, guide additions, tweaks --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Options/LUT/LutApplyOptions.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 324dcb1..9ca7fed 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -151,9 +151,9 @@ namespace grapher public void RefreshActive() { + UpdateShownActiveValues(Settings.UserSettings); UpdateGraph(); UpdateInputManagers(); - UpdateShownActiveValues(Settings.UserSettings); } public void RefreshUser() diff --git a/grapher/Models/Options/LUT/LutApplyOptions.cs b/grapher/Models/Options/LUT/LutApplyOptions.cs index 897460e..7d8c737 100644 --- a/grapher/Models/Options/LUT/LutApplyOptions.cs +++ b/grapher/Models/Options/LUT/LutApplyOptions.cs @@ -139,6 +139,7 @@ namespace grapher.Models.Options.LUT { Label.Hide(); ApplyOptions.Hide(); + ActiveValueLabel.Hide(); ShouldShow = false; } @@ -152,6 +153,7 @@ namespace grapher.Models.Options.LUT } ApplyOptions.Show(); + ActiveValueLabel.Show(); ShouldShow = true; } -- cgit v1.2.3 From 6a5cfb45bf4a9d3151a9de6f320fdaf4b7296f18 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 3 Jul 2021 15:18:47 -0700 Subject: Guide updates and accel type choice fixed --- grapher/Models/Options/AccelTypeOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 30940ad..02f4acb 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -387,7 +387,7 @@ namespace grapher switch (args.mode) { - case AccelMode.classic: return (args.power == 2) ? Linear : Classic; + case AccelMode.classic: return (args.exponent == 2) ? Linear : Classic; case AccelMode.jump: return Jump; case AccelMode.natural: return Natural; case AccelMode.motivity: return Motivity; -- cgit v1.2.3 From 9a8042fe9c7506d0a41e3c635641d8d9e2424edc Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Sat, 3 Jul 2021 15:30:47 -0700 Subject: Handle power\exponent correctly in GUI --- grapher/Models/Options/AccelTypeOptions.cs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index 02f4acb..f97df2d 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -245,7 +245,7 @@ namespace grapher Acceleration.SetActiveValue(AccelerationParameterFromArgs(ref args)); Scale.SetActiveValue(args.scale); Limit.SetActiveValue(args.limit); - Exponent.SetActiveValue(args.exponent); + Exponent.SetActiveValue(ExponentParameterFromArgs(ref args)); Midpoint.SetActiveValue(args.midpoint); LutPanel.SetActiveValues(args.tableData.points, args.tableData.length); LutApply.SetActiveValue(args.tableData.velocity); @@ -307,7 +307,17 @@ namespace grapher if (Scale.Visible) args.scale = Scale.Field.Data; if (Cap.Visible) args.cap = Cap.Field.Data; if (Limit.Visible) args.limit = Limit.Field.Data; - if (Exponent.Visible) args.exponent = Exponent.Field.Data; + if (Exponent.Visible) + { + if (args.mode == AccelMode.classic) + { + args.power = Exponent.Field.Data; + } + else + { + args.exponent = Exponent.Field.Data; + } + } if (Offset.Visible) args.offset = Offset.Field.Data; if (Midpoint.Visible) args.midpoint = Midpoint.Field.Data; if (Weight.Visible) args.weight = Weight.Field.Data; @@ -387,7 +397,7 @@ namespace grapher switch (args.mode) { - case AccelMode.classic: return (args.exponent == 2) ? Linear : Classic; + case AccelMode.classic: return (args.power == 2) ? Linear : Classic; case AccelMode.jump: return Jump; case AccelMode.natural: return Natural; case AccelMode.motivity: return Motivity; @@ -413,6 +423,18 @@ namespace grapher } } + private double ExponentParameterFromArgs(ref AccelArgs args) + { + if (args.mode == AccelMode.classic) + { + return args.power; + } + else + { + return args.exponent; + } + } + #endregion Methods } } -- cgit v1.2.3