Skip to content

Commit

Permalink
Replace ZoomFactors with a plain Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Jun 6, 2024
1 parent 7bb7cde commit df05537
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public void FrameSkip(int numFrames)

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;

Expand Down Expand Up @@ -194,7 +195,7 @@ public void SetWindowSize(int size)
{
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");
}
Expand Down
9 changes: 8 additions & 1 deletion src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using BizHawk.Bizware.Graphics;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.PathExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores;
Expand Down Expand Up @@ -96,7 +97,13 @@ public void ResolveDefaults()

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
public int TargetScanlineFilterIntensity { get; set; } = 128;
Expand Down
22 changes: 0 additions & 22 deletions src/BizHawk.Client.Common/config/ZoomFactors.cs

This file was deleted.

5 changes: 3 additions & 2 deletions src/BizHawk.Client.EmuHawk/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,15 +692,16 @@ private void ViewSubMenu_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)
{
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();
}

Expand Down
18 changes: 11 additions & 7 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ public void FrameBufferResized()
// 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;
Expand Down Expand Up @@ -2788,21 +2788,25 @@ public BitmapBuffer CaptureLua()

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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public sealed class SerializationStabilityTests
[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,
};

Expand Down

0 comments on commit df05537

Please sign in to comment.