From 6dbeca0806f32fae5a8fb4a27465bea46e22d58d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Oct 2020 00:19:56 -0400 Subject: add static default settings in wrapper --- 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 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; -- cgit v1.2.3 From 187de539ea370210146c7f1bcf398c2a100f758f Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Oct 2020 02:54:27 -0400 Subject: ease requirements for loading driver settings gui settings are no longer needed this covers edge case where interaccel converter is used but the gui does not run until after reboot --- grapher/Models/Serialized/RawAccelSettings.cs | 29 +++++++++++++++++++----- grapher/Models/Serialized/SettingsManager.cs | 32 +++++++++++++-------------- 2 files changed, 39 insertions(+), 22 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 570a6c8..6f48d44 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 DefaultGUISettingsSupplier) { - return Load(DefaultSettingsFile); + return Load(DefaultSettingsFile, DefaultGUISettingsSupplier); } - public static RawAccelSettings Load(string file) + public static RawAccelSettings Load(string file, Func DefaultGUISettingsSupplier) { try { - var settings = JsonConvert.DeserializeObject(File.ReadAllText(file), SerializerSettings); - if (settings is null) throw new JsonException($"{file} contains invalid JSON"); + RawAccelSettings settings = null; + + JObject jo = JObject.Parse(File.ReadAllText(file)); + if (jo.ContainsKey(DriverSettings.Key)) + { + settings = jo.ToObject(JsonSerializer.Create(SerializerSettings)); + } + else + { + settings = new RawAccelSettings + { + AccelerationSettings = jo.ToObject(), + GUISettings = DefaultGUISettingsSupplier() + }; + } + + if (settings is null || settings.AccelerationSettings is null) + { + throw new JsonException($"{file} contains invalid JSON"); + } + return settings; } catch (FileNotFoundException e) diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index 416823e..f53c9c9 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -83,15 +83,7 @@ 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(); } @@ -128,13 +120,25 @@ namespace grapher.Models.Serialized return errors; } + public GUISettings MakeGUISettingsFromFields() + { + return new GUISettings + { + AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, + DPI = (int)DpiField.Data, + PollRate = (int)PollRateField.Data, + ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, + ShowVelocityAndGain = ShowVelocityAndGainMoveMenuItem.Checked + }; + } + public void Startup() { if (RawAccelSettings.Exists()) { try { - RawAccelSettings = RawAccelSettings.Load(); + RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) { UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); @@ -149,13 +153,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(); } -- cgit v1.2.3 From 2be0106211cb4ce30036fc0c8e84ae70dff68c87 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 02:07:56 -0400 Subject: add toggle button + save gui settings on close remove option to disable write on startup --- grapher/Models/AccelGUI.cs | 150 ++++++++++++++++++++------ grapher/Models/AccelGUIFactory.cs | 4 +- grapher/Models/Charts/AccelCharts.cs | 4 +- grapher/Models/Serialized/GUISettings.cs | 27 ++--- grapher/Models/Serialized/RawAccelSettings.cs | 12 +++ grapher/Models/Serialized/SettingsManager.cs | 22 ++-- 6 files changed, 159 insertions(+), 60 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 11685ee..c561b23 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,28 @@ namespace grapher AccelCharts = accelCharts; ApplyOptions = applyOptions; WriteButton = writeButton; + ToggleButton = (CheckBox)toggleButton; ScaleMenuItem = scaleMenuItem; Settings = settings; Settings.Startup(); - RefreshOnRead(); + RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); + + DefaultButtonFont = WriteButton.Font; + SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * 0.666f); 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 +70,8 @@ namespace grapher public Button WriteButton { get; } + public CheckBox ToggleButton { get; } + public Timer ButtonTimer { get; } public MouseWatcher MouseWatcher { get; } @@ -66,10 +80,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.ValueEquals(guiSettings)) + { + Settings.RawAccelSettings.GUISettings = guiSettings; + Settings.RawAccelSettings.Save(); + } + } + public void UpdateActiveSettingsFromFields() { var driverSettings = Settings.RawAccelSettings.AccelerationSettings; @@ -92,7 +126,8 @@ namespace grapher SettingsErrors errors = Settings.TryUpdateActiveSettings(settings); if (errors.Empty()) { - RefreshOnRead(); + RefreshToggleStateFromNewSettings(); + RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); } else { @@ -100,26 +135,24 @@ 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); + AccelCharts.ShowActive(args); + ApplyOptions.SetActiveValues(args); } private Timer SetupChartTimer() @@ -131,38 +164,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; + SetWriteButtonDefault(); + + ToggleButton.Appearance = Appearance.Button; + ToggleButton.FlatStyle = FlatStyle.System; + ToggleButton.TextAlign = ContentAlignment.MiddleCenter; + ToggleButton.Size = WriteButton.Size; + ToggleButton.Top = WriteButton.Top; + + RefreshToggleStateFromNewSettings(); + SetToggleButtonDefault(); } - 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.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 +212,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(); SetWriteButtonDefault(); + SetToggleButtonDefault(); } - 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..579e664 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, @@ -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..9087b30 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -133,14 +133,14 @@ namespace grapher { ChartState.SetWidened(); UpdateFormWidth(); - AlignWriteButton(); + //AlignWriteButton(); } public void SetNarrowed() { ChartState.SetNarrowed(); UpdateFormWidth(); - AlignWriteButton(); + //AlignWriteButton(); } public void Redraw() diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index 84e681b..f9e5755 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -10,32 +10,35 @@ 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 bool ValueEquals(GUISettings other) + { + return DPI == other.DPI && + PollRate == other.PollRate && + ShowLastMouseMove == other.ShowLastMouseMove && + ShowVelocityAndGain == other.ShowVelocityAndGain; + } + + #endregion Methods } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 6f48d44..e0362ff 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -115,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 f53c9c9..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; } @@ -90,17 +86,20 @@ namespace grapher.Models.Serialized 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); @@ -124,7 +123,6 @@ namespace grapher.Models.Serialized { return new GUISettings { - AutoWriteToDriverOnStartup = AutoWriteMenuItem.Checked, DPI = (int)DpiField.Data, PollRate = (int)PollRateField.Data, ShowLastMouseMove = ShowLastMouseMoveMenuItem.Checked, @@ -139,10 +137,8 @@ namespace grapher.Models.Serialized try { RawAccelSettings = RawAccelSettings.Load(() => MakeGUISettingsFromFields()); - if (RawAccelSettings.GUISettings.AutoWriteToDriverOnStartup) - { - UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); - } + UpdateFieldsFromGUISettings(); + UpdateActiveAccelFromFileSettings(RawAccelSettings.AccelerationSettings); return; } catch (JsonException e) -- cgit v1.2.3 From 37d2cb7d3ed25862683ef807712c7d50f71e8493 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 02:08:27 -0400 Subject: add scroll to charts --- grapher/Models/AccelGUI.cs | 2 ++ grapher/Models/Charts/AccelCharts.cs | 34 ++++------------------- grapher/Models/Charts/ChartState/ChartState.cs | 25 ++--------------- grapher/Models/Charts/ChartXY.cs | 38 +++----------------------- grapher/Models/Options/ApplyOptions.cs | 7 ++--- 5 files changed, 15 insertions(+), 91 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index c561b23..50207b2 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -35,6 +35,7 @@ namespace grapher Settings = settings; Settings.Startup(); RefreshOnRead(Settings.RawAccelSettings.AccelerationSettings); + AccelForm.DoResize(); DefaultButtonFont = WriteButton.Font; SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * 0.666f); @@ -151,6 +152,7 @@ namespace grapher public void UpdateShownActiveValues(DriverSettings args) { + AccelForm.ResetAutoScroll(); AccelCharts.ShowActive(args); ApplyOptions.SetActiveValues(args); } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 9087b30..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/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() -- cgit v1.2.3 From eb32e441cd3fd5f53312df1af81400647833b213 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 18:44:07 -0400 Subject: rename sensitivity field to 'sens multiplier' --- 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 579e664..51bbc2b 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -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, -- cgit v1.2.3 From 0039d6e84d4e05e842542ad021a9c21e619c69c2 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 8 Oct 2020 19:44:40 -0700 Subject: Follow full C# convention --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Serialized/GUISettings.cs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index 50207b2..d93017a 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -98,7 +98,7 @@ namespace grapher private void SaveGUISettingsOnClose(Object sender, FormClosingEventArgs e) { var guiSettings = Settings.MakeGUISettingsFromFields(); - if (!Settings.RawAccelSettings.GUISettings.ValueEquals(guiSettings)) + if (!Settings.RawAccelSettings.GUISettings.Equals(guiSettings)) { Settings.RawAccelSettings.GUISettings = guiSettings; Settings.RawAccelSettings.Save(); diff --git a/grapher/Models/Serialized/GUISettings.cs b/grapher/Models/Serialized/GUISettings.cs index f9e5755..c8f87ae 100644 --- a/grapher/Models/Serialized/GUISettings.cs +++ b/grapher/Models/Serialized/GUISettings.cs @@ -31,7 +31,19 @@ namespace grapher.Models.Serialized #region Methods - public bool ValueEquals(GUISettings other) + 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 && @@ -39,6 +51,14 @@ namespace grapher.Models.Serialized ShowVelocityAndGain == other.ShowVelocityAndGain; } + public override int GetHashCode() + { + return DPI.GetHashCode() ^ + PollRate.GetHashCode() ^ + ShowLastMouseMove.GetHashCode() ^ + ShowVelocityAndGain.GetHashCode(); + } + #endregion Methods } } -- cgit v1.2.3 From a44294e7e689e43417323d6b1684f7462d113cb1 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 22:53:31 -0400 Subject: improve comments, variable names --- grapher/Models/Serialized/RawAccelSettings.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index e0362ff..818bfb6 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -55,16 +55,16 @@ namespace grapher.Models.Serialized { RawAccelSettings settings = null; - JObject jo = JObject.Parse(File.ReadAllText(file)); - if (jo.ContainsKey(DriverSettings.Key)) + JObject settingsJObject = JObject.Parse(File.ReadAllText(file)); + if (settingsJObject.ContainsKey(DriverSettings.Key)) { - settings = jo.ToObject(JsonSerializer.Create(SerializerSettings)); + settings = settingsJObject.ToObject(JsonSerializer.Create(SerializerSettings)); } else { settings = new RawAccelSettings { - AccelerationSettings = jo.ToObject(), + AccelerationSettings = settingsJObject.ToObject(), GUISettings = DefaultGUISettingsSupplier() }; } -- cgit v1.2.3 From 3b4796723709ae0cce9518ec0f682b737c6f7447 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 23:04:00 -0400 Subject: disable write button when settings are toggled off --- grapher/Models/AccelGUI.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index d93017a..f75d284 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -169,8 +169,7 @@ namespace grapher private void SetupButtons() { WriteButton.Top = AccelCharts.Top + AccelCharts.TopChartHeight - Constants.ButtonVerticalOffset; - SetWriteButtonDefault(); - + ToggleButton.Appearance = Appearance.Button; ToggleButton.FlatStyle = FlatStyle.System; ToggleButton.TextAlign = ContentAlignment.MiddleCenter; @@ -179,6 +178,7 @@ namespace grapher RefreshToggleStateFromNewSettings(); SetToggleButtonDefault(); + SetWriteButtonDefault(); } private void RefreshToggleStateFromNewSettings() @@ -191,7 +191,7 @@ namespace grapher { WriteButton.Font = DefaultButtonFont; WriteButton.Text = Constants.WriteButtonDefaultText; - WriteButton.Enabled = true; + WriteButton.Enabled = ToggleButton.Checked || !ToggleButton.Enabled; WriteButton.Update(); } @@ -230,8 +230,8 @@ namespace grapher private void OnButtonTimerTick(object sender, EventArgs e) { ButtonTimer.Stop(); - SetWriteButtonDefault(); SetToggleButtonDefault(); + SetWriteButtonDefault(); } private void StartButtonTimer() -- cgit v1.2.3 From bcacf971e4cace869243edd5fff3fdb435d48c44 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 8 Oct 2020 23:08:11 -0400 Subject: add magic number to constants --- grapher/Models/AccelGUI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index f75d284..dd1e37d 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -38,7 +38,7 @@ namespace grapher AccelForm.DoResize(); DefaultButtonFont = WriteButton.Font; - SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * 0.666f); + SmallButtonFont = new Font(WriteButton.Font.Name, WriteButton.Font.Size * Constants.SmallButtonSizeFactor); MouseWatcher = mouseWatcher; -- cgit v1.2.3