Skip to content

Commit b632b27

Browse files
committed
feat(gui): implement user based font scaling
1 parent a4caabb commit b632b27

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ class GlobalData : public SubsystemInterface
409409
Int m_systemTimeFontSize;
410410
Int m_gameTimeFontSize;
411411

412+
// TheSuperHackers @feature user adjustable font size percentage
413+
Real m_userFontSizeAdjustment;
414+
412415
Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
413416
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
414417
Real m_shakeStrongIntensity; ///< Intensity for shaking a camera with SHAKE_STRONG

GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class OptionPreferences : public UserPreferences
135135

136136
Int getSystemTimeFontSize(void);
137137
Int getGameTimeFontSize(void);
138+
139+
Real getUserFontScale(void);
138140
};
139141

140142
//-----------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Include/GameClient/GlobalLanguage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class GlobalLanguage : public SubsystemInterface
101101
FontDesc m_creditsNormalFont;
102102

103103
Real m_resolutionFontSizeAdjustment;
104+
Real m_userFontSizeAdjustment;
104105

105106
//UnicodeString m_unicodeFontNameUStr;
106107

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,8 @@ GlobalData::GlobalData()
937937
m_systemTimeFontSize = 8;
938938
m_gameTimeFontSize = 8;
939939

940+
m_userFontSizeAdjustment = 1.0f;
941+
940942
m_debugShowGraphicalFramerate = FALSE;
941943

942944
// By default, show all asserts.
@@ -1204,6 +1206,8 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12041206
TheWritableGlobalData->m_systemTimeFontSize = optionPref.getSystemTimeFontSize();
12051207
TheWritableGlobalData->m_gameTimeFontSize = optionPref.getGameTimeFontSize();
12061208

1209+
TheWritableGlobalData->m_userFontSizeAdjustment = optionPref.getUserFontScale();
1210+
12071211
Int val=optionPref.getGammaValue();
12081212
//generate a value between 0.6 and 2.0.
12091213
if (val < 50)

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,20 @@ Int OptionPreferences::getGameTimeFontSize(void)
828828
return fontSize;
829829
}
830830

831+
Real OptionPreferences::getUserFontScale(void)
832+
{
833+
OptionPreferences::const_iterator it = find("UserFontScale");
834+
if (it == end())
835+
return 1.0f;
836+
837+
Real fontScale = (Real)atof(it->second.str()) / 100.0f;
838+
if (fontScale < 0.5f)
839+
{
840+
fontScale = 0.5f;
841+
}
842+
return fontScale;
843+
}
844+
831845
static OptionPreferences *pref = NULL;
832846

833847
static void setDefaults( void )
@@ -1354,6 +1368,16 @@ static void saveOptions( void )
13541368
TheInGameUI->refreshGameTimeResources();
13551369
}
13561370

1371+
//-------------------------------------------------------------------------------------------------
1372+
// Set User Font Scaling Percentage
1373+
val = pref->getUserFontScale() * 100.0f; // TheSuperHackers @todo replace with options input when applicable
1374+
if (val >= 50)
1375+
{
1376+
AsciiString prefString;
1377+
prefString.format("%d", REAL_TO_INT( val ) );
1378+
(*pref)["UserFontScale"] = prefString;
1379+
}
1380+
13571381
//-------------------------------------------------------------------------------------------------
13581382
// Resolution
13591383
//

GeneralsMD/Code/GameEngine/Source/GameClient/GlobalLanguage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
193193
{
194194
// TheSuperHackers @bugfix Mauller 10/08/2025 Scale fonts based on the smallest screen dimension so they are independent of aspect ratio
195195
Real adjustFactor = min(TheGlobalData->m_xResolution/800.0f, TheGlobalData->m_yResolution/600.0f);
196-
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
196+
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment * TheGlobalData->m_userFontSizeAdjustment;
197197
if (adjustFactor<1.0f) adjustFactor = 1.0f;
198198
if (adjustFactor>2.0f) adjustFactor = 2.0f;
199199
Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);

0 commit comments

Comments
 (0)