diff options
| author | a1xd <[email protected]> | 2020-10-25 23:57:44 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-10-25 23:57:44 -0400 |
| commit | 1601eaffd7c83888fd804c00eae0b0e8633232ee (patch) | |
| tree | 72beb1b8b32b82ebfd853c04fe85c1f67e1d4afe /grapher/Models | |
| parent | Merge pull request #37 from JacobPalecki/GUI (diff) | |
| parent | update signed (diff) | |
| download | rawaccel-1.2.0.tar.xz rawaccel-1.2.0.zip | |
1.2.0
Diffstat (limited to 'grapher/Models')
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 99 | ||||
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Options/ActiveValueLabelXY.cs | 3 | ||||
| -rw-r--r-- | grapher/Models/Serialized/GUISettings.cs | 10 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 17 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 25 |
6 files changed, 85 insertions, 71 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index dd1e37d..c08313b 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -33,13 +33,8 @@ namespace grapher ToggleButton = (CheckBox)toggleButton; ScaleMenuItem = scaleMenuItem; Settings = settings; - Settings.Startup(); - RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); - AccelForm.DoResize(); - DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); - MouseWatcher = mouseWatcher; ScaleMenuItem.Click += new System.EventHandler(OnScaleMenuItemClick); @@ -50,9 +45,30 @@ namespace grapher ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs); ButtonTimer = new Timer(); ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); - SetupButtons(); ChartRefresh = SetupChartTimer(); + + bool settingsActive = Settings.Startup(); + SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); + + if (settingsActive) + { + LastToggleChecked = SettingsNotDefault; + ToggleButton.Enabled = LastToggleChecked; + RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); + } + else + { + DriverSettings active = DriverInterop.GetActiveSettings(); + bool activeNotDefault = !RawAccelSettings.IsDefaultEquivalent(active); + + LastToggleChecked = activeNotDefault; + ToggleButton.Enabled = SettingsNotDefault || activeNotDefault; + RefreshOnRead(active); + } + + SetupButtons(); + AccelForm.DoResize(); } #endregion Constructors @@ -109,6 +125,10 @@ 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 { rotation = ApplyOptions.Rotation.Field.Data, @@ -119,15 +139,16 @@ namespace grapher }, combineMagnitudes = ApplyOptions.IsWhole, modes = ApplyOptions.GetModes(), - args = ApplyOptions.GetArgs(), + args = newArgs, minimumTime = driverSettings.minimumTime }; - WriteButtonDelay(); + ButtonDelay(WriteButton); SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); if (errors.Empty()) { - RefreshToggleStateFromNewSettings(); + SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); + LastToggleChecked = SettingsNotDefault; RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); } else @@ -176,34 +197,23 @@ namespace grapher ToggleButton.Size = WriteButton.Size; ToggleButton.Top = WriteButton.Top; - RefreshToggleStateFromNewSettings(); - SetToggleButtonDefault(); - SetWriteButtonDefault(); + SetButtonDefaults(); } - private void RefreshToggleStateFromNewSettings() + private void SetButtonDefaults() { - SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); - LastToggleChecked = SettingsNotDefault; - } + ToggleButton.Checked = LastToggleChecked; + + ToggleButton.Font = DefaultButtonFont; + ToggleButton.Text = ToggleButton.Checked ? "Enabled" : "Disabled"; + ToggleButton.Update(); - private void SetWriteButtonDefault() - { WriteButton.Font = DefaultButtonFont; WriteButton.Text = Constants.WriteButtonDefaultText; WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled; WriteButton.Update(); } - private void SetToggleButtonDefault() - { - ToggleButton.Checked = LastToggleChecked; - ToggleButton.Enabled = SettingsNotDefault; - ToggleButton.Font = DefaultButtonFont; - ToggleButton.Text = ToggleButton.Checked ? "Enabled" : "Disabled"; - ToggleButton.Update(); - } - private void OnScaleMenuItemClick(object sender, EventArgs e) { UpdateGraph(Settings.RawAccelSettings.AccelerationSettings); @@ -220,7 +230,8 @@ namespace grapher Settings.RawAccelSettings.AccelerationSettings : DriverInterop.DefaultSettings; - ToggleButtonDelay(); + LastToggleChecked = ToggleButton.Checked; + ButtonDelay(ToggleButton); SettingsManager.SendToDriver(settings); Settings.ActiveAccel.UpdateFromSettings(settings); @@ -230,8 +241,8 @@ namespace grapher private void OnButtonTimerTick(object sender, EventArgs e) { ButtonTimer.Stop(); - SetToggleButtonDefault(); - SetWriteButtonDefault(); + ToggleButton.Enabled = SettingsNotDefault; + SetButtonDefaults(); } private void StartButtonTimer() @@ -240,33 +251,17 @@ namespace grapher ButtonTimer.Start(); } - private void WriteButtonDelay() + private void ButtonDelay(ButtonBase btn) { - WriteButton.Font = SmallButtonFont; - WriteButton.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; + ToggleButton.Checked = false; + + ToggleButton.Enabled = false; WriteButton.Enabled = false; - WriteButton.Update(); - if (ToggleButton.Enabled) - { - LastToggleChecked = ToggleButton.Checked; - ToggleButton.Checked = false; - ToggleButton.Enabled = false; - ToggleButton.Update(); - } - StartButtonTimer(); - } + btn.Font = SmallButtonFont; + btn.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; - private void ToggleButtonDelay() - { - LastToggleChecked = ToggleButton.Checked; - ToggleButton.Checked = false; - ToggleButton.Enabled = false; - ToggleButton.Font = SmallButtonFont; - ToggleButton.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; ToggleButton.Update(); - - WriteButton.Enabled = false; WriteButton.Update(); StartButtonTimer(); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 51bbc2b..3dc2a74 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -32,6 +32,7 @@ namespace grapher.Models ToolStripMenuItem legacyCapToolStripMenuItem, ToolStripMenuItem gainOffsetToolStripMenuItem, ToolStripMenuItem legacyOffsetToolStripMenuItem, + ToolStripMenuItem autoWriteMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -326,6 +327,7 @@ namespace grapher.Models activeAccel, accelCalculator.DPI, accelCalculator.PollRate, + autoWriteMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); diff --git a/grapher/Models/Options/ActiveValueLabelXY.cs b/grapher/Models/Options/ActiveValueLabelXY.cs index 1367a6a..381779c 100644 --- a/grapher/Models/Options/ActiveValueLabelXY.cs +++ b/grapher/Models/Options/ActiveValueLabelXY.cs @@ -143,7 +143,8 @@ namespace grapher.Models.Options private void Align (int width) { FullWidth = width; - ShortenedWidth = FullWidth / 2; + // ShortenedWidth = FullWidth / 2; + ShortenedWidth = FullWidth; SetYLeft(); Y.Width = ShortenedWidth; diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index c8f87ae..bb35055 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -4,6 +4,7 @@ using System; namespace grapher.Models.Serialized { [Serializable] + [JsonObject(ItemRequired = Required.Always)] public class GUISettings { #region Constructors @@ -27,6 +28,9 @@ namespace grapher.Models.Serialized [JsonProperty(Order = 4)] public bool ShowVelocityAndGain { get; set; } + [JsonProperty(Order = 5)] + public bool AutoWriteToDriverOnStartup { get; set; } + #endregion Properties #region Methods @@ -48,7 +52,8 @@ namespace grapher.Models.Serialized return DPI == other.DPI && PollRate == other.PollRate && ShowLastMouseMove == other.ShowLastMouseMove && - ShowVelocityAndGain == other.ShowVelocityAndGain; + ShowVelocityAndGain == other.ShowVelocityAndGain && + AutoWriteToDriverOnStartup == other.AutoWriteToDriverOnStartup; } public override int GetHashCode() @@ -56,7 +61,8 @@ namespace grapher.Models.Serialized return DPI.GetHashCode() ^ PollRate.GetHashCode() ^ ShowLastMouseMove.GetHashCode() ^ - ShowVelocityAndGain.GetHashCode(); + ShowVelocityAndGain.GetHashCode() ^ + AutoWriteToDriverOnStartup.GetHashCode(); } #endregion Methods diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 818bfb6..af87a65 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -117,13 +117,18 @@ namespace grapher.Models.Serialized public bool IsDefaultEquivalent() { - bool wholeOrNoY = AccelerationSettings.combineMagnitudes || - AccelerationSettings.modes.y == AccelMode.noaccel; + return IsDefaultEquivalent(AccelerationSettings); + } + + public static bool IsDefaultEquivalent(DriverSettings accelSettings) + { + bool wholeOrNoY = accelSettings.combineMagnitudes || + accelSettings.modes.y == AccelMode.noaccel; - return AccelerationSettings.sensitivity.x == 1 && - AccelerationSettings.sensitivity.y == 1 && - AccelerationSettings.rotation == 0 && - AccelerationSettings.modes.x == AccelMode.noaccel && + return accelSettings.sensitivity.x == 1 && + accelSettings.sensitivity.y == 1 && + accelSettings.rotation == 0 && + accelSettings.modes.x == AccelMode.noaccel && wholeOrNoY; } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 8712c87..f13ba81 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -14,12 +14,14 @@ namespace grapher.Models.Serialized ManagedAccel activeAccel, Field dpiField, Field pollRateField, + ToolStripMenuItem autoWrite, ToolStripMenuItem showLastMouseMove, ToolStripMenuItem showVelocityAndGain) { ActiveAccel = activeAccel; DpiField = dpiField; PollRateField = pollRateField; + AutoWriteMenuItem = autoWrite; ShowLastMouseMoveMenuItem = showLastMouseMove; ShowVelocityAndGainMoveMenuItem = showVelocityAndGain; } @@ -36,6 +38,8 @@ namespace grapher.Models.Serialized private Field PollRateField { get; set; } + private ToolStripMenuItem AutoWriteMenuItem { get; set; } + private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } @@ -92,12 +96,7 @@ namespace grapher.Models.Serialized PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; - } - - public void UpdateActiveAccelFromFileSettings(DriverSettings settings) - { - TryUpdateAccel(settings); - UpdateFieldsFromGUISettings(); + AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; } public SettingsErrors TryUpdateAccel(DriverSettings settings) @@ -126,11 +125,13 @@ namespace grapher.Models.Serialized DPI = (int)DpiField.Data, PollRate = (int)PollRateField.Data, ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked }; } - public void Startup() + // Returns true when file settings are active + public bool Startup() { if (RawAccelSettings.Exists()) { @@ -138,8 +139,11 @@ namespace grapher.Models.Serialized { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); UpdateFieldsFromGUISettings(); - UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); - return; + if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) + { + TryUpdateAccel(RawAccelSettings.AccelerationSettings); + } + return RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; } catch (JsonException e) { @@ -151,6 +155,7 @@ namespace grapher.Models.Serialized DriverInterop.GetActiveSettings(), MakeGUISettingsFromFields()); RawAccelSettings.Save(); + return true; } #endregion Methods |