diff options
Diffstat (limited to 'grapher/Models')
| -rw-r--r-- | grapher/Models/AccelGUI.cs | 154 | ||||
| -rw-r--r-- | grapher/Models/AccelGUIFactory.cs | 6 | ||||
| -rw-r--r-- | grapher/Models/Charts/AccelCharts.cs | 34 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartState/ChartState.cs | 25 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartXY.cs | 38 | ||||
| -rw-r--r-- | grapher/Models/Options/AccelTypeOptions.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Options/ApplyOptions.cs | 7 | ||||
| -rw-r--r-- | grapher/Models/Serialized/GUISettings.cs | 47 | ||||
| -rw-r--r-- | grapher/Models/Serialized/RawAccelSettings.cs | 41 | ||||
| -rw-r--r-- | grapher/Models/Serialized/SettingsManager.cs | 52 |
10 files changed, 233 insertions, 173 deletions
diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 11685ee..dd1e37d 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -3,7 +3,9 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; using System; +using System.Drawing; using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; namespace grapher { @@ -19,6 +21,7 @@ namespace grapher SettingsManager settings, ApplyOptions applyOptions, Button writeButton, + ButtonBase toggleButton, MouseWatcher mouseWatcher, ToolStripMenuItem scaleMenuItem) { @@ -27,19 +30,29 @@ namespace grapher AccelCharts = accelCharts; ApplyOptions = applyOptions; WriteButton = writeButton; + ToggleButton = (CheckBox)toggleButton; ScaleMenuItem = scaleMenuItem; Settings = settings; Settings.Startup(); - RefreshOnRead(); + 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); WriteButton.Click += new System.EventHandler(OnWriteButtonClick); + ToggleButton.Click += new System.EventHandler(OnToggleButtonClick); + AccelForm.FormClosing += new FormClosingEventHandler(SaveGUISettingsOnClose); + + ButtonTimerInterval = Convert.ToInt32(DriverInterop.WriteDelayMs); + ButtonTimer = new Timer(); + ButtonTimer.Tick += new System.EventHandler(OnButtonTimerTick); + SetupButtons(); - ButtonTimer = SetupButtonTimer(); ChartRefresh = SetupChartTimer(); - SetupWriteButton(); } #endregion Constructors @@ -58,6 +71,8 @@ namespace grapher public Button WriteButton { get; } + public CheckBox ToggleButton { get; } + public Timer ButtonTimer { get; } public MouseWatcher MouseWatcher { get; } @@ -66,10 +81,30 @@ namespace grapher private Timer ChartRefresh { get; } + private Font SmallButtonFont { get; } + + private Font DefaultButtonFont { get; } + + private bool SettingsNotDefault { get; set; } + + private bool LastToggleChecked { get; set; } + + private int ButtonTimerInterval { get; } + #endregion Properties #region Methods + private void SaveGUISettingsOnClose(Object sender, FormClosingEventArgs e) + { + var guiSettings = Settings.MakeGUISettingsFromFields(); + if (!Settings.RawAccelSettings.GUISettings.Equals(guiSettings)) + { + Settings.RawAccelSettings.GUISettings = guiSettings; + Settings.RawAccelSettings.Save(); + } + } + public void UpdateActiveSettingsFromFields() { var driverSettings = Settings.RawAccelSettings.AccelerationSettings; @@ -92,7 +127,8 @@ namespace grapher SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); if (errors.Empty()) { - RefreshOnRead(); + RefreshToggleStateFromNewSettings(); + RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); } else { @@ -100,26 +136,25 @@ namespace grapher } } - public void RefreshOnRead() + public void RefreshOnRead(DriverSettings args) { - UpdateShownActiveValues(); - UpdateGraph(); + UpdateShownActiveValues(args); + UpdateGraph(args); } - public void UpdateGraph() + public void UpdateGraph(DriverSettings args) { AccelCharts.Calculate( - Settings.ActiveAccel, - Settings.RawAccelSettings.AccelerationSettings); + Settings.ActiveAccel, + args); AccelCharts.Bind(); } - public void UpdateShownActiveValues() + public void UpdateShownActiveValues(DriverSettings args) { - var settings = Settings.RawAccelSettings.AccelerationSettings; - - AccelCharts.ShowActive(settings); - ApplyOptions.SetActiveValues(settings); + AccelForm.ResetAutoScroll(); + AccelCharts.ShowActive(args); + ApplyOptions.SetActiveValues(args); } private Timer SetupChartTimer() @@ -131,38 +166,47 @@ namespace grapher return chartTimer; } - private Timer SetupButtonTimer() + private void SetupButtons() { - Timer buttonTimer = new Timer(); - buttonTimer.Enabled = true; - buttonTimer.Interval = Convert.ToInt32(DriverInterop.WriteDelayMs); - buttonTimer.Tick += new System.EventHandler(OnButtonTimerTick); - return buttonTimer; + WriteButton.Top = AccelCharts.Top + AccelCharts.TopChartHeight - Constants.ButtonVerticalOffset; + + ToggleButton.Appearance = Appearance.Button; + ToggleButton.FlatStyle = FlatStyle.System; + ToggleButton.TextAlign = ContentAlignment.MiddleCenter; + ToggleButton.Size = WriteButton.Size; + ToggleButton.Top = WriteButton.Top; + + RefreshToggleStateFromNewSettings(); + SetToggleButtonDefault(); + SetWriteButtonDefault(); } - private void SetupWriteButton() + private void RefreshToggleStateFromNewSettings() { - WriteButton.Top = AccelCharts.Top + AccelCharts.TopChartHeight - Constants.WriteButtonVerticalOffset; - SetWriteButtonDefault(); + SettingsNotDefault = !Settings.RawAccelSettings.IsDefaultEquivalent(); + LastToggleChecked = SettingsNotDefault; } private void SetWriteButtonDefault() { + WriteButton.Font = DefaultButtonFont; WriteButton.Text = Constants.WriteButtonDefaultText; - WriteButton.Enabled = true; + WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled; WriteButton.Update(); } - private void SetWriteButtonDelay() + private void SetToggleButtonDefault() { - WriteButton.Enabled = false; - WriteButton.Text = $"{Constants.WriteButtonDelayText} : {ButtonTimer.Interval} ms"; - WriteButton.Update(); + 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(); + UpdateGraph(Settings.RawAccelSettings.AccelerationSettings); } private void OnWriteButtonClick(object sender, EventArgs e) @@ -170,18 +214,64 @@ namespace grapher UpdateActiveSettingsFromFields(); } + private void OnToggleButtonClick(object sender, EventArgs e) + { + var settings = ToggleButton.Checked ? + Settings.RawAccelSettings.AccelerationSettings : + DriverInterop.DefaultSettings; + + ToggleButtonDelay(); + + SettingsManager.SendToDriver(settings); + Settings.ActiveAccel.UpdateFromSettings(settings); + RefreshOnRead(settings); + } + private void OnButtonTimerTick(object sender, EventArgs e) { ButtonTimer.Stop(); + SetToggleButtonDefault(); SetWriteButtonDefault(); } - private void WriteButtonDelay() + private void StartButtonTimer() { - SetWriteButtonDelay(); + ButtonTimer.Interval = ButtonTimerInterval; ButtonTimer.Start(); } + private void WriteButtonDelay() + { + WriteButton.Font = SmallButtonFont; + WriteButton.Text = $"{Constants.ButtonDelayText} : {ButtonTimerInterval} ms"; + WriteButton.Enabled = false; + WriteButton.Update(); + + if (ToggleButton.Enabled) + { + LastToggleChecked = ToggleButton.Checked; + ToggleButton.Checked = false; + ToggleButton.Enabled = false; + ToggleButton.Update(); + } + StartButtonTimer(); + } + + 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(); + } + private void OnChartTimerTick(object sender, EventArgs e) { AccelCharts.DrawLastMovement(); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 9f557f3..51bbc2b 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -23,6 +23,7 @@ namespace grapher.Models ComboBox accelTypeDropX, ComboBox accelTypeDropY, Button writeButton, + ButtonBase toggleButton, ToolStripMenuItem showVelocityGainToolStripMenuItem, ToolStripMenuItem showLastMouseMoveMenuItem, ToolStripMenuItem wholeVectorToolStripMenuItem, @@ -31,7 +32,6 @@ namespace grapher.Models ToolStripMenuItem legacyCapToolStripMenuItem, ToolStripMenuItem gainOffsetToolStripMenuItem, ToolStripMenuItem legacyOffsetToolStripMenuItem, - ToolStripMenuItem autoWriteMenuItem, ToolStripMenuItem scaleMenuItem, ToolStripTextBox dpiTextBox, ToolStripTextBox pollRateTextBox, @@ -126,7 +126,7 @@ namespace grapher.Models new ActiveValueLabelXY( new ActiveValueLabel(sensitivityActiveXLabel, activeValueTitleX), new ActiveValueLabel(sensitivityActiveYLabel, activeValueTitleX)), - "Sensitivity"); + "Sens Multiplier"); var rotation = new Option( rotationBox, @@ -326,7 +326,6 @@ namespace grapher.Models activeAccel, accelCalculator.DPI, accelCalculator.PollRate, - autoWriteMenuItem, showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); @@ -339,6 +338,7 @@ namespace grapher.Models settings, applyOptions, writeButton, + toggleButton, mouseWatcher, scaleMenuItem); } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 7484a3a..6247811 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -13,7 +13,7 @@ namespace grapher #region Constructors public AccelCharts( - Form form, + RawAcceleration form, ChartXY sensitivityChart, ChartXY velocityChart, ChartXY gainChart, @@ -34,10 +34,6 @@ namespace grapher EnableLastValue = enableLastMouseMove; WriteButton = writeButton; - - Rectangle screenRectangle = ContainingForm.RectangleToScreen(ContainingForm.ClientRectangle); - FormBorderHeight = screenRectangle.Top - ContainingForm.Top; - EnableVelocityAndGain.Click += new System.EventHandler(OnEnableClick); EnableVelocityAndGain.CheckedChanged += new System.EventHandler(OnEnableVelocityGainCheckStateChange); @@ -52,7 +48,7 @@ namespace grapher #region Properties - public Form ContainingForm { get; } + public RawAcceleration ContainingForm { get; } public ToolStripMenuItem EnableVelocityAndGain { get; } @@ -125,23 +121,9 @@ namespace grapher { ChartState = ChartStateManager.DetermineState(driverSettings); ChartState.Activate(); - UpdateFormWidth(); Bind(); } - public void SetWidened() - { - ChartState.SetWidened(); - UpdateFormWidth(); - AlignWriteButton(); - } - - public void SetNarrowed() - { - ChartState.SetNarrowed(); - UpdateFormWidth(); - AlignWriteButton(); - } public void Redraw() { @@ -176,8 +158,6 @@ namespace grapher velocityChart.SetTop(sensitivityChart.Height + Constants.ChartSeparationVertical); gainChart.SetHeight(sensitivityChart.Height); gainChart.SetTop(velocityChart.Top + velocityChart.Height + Constants.ChartSeparationVertical); - - sensitivityChart.Show(); } private void OnEnableClick(object sender, EventArgs e) @@ -187,6 +167,7 @@ namespace grapher private void OnEnableVelocityGainCheckStateChange(object sender, EventArgs e) { + ContainingForm.ResetAutoScroll(); if (EnableVelocityAndGain.Checked) { ShowVelocityAndGain(); @@ -207,17 +188,12 @@ namespace grapher private void ShowVelocityAndGain() { - ChartState.ShowVelocityAndGain(ContainingForm, FormBorderHeight); + ChartState.ShowVelocityAndGain(); } private void HideVelocityAndGain() { - ChartState.HideVelocityAndGain(ContainingForm, FormBorderHeight); - } - - private void UpdateFormWidth() - { - ContainingForm.Width = ChartState.SensitivityChart.Left + ChartState.SensitivityChart.Width; + ChartState.HideVelocityAndGain(); } private void AlignWriteButton() diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index 1898e12..270e212 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -68,20 +68,6 @@ namespace grapher.Models.Charts.ChartState GainChart.DrawLastMovementValue(TwoDotsPerGraph); } - public void SetWidened() - { - SensitivityChart.SetWidened(); - VelocityChart.SetWidened(); - GainChart.SetWidened(); - } - - public void SetNarrowed() - { - SensitivityChart.SetNarrowed(); - VelocityChart.SetNarrowed(); - GainChart.SetNarrowed(); - } - public void ClearLastValue() { SensitivityChart.ClearLastValue(); @@ -89,23 +75,16 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearLastValue(); } - public void ShowVelocityAndGain(Form form, int borderHeight) + public void ShowVelocityAndGain() { VelocityChart.Show(); GainChart.Show(); - form.Height = SensitivityChart.Height + - Constants.ChartSeparationVertical + - VelocityChart.Height + - Constants.ChartSeparationVertical + - GainChart.Height + - borderHeight; } - public void HideVelocityAndGain(Form form, int borderHeight) + public void HideVelocityAndGain() { VelocityChart.Hide(); GainChart.Hide(); - form.Height = SensitivityChart.Height + borderHeight; } public void SetLogarithmic(bool x, bool y) diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 27b63b5..98ba059 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -24,9 +24,7 @@ namespace grapher Combined = false; SetCombined(); - - Widened = false; - SetWidened(); + Visible = true; } #endregion Constructors @@ -72,11 +70,9 @@ namespace grapher } } - public bool Combined { get; private set; } - - public bool Widened { get; private set; } + public bool Combined { get; set; } - public bool Visible { get; private set; } + public bool Visible { get; set; } public string Title { get; } @@ -273,36 +269,10 @@ namespace grapher } } - public void SetWidened() - { - if (!Widened) - { - ChartX.Width = Constants.WideChartWidth; - ChartY.Width = Constants.WideChartWidth; - - ChartX.Left = Constants.WideChartLeft; - ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal; - - Widened = true; - } - } - - public void SetNarrowed() - { - if (Widened) - { - ChartX.Width = Constants.NarrowChartWidth; - ChartY.Width = Constants.NarrowChartWidth; - - ChartX.Left = Constants.NarrowChartLeft; - ChartY.Left = ChartX.Left + ChartX.Width + Constants.ChartSeparationHorizontal; - - Widened = false; - } - } public void Hide() { + if (Visible) { ChartX.Hide(); diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs index f9ecac1..4410a12 100644 --- a/grapher/Models/Options/AccelTypeOptions.cs +++ b/grapher/Models/Options/AccelTypeOptions.cs @@ -227,7 +227,7 @@ namespace grapher public void SetArgs(ref AccelArgs args) { - AccelArgs defaults = (AccelArgs)DriverInterop.DefaultArgs; + AccelArgs defaults = DriverInterop.DefaultSettings.args.x; args.acceleration = Acceleration.Visible ? Acceleration.Field.Data : defaults.acceleration; args.scale = Scale.Visible ? Scale.Field.Data : defaults.scale; args.gainCap = Cap.Visible ? Cap.VelocityGainCap : defaults.gainCap; diff --git a/grapher/Models/Options/ApplyOptions.cs b/grapher/Models/Options/ApplyOptions.cs index 71e580d..b8cc9bf 100644 --- a/grapher/Models/Options/ApplyOptions.cs +++ b/grapher/Models/Options/ApplyOptions.cs @@ -175,16 +175,14 @@ namespace grapher.Models.Options { OptionSetX.SetRegularMode(); OptionSetY.Hide(); - AccelCharts.SetWidened(); - SetActiveTitlesWhole(); + //SetActiveTitlesWhole(); } public void ShowByComponentAsOneSet() { OptionSetX.SetTitleMode("X = Y"); OptionSetY.Hide(); - AccelCharts.SetWidened(); - SetActiveTitlesByComponents(); + //SetActiveTitlesByComponents(); } public void ShowByComponentAsTwoSets() @@ -192,7 +190,6 @@ namespace grapher.Models.Options OptionSetX.SetTitleMode("X"); OptionSetY.SetTitleMode("Y"); OptionSetY.Show(); - AccelCharts.SetNarrowed(); } public void ShowByComponentSet() diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index 84e681b..c8f87ae 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -10,32 +10,55 @@ namespace grapher.Models.Serialized public GUISettings() {} - public GUISettings(bool autoWrite, int dpi, int pollRate) - { - AutoWriteToDriverOnStartup = autoWrite; - DPI = dpi; - PollRate = pollRate; - } - #endregion Constructors #region Properties - [JsonProperty(Order = 1)] - public bool AutoWriteToDriverOnStartup { get; set; } - [JsonProperty(Order = 2)] + [JsonProperty(Order = 1)] public int DPI { get; set; } - [JsonProperty(Order = 3)] + [JsonProperty(Order = 2)] public int PollRate { get; set; } - [JsonProperty(Order = 4)] + [JsonProperty(Order = 3)] public bool ShowLastMouseMove { get; set; } [JsonProperty(Order = 4)] public bool ShowVelocityAndGain { get; set; } #endregion Properties + + #region Methods + + public override bool Equals(object obj) + { + var other = obj as GUISettings; + + if (other == null) + { + return false; + } + + return Equals(other); + } + + public bool Equals(GUISettings other) + { + return DPI == other.DPI && + PollRate == other.PollRate && + ShowLastMouseMove == other.ShowLastMouseMove && + ShowVelocityAndGain == other.ShowVelocityAndGain; + } + + public override int GetHashCode() + { + return DPI.GetHashCode() ^ + PollRate.GetHashCode() ^ + ShowLastMouseMove.GetHashCode() ^ + ShowVelocityAndGain.GetHashCode(); + } + + #endregion Methods } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 570a6c8..818bfb6 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -44,17 +44,36 @@ namespace grapher.Models.Serialized #region Methods - public static RawAccelSettings Load() + public static RawAccelSettings Load(Func<GUISettings> DefaultGUISettingsSupplier) { - return Load(DefaultSettingsFile); + return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); } - public static RawAccelSettings Load(string file) + public static RawAccelSettings Load(string file, Func<GUISettings> DefaultGUISettingsSupplier) { try { - var settings = JsonConvert.DeserializeObject<RawAccelSettings>(File.ReadAllText(file), SerializerSettings); - if (settings is null) throw new JsonException($"{file} contains invalid JSON"); + RawAccelSettings settings = null; + + JObject settingsJObject = JObject.Parse(File.ReadAllText(file)); + if (settingsJObject.ContainsKey(DriverSettings.Key)) + { + settings = settingsJObject.ToObject<RawAccelSettings>(JsonSerializer.Create(SerializerSettings)); + } + else + { + settings = new RawAccelSettings + { + AccelerationSettings = settingsJObject.ToObject<DriverSettings>(), + GUISettings = DefaultGUISettingsSupplier() + }; + } + + if (settings is null || settings.AccelerationSettings is null) + { + throw new JsonException($"{file} contains invalid JSON"); + } + return settings; } catch (FileNotFoundException e) @@ -96,6 +115,18 @@ namespace grapher.Models.Serialized .AddFirst(new JProperty("### Mode Types ###", modes)); } + public bool IsDefaultEquivalent() + { + bool wholeOrNoY = AccelerationSettings.combineMagnitudes || + AccelerationSettings.modes.y == AccelMode.noaccel; + + return AccelerationSettings.sensitivity.x == 1 && + AccelerationSettings.sensitivity.y == 1 && + AccelerationSettings.rotation == 0 && + AccelerationSettings.modes.x == AccelMode.noaccel && + wholeOrNoY; + } + #endregion Methods } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 416823e..8712c87 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -14,14 +14,12 @@ 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; } @@ -38,8 +36,6 @@ namespace grapher.Models.Serialized private Field PollRateField { get; set; } - private ToolStripMenuItem AutoWriteMenuItem { get; set; } - private ToolStripMenuItem ShowLastMouseMoveMenuItem { get; set; } private ToolStripMenuItem ShowVelocityAndGainMoveMenuItem { get; set; } @@ -83,32 +79,27 @@ namespace grapher.Models.Serialized if (errors.Empty()) { RawAccelSettings.AccelerationSettings = settings; - RawAccelSettings.GUISettings = new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked, - }; - + RawAccelSettings.GUISettings = MakeGUISettingsFromFields(); RawAccelSettings.Save(); } return errors; } - public void UpdateActiveAccelFromFileSettings(DriverSettings settings) + public void UpdateFieldsFromGUISettings() { - TryUpdateAccel(settings); - DpiField.SetToEntered(RawAccelSettings.GUISettings.DPI); PollRateField.SetToEntered(RawAccelSettings.GUISettings.PollRate); - AutoWriteMenuItem.Checked = RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup; ShowLastMouseMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowLastMouseMove; ShowVelocityAndGainMoveMenuItem.Checked = RawAccelSettings.GUISettings.ShowVelocityAndGain; } + public void UpdateActiveAccelFromFileSettings(DriverSettings settings) + { + TryUpdateAccel(settings); + UpdateFieldsFromGUISettings(); + } + public SettingsErrors TryUpdateAccel(DriverSettings settings) { var errors = SendToDriverSafe(settings); @@ -128,17 +119,26 @@ namespace grapher.Models.Serialized return errors; } + public GUISettings MakeGUISettingsFromFields() + { + return new GUISettings + { + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked + }; + } + public void Startup() { if (RawAccelSettings.Exists()) { try { - RawAccelSettings = RawAccelSettings.Load(); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) - { - UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); - } + RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); + UpdateFieldsFromGUISettings(); + UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); return; } catch (JsonException e) @@ -149,13 +149,7 @@ namespace grapher.Models.Serialized RawAccelSettings = new RawAccelSettings( DriverInterop.GetActiveSettings(), - new GUISettings - { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, - DPI = (int)DpiField.Data, - PollRate = (int)PollRateField.Data, - ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, - }); + MakeGUISettingsFromFields()); RawAccelSettings.Save(); } |