From 76d6c4b4234d67e9634d6e65efa3b24757ba06b9 Mon Sep 17 00:00:00 2001 From: Aiden Dax Date: Sat, 17 Jul 2021 05:31:48 +0100 Subject: [PATCH] Fix initial window size and remember window pos On startup, set the window's size to a more appropriate value so as not to see the ugly scrollbars. Also, remember the window's location on exit and reapply it on startup. Author's note: This should not be merged upstream! This is just a hasty custom patch that I made that works well for my personal setup, where I use it with my custom profile switcher. I do not know whether the window size values used here only work well on my machine, or whether they would also work well for everyone. On my machine it is pixel perfect, such that the scroll bars don't appear but it is also not any larger than it needs to be. Also, for storing the window's location, it may be better to use GUISettings now (i.e the .config file), rather than what is utilized here (a .NET user.config file located in %LocalAppData%\grapher). As I say, I just put this together for my own personal benefit. --- grapher/App.config | 15 +++++++++++ grapher/Form1.Designer.cs | 1 + grapher/Form1.cs | 33 ++++++++++++++++++++----- grapher/Properties/Settings.Designer.cs | 30 ++++++++++++++++++++++ grapher/Properties/Settings.settings | 17 ++++++++----- 5 files changed, 84 insertions(+), 12 deletions(-) diff --git a/grapher/App.config b/grapher/App.config index 56efbc7..9171e6d 100644 --- a/grapher/App.config +++ b/grapher/App.config @@ -1,6 +1,21 @@  + + +
+ + + + + + 0, 0 + + + False + + + \ No newline at end of file diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index 89eafda..999e513 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -2337,6 +2337,7 @@ private void InitializeComponent() this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "RawAcceleration"; this.Text = "Raw Accel"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RawAcceleration_FormClosing); this.optionsPanel.ResumeLayout(false); this.optionsPanel.PerformLayout(); this.DirectionalityPanel.ResumeLayout(false); diff --git a/grapher/Form1.cs b/grapher/Form1.cs index b36d511..85ec3d4 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -279,16 +279,37 @@ public void ResizeAndCenter() Size = new Size { - Width = Math.Min(workingArea.Width, optionsPanel.Size.Width + chartsPreferredSize.Width), - Height = Math.Min(workingArea.Height, chartsPreferredSize.Height + 48) + Width = optionsPanel.Size.Width + chartsPreferredSize.Width + 13, + Height = chartsPreferredSize.Height + 36 }; - Location = new Point + Location = Properties.Settings.Default.WindowLocation; + + if (Properties.Settings.Default.WindowMaximized) { - X = workingArea.X + (workingArea.Width - Size.Width) / 2, - Y = workingArea.Y + (workingArea.Height - Size.Height) / 2 - }; + WindowState = FormWindowState.Maximized; + } + } + + private void RawAcceleration_FormClosing(object sender, FormClosingEventArgs e) + { + switch (WindowState) + { + case FormWindowState.Maximized: + Properties.Settings.Default.WindowMaximized = true; + Properties.Settings.Default.WindowLocation = RestoreBounds.Location; + break; + case FormWindowState.Minimized: + Properties.Settings.Default.WindowMaximized = false; + Properties.Settings.Default.WindowLocation = RestoreBounds.Location; + break; + case FormWindowState.Normal: + Properties.Settings.Default.WindowMaximized = false; + Properties.Settings.Default.WindowLocation = Location; + break; + } + Properties.Settings.Default.Save(); } #endregion Method diff --git a/grapher/Properties/Settings.Designer.cs b/grapher/Properties/Settings.Designer.cs index d305209..b04bbed 100644 --- a/grapher/Properties/Settings.Designer.cs +++ b/grapher/Properties/Settings.Designer.cs @@ -26,5 +26,35 @@ public static Settings Default return defaultInstance; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0, 0")] + public global::System.Drawing.Point WindowLocation + { + get + { + return ((global::System.Drawing.Point)(this["WindowLocation"])); + } + set + { + this["WindowLocation"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool WindowMaximized + { + get + { + return ((bool)(this["WindowMaximized"])); + } + set + { + this["WindowMaximized"] = value; + } + } } } diff --git a/grapher/Properties/Settings.settings b/grapher/Properties/Settings.settings index 3964565..7f25cf1 100644 --- a/grapher/Properties/Settings.settings +++ b/grapher/Properties/Settings.settings @@ -1,7 +1,12 @@  - - - - - - + + + + + 0, 0 + + + False + + + \ No newline at end of file