Don't position tools to last saved position if that position is not visible on screen

This commit is contained in:
adelikat 2017-02-20 10:42:48 -06:00
parent b5730bda3a
commit c61d432fd6
7 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,8 @@
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Newtonsoft.Json;
namespace BizHawk.Client.Common
@ -56,6 +58,25 @@ namespace BizHawk.Client.Common
}
}
/// <summary>
/// Represents the top left corner coordinate, if Wndx and Wndy form a valid point
/// Throws an InvalidOperationException if Wndx or Wndy is null
/// It is expected to check for this before using this property
/// </summary>
[JsonIgnore]
public Point TopLeft
{
get
{
if (_wndx.HasValue && _wndy.HasValue)
{
return new Point(_wndx.Value, _wndy.Value);
}
throw new InvalidOperationException("TopLeft can not be used when one of the coordinates is null");
}
}
public int? Width { get; set; }
public int? Height { get; set; }

View File

@ -212,7 +212,7 @@ namespace BizHawk.Client.EmuHawk
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Settings.UseWindowPosition)
if (Settings.UseWindowPosition && IsOnScreen(Settings.TopLeft))
{
Location = Settings.WindowPosition;
}

View File

@ -25,7 +25,7 @@ namespace BizHawk.Client.EmuHawk
private void TI83KeyPad_Load(object sender, EventArgs e)
{
if (Global.Config.TI83KeypadSettings.UseWindowPosition)
if (Global.Config.TI83KeypadSettings.UseWindowPosition && IsOnScreen(Global.Config.TI83KeypadSettings.TopLeft))
{
Location = Global.Config.TI83KeypadSettings.WindowPosition;
}

View File

@ -9,6 +9,7 @@ using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions;
using System.Drawing;
namespace BizHawk.Client.EmuHawk
{
@ -131,5 +132,10 @@ namespace BizHawk.Client.EmuHawk
{
Owner = floatingWindow ? null : GlobalWin.MainForm;
}
protected bool IsOnScreen(Point topLeft)
{
return ToolManager.IsOnScreen(topLeft);
}
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
@ -244,7 +245,7 @@ namespace BizHawk.Client.EmuHawk
RefreshSettings(form, dest, settings, idx);
if (settings.UseWindowPosition)
if (settings.UseWindowPosition && IsOnScreen(settings.TopLeft))
{
form.StartPosition = FormStartPosition.Manual;
form.Location = settings.WindowPosition;
@ -364,6 +365,12 @@ namespace BizHawk.Client.EmuHawk
return false;
}
public static bool IsOnScreen(Point topLeft)
{
return Screen.AllScreens.Any(
screen => screen.WorkingArea.Contains(topLeft));
}
/// <summary>
/// Returns true if an instance of T exists
/// </summary>

View File

@ -233,7 +233,7 @@ namespace BizHawk.Client.EmuHawk
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Settings.UseWindowPosition)
if (Settings.UseWindowPosition && IsOnScreen(Settings.TopLeft))
{
Location = Settings.WindowPosition;
}

View File

@ -464,7 +464,7 @@ namespace BizHawk.Client.EmuHawk
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Settings.UseWindowPosition)
if (Settings.UseWindowPosition && IsOnScreen(Settings.TopLeft))
{
Location = Settings.WindowPosition;
}