From 4a7f05ed36c792d421174f838097de8d224e02b0 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 24 Sep 2022 17:13:09 +0100 Subject: [PATCH] Full-screen: Retain uniform x and y scaling, unless user specifies a full-screen resolution (#1121) --- source/Windows/AppleWin.cpp | 10 ++++++++++ source/Windows/AppleWin.h | 1 + source/Windows/WinFrame.cpp | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index d72267fc..7d96722c 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -64,6 +64,8 @@ static bool g_bSysClkOK = false; bool g_bRestartFullScreen = false; +static bool g_fullScreenResolutionChangedByUser = false; + //=========================================================================== bool GetLoadedSaveStateFlag(void) @@ -86,6 +88,11 @@ bool GetHookAltGrControl(void) return g_bHookAltGrControl; } +bool GetFullScreenResolutionChangedByUser(void) +{ + return g_fullScreenResolutionChangedByUser; +} + static void ResetToLogoMode(void) { g_nAppMode = MODE_LOGO; @@ -809,6 +816,9 @@ static void RepeatInitialization(void) LogFileOutput("Best resolution for -fs-width/height=x switch(es): Width=%d, Height=%d\n", bestWidth, bestHeight); else LogFileOutput("Failed to set parameter for -fs-width/height=x switch(es)\n"); + + if (res) + g_fullScreenResolutionChangedByUser = true; } // Pre: may need g_hFrameWindow for MessageBox errors diff --git a/source/Windows/AppleWin.h b/source/Windows/AppleWin.h index 31c348e2..16e4f03d 100644 --- a/source/Windows/AppleWin.h +++ b/source/Windows/AppleWin.h @@ -8,5 +8,6 @@ void SingleStep(bool bReinit); bool GetLoadedSaveStateFlag(void); bool GetHookAltTab(void); bool GetHookAltGrControl(void); +bool GetFullScreenResolutionChangedByUser(void); extern bool g_bRestartFullScreen; diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp index 53c6f7e3..dcf7f023 100644 --- a/source/Windows/WinFrame.cpp +++ b/source/Windows/WinFrame.cpp @@ -2149,6 +2149,13 @@ void Win32Frame::SetFullScreenMode(void) scalex = width / GetVideo().GetFrameBufferBorderlessWidth(); scaley = height / GetVideo().GetFrameBufferBorderlessHeight(); + // Retain aspect ratio if user hasn't changed full-screen resolution (GH#1121) + if (!GetFullScreenResolutionChangedByUser()) + { + const int minimumScale = (scalex <= scaley) ? scalex : scaley; + scalex = scaley = minimumScale; + } + // NB. Separate x,y scaling is OK in full-screen mode // . eg. SHR 640x400 (scalex=2, scaley=3) => 1280x1200, which roughly gives a 4:3 aspect ratio for a resolution of 1600x1200 g_win_fullscreen_offsetx = ((int)width - (int)(scalex * GetVideo().GetFrameBufferBorderlessWidth())) / 2;