Add option to disable automatic resize of main window (squashed PR #4011)
* Add option to disable automatic main window resize * Add option to window size submenu * Rename parameter to `forceWindowResize` * Add XML doc comments * Save main window size * Make `Config.MainWndx `/`MainWndy` nullable * Reduce total diff size * Move cast inside of `foreach` * Remove obsolete workaround Position isn't saved anymore when minimized * Combine config values into `Point` and `Size` * Add `Point` and `Size` to known good serializable types * Remove doc comment from implementation
This commit is contained in:
parent
d0482ac787
commit
2e4d2ce232
|
@ -197,7 +197,7 @@ namespace BizHawk.Client.Common
|
||||||
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
|
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
|
||||||
{
|
{
|
||||||
_config.SetWindowScaleFor(Emulator.SystemId, size);
|
_config.SetWindowScaleFor(Emulator.SystemId, size);
|
||||||
_mainForm.FrameBufferResized();
|
_mainForm.FrameBufferResized(forceWindowResize: true);
|
||||||
_displayManager.OSD.AddMessage($"Window size set to {size}x");
|
_displayManager.OSD.AddMessage($"Window size set to {size}x");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -53,7 +53,8 @@ namespace BizHawk.Client.Common
|
||||||
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
|
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
|
||||||
void FrameAdvance(bool discardApiHawkSurfaces = true);
|
void FrameAdvance(bool discardApiHawkSurfaces = true);
|
||||||
|
|
||||||
void FrameBufferResized();
|
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
|
||||||
|
void FrameBufferResized(bool forceWindowResize = false);
|
||||||
|
|
||||||
void FrameSkipMessage();
|
void FrameSkipMessage();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using BizHawk.Bizware.Graphics;
|
using BizHawk.Bizware.Graphics;
|
||||||
|
@ -139,8 +140,8 @@ namespace BizHawk.Client.Common
|
||||||
public bool MainFormStayOnTop { get; set; }
|
public bool MainFormStayOnTop { get; set; }
|
||||||
public bool StartPaused { get; set; }
|
public bool StartPaused { get; set; }
|
||||||
public bool StartFullscreen { get; set; }
|
public bool StartFullscreen { get; set; }
|
||||||
public int MainWndx { get; set; } = -1; // Negative numbers will be ignored
|
public Point? MainWindowPosition { get; set; }
|
||||||
public int MainWndy { get; set; } = -1;
|
public Size? MainWindowSize { get; set; }
|
||||||
public bool RunInBackground { get; set; } = true;
|
public bool RunInBackground { get; set; } = true;
|
||||||
public bool AcceptBackgroundInput { get; set; }
|
public bool AcceptBackgroundInput { get; set; }
|
||||||
public bool AcceptBackgroundInputControllerOnly { get; set; }
|
public bool AcceptBackgroundInputControllerOnly { get; set; }
|
||||||
|
@ -277,6 +278,11 @@ namespace BizHawk.Client.Common
|
||||||
public int DispCropRight { get; set; } = 0;
|
public int DispCropRight { get; set; } = 0;
|
||||||
public int DispCropBottom { get; set; } = 0;
|
public int DispCropBottom { get; set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatically resize main window when framebuffer size changes (default behavior)
|
||||||
|
/// </summary>
|
||||||
|
public bool ResizeWithFramebuffer { get; set; } = true;
|
||||||
|
|
||||||
// Sound options
|
// Sound options
|
||||||
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasXAudio2 ? ESoundOutputMethod.XAudio2 : ESoundOutputMethod.OpenAL;
|
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasXAudio2 ? ESoundOutputMethod.XAudio2 : ESoundOutputMethod.OpenAL;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
void FrameAdvance(bool discardApiHawkSurfaces = true);
|
void FrameAdvance(bool discardApiHawkSurfaces = true);
|
||||||
|
|
||||||
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
|
/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
|
||||||
void FrameBufferResized();
|
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
|
||||||
|
void FrameBufferResized(bool forceWindowResize = false);
|
||||||
|
|
||||||
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
|
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
|
||||||
bool LoadQuickSave(int slot, bool suppressOSD = false);
|
bool LoadQuickSave(int slot, bool suppressOSD = false);
|
||||||
|
|
|
@ -123,6 +123,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
this.LoadedCoreNameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
this.LoadedCoreNameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
this.ViewSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
this.ViewSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
this.WindowSizeSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
this.WindowSizeSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
|
this.toolStripSeparator26 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
|
||||||
|
this.DisableResizeWithFramebufferMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
this.SwitchToFullscreenMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
this.SwitchToFullscreenMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
this.toolStripSeparator2 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
|
this.toolStripSeparator2 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
|
||||||
this.DisplayFPSMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
this.DisplayFPSMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
|
||||||
|
@ -978,9 +980,18 @@ namespace BizHawk.Client.EmuHawk
|
||||||
//
|
//
|
||||||
// WindowSizeSubMenu
|
// WindowSizeSubMenu
|
||||||
//
|
//
|
||||||
|
this.WindowSizeSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
|
this.toolStripSeparator26,
|
||||||
|
this.DisableResizeWithFramebufferMenuItem});
|
||||||
this.WindowSizeSubMenu.Text = "&Window Size";
|
this.WindowSizeSubMenu.Text = "&Window Size";
|
||||||
this.WindowSizeSubMenu.DropDownOpened += new System.EventHandler(this.WindowSizeSubMenu_DropDownOpened);
|
this.WindowSizeSubMenu.DropDownOpened += new System.EventHandler(this.WindowSizeSubMenu_DropDownOpened);
|
||||||
//
|
//
|
||||||
|
// ResizeWithFramebufferMenuItem
|
||||||
|
//
|
||||||
|
this.DisableResizeWithFramebufferMenuItem.CheckOnClick = true;
|
||||||
|
this.DisableResizeWithFramebufferMenuItem.Text = "&Static Size";
|
||||||
|
this.DisableResizeWithFramebufferMenuItem.Click += new System.EventHandler(this.DisableResizeWithFramebufferMenuItem_Click);
|
||||||
|
//
|
||||||
// SwitchToFullscreenMenuItem
|
// SwitchToFullscreenMenuItem
|
||||||
//
|
//
|
||||||
this.SwitchToFullscreenMenuItem.Text = "Switch to Fullscreen";
|
this.SwitchToFullscreenMenuItem.Text = "Switch to Fullscreen";
|
||||||
|
@ -2767,5 +2778,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private ToolStripSeparatorEx toolStripSeparator24;
|
private ToolStripSeparatorEx toolStripSeparator24;
|
||||||
private ToolStripMenuItemEx AutosaveLastSlotMenuItem;
|
private ToolStripMenuItemEx AutosaveLastSlotMenuItem;
|
||||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator25;
|
private System.Windows.Forms.ToolStripSeparator toolStripSeparator25;
|
||||||
|
private ToolStripMenuItemEx DisableResizeWithFramebufferMenuItem;
|
||||||
|
private ToolStripSeparatorEx toolStripSeparator26;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -611,16 +611,27 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)
|
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var windowScale = Config.GetWindowScaleFor(Emulator.SystemId);
|
var windowScale = Config.GetWindowScaleFor(Emulator.SystemId);
|
||||||
foreach (ToolStripMenuItem item in WindowSizeSubMenu.DropDownItems)
|
foreach (var item in WindowSizeSubMenu.DropDownItems)
|
||||||
{
|
{
|
||||||
item.Checked = (int) item.Tag == windowScale;
|
// filter out separators
|
||||||
|
if (item is ToolStripMenuItem menuItem && menuItem.Tag is int itemScale)
|
||||||
|
{
|
||||||
|
menuItem.Checked = itemScale == windowScale && Config.ResizeWithFramebuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
DisableResizeWithFramebufferMenuItem.Checked = !Config.ResizeWithFramebuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DisableResizeWithFramebufferMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.ResizeWithFramebuffer = !DisableResizeWithFramebufferMenuItem.Checked;
|
||||||
|
FrameBufferResized();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WindowSize_Click(object sender, EventArgs e)
|
private void WindowSize_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag);
|
Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag);
|
||||||
FrameBufferResized();
|
FrameBufferResized(forceWindowResize: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwitchToFullscreenMenuItem_Click(object sender, EventArgs e)
|
private void SwitchToFullscreenMenuItem_Click(object sender, EventArgs e)
|
||||||
|
|
|
@ -61,9 +61,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
UpdateWindowTitle();
|
UpdateWindowTitle();
|
||||||
|
|
||||||
ToolStripItem[] CreateWindowSizeFactorSubmenus()
|
|
||||||
{
|
{
|
||||||
var items = new ToolStripItem[WINDOW_SCALE_MAX];
|
|
||||||
for (int i = 1; i <= WINDOW_SCALE_MAX; i++)
|
for (int i = 1; i <= WINDOW_SCALE_MAX; i++)
|
||||||
{
|
{
|
||||||
long quotient = Math.DivRem(i, 10, out long remainder);
|
long quotient = Math.DivRem(i, 10, out long remainder);
|
||||||
|
@ -73,11 +71,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Text = $"{(quotient > 0 ? quotient : "")}&{remainder}x"
|
Text = $"{(quotient > 0 ? quotient : "")}&{remainder}x"
|
||||||
};
|
};
|
||||||
temp.Click += this.WindowSize_Click;
|
temp.Click += this.WindowSize_Click;
|
||||||
items[i - 1] = temp;
|
WindowSizeSubMenu.DropDownItems.Insert(i - 1, temp);
|
||||||
}
|
}
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
WindowSizeSubMenu.DropDownItems.AddRange(CreateWindowSizeFactorSubmenus());
|
|
||||||
|
|
||||||
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData)
|
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData)
|
||||||
{
|
{
|
||||||
|
@ -603,20 +599,17 @@ namespace BizHawk.Client.EmuHawk
|
||||||
CheatList.Changed += Tools.UpdateCheatRelatedTools;
|
CheatList.Changed += Tools.UpdateCheatRelatedTools;
|
||||||
RewireSound();
|
RewireSound();
|
||||||
|
|
||||||
// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
|
if (Config.SaveWindowPosition)
|
||||||
if (Config.MainWndx == -32000)
|
|
||||||
{
|
{
|
||||||
Config.MainWndx = 0;
|
if (Config.MainWindowPosition is Point position)
|
||||||
}
|
{
|
||||||
|
Location = position;
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.MainWndy == -32000)
|
if (Config.MainWindowSize is Size size && !Config.ResizeWithFramebuffer)
|
||||||
{
|
{
|
||||||
Config.MainWndy = 0;
|
Size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.MainWndx != -1 && Config.MainWndy != -1 && Config.SaveWindowPosition)
|
|
||||||
{
|
|
||||||
Location = new Point(Config.MainWndx, Config.MainWndy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.MainFormStayOnTop) TopMost = true;
|
if (Config.MainFormStayOnTop) TopMost = true;
|
||||||
|
@ -1395,8 +1388,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
AddOnScreenMessage($"{fi.Name} saved.");
|
AddOnScreenMessage($"{fi.Name} saved.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FrameBufferResized()
|
public void FrameBufferResized(bool forceWindowResize = false)
|
||||||
{
|
{
|
||||||
|
if (!Config.ResizeWithFramebuffer && !forceWindowResize)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
|
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
|
@ -2422,20 +2419,16 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (Config.SaveWindowPosition)
|
if (Config.SaveWindowPosition)
|
||||||
{
|
{
|
||||||
if (Config.MainWndx != -32000) // When minimized location is -32000, don't save this into the config file!
|
if (WindowState is FormWindowState.Normal)
|
||||||
{
|
{
|
||||||
Config.MainWndx = Location.X;
|
Config.MainWindowPosition = Location;
|
||||||
}
|
Config.MainWindowSize = Size;
|
||||||
|
|
||||||
if (Config.MainWndy != -32000)
|
|
||||||
{
|
|
||||||
Config.MainWndy = Location.Y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Config.MainWndx = -1;
|
Config.MainWindowPosition = null;
|
||||||
Config.MainWndy = -1;
|
Config.MainWindowSize = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config.LastWrittenFrom = VersionInfo.MainVersion;
|
Config.LastWrittenFrom = VersionInfo.MainVersion;
|
||||||
|
@ -2591,7 +2584,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
|
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
|
||||||
}
|
}
|
||||||
AddOnScreenMessage($"Screensize set to {windowScale}x");
|
AddOnScreenMessage($"Screensize set to {windowScale}x");
|
||||||
FrameBufferResized();
|
FrameBufferResized(forceWindowResize: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DecreaseWindowSize()
|
private void DecreaseWindowSize()
|
||||||
|
@ -2603,7 +2596,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
|
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
|
||||||
}
|
}
|
||||||
AddOnScreenMessage($"Screensize set to {windowScale}x");
|
AddOnScreenMessage($"Screensize set to {windowScale}x");
|
||||||
FrameBufferResized();
|
FrameBufferResized(forceWindowResize: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly int[] SpeedPercents = { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 300, 400, 800, 1600, 3200, 6400 };
|
private static readonly int[] SpeedPercents = { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 300, 400, 800, 1600, 3200, 6400 };
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
@ -32,8 +33,10 @@ namespace BizHawk.Tests.Client.Common.config
|
||||||
typeof(List<>),
|
typeof(List<>),
|
||||||
typeof(Nullable<>),
|
typeof(Nullable<>),
|
||||||
typeof(object),
|
typeof(object),
|
||||||
|
typeof(Point),
|
||||||
typeof(Queue<>),
|
typeof(Queue<>),
|
||||||
typeof(float),
|
typeof(float),
|
||||||
|
typeof(Size),
|
||||||
typeof(string),
|
typeof(string),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue