Replace `ZoomFactors` with a plain `Dictionary`

This commit is contained in:
YoshiRulz 2024-06-06 13:02:11 +10:00
parent 7bb7cdeaee
commit df05537ca6
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
6 changed files with 25 additions and 35 deletions

View File

@ -121,7 +121,8 @@ namespace BizHawk.Client.Common
public int GetTargetScanlineIntensity() => _config.TargetScanlineFilterIntensity; 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; 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) 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(); _mainForm.FrameBufferResized();
_displayManager.OSD.AddMessage($"Window size set to {size}x"); _displayManager.OSD.AddMessage($"Window size set to {size}x");
} }

View File

@ -4,6 +4,7 @@ using System.IO;
using BizHawk.Bizware.Graphics; using BizHawk.Bizware.Graphics;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.PathExtensions; using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores; using BizHawk.Emulation.Cores;
@ -96,7 +97,13 @@ namespace BizHawk.Client.Common
public bool StackOSDMessages { get; set; } = true; public bool StackOSDMessages { get; set; } = true;
public ZoomFactors TargetZoomFactors { get; set; } = new ZoomFactors(); private Dictionary<string, int> 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 // choose between 0 and 256
public int TargetScanlineFilterIntensity { get; set; } = 128; public int TargetScanlineFilterIntensity { get; set; } = 128;

View File

@ -1,22 +0,0 @@
using System.Collections.Generic;
namespace BizHawk.Client.Common
{
public class ZoomFactors : Dictionary<string, int>
{
public new int this[string index]
{
get
{
if (!ContainsKey(index))
{
Add(index, 2);
}
return base[index];
}
set => base[index] = value;
}
}
}

View File

@ -692,15 +692,16 @@ 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);
foreach (ToolStripMenuItem item in WindowSizeSubMenu.DropDownItems) 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) 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(); FrameBufferResized();
} }

View File

@ -1381,7 +1381,7 @@ namespace BizHawk.Client.EmuHawk
// 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++)
{ {
int zoom = Config.TargetZoomFactors[Emulator.SystemId]; int zoom = Config.GetWindowScaleFor(Emulator.SystemId);
var area = Screen.FromControl(this).WorkingArea; var area = Screen.FromControl(this).WorkingArea;
int borderWidth = Size.Width - _presentationPanel.Control.Size.Width; int borderWidth = Size.Width - _presentationPanel.Control.Size.Width;
@ -2788,21 +2788,25 @@ namespace BizHawk.Client.EmuHawk
private void IncreaseWindowSize() 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(); FrameBufferResized();
} }
private void DecreaseWindowSize() 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(); FrameBufferResized();
} }

View File

@ -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(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(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(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, [typeof(ZwinderStateManagerSettings)] = ZWINDER_SER,
}; };