Skip to content

feat(gui): implement user based font scaling #1457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,

Int GlobalLanguage::adjustFontSize(Int theFontSize)
{
Real adjustFactor = TheGlobalData->m_xResolution/800.0f;
// TheSuperHackers @bugfix Mauller 10/08/2025 Scale fonts based on the smallest screen dimension so they are independent of aspect ratio
Real adjustFactor = min(TheGlobalData->m_xResolution/800.0f, TheGlobalData->m_yResolution/600.0f);
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
if (adjustFactor<1.0f) adjustFactor = 1.0f;
if (adjustFactor>2.0f) adjustFactor = 2.0f;
Expand Down
3 changes: 3 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ class GlobalData : public SubsystemInterface
Int m_systemTimeFontSize;
Int m_gameTimeFontSize;

// TheSuperHackers @feature user adjustable font size percentage
Real m_userFontSizeAdjustment;

Real m_shakeSubtleIntensity; ///< Intensity for shaking a camera with SHAKE_SUBTLE
Real m_shakeNormalIntensity; ///< Intensity for shaking a camera with SHAKE_NORMAL
Real m_shakeStrongIntensity; ///< Intensity for shaking a camera with SHAKE_STRONG
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class OptionPreferences : public UserPreferences

Int getSystemTimeFontSize(void);
Int getGameTimeFontSize(void);

Real getUserFontScale(void);
};

//-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class GlobalLanguage : public SubsystemInterface
FontDesc m_creditsNormalFont;

Real m_resolutionFontSizeAdjustment;
Real m_userFontSizeAdjustment;

//UnicodeString m_unicodeFontNameUStr;

Expand Down
4 changes: 4 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ GlobalData::GlobalData()
m_systemTimeFontSize = 8;
m_gameTimeFontSize = 8;

m_userFontSizeAdjustment = 1.0f;

m_debugShowGraphicalFramerate = FALSE;

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

TheWritableGlobalData->m_userFontSizeAdjustment = optionPref.getUserFontScale();

Int val=optionPref.getGammaValue();
//generate a value between 0.6 and 2.0.
if (val < 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,20 @@ Int OptionPreferences::getGameTimeFontSize(void)
return fontSize;
}

Real OptionPreferences::getUserFontScale(void)
{
OptionPreferences::const_iterator it = find("UserFontScale");
if (it == end())
return 1.0f;

Real fontScale = (Real)atof(it->second.str()) / 100.0f;
if (fontScale < 0.5f)
{
fontScale = 0.5f;
}
return fontScale;
}

static OptionPreferences *pref = NULL;

static void setDefaults( void )
Expand Down Expand Up @@ -1354,6 +1368,16 @@ static void saveOptions( void )
TheInGameUI->refreshGameTimeResources();
}

//-------------------------------------------------------------------------------------------------
// Set User Font Scaling Percentage
val = pref->getUserFontScale() * 100.0f; // TheSuperHackers @todo replace with options input when applicable
if (val >= 50)
{
AsciiString prefString;
prefString.format("%d", REAL_TO_INT( val ) );
(*pref)["UserFontScale"] = prefString;
}

//-------------------------------------------------------------------------------------------------
// Resolution
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,

Int GlobalLanguage::adjustFontSize(Int theFontSize)
{
Real adjustFactor = TheGlobalData->m_xResolution/800.0f;
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
// TheSuperHackers @bugfix Mauller 10/08/2025 Scale fonts based on the smallest screen dimension so they are independent of aspect ratio
Real adjustFactor = min(TheGlobalData->m_xResolution/800.0f, TheGlobalData->m_yResolution/600.0f);
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment * TheGlobalData->m_userFontSizeAdjustment;
if (adjustFactor<1.0f) adjustFactor = 1.0f;
if (adjustFactor>2.0f) adjustFactor = 2.0f;
Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);
Expand Down
Loading