Skip to content

Commit 40ac1c0

Browse files
authored
feat(gui): Add user option to adjust scale of game fonts in relation to resolution (#1457)
Adds new option ResolutionFontAdjustment=0..100 to Options.ini
1 parent 36b5277 commit 40ac1c0

File tree

8 files changed

+94
-4
lines changed

8 files changed

+94
-4
lines changed

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

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

138138
Int getSystemTimeFontSize(void);
139139
Int getGameTimeFontSize(void);
140+
141+
Real getResolutionFontAdjustment(void);
140142
};
141143

142144
//-----------------------------------------------------------------------------

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ class GlobalLanguage : public SubsystemInterface
100100
FontDesc m_creditsNormalFont;
101101

102102
Real m_resolutionFontSizeAdjustment;
103+
Real m_userResolutionFontSizeAdjustment;
103104

104105
//UnicodeString m_unicodeFontNameUStr;
105106

107+
float getResolutionFontSizeAdjustment() const;
106108
Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.
107109

108110
typedef std::list<AsciiString> StringList; // Used for our font file names that we want to load

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "GameClient/IMEManager.h"
6464
#include "GameClient/ShellHooks.h"
6565
#include "GameClient/GUICallbacks.h"
66+
#include "GameClient/GlobalLanguage.h"
6667
#include "GameNetwork/FirewallHelper.h"
6768
#include "GameNetwork/IPEnumeration.h"
6869
#include "GameNetwork/GameSpyOverlay.h"
@@ -843,6 +844,20 @@ Int OptionPreferences::getGameTimeFontSize(void)
843844
return fontSize;
844845
}
845846

847+
Real OptionPreferences::getResolutionFontAdjustment(void)
848+
{
849+
OptionPreferences::const_iterator it = find("ResolutionFontAdjustment");
850+
if (it == end())
851+
return -1.0f;
852+
853+
Real fontScale = (Real)atof(it->second.str()) / 100.0f;
854+
if (fontScale < 0.0f)
855+
{
856+
fontScale = -1.0f;
857+
}
858+
return fontScale;
859+
}
860+
846861
static OptionPreferences *pref = NULL;
847862

848863
static void setDefaults( void )
@@ -1379,6 +1394,17 @@ static void saveOptions( void )
13791394
TheInGameUI->refreshGameTimeResources();
13801395
}
13811396

1397+
//-------------------------------------------------------------------------------------------------
1398+
// Set User Font Scaling Percentage
1399+
val = pref->getResolutionFontAdjustment() * 100.0f; // TheSuperHackers @todo replace with options input when applicable
1400+
if (val >= 0 || val == -100)
1401+
{
1402+
AsciiString prefString;
1403+
prefString.format("%d", REAL_TO_INT( val ) );
1404+
(*pref)["ResolutionFontAdjustment"] = prefString;
1405+
TheGlobalLanguageData->m_userResolutionFontSizeAdjustment = (Real)val / 100.0f;
1406+
}
1407+
13821408
//-------------------------------------------------------------------------------------------------
13831409
// Resolution
13841410
//

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454

5555
#include "Common/INI.h"
5656
#include "Common/Registry.h"
57-
#include "GameClient/GlobalLanguage.h"
5857
#include "Common/FileSystem.h"
58+
#include "Common/UserPreferences.h"
59+
60+
#include "GameClient/GlobalLanguage.h"
5961

6062
//-----------------------------------------------------------------------------
6163
// DEFINES ////////////////////////////////////////////////////////////////////
@@ -117,6 +119,8 @@ GlobalLanguage::GlobalLanguage()
117119
m_useHardWrap = FALSE;
118120
m_resolutionFontSizeAdjustment = 0.7f;
119121
//End Add
122+
123+
m_userResolutionFontSizeAdjustment = -1.0f;
120124
}
121125

122126
GlobalLanguage::~GlobalLanguage()
@@ -156,6 +160,9 @@ void GlobalLanguage::init( void )
156160
++it;
157161
}
158162

163+
// override values with user preferences
164+
OptionPreferences optionPref;
165+
m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment();
159166

160167
}
161168
void GlobalLanguage::reset( void ) {}
@@ -176,10 +183,18 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,
176183
monkey->m_localFonts.push_front(asciiString);
177184
}
178185

186+
float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const
187+
{
188+
if (m_userResolutionFontSizeAdjustment >= 0.0f)
189+
return m_userResolutionFontSizeAdjustment;
190+
else
191+
return m_resolutionFontSizeAdjustment;
192+
}
193+
179194
Int GlobalLanguage::adjustFontSize(Int theFontSize)
180195
{
181196
Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH;
182-
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
197+
adjustFactor = 1.0f + (adjustFactor-1.0f) * getResolutionFontSizeAdjustment();
183198
if (adjustFactor<1.0f) adjustFactor = 1.0f;
184199
if (adjustFactor>2.0f) adjustFactor = 2.0f;
185200
Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);

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

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

142142
Int getSystemTimeFontSize(void);
143143
Int getGameTimeFontSize(void);
144+
145+
Real getResolutionFontAdjustment(void);
144146
};
145147

146148
//-----------------------------------------------------------------------------

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ class GlobalLanguage : public SubsystemInterface
101101
FontDesc m_creditsNormalFont;
102102

103103
Real m_resolutionFontSizeAdjustment;
104+
Real m_userResolutionFontSizeAdjustment;
104105

105106
//UnicodeString m_unicodeFontNameUStr;
106107

108+
float getResolutionFontSizeAdjustment() const;
107109
Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.
108110

109111
typedef std::list<AsciiString> StringList; // Used for our font file names that we want to load

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "GameClient/IMEManager.h"
6464
#include "GameClient/ShellHooks.h"
6565
#include "GameClient/GUICallbacks.h"
66+
#include "GameClient/GlobalLanguage.h"
6667
#include "GameNetwork/FirewallHelper.h"
6768
#include "GameNetwork/IPEnumeration.h"
6869
#include "GameNetwork/GameSpyOverlay.h"
@@ -887,6 +888,20 @@ Int OptionPreferences::getGameTimeFontSize(void)
887888
return fontSize;
888889
}
889890

891+
Real OptionPreferences::getResolutionFontAdjustment(void)
892+
{
893+
OptionPreferences::const_iterator it = find("ResolutionFontAdjustment");
894+
if (it == end())
895+
return -1.0f;
896+
897+
Real fontScale = (Real)atof(it->second.str()) / 100.0f;
898+
if (fontScale < 0.0f)
899+
{
900+
fontScale = -1.0f;
901+
}
902+
return fontScale;
903+
}
904+
890905
static OptionPreferences *pref = NULL;
891906

892907
static void setDefaults( void )
@@ -1439,6 +1454,17 @@ static void saveOptions( void )
14391454
TheInGameUI->refreshGameTimeResources();
14401455
}
14411456

1457+
//-------------------------------------------------------------------------------------------------
1458+
// Set User Font Scaling Percentage
1459+
val = pref->getResolutionFontAdjustment() * 100.0f; // TheSuperHackers @todo replace with options input when applicable
1460+
if (val >= 0 || val == -100)
1461+
{
1462+
AsciiString prefString;
1463+
prefString.format("%d", REAL_TO_INT( val ) );
1464+
(*pref)["ResolutionFontAdjustment"] = prefString;
1465+
TheGlobalLanguageData->m_userResolutionFontSizeAdjustment = (Real)val / 100.0f;
1466+
}
1467+
14421468
//-------------------------------------------------------------------------------------------------
14431469
// Resolution
14441470
//

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@
5454

5555
#include "Common/INI.h"
5656
#include "Common/Registry.h"
57-
#include "GameClient/GlobalLanguage.h"
5857
#include "Common/FileSystem.h"
58+
#include "Common/UserPreferences.h"
59+
60+
#include "GameClient/GlobalLanguage.h"
5961

6062
//-----------------------------------------------------------------------------
6163
// DEFINES ////////////////////////////////////////////////////////////////////
@@ -119,6 +121,8 @@ GlobalLanguage::GlobalLanguage()
119121
m_resolutionFontSizeAdjustment = 0.7f;
120122
m_militaryCaptionDelayMS = 750;
121123
//End Add
124+
125+
m_userResolutionFontSizeAdjustment = -1.0f;
122126
}
123127

124128
GlobalLanguage::~GlobalLanguage()
@@ -158,6 +162,9 @@ void GlobalLanguage::init( void )
158162
++it;
159163
}
160164

165+
// override values with user preferences
166+
OptionPreferences optionPref;
167+
m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment();
161168

162169
}
163170
void GlobalLanguage::reset( void ) {}
@@ -178,10 +185,18 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,
178185
monkey->m_localFonts.push_front(asciiString);
179186
}
180187

188+
float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const
189+
{
190+
if (m_userResolutionFontSizeAdjustment >= 0.0f)
191+
return m_userResolutionFontSizeAdjustment;
192+
else
193+
return m_resolutionFontSizeAdjustment;
194+
}
195+
181196
Int GlobalLanguage::adjustFontSize(Int theFontSize)
182197
{
183198
Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH;
184-
adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment;
199+
adjustFactor = 1.0f + (adjustFactor-1.0f) * getResolutionFontSizeAdjustment();
185200
if (adjustFactor<1.0f) adjustFactor = 1.0f;
186201
if (adjustFactor>2.0f) adjustFactor = 2.0f;
187202
Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);

0 commit comments

Comments
 (0)