diff --git a/GUI.NET/Debugger/frmApuViewer.cs b/GUI.NET/Debugger/frmApuViewer.cs index 63487929..a6f0526e 100644 --- a/GUI.NET/Debugger/frmApuViewer.cs +++ b/GUI.NET/Debugger/frmApuViewer.cs @@ -25,10 +25,7 @@ namespace Mesen.GUI.Debugger this.Width = (int)(this.Width * 1.2); } - if(ConfigManager.Config.DebugInfo.ApuViewerLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.DebugInfo.ApuViewerLocation.Value; - } + RestoreLocation(ConfigManager.Config.DebugInfo.ApuViewerLocation); } } diff --git a/GUI.NET/Debugger/frmAssembler.cs b/GUI.NET/Debugger/frmAssembler.cs index 46cc038b..e2e4ac8b 100644 --- a/GUI.NET/Debugger/frmAssembler.cs +++ b/GUI.NET/Debugger/frmAssembler.cs @@ -36,11 +36,8 @@ namespace Mesen.GUI.Debugger DebugInfo config = ConfigManager.Config.DebugInfo; - if(!config.AssemblerSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = config.AssemblerSize; - this.Location = config.AssemblerLocation; - } + RestoreLocation(config.AssemblerLocation, config.AssemblerSize); + mnuEnableSyntaxHighlighting.Checked = config.AssemblerCodeHighlighting; txtCode.Font = new Font(config.AssemblerFontFamily, config.AssemblerFontSize, config.AssemblerFontStyle); diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index 70ba2fe4..abfdd177 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -134,10 +134,7 @@ namespace Mesen.GUI.Debugger ctrlDebuggerCodeSplit.ShowMemoryValues = mnuShowMemoryValues.Checked; if(ConfigManager.Config.DebugInfo.WindowWidth > -1) { - this.StartPosition = FormStartPosition.Manual; - this.Width = ConfigManager.Config.DebugInfo.WindowWidth; - this.Height = ConfigManager.Config.DebugInfo.WindowHeight; - this.Location = ConfigManager.Config.DebugInfo.WindowLocation; + RestoreLocation(ConfigManager.Config.DebugInfo.WindowLocation, new Size(ConfigManager.Config.DebugInfo.WindowWidth, ConfigManager.Config.DebugInfo.WindowHeight)); } tsToolbar.Visible = mnuShowToolbar.Checked; diff --git a/GUI.NET/Debugger/frmEventViewer.cs b/GUI.NET/Debugger/frmEventViewer.cs index 8d2c5a62..c500a770 100644 --- a/GUI.NET/Debugger/frmEventViewer.cs +++ b/GUI.NET/Debugger/frmEventViewer.cs @@ -63,10 +63,7 @@ namespace Mesen.GUI.Debugger DebugWorkspaceManager.GetWorkspace(); - if(!ConfigManager.Config.DebugInfo.EventViewerLocation.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.DebugInfo.EventViewerLocation; - } + RestoreLocation(ConfigManager.Config.DebugInfo.EventViewerLocation); this._notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId); this._notifListener.OnNotification += this._notifListener_OnNotification; diff --git a/GUI.NET/Debugger/frmMemoryViewer.cs b/GUI.NET/Debugger/frmMemoryViewer.cs index bf9fe0eb..b6c593c8 100644 --- a/GUI.NET/Debugger/frmMemoryViewer.cs +++ b/GUI.NET/Debugger/frmMemoryViewer.cs @@ -94,11 +94,7 @@ namespace Mesen.GUI.Debugger this.mnuShowCharacters.CheckedChanged += this.mnuShowCharacters_CheckedChanged; this.mnuIgnoreRedundantWrites.CheckedChanged += mnuIgnoreRedundantWrites_CheckedChanged; - if(!ConfigManager.Config.DebugInfo.MemoryViewerSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = ConfigManager.Config.DebugInfo.MemoryViewerSize; - this.Location = ConfigManager.Config.DebugInfo.MemoryViewerLocation; - } + RestoreLocation(ConfigManager.Config.DebugInfo.MemoryViewerLocation, ConfigManager.Config.DebugInfo.MemoryViewerSize); this.InitShortcuts(); } diff --git a/GUI.NET/Debugger/frmPpuViewer.cs b/GUI.NET/Debugger/frmPpuViewer.cs index 9e3d7126..ef857a37 100644 --- a/GUI.NET/Debugger/frmPpuViewer.cs +++ b/GUI.NET/Debugger/frmPpuViewer.cs @@ -48,10 +48,7 @@ namespace Mesen.GUI.Debugger default: startupLocation = ConfigManager.Config.DebugInfo.PpuWindowLocation; break; } - if(startupLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = startupLocation.Value; - } + RestoreLocation(startupLocation); } public static int GetNextPpuViewerId() diff --git a/GUI.NET/Debugger/frmProfiler.cs b/GUI.NET/Debugger/frmProfiler.cs index 2965638c..96e1b76b 100644 --- a/GUI.NET/Debugger/frmProfiler.cs +++ b/GUI.NET/Debugger/frmProfiler.cs @@ -24,11 +24,7 @@ namespace Mesen.GUI.Debugger ctrlProfiler.RefreshData(); tmrRefresh.Start(); - if(!ConfigManager.Config.DebugInfo.ProfilerSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = ConfigManager.Config.DebugInfo.ProfilerSize; - this.Location = ConfigManager.Config.DebugInfo.ProfilerLocation; - } + RestoreLocation(ConfigManager.Config.DebugInfo.ProfilerLocation, ConfigManager.Config.DebugInfo.ProfilerSize); } } diff --git a/GUI.NET/Debugger/frmScript.cs b/GUI.NET/Debugger/frmScript.cs index 03db22db..42dfa1f2 100644 --- a/GUI.NET/Debugger/frmScript.cs +++ b/GUI.NET/Debugger/frmScript.cs @@ -103,11 +103,7 @@ namespace Mesen.GUI.Debugger } } - if(!config.ScriptWindowSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = config.ScriptWindowSize; - this.Location = config.ScriptWindowLocation; - } + RestoreLocation(config.ScriptWindowLocation, config.ScriptWindowSize); mnuSaveBeforeRun.Checked = config.SaveScriptBeforeRun; if(config.ScriptCodeWindowHeight >= ctrlSplit.Panel1MinSize) { diff --git a/GUI.NET/Debugger/frmTextHooker.cs b/GUI.NET/Debugger/frmTextHooker.cs index 9dca73b2..33645738 100644 --- a/GUI.NET/Debugger/frmTextHooker.cs +++ b/GUI.NET/Debugger/frmTextHooker.cs @@ -36,10 +36,7 @@ namespace Mesen.GUI.Debugger this.mnuAutoRefresh.Checked = ConfigManager.Config.DebugInfo.TextHookerAutoRefresh; this.mnuRefreshOnBreak.Checked = ConfigManager.Config.DebugInfo.TextHookerRefreshOnBreak; - if(ConfigManager.Config.DebugInfo.TextHookerWindowLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.DebugInfo.TextHookerWindowLocation.Value; - } + RestoreLocation(ConfigManager.Config.DebugInfo.TextHookerWindowLocation); } static frmTextHooker() diff --git a/GUI.NET/Debugger/frmTraceLogger.cs b/GUI.NET/Debugger/frmTraceLogger.cs index 2ab954dc..5cbd9cb2 100644 --- a/GUI.NET/Debugger/frmTraceLogger.cs +++ b/GUI.NET/Debugger/frmTraceLogger.cs @@ -32,11 +32,7 @@ namespace Mesen.GUI.Debugger InitializeComponent(); DebugInfo debugInfo = ConfigManager.Config.DebugInfo; - if(!debugInfo.TraceLoggerSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = debugInfo.TraceLoggerSize; - this.Location = debugInfo.TraceLoggerLocation; - } + RestoreLocation(debugInfo.TraceLoggerLocation, debugInfo.TraceLoggerSize); _tooltipManager = new CodeTooltipManager(this, txtTraceLog); diff --git a/GUI.NET/Debugger/frmWatchWindow.cs b/GUI.NET/Debugger/frmWatchWindow.cs index 2a4a5a15..f07a7dbf 100644 --- a/GUI.NET/Debugger/frmWatchWindow.cs +++ b/GUI.NET/Debugger/frmWatchWindow.cs @@ -21,12 +21,7 @@ namespace Mesen.GUI.Debugger InitializeComponent(); if(!DesignMode) { - if(!ConfigManager.Config.DebugInfo.WatchWindowSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = ConfigManager.Config.DebugInfo.WatchWindowSize; - this.Location = ConfigManager.Config.DebugInfo.WatchWindowLocation; - } - + RestoreLocation(ConfigManager.Config.DebugInfo.WatchWindowLocation, ConfigManager.Config.DebugInfo.WatchWindowSize); this.toolTip.SetToolTip(picWatchHelp, ctrlWatch.GetTooltipText()); } } diff --git a/GUI.NET/Forms/BaseForm.cs b/GUI.NET/Forms/BaseForm.cs index 095c1d6e..31c9ba06 100644 --- a/GUI.NET/Forms/BaseForm.cs +++ b/GUI.NET/Forms/BaseForm.cs @@ -197,7 +197,27 @@ namespace Mesen.GUI.Forms base.AutoScaleMode = value; } } - } + } + + protected void RestoreLocation(Point? location, Size? size = null) + { + if(!location.HasValue || size.HasValue && size.Value.IsEmpty) { + return; + } + + this.StartPosition = FormStartPosition.Manual; + + if(!Screen.AllScreens.Any((screen) => screen.Bounds.Contains(location.Value))) { + //If no screen contains the top left corner of the form, reset it to the primary screen + this.Location = Screen.PrimaryScreen.Bounds.Location; + } else { + this.Location = location.Value; + } + + if(size != null) { + this.Size = size.Value; + } + } private void InitializeComponent() { diff --git a/GUI.NET/Forms/Cheats/frmCheatList.cs b/GUI.NET/Forms/Cheats/frmCheatList.cs index 77156e41..144e1202 100644 --- a/GUI.NET/Forms/Cheats/frmCheatList.cs +++ b/GUI.NET/Forms/Cheats/frmCheatList.cs @@ -33,11 +33,7 @@ namespace Mesen.GUI.Forms.Cheats ctrlCheatFinder.OnAddCheat += CtrlCheatFinder_OnAddCheat; - if(!ConfigManager.Config.CheatWindowSize.IsEmpty) { - this.StartPosition = FormStartPosition.Manual; - this.Size = ConfigManager.Config.CheatWindowSize; - this.Location = ConfigManager.Config.CheatWindowLocation; - } + RestoreLocation(ConfigManager.Config.CheatWindowLocation, ConfigManager.Config.CheatWindowSize); } } diff --git a/GUI.NET/Forms/frmHistoryViewer.cs b/GUI.NET/Forms/frmHistoryViewer.cs index cd55b625..054734b7 100644 --- a/GUI.NET/Forms/frmHistoryViewer.cs +++ b/GUI.NET/Forms/frmHistoryViewer.cs @@ -27,13 +27,7 @@ namespace Mesen.GUI.Forms { base.OnLoad(e); - if(ConfigManager.Config.HistoryViewerInfo.WindowSize.HasValue) { - this.Size = ConfigManager.Config.HistoryViewerInfo.WindowSize.Value; - } - if(ConfigManager.Config.HistoryViewerInfo.WindowLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.HistoryViewerInfo.WindowLocation.Value; - } + RestoreLocation(ConfigManager.Config.HistoryViewerInfo.WindowLocation, ConfigManager.Config.HistoryViewerInfo.WindowSize); _isNsf = InteropEmu.IsNsf(); tlpRenderer.Visible = !_isNsf; diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 206fb6eb..ea2edadc 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -237,10 +237,7 @@ namespace Mesen.GUI.Forms InitializeStateMenu(mnuSaveState, true); InitializeStateMenu(mnuLoadState, false); - if(ConfigManager.Config.WindowLocation.HasValue) { - this.StartPosition = FormStartPosition.Manual; - this.Location = ConfigManager.Config.WindowLocation.Value; - } + RestoreLocation(ConfigManager.Config.WindowLocation); if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) { Task.Run(() => CloudSyncHelper.Sync());