UI: Prevent windows from appearing outside the available screens when restoring their position

This commit is contained in:
Sour 2019-10-06 19:58:56 -04:00
parent 2310e8d0e9
commit 8ee5bd5a10
10 changed files with 27 additions and 47 deletions

View file

@ -33,11 +33,7 @@ namespace Mesen.GUI.Debugger
InitShortcuts();
EventViewerConfig config = ConfigManager.Config.Debug.EventViewer;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
mnuRefreshOnBreakPause.Checked = ConfigManager.Config.Debug.EventViewer.RefreshOnBreakPause;
ctrlPpuView.ImageScale = config.ImageScale;

View file

@ -82,11 +82,7 @@ namespace Mesen.GUI.Debugger
this.mnuShowCharacters.CheckedChanged += this.mnuShowCharacters_CheckedChanged;
this.mnuIgnoreRedundantWrites.CheckedChanged += mnuIgnoreRedundantWrites_CheckedChanged;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
this.InitShortcuts();
}

View file

@ -49,11 +49,7 @@ namespace Mesen.GUI.Debugger
InitShortcuts();
SpriteViewerConfig config = ConfigManager.Config.Debug.SpriteViewer;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
_refreshManager = new WindowRefreshManager(this);
_refreshManager.AutoRefresh = config.AutoRefresh;

View file

@ -55,11 +55,7 @@ namespace Mesen.GUI.Debugger
InitShortcuts();
TileViewerConfig config = ConfigManager.Config.Debug.TileViewer;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
cboMemoryType.SetEnumValue(config.Source);
cboFormat.SetEnumValue(config.Format);

View file

@ -49,11 +49,7 @@ namespace Mesen.GUI.Debugger
InitShortcuts();
TilemapViewerConfig config = ConfigManager.Config.Debug.TilemapViewer;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
mnuAutoRefresh.Checked = config.AutoRefresh;
chkShowTileGrid.Checked = config.ShowTileGrid;

View file

@ -98,11 +98,7 @@ namespace Mesen.GUI.Debugger
LoadBuiltInScript("Example.lua");
}
if(!cfg.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = cfg.WindowSize;
this.Location = cfg.WindowLocation;
}
RestoreLocation(cfg.WindowLocation, cfg.WindowSize);
mnuSaveBeforeRun.Checked = cfg.SaveScriptBeforeRun;
if(cfg.CodeWindowHeight >= ctrlSplit.Panel1MinSize) {

View file

@ -291,11 +291,7 @@ namespace Mesen.GUI.Debugger
ctrlDisassemblyView.CodeViewer.BaseFont = font;
ctrlDisassemblyView.CodeViewer.TextZoom = cfg.TextZoom;
if(!cfg.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = cfg.WindowSize;
this.Location = cfg.WindowLocation;
}
RestoreLocation(cfg.WindowLocation, cfg.WindowSize);
if(cfg.SplitterDistance.HasValue) {
ctrlSplitContainer.SplitterDistance = cfg.SplitterDistance.Value;

View file

@ -32,11 +32,7 @@ namespace Mesen.GUI.Debugger
InitializeComponent();
TraceLoggerInfo config = ConfigManager.Config.Debug.TraceLogger;
if(!config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Size = config.WindowSize;
this.Location = config.WindowLocation;
}
RestoreLocation(config.WindowLocation, config.WindowSize);
txtTraceLog.BaseFont = new Font(config.FontFamily, config.FontSize, config.FontStyle);
txtTraceLog.TextZoom = config.TextZoom;

View file

@ -160,7 +160,24 @@ namespace Mesen.GUI.Forms
base.AutoScaleMode = value;
}
}
}
}
protected void RestoreLocation(Point location, Size size)
{
if(size.IsEmpty) {
return;
}
this.StartPosition = FormStartPosition.Manual;
if(!Screen.AllScreens.Any((screen) => screen.Bounds.Contains(location))) {
//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;
}
this.Size = size;
}
private void InitializeComponent()
{

View file

@ -44,12 +44,7 @@ namespace Mesen.GUI.Forms
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if(!ConfigManager.Config.WindowSize.IsEmpty) {
this.StartPosition = FormStartPosition.Manual;
this.Location = ConfigManager.Config.WindowLocation;
this.Size = ConfigManager.Config.WindowSize;
}
RestoreLocation(ConfigManager.Config.WindowLocation, ConfigManager.Config.WindowSize);
}
protected override void OnShown(EventArgs e)