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:
kalimag 2024-09-13 14:17:27 +02:00 committed by GitHub
parent d0482ac787
commit 2e4d2ce232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 65 additions and 37 deletions

View File

@ -197,7 +197,7 @@ namespace BizHawk.Client.Common
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
{
_config.SetWindowScaleFor(Emulator.SystemId, size);
_mainForm.FrameBufferResized();
_mainForm.FrameBufferResized(forceWindowResize: true);
_displayManager.OSD.AddMessage($"Window size set to {size}x");
}
else

View File

@ -53,7 +53,8 @@ namespace BizHawk.Client.Common
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
void FrameAdvance(bool discardApiHawkSurfaces = true);
void FrameBufferResized();
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
void FrameBufferResized(bool forceWindowResize = false);
void FrameSkipMessage();

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using BizHawk.Bizware.Graphics;
@ -139,8 +140,8 @@ namespace BizHawk.Client.Common
public bool MainFormStayOnTop { get; set; }
public bool StartPaused { get; set; }
public bool StartFullscreen { get; set; }
public int MainWndx { get; set; } = -1; // Negative numbers will be ignored
public int MainWndy { get; set; } = -1;
public Point? MainWindowPosition { get; set; }
public Size? MainWindowSize { get; set; }
public bool RunInBackground { get; set; } = true;
public bool AcceptBackgroundInput { get; set; }
public bool AcceptBackgroundInputControllerOnly { get; set; }
@ -277,6 +278,11 @@ namespace BizHawk.Client.Common
public int DispCropRight { 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
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasXAudio2 ? ESoundOutputMethod.XAudio2 : ESoundOutputMethod.OpenAL;

View File

@ -58,7 +58,8 @@ namespace BizHawk.Client.EmuHawk
void FrameAdvance(bool discardApiHawkSurfaces = true);
/// <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>
bool LoadQuickSave(int slot, bool suppressOSD = false);

View File

@ -123,6 +123,8 @@ namespace BizHawk.Client.EmuHawk
this.LoadedCoreNameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.ViewSubMenu = 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.toolStripSeparator2 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.DisplayFPSMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
@ -978,9 +980,18 @@ namespace BizHawk.Client.EmuHawk
//
// WindowSizeSubMenu
//
this.WindowSizeSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripSeparator26,
this.DisableResizeWithFramebufferMenuItem});
this.WindowSizeSubMenu.Text = "&Window Size";
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
//
this.SwitchToFullscreenMenuItem.Text = "Switch to Fullscreen";
@ -2767,5 +2778,7 @@ namespace BizHawk.Client.EmuHawk
private ToolStripSeparatorEx toolStripSeparator24;
private ToolStripMenuItemEx AutosaveLastSlotMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator25;
private ToolStripMenuItemEx DisableResizeWithFramebufferMenuItem;
private ToolStripSeparatorEx toolStripSeparator26;
}
}

View File

@ -611,16 +611,27 @@ namespace BizHawk.Client.EmuHawk
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)
{
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)
{
Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag);
FrameBufferResized();
FrameBufferResized(forceWindowResize: true);
}
private void SwitchToFullscreenMenuItem_Click(object sender, EventArgs e)

View File

@ -61,9 +61,7 @@ namespace BizHawk.Client.EmuHawk
{
UpdateWindowTitle();
ToolStripItem[] CreateWindowSizeFactorSubmenus()
{
var items = new ToolStripItem[WINDOW_SCALE_MAX];
for (int i = 1; i <= WINDOW_SCALE_MAX; i++)
{
long quotient = Math.DivRem(i, 10, out long remainder);
@ -73,11 +71,9 @@ namespace BizHawk.Client.EmuHawk
Text = $"{(quotient > 0 ? quotient : "")}&{remainder}x"
};
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)
{
@ -603,20 +599,17 @@ namespace BizHawk.Client.EmuHawk
CheatList.Changed += Tools.UpdateCheatRelatedTools;
RewireSound();
// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
if (Config.MainWndx == -32000)
if (Config.SaveWindowPosition)
{
Config.MainWndx = 0;
}
if (Config.MainWindowPosition is Point position)
{
Location = position;
}
if (Config.MainWndy == -32000)
{
Config.MainWndy = 0;
}
if (Config.MainWndx != -1 && Config.MainWndy != -1 && Config.SaveWindowPosition)
{
Location = new Point(Config.MainWndx, Config.MainWndy);
if (Config.MainWindowSize is Size size && !Config.ResizeWithFramebuffer)
{
Size = size;
}
}
if (Config.MainFormStayOnTop) TopMost = true;
@ -1395,8 +1388,12 @@ namespace BizHawk.Client.EmuHawk
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
for (int i = 0; i < 2; i++)
{
@ -2422,20 +2419,16 @@ namespace BizHawk.Client.EmuHawk
{
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;
}
if (Config.MainWndy != -32000)
{
Config.MainWndy = Location.Y;
Config.MainWindowPosition = Location;
Config.MainWindowSize = Size;
}
}
else
{
Config.MainWndx = -1;
Config.MainWndy = -1;
Config.MainWindowPosition = null;
Config.MainWindowSize = null;
}
Config.LastWrittenFrom = VersionInfo.MainVersion;
@ -2591,7 +2584,7 @@ namespace BizHawk.Client.EmuHawk
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
}
AddOnScreenMessage($"Screensize set to {windowScale}x");
FrameBufferResized();
FrameBufferResized(forceWindowResize: true);
}
private void DecreaseWindowSize()
@ -2603,7 +2596,7 @@ namespace BizHawk.Client.EmuHawk
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
}
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 };

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using BizHawk.Client.Common;
@ -32,8 +33,10 @@ namespace BizHawk.Tests.Client.Common.config
typeof(List<>),
typeof(Nullable<>),
typeof(object),
typeof(Point),
typeof(Queue<>),
typeof(float),
typeof(Size),
typeof(string),
};