From 01b3fff8f1980bee418adfa9341bedeba40bf923 Mon Sep 17 00:00:00 2001 From: JaceCear <11230293+JaceCear@users.noreply.github.com> Date: Mon, 3 Mar 2025 13:00:44 +0100 Subject: [PATCH] Options: Add Custom Aspect Ratios --- UnleashedRecomp/gpu/video.cpp | 22 ++++++++++++++++++++++ UnleashedRecomp/locale/config_locale.cpp | 16 +++++++++++++++- UnleashedRecomp/ui/options_menu.cpp | 2 ++ UnleashedRecomp/user/config.cpp | 1 + UnleashedRecomp/user/config.h | 3 ++- UnleashedRecomp/user/config_def.h | 2 ++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 3919877..d78fd73 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -2913,6 +2913,26 @@ void Video::ComputeViewportDimensions() break; } + + case EAspectRatio::Custom: + { + uint32_t horzAspect = Config::AspectWidth; + uint32_t vertAspect = Config::AspectHeight; + float customAspectRatio = float(horzAspect) / float(vertAspect); + + if (aspectRatio > customAspectRatio) + { + s_viewportWidth = height * horzAspect / vertAspect; + s_viewportHeight = height; + } + else + { + s_viewportWidth = width; + s_viewportHeight = width * vertAspect / horzAspect; + } + + break; + } default: s_viewportWidth = width; @@ -7344,6 +7364,8 @@ void VideoConfigValueChangedCallback(IConfigDef* config) // Config options that require internal resolution resize g_needsResize |= config == &Config::AspectRatio || + config == &Config::AspectWidth || + config == &Config::AspectHeight || config == &Config::ResolutionScale || config == &Config::AntiAliasing || config == &Config::ShadowResolution; diff --git a/UnleashedRecomp/locale/config_locale.cpp b/UnleashedRecomp/locale/config_locale.cpp index a02b10f..a4c9c0b 100644 --- a/UnleashedRecomp/locale/config_locale.cpp +++ b/UnleashedRecomp/locale/config_locale.cpp @@ -546,7 +546,8 @@ CONFIG_DEFINE_ENUM_LOCALE(EAspectRatio) { EAspectRatio::Auto, { "AUTO", "Auto: the aspect ratio will dynamically adjust to the window size." } }, { EAspectRatio::Wide, { "16:9", "16:9: locks the game to a widescreen aspect ratio." } }, { EAspectRatio::Narrow, { "4:3", "4:3: locks the game to a narrow aspect ratio." } }, - { EAspectRatio::OriginalNarrow, { "ORIGINAL 4:3", "Original 4:3: locks the game to a narrow aspect ratio and retains parity with the game's original implementation." } } + { EAspectRatio::OriginalNarrow, { "ORIGINAL 4:3", "Original 4:3: locks the game to a narrow aspect ratio and retains parity with the game's original implementation." } }, + { EAspectRatio::Custom, { "Custom", "The aspect ratio is set to the values in 'Aspect Width' and 'Aspect Height'." } } } }, { @@ -565,6 +566,7 @@ CONFIG_DEFINE_ENUM_LOCALE(EAspectRatio) { EAspectRatio::Wide, { "16:9", "16:9: Stellt das Spiel in einem Breitbildschirm-Vormat dar." } }, { EAspectRatio::Narrow, { "4:3", "4:3: Stellt das Spiel in einem Mittel-Vormat dar." } }, { EAspectRatio::OriginalNarrow, { "ORIGINAL 4:3", "Original 4:3: Stellt das Spiel in einem Mittel-Vormat dar, was der ursprünglichen Implementation originalgetreut bleibt." } } + { EAspectRatio::Custom, { "Benutzerdefiniert", "Das Seitenverhältnis entspricht den Werten in 'Seitenverhältnis-Breite' und 'Seitenverhältnis-Höhe'." } } } }, { @@ -596,6 +598,18 @@ CONFIG_DEFINE_ENUM_LOCALE(EAspectRatio) } }; +CONFIG_DEFINE_LOCALE(AspectWidth) +{ + { ELanguage::English, { "Aspect Width", "Adjust aspect width for custom aspect ratios." } }, + { ELanguage::German, { "Seitenverhältnis-Breite", "Passe die Breite für benutzerdefinierte Seitenverhältnisse an." } } +}; + +CONFIG_DEFINE_LOCALE(AspectHeight) +{ + { ELanguage::English, { "Aspect Height", "Adjust aspect height for custom aspect ratios." } }, + { ELanguage::German, { "Seitenverhältnis-Höhe", "Passe die Höhe für benutzerdefinierte Seitenverhältnisse an." } } +}; + // Japanese Notes: This localization should include furigana. CONFIG_DEFINE_LOCALE(ResolutionScale) { diff --git a/UnleashedRecomp/ui/options_menu.cpp b/UnleashedRecomp/ui/options_menu.cpp index a9955d2..35ea89b 100644 --- a/UnleashedRecomp/ui/options_menu.cpp +++ b/UnleashedRecomp/ui/options_menu.cpp @@ -1266,6 +1266,8 @@ static void DrawConfigOptions() DrawConfigOption(rowCount++, yOffset, &Config::Monitor, canChangeMonitor, monitorReason, 0, 0, displayCount - 1, false); DrawConfigOption(rowCount++, yOffset, &Config::AspectRatio, true); + DrawConfigOption(rowCount++, yOffset, &Config::AspectWidth, true, nullptr, 1, 50, 100); + DrawConfigOption(rowCount++, yOffset, &Config::AspectHeight, true, nullptr, 1, 50, 100); DrawConfigOption(rowCount++, yOffset, &Config::ResolutionScale, true, nullptr, 0.25f, 1.0f, 2.0f); DrawConfigOption(rowCount++, yOffset, &Config::Fullscreen, true); DrawConfigOption(rowCount++, yOffset, &Config::VSync, true); diff --git a/UnleashedRecomp/user/config.cpp b/UnleashedRecomp/user/config.cpp index dddcf5a..ec6d616 100644 --- a/UnleashedRecomp/user/config.cpp +++ b/UnleashedRecomp/user/config.cpp @@ -322,6 +322,7 @@ CONFIG_DEFINE_ENUM_TEMPLATE(EAspectRatio) { "16:9", EAspectRatio::Wide }, { "4:3", EAspectRatio::Narrow }, { "Original 4:3", EAspectRatio::OriginalNarrow }, + { "Custom", EAspectRatio::Custom }, }; CONFIG_DEFINE_ENUM_TEMPLATE(ETripleBuffering) diff --git a/UnleashedRecomp/user/config.h b/UnleashedRecomp/user/config.h index e038d02..51be2e3 100644 --- a/UnleashedRecomp/user/config.h +++ b/UnleashedRecomp/user/config.h @@ -84,7 +84,8 @@ enum class EAspectRatio : uint32_t Auto, Wide, Narrow, - OriginalNarrow + OriginalNarrow, + Custom }; enum class ETripleBuffering : uint32_t diff --git a/UnleashedRecomp/user/config_def.h b/UnleashedRecomp/user/config_def.h index cb282c1..7982cd3 100644 --- a/UnleashedRecomp/user/config_def.h +++ b/UnleashedRecomp/user/config_def.h @@ -56,6 +56,8 @@ CONFIG_DEFINE("Video", int32_t, WindowHeight, 720); CONFIG_DEFINE_ENUM("Video", EWindowState, WindowState, EWindowState::Normal); CONFIG_DEFINE_LOCALISED("Video", int32_t, Monitor, 0); CONFIG_DEFINE_ENUM_LOCALISED("Video", EAspectRatio, AspectRatio, EAspectRatio::Auto); +CONFIG_DEFINE_LOCALISED("Video", int32_t, AspectWidth, 16); +CONFIG_DEFINE_LOCALISED("Video", int32_t, AspectHeight, 9); CONFIG_DEFINE_LOCALISED("Video", float, ResolutionScale, 1.0f); CONFIG_DEFINE_LOCALISED("Video", bool, Fullscreen, true); CONFIG_DEFINE_LOCALISED("Video", bool, VSync, true);