From 0188f4950e35bdb1675967c3379009ec9c95769b Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Thu, 14 Aug 2025 19:39:03 +0100 Subject: [PATCH] feat(gui): implement user based font scaling --- .../Include/Common/UserPreferences.h | 2 ++ .../Include/GameClient/GlobalLanguage.h | 2 ++ .../GUI/GUICallbacks/Menus/OptionsMenu.cpp | 26 +++++++++++++++++++ .../Source/GameClient/GlobalLanguage.cpp | 19 ++++++++++++-- .../Include/Common/UserPreferences.h | 2 ++ .../Include/GameClient/GlobalLanguage.h | 2 ++ .../GUI/GUICallbacks/Menus/OptionsMenu.cpp | 26 +++++++++++++++++++ .../Source/GameClient/GlobalLanguage.cpp | 19 ++++++++++++-- 8 files changed, 94 insertions(+), 4 deletions(-) diff --git a/Generals/Code/GameEngine/Include/Common/UserPreferences.h b/Generals/Code/GameEngine/Include/Common/UserPreferences.h index 85030853e0..39c25f0791 100644 --- a/Generals/Code/GameEngine/Include/Common/UserPreferences.h +++ b/Generals/Code/GameEngine/Include/Common/UserPreferences.h @@ -131,6 +131,8 @@ class OptionPreferences : public UserPreferences Int getSystemTimeFontSize(void); Int getGameTimeFontSize(void); + + Real getResolutionFontAdjustment(void); }; //----------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Include/GameClient/GlobalLanguage.h b/Generals/Code/GameEngine/Include/GameClient/GlobalLanguage.h index 6ffd8bb050..2f7d1557de 100644 --- a/Generals/Code/GameEngine/Include/GameClient/GlobalLanguage.h +++ b/Generals/Code/GameEngine/Include/GameClient/GlobalLanguage.h @@ -100,9 +100,11 @@ class GlobalLanguage : public SubsystemInterface FontDesc m_creditsNormalFont; Real m_resolutionFontSizeAdjustment; + Real m_userResolutionFontSizeAdjustment; //UnicodeString m_unicodeFontNameUStr; + float getResolutionFontSizeAdjustment() const; Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba. typedef std::list StringList; // Used for our font file names that we want to load diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp index 47f8c34a92..67a9df7f4d 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp @@ -62,6 +62,7 @@ #include "GameClient/IMEManager.h" #include "GameClient/ShellHooks.h" #include "GameClient/GUICallbacks.h" +#include "GameClient/GlobalLanguage.h" #include "GameNetwork/FirewallHelper.h" #include "GameNetwork/IPEnumeration.h" #include "GameNetwork/GameSpyOverlay.h" @@ -784,6 +785,20 @@ Int OptionPreferences::getGameTimeFontSize(void) return fontSize; } +Real OptionPreferences::getResolutionFontAdjustment(void) +{ + OptionPreferences::const_iterator it = find("ResolutionFontAdjustment"); + if (it == end()) + return -1.0f; + + Real fontScale = (Real)atof(it->second.str()) / 100.0f; + if (fontScale < 0.0f) + { + fontScale = -1.0f; + } + return fontScale; +} + static OptionPreferences *pref = NULL; static void setDefaults( void ) @@ -1294,6 +1309,17 @@ static void saveOptions( void ) TheInGameUI->refreshGameTimeResources(); } + //------------------------------------------------------------------------------------------------- + // Set User Font Scaling Percentage + val = pref->getResolutionFontAdjustment() * 100.0f; // TheSuperHackers @todo replace with options input when applicable + if (val >= 0 || val == -100) + { + AsciiString prefString; + prefString.format("%d", REAL_TO_INT( val ) ); + (*pref)["ResolutionFontAdjustment"] = prefString; + TheGlobalLanguageData->m_userResolutionFontSizeAdjustment = (Real)val / 100.0f; + } + //------------------------------------------------------------------------------------------------- // Resolution // diff --git a/Generals/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp b/Generals/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp index ccc41f9eec..fe3e43c242 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp @@ -54,8 +54,10 @@ #include "Common/INI.h" #include "Common/Registry.h" -#include "GameClient/GlobalLanguage.h" #include "Common/FileSystem.h" +#include "Common/UserPreferences.h" + +#include "GameClient/GlobalLanguage.h" //----------------------------------------------------------------------------- // DEFINES //////////////////////////////////////////////////////////////////// @@ -117,6 +119,8 @@ GlobalLanguage::GlobalLanguage() m_useHardWrap = FALSE; m_resolutionFontSizeAdjustment = 0.7f; //End Add + + m_userResolutionFontSizeAdjustment = -1.0f; } GlobalLanguage::~GlobalLanguage() @@ -165,6 +169,9 @@ void GlobalLanguage::init( void ) ++it; } + // override values with user preferences + OptionPreferences optionPref; + m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment(); } void GlobalLanguage::reset( void ) {} @@ -185,10 +192,18 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, monkey->m_localFonts.push_front(asciiString); } +float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const +{ + if (m_userResolutionFontSizeAdjustment >= 0.0f) + return m_userResolutionFontSizeAdjustment; + else + return m_resolutionFontSizeAdjustment; +} + Int GlobalLanguage::adjustFontSize(Int theFontSize) { Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH; - adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment; + adjustFactor = 1.0f + (adjustFactor-1.0f) * getResolutionFontSizeAdjustment(); if (adjustFactor<1.0f) adjustFactor = 1.0f; if (adjustFactor>2.0f) adjustFactor = 2.0f; Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor); diff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h index 9e4d83a4bf..2aa8253837 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h @@ -135,6 +135,8 @@ class OptionPreferences : public UserPreferences Int getSystemTimeFontSize(void); Int getGameTimeFontSize(void); + + Real getResolutionFontAdjustment(void); }; //----------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h index a8324393c9..d3a0a79d44 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h +++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h @@ -101,9 +101,11 @@ class GlobalLanguage : public SubsystemInterface FontDesc m_creditsNormalFont; Real m_resolutionFontSizeAdjustment; + Real m_userResolutionFontSizeAdjustment; //UnicodeString m_unicodeFontNameUStr; + float getResolutionFontSizeAdjustment() const; Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba. typedef std::list StringList; // Used for our font file names that we want to load diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp index 2f4a306071..11f931762c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp @@ -62,6 +62,7 @@ #include "GameClient/IMEManager.h" #include "GameClient/ShellHooks.h" #include "GameClient/GUICallbacks.h" +#include "GameClient/GlobalLanguage.h" #include "GameNetwork/FirewallHelper.h" #include "GameNetwork/IPEnumeration.h" #include "GameNetwork/GameSpyOverlay.h" @@ -828,6 +829,20 @@ Int OptionPreferences::getGameTimeFontSize(void) return fontSize; } +Real OptionPreferences::getResolutionFontAdjustment(void) +{ + OptionPreferences::const_iterator it = find("ResolutionFontAdjustment"); + if (it == end()) + return -1.0f; + + Real fontScale = (Real)atof(it->second.str()) / 100.0f; + if (fontScale < 0.0f) + { + fontScale = -1.0f; + } + return fontScale; +} + static OptionPreferences *pref = NULL; static void setDefaults( void ) @@ -1354,6 +1369,17 @@ static void saveOptions( void ) TheInGameUI->refreshGameTimeResources(); } + //------------------------------------------------------------------------------------------------- + // Set User Font Scaling Percentage + val = pref->getResolutionFontAdjustment() * 100.0f; // TheSuperHackers @todo replace with options input when applicable + if (val >= 0 || val == -100) + { + AsciiString prefString; + prefString.format("%d", REAL_TO_INT( val ) ); + (*pref)["ResolutionFontAdjustment"] = prefString; + TheGlobalLanguageData->m_userResolutionFontSizeAdjustment = (Real)val / 100.0f; + } + //------------------------------------------------------------------------------------------------- // Resolution // diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp index 6ab0a30fe6..6175a0f72f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp @@ -54,8 +54,10 @@ #include "Common/INI.h" #include "Common/Registry.h" -#include "GameClient/GlobalLanguage.h" #include "Common/FileSystem.h" +#include "Common/UserPreferences.h" + +#include "GameClient/GlobalLanguage.h" //----------------------------------------------------------------------------- // DEFINES //////////////////////////////////////////////////////////////////// @@ -119,6 +121,8 @@ GlobalLanguage::GlobalLanguage() m_resolutionFontSizeAdjustment = 0.7f; m_militaryCaptionDelayMS = 750; //End Add + + m_userResolutionFontSizeAdjustment = -1.0f; } GlobalLanguage::~GlobalLanguage() @@ -169,6 +173,9 @@ void GlobalLanguage::init( void ) ++it; } + // override values with user preferences + OptionPreferences optionPref; + m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment(); } void GlobalLanguage::reset( void ) {} @@ -189,10 +196,18 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, monkey->m_localFonts.push_front(asciiString); } +float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const +{ + if (m_userResolutionFontSizeAdjustment >= 0.0f) + return m_userResolutionFontSizeAdjustment; + else + return m_resolutionFontSizeAdjustment; +} + Int GlobalLanguage::adjustFontSize(Int theFontSize) { Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH; - adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment; + adjustFactor = 1.0f + (adjustFactor-1.0f) * getResolutionFontSizeAdjustment(); if (adjustFactor<1.0f) adjustFactor = 1.0f; if (adjustFactor>2.0f) adjustFactor = 2.0f; Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);