diff --git a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs index 113cfcce53..f191b3124b 100644 --- a/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs @@ -121,7 +121,8 @@ namespace BizHawk.Client.Common public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity; - public int GetWindowSize() => _config.TargetZoomFactors[Emulator.SystemId]; + public int GetWindowSize() + => _config.GetWindowScaleFor(Emulator.SystemId); public void InvisibleEmulation(bool invisible) => _mainForm.InvisibleEmulation = invisible; @@ -194,7 +195,7 @@ namespace BizHawk.Client.Common { if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10) { - _config.TargetZoomFactors[Emulator.SystemId] = size; + _config.SetWindowScaleFor(Emulator.SystemId, size); _mainForm.FrameBufferResized(); _displayManager.OSD.AddMessage($"Window size set to {size}x"); } diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 3d02de1da9..d794dc2f5e 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -4,6 +4,7 @@ using System.IO; using BizHawk.Bizware.Graphics; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Common.PathExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores; @@ -96,7 +97,13 @@ namespace BizHawk.Client.Common public bool StackOSDMessages { get; set; } = true; - public ZoomFactors TargetZoomFactors { get; set; } = new ZoomFactors(); + private Dictionary TargetZoomFactors { get; set; } = new(); + + public int GetWindowScaleFor(string sysID) + => TargetZoomFactors.GetValueOrPut(sysID, static _ => 2); + + public void SetWindowScaleFor(string sysID, int windowScale) + => TargetZoomFactors[sysID] = windowScale; // choose between 0 and 256 public int TargetScanlineFilterIntensity { get; set; } = 128; diff --git a/src/BizHawk.Client.Common/config/ZoomFactors.cs b/src/BizHawk.Client.Common/config/ZoomFactors.cs deleted file mode 100644 index bf5572142c..0000000000 --- a/src/BizHawk.Client.Common/config/ZoomFactors.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; - -namespace BizHawk.Client.Common -{ - public class ZoomFactors : Dictionary - { - public new int this[string index] - { - get - { - if (!ContainsKey(index)) - { - Add(index, 2); - } - - return base[index]; - } - - set => base[index] = value; - } - } -} diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 8cc5fec2cd..bccbdbc7c5 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -692,15 +692,16 @@ namespace BizHawk.Client.EmuHawk private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e) { + var windowScale = Config.GetWindowScaleFor(Emulator.SystemId); foreach (ToolStripMenuItem item in WindowSizeSubMenu.DropDownItems) { - item.Checked = Config.TargetZoomFactors[Emulator.SystemId] == (int) item.Tag; + item.Checked = (int) item.Tag == windowScale; } } private void WindowSize_Click(object sender, EventArgs e) { - Config.TargetZoomFactors[Emulator.SystemId] = (int) ((ToolStripMenuItem) sender).Tag; + Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag); FrameBufferResized(); } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 34e200ccbe..598c06cc30 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -1381,7 +1381,7 @@ namespace BizHawk.Client.EmuHawk // run this entire thing exactly twice, since the first resize may adjust the menu stacking for (int i = 0; i < 2; i++) { - int zoom = Config.TargetZoomFactors[Emulator.SystemId]; + int zoom = Config.GetWindowScaleFor(Emulator.SystemId); var area = Screen.FromControl(this).WorkingArea; int borderWidth = Size.Width - _presentationPanel.Control.Size.Width; @@ -2788,21 +2788,25 @@ namespace BizHawk.Client.EmuHawk private void IncreaseWindowSize() { - if (Config.TargetZoomFactors[Emulator.SystemId] < WINDOW_SCALE_MAX) + var windowScale = Config.GetWindowScaleFor(Emulator.SystemId); + if (windowScale < WINDOW_SCALE_MAX) { - Config.TargetZoomFactors[Emulator.SystemId]++; + windowScale++; + Config.SetWindowScaleFor(Emulator.SystemId, windowScale); } - AddOnScreenMessage($"Screensize set to {Config.TargetZoomFactors[Emulator.SystemId]}x"); + AddOnScreenMessage($"Screensize set to {windowScale}x"); FrameBufferResized(); } private void DecreaseWindowSize() { - if (Config.TargetZoomFactors[Emulator.SystemId] > 1) + var windowScale = Config.GetWindowScaleFor(Emulator.SystemId); + if (windowScale > 1) { - Config.TargetZoomFactors[Emulator.SystemId]--; + windowScale--; + Config.SetWindowScaleFor(Emulator.SystemId, windowScale); } - AddOnScreenMessage($"Screensize set to {Config.TargetZoomFactors[Emulator.SystemId]}x"); + AddOnScreenMessage($"Screensize set to {windowScale}x"); FrameBufferResized(); } diff --git a/src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs b/src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs index 1382400490..05fb558520 100644 --- a/src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs +++ b/src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs @@ -52,7 +52,6 @@ namespace BizHawk.Tests.Client.Common.config [typeof(RewindConfig)] = @"{""UseCompression"":false,""UseDelta"":false,""Enabled"":true,""AllowSlowStates"":false,""BufferSize"":512,""UseFixedRewindInterval"":false,""TargetFrameLength"":600,""TargetRewindInterval"":5,""AllowOutOfOrderStates"":true,""BackingStore"":0}", [typeof(SaveStateConfig)] = @"{""Type"":0,""CompressionLevelNormal"":1,""CompressionLevelRewind"":0,""MakeBackups"":true,""SaveScreenshot"":true,""BigScreenshotSize"":131072,""NoLowResLargeScreenshots"":false}", [typeof(ToolDialogSettings)] = @"{""_wndx"":52,""_wndy"":44,""Width"":796,""Height"":455,""SaveWindowPosition"":true,""TopMost"":false,""FloatingWindow"":true,""AutoLoad"":false}", - [typeof(ZoomFactors)] = @"{""NULL"":2,""GB"":3}", [typeof(ZwinderStateManagerSettings)] = ZWINDER_SER, };