6464// -----------------------------------------------------------------------------
6565// DEFINES ////////////////////////////////////////////////////////////////////
6666// -----------------------------------------------------------------------------
67- GlobalLanguage *TheGlobalLanguageData = nullptr ; // /< The global language singleton
67+ GlobalLanguage *TheGlobalLanguageData = nullptr ;
6868
6969static const LookupListRec ResolutionFontSizeMethodNames[] =
7070{
@@ -116,7 +116,7 @@ void INI::parseLanguageDefinition( INI *ini )
116116 DEBUG_ASSERTCRASH (TheGlobalLanguageData, (" INI::parseLanguageDefinition - TheGlobalLanguage Data is not around, please create it before trying to parse the ini file." ));
117117 return ;
118118 }
119- // parse the ini weapon definition
119+
120120 ini->initFromINI ( TheGlobalLanguageData, TheGlobalLanguageDataFieldParseTable );
121121}
122122
@@ -136,7 +136,7 @@ GlobalLanguage::GlobalLanguage()
136136
137137GlobalLanguage::~GlobalLanguage ()
138138{
139- StringListIt it = m_localFonts.begin ();
139+ StringList::iterator it = m_localFonts.begin ();
140140 while ( it != m_localFonts.end ())
141141 {
142142 AsciiString font = *it;
@@ -146,7 +146,7 @@ GlobalLanguage::~GlobalLanguage()
146146 }
147147}
148148
149- void GlobalLanguage::init ( void )
149+ void GlobalLanguage::init ()
150150{
151151 {
152152 AsciiString fname;
@@ -156,7 +156,7 @@ void GlobalLanguage::init( void )
156156 ini.loadFileDirectory ( fname, INI_LOAD_OVERWRITE , nullptr );
157157 }
158158
159- StringListIt it = m_localFonts.begin ();
159+ StringList::iterator it = m_localFonts.begin ();
160160 while ( it != m_localFonts.end ())
161161 {
162162 AsciiString font = *it;
@@ -174,49 +174,48 @@ void GlobalLanguage::init( void )
174174 // override values with user preferences
175175 OptionPreferences optionPref;
176176 m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment ();
177-
178177}
179- void GlobalLanguage::reset ( void ) {}
180178
179+ void GlobalLanguage::reset ()
180+ {
181+ }
181182
182- void GlobalLanguage::parseFontDesc (INI *ini, void *instance, void *store, const void * userData)
183+ void GlobalLanguage::parseFontDesc (INI *ini, void *instance, void *store, const void * userData)
183184{
184185 FontDesc *fontDesc = (FontDesc *)store;
185186 fontDesc->name = ini->getNextQuotedAsciiString ();
186187 fontDesc->size = ini->scanInt (ini->getNextToken ());
187188 fontDesc->bold = ini->scanBool (ini->getNextToken ());
188189}
189190
190- void GlobalLanguage::parseFontFileName ( INI *ini, void * instance, void *store, const void * userData )
191+ void GlobalLanguage::parseFontFileName (INI *ini, void *instance, void *store, const void * userData)
191192{
192- GlobalLanguage *monkey = ( GlobalLanguage *) instance;
193+ GlobalLanguage *globalLanguage = static_cast < GlobalLanguage *>( instance) ;
193194 AsciiString asciiString = ini->getNextAsciiString ();
194- monkey ->m_localFonts .push_front (asciiString);
195+ globalLanguage ->m_localFonts .push_front (asciiString);
195196}
196197
197- float GlobalLanguage::getResolutionFontSizeAdjustment ( void ) const
198+ Real GlobalLanguage::getResolutionFontSizeAdjustment () const
198199{
199200 if (m_userResolutionFontSizeAdjustment >= 0 .0f )
200201 return m_userResolutionFontSizeAdjustment;
201202 else
202203 return m_resolutionFontSizeAdjustment;
203204}
204205
205- Int GlobalLanguage::adjustFontSize (Int theFontSize )
206+ Real GlobalLanguage::getResolutionFontSizeScale (ResolutionFontSizeMethod method, Real scaler )
206207{
207- // TheSuperHackers @todo This function is called very often.
208- // Therefore cache the adjustFactor on resolution change to not recompute it on every call.
209208 Real adjustFactor;
210209
211- switch (m_resolutionFontSizeMethod )
210+ switch (method )
212211 {
213212 default :
214213 case ResolutionFontSizeMethod_Classic:
215214 {
216215 // TheSuperHackers @info The original font scaling for this game.
217216 // Useful for not breaking legacy Addons and Mods. Scales poorly with large resolutions.
218217 adjustFactor = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH ;
219- adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment () ;
218+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * scaler ;
220219 if (adjustFactor > 2 .0f )
221220 adjustFactor = 2 .0f ;
222221 break ;
@@ -226,7 +225,7 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
226225 // TheSuperHackers @feature The original font scaling, but without ceiling.
227226 // Useful for not changing the original look of the game. Scales alright with large resolutions.
228227 adjustFactor = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH ;
229- adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment () ;
228+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * scaler ;
230229 break ;
231230 }
232231 case ResolutionFontSizeMethod_Strict:
@@ -236,7 +235,7 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
236235 const Real wScale = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH ;
237236 const Real hScale = TheDisplay->getHeight () / (Real)DEFAULT_DISPLAY_HEIGHT ;
238237 adjustFactor = min (wScale, hScale);
239- adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment () ;
238+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * scaler ;
240239 break ;
241240 }
242241 case ResolutionFontSizeMethod_Balanced:
@@ -265,14 +264,25 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
265264 hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT ;
266265 }
267266 adjustFactor = (wScale + hScale) * 0 .5f ;
268- adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment () ;
267+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * scaler ;
269268 break ;
270269 }
271270 }
272271
273272 if (adjustFactor < 1 .0f )
274273 adjustFactor = 1 .0f ;
275- Int pointSize = REAL_TO_INT_FLOOR (theFontSize*adjustFactor);
274+
275+ return adjustFactor;
276+ }
277+
278+ Int GlobalLanguage::adjustFontSize (Int theFontSize)
279+ {
280+ // TheSuperHackers @todo This function is called very often.
281+ // Therefore cache the adjustFactor on resolution change to not recompute it on every call.
282+ const Real resolutionScaler = getResolutionFontSizeAdjustment ();
283+ const Real adjustFactor = getResolutionFontSizeScale (m_resolutionFontSizeMethod, resolutionScaler);
284+ const Int pointSize = REAL_TO_INT_FLOOR (theFontSize * adjustFactor);
285+
276286 return pointSize;
277287}
278288
@@ -288,9 +298,9 @@ void GlobalLanguage::parseCustomDefinition()
288298
289299FontDesc::FontDesc (void )
290300{
291- name = " Arial Unicode MS" ; // /<name of font
292- size = 12 ; // /<point size
293- bold = FALSE ; // /<is bold?
301+ name = " Arial Unicode MS" ;
302+ size = 12 ;
303+ bold = FALSE ;
294304}
295305// -----------------------------------------------------------------------------
296306// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
0 commit comments