@@ -282,10 +282,9 @@ int32_t *drawIconFromItem(int32_t position[3], int16_t itemNum, float scale)
282
282
return drawIcon (position, iconNum, scale);
283
283
}
284
284
285
- // Set alignBaseString to nullptr to not align the text to the right
286
285
// Set width to a negative value to not have a width limit
287
- void drawTextMain (const char *text, int32_t x, int32_t y, uint32_t color,
288
- const char *alignBaseString , float scale, float width)
286
+ void drawTextMain (const char *text, int32_t x, int32_t y,
287
+ uint32_t color, bool alignRight , float scale, float width)
289
288
{
290
289
// Make sure the text isn't an empty string
291
290
if (text[0 ] == ' \0 ' )
@@ -294,12 +293,18 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
294
293
}
295
294
296
295
float NewPosX = intToFloat (x);
296
+ uint32_t TextLength = 0 ;
297
297
298
298
// Check if aligning the text to the right
299
- if (alignBaseString )
299
+ if (alignRight )
300
300
{
301
- uint32_t BaseLength = ttyd::fontmgr::FontGetMessageWidth (alignBaseString);
302
- uint32_t TextLength = ttyd::fontmgr::FontGetMessageWidth (text);
301
+ #ifdef TTYD_JP
302
+ const char *AlignBase = ttyd::win_main::str_999_jpn_winMain;
303
+ #else
304
+ const char *AlignBase = ttyd::win_main::str_999_winMain;
305
+ #endif
306
+ uint32_t BaseLength = ttyd::fontmgr::FontGetMessageWidth (AlignBase);
307
+ TextLength = ttyd::fontmgr::FontGetMessageWidth (text);
303
308
304
309
NewPosX += intToFloat (BaseLength - TextLength) * scale;
305
310
}
@@ -308,15 +313,19 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
308
313
float ScaleX = scale;
309
314
if (!std::signbit (width)) // Check if positive, works for checking against +0.0 and -0.0
310
315
{
311
- uint32_t TextLength = ttyd::fontmgr::FontGetMessageWidth (text);
312
- float TextLengthScaled = intToFloat (static_cast <int32_t >(TextLength)) * scale;
316
+ // Prevent calling FontGetMessageWidth again if unnecessary
317
+ if (TextLength == 0 )
318
+ {
319
+ TextLength = ttyd::fontmgr::FontGetMessageWidth (text);
320
+ }
313
321
322
+ float TextLengthScaled = intToFloat (static_cast <int32_t >(TextLength)) * scale;
314
323
if (TextLengthScaled > width)
315
324
{
316
325
ScaleX = (width / TextLengthScaled) * scale;
317
326
318
327
// If aligning the text to the right, account for the new X scale
319
- if (alignBaseString )
328
+ if (alignRight )
320
329
{
321
330
NewPosX += TextLengthScaled - width;
322
331
}
@@ -340,24 +349,23 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
340
349
341
350
void drawText (const char *text, int32_t x, int32_t y, uint32_t color, float scale)
342
351
{
343
- drawTextMain (text, x, y, color, nullptr , scale, -0 .f );
352
+ drawTextMain (text, x, y, color, false , scale, -0 .f );
344
353
}
345
354
346
355
void drawTextWidth (const char *text, int32_t x,
347
356
int32_t y, uint32_t color, float scale, float width)
348
357
{
349
- drawTextMain (text, x, y, color, nullptr , scale, width);
358
+ drawTextMain (text, x, y, color, false , scale, width);
350
359
}
351
360
352
- void drawTextAlignRight (const char *text, int32_t x, int32_t y,
353
- uint32_t color, const char *alignBaseString, float scale)
361
+ void drawTextAlignRight (const char *text, int32_t x, int32_t y, uint32_t color, float scale)
354
362
{
355
- drawTextMain (text, x, y, color, alignBaseString , scale, -0 .f );
363
+ drawTextMain (text, x, y, color, true , scale, -0 .f );
356
364
}
357
365
358
366
// Credits to Jdaster64 for writing the original code for this function
359
367
void drawTextMultipleLinesMain (const char *text, int32_t x, int32_t y,
360
- uint32_t color, const char *alignBaseString , float scale, float width)
368
+ uint32_t color, bool alignRight , float scale, float width)
361
369
{
362
370
char LineBuffer[128 ];
363
371
const char *CurrentLine = text;
@@ -390,7 +398,7 @@ void drawTextMultipleLinesMain(const char *text, int32_t x, int32_t y,
390
398
char *tempBuffer = strncpy (LineBuffer, CurrentLine, LineLength);
391
399
tempBuffer[LineLength] = ' \0 ' ;
392
400
393
- drawTextMain (tempBuffer, x, y, color, alignBaseString , scale, width);
401
+ drawTextMain (tempBuffer, x, y, color, alignRight , scale, width);
394
402
}
395
403
396
404
// Advance to the next line
@@ -399,18 +407,18 @@ void drawTextMultipleLinesMain(const char *text, int32_t x, int32_t y,
399
407
}
400
408
401
409
// Draw the rest of the text
402
- drawTextMain (CurrentLine, x, y, color, alignBaseString , scale, width);
410
+ drawTextMain (CurrentLine, x, y, color, alignRight , scale, width);
403
411
}
404
412
405
413
void drawTextMultipleLines (const char *text, int32_t x, int32_t y, uint32_t color, float scale)
406
414
{
407
- drawTextMultipleLinesMain (text, x, y, color, nullptr , scale, -0 .f );
415
+ drawTextMultipleLinesMain (text, x, y, color, false , scale, -0 .f );
408
416
}
409
417
410
418
void drawTextMultipleLinesWidth (const char *text, int32_t x,
411
419
int32_t y, uint32_t color, float scale, float width)
412
420
{
413
- drawTextMultipleLinesMain (text, x, y, color, nullptr , scale, width);
421
+ drawTextMultipleLinesMain (text, x, y, color, false , scale, width);
414
422
}
415
423
416
424
void drawTextInit (uint8_t alpha, bool drawFontEdge)
@@ -1193,13 +1201,7 @@ void drawMarioStats()
1193
1201
" %" PRId32,
1194
1202
MarioStatsArray[Counter]);
1195
1203
1196
- #ifdef TTYD_JP
1197
- const char *AlignBase = ttyd::win_main::str_999_jpn_winMain;
1198
- #else
1199
- const char *AlignBase = ttyd::win_main::str_999_winMain;
1200
- #endif
1201
-
1202
- drawTextMain (tempDisplayBuffer, ValuesPosX, PosY, Color, AlignBase, TextScale, MaxWidth);
1204
+ drawTextMain (tempDisplayBuffer, ValuesPosX, PosY, Color, true , TextScale, MaxWidth);
1203
1205
Counter++;
1204
1206
}
1205
1207
@@ -2698,6 +2700,7 @@ void drawBattlesStatusesList()
2698
2700
int32_t Width = 362 ;
2699
2701
int32_t Height = 35 ;
2700
2702
int32_t Curve = 0 ;
2703
+
2701
2704
drawWindow (WindowColor, WindowPosX, WindowPosY, Width, Height, Curve);
2702
2705
}
2703
2706
@@ -2764,13 +2767,13 @@ void drawBattlesStatusesList()
2764
2767
Color = 0xFFFFFFFF ;
2765
2768
}
2766
2769
2770
+ int32_t TextPosXIncrement = 291 ;
2771
+
2767
2772
#ifdef TTYD_JP
2768
- const char *AlignBase = " \x82\x58\x82\x58 " ; // Japanese characters for 99
2769
- #else
2770
- const char *AlignBase = " 99" ;
2773
+ TextPosXIncrement -= 3 ;
2771
2774
#endif
2772
2775
2773
- drawTextAlignRight (TextToDraw, TextPosX + 300 , TextPosY, Color, AlignBase , TextScale);
2776
+ drawTextAlignRight (TextToDraw, TextPosX + TextPosXIncrement , TextPosY, Color, TextScale);
2774
2777
TextPosY -= 30 ;
2775
2778
}
2776
2779
}
@@ -3764,16 +3767,10 @@ void drawVersionNumber(int32_t posX, int32_t posY)
3764
3767
// uint8_t Alpha = 0xFF;
3765
3768
float Scale = 0 .6f ;
3766
3769
3767
- #ifdef TTYD_JP
3768
- const char *AlignBase = " \x82\x58 " ; // Japanese character for 9
3769
- #else
3770
- const char *AlignBase = " 9" ;
3771
- #endif
3772
-
3773
- drawTextAlignRight (VersionNumber, posX, posY, Color, AlignBase, Scale);
3770
+ drawTextAlignRight (VersionNumber, posX, posY, Color, Scale);
3774
3771
}
3775
3772
3776
- void drawPageNumberMain (int32_t posX, int32_t posY, uint32_t currentPage, const char *alignBase )
3773
+ void drawPageNumberMain (int32_t posX, int32_t posY, uint32_t currentPage, bool alignRight )
3777
3774
{
3778
3775
uint32_t Color = 0xFFFFFFFF ;
3779
3776
// uint8_t Alpha = 0xFF;
@@ -3784,25 +3781,17 @@ void drawPageNumberMain(int32_t posX, int32_t posY, uint32_t currentPage, const
3784
3781
" Page %" PRIu32,
3785
3782
currentPage + 1 );
3786
3783
3787
- drawTextAlignRight (tempDisplayBuffer, posX, posY, Color, alignBase , Scale);
3784
+ drawTextMain (tempDisplayBuffer, posX, posY, Color, alignRight , Scale, - 0 . f );
3788
3785
}
3789
3786
3790
3787
void drawPageNumberAlignLeft (int32_t posX, int32_t posY, uint32_t currentPage)
3791
3788
{
3792
- drawPageNumberMain (posX, posY, currentPage, nullptr );
3789
+ drawPageNumberMain (posX, posY, currentPage, false );
3793
3790
}
3794
3791
3795
3792
void drawPageNumber (int32_t posX, int32_t posY, uint32_t currentPage)
3796
3793
{
3797
- const char *AlignBase;
3798
-
3799
- #ifdef TTYD_JP
3800
- AlignBase = " \x82\x58 " ; // Japanese character for 9
3801
- #else
3802
- AlignBase = " 9" ;
3803
- #endif
3804
-
3805
- drawPageNumberMain (posX, posY, currentPage, AlignBase);
3794
+ drawPageNumberMain (posX, posY, currentPage, true );
3806
3795
}
3807
3796
3808
3797
void drawBoolOnOrOff (bool tempBool, const char *currentLine, int32_t posY)
@@ -5243,10 +5232,7 @@ void Mod::drawSequenceInPauseMenu(ttyd::dispdrv::CameraId cameraId, void *winWor
5243
5232
" %" PRIu32,
5244
5233
getSequencePosition ());
5245
5234
5246
- #ifdef TTYD_JP
5247
- const char *AlignBase = ttyd::win_main::str_999_jpn_winMain;
5248
- #else
5249
- const char *AlignBase = ttyd::win_main::str_999_winMain;
5235
+ #ifndef TTYD_JP
5250
5236
Scale = 0 .9f ;
5251
5237
#endif
5252
5238
@@ -5255,7 +5241,6 @@ void Mod::drawSequenceInPauseMenu(ttyd::dispdrv::CameraId cameraId, void *winWor
5255
5241
WindowPosX + 214 ,
5256
5242
WindowPosY + PosYIncrement,
5257
5243
Color,
5258
- AlignBase,
5259
5244
Scale);
5260
5245
}
5261
5246
0 commit comments