Skip to content

Commit 4c1350d

Browse files
committed
Hardcode the right alignment base in drawTextMain
The actual base used doesn't really make much of a difference, so drawTextMain was changed to use what the vanilla code in winFontSetR uses. Also changed drawTextMain to initialize TextLength to 0, and only update it in the width check if it's still at 0.
1 parent 18698b0 commit 4c1350d

File tree

3 files changed

+68
-64
lines changed

3 files changed

+68
-64
lines changed

ttyd-tools/rel/include/draw.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@ void drawTextWithWindow(const char *text, int32_t textPosX, int32_t textPosY,
2323
int32_t *drawIcon(int32_t position[3], int16_t iconNum, float scale);
2424
int32_t *drawIconFromItem(int32_t position[3], int16_t itemNum, float scale);
2525

26-
void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
27-
const char *alignBaseString, float scale, float width);
26+
void drawTextMain(const char *text, int32_t x, int32_t y,
27+
uint32_t color, bool alignRight, float scale, float width);
2828

2929
void drawText(const char *text, int32_t x, int32_t y, uint32_t color, float scale);
3030

3131
void drawTextWidth(const char *text, int32_t x,
3232
int32_t y, uint32_t color, float scale, float width);
3333

34-
void drawTextAlignRight(const char *text, int32_t x, int32_t y,
35-
uint32_t color, const char *alignBaseString, float scale);
34+
void drawTextAlignRight(const char *text, int32_t x, int32_t y, uint32_t color, float scale);
3635

3736
void drawTextMultipleLinesMain(const char *text, int32_t x, int32_t y,
38-
uint32_t color, const char *alignBaseString, float scale, float width);
37+
uint32_t color, bool alignRight, float scale, float width);
3938

4039
void drawTextMultipleLines(const char *text, int32_t x, int32_t y, uint32_t color, float scale);
4140

@@ -128,7 +127,7 @@ void drawAddByIcon(uint32_t currentMenu);
128127
void drawAddById(uint32_t currentMenu);
129128

130129
void drawVersionNumber(int32_t posX, int32_t posY);
131-
void drawPageNumberMain(int32_t posX, int32_t posY, uint32_t currentPage, const char *alignBase);
130+
void drawPageNumberMain(int32_t posX, int32_t posY, uint32_t currentPage, bool alignRight);
132131
void drawPageNumberAlignLeft(int32_t posX, int32_t posY, uint32_t currentPage);
133132
void drawPageNumber(int32_t posX, int32_t posY, uint32_t currentPage);
134133
void drawBoolOnOrOff(bool tempBool, const char *currentLine, int32_t posY);

ttyd-tools/rel/source/draw.cpp

Lines changed: 39 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,9 @@ int32_t *drawIconFromItem(int32_t position[3], int16_t itemNum, float scale)
282282
return drawIcon(position, iconNum, scale);
283283
}
284284

285-
// Set alignBaseString to nullptr to not align the text to the right
286285
// 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)
289288
{
290289
// Make sure the text isn't an empty string
291290
if (text[0] == '\0')
@@ -294,12 +293,18 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
294293
}
295294

296295
float NewPosX = intToFloat(x);
296+
uint32_t TextLength = 0;
297297

298298
// Check if aligning the text to the right
299-
if (alignBaseString)
299+
if (alignRight)
300300
{
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);
303308

304309
NewPosX += intToFloat(BaseLength - TextLength) * scale;
305310
}
@@ -308,15 +313,19 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
308313
float ScaleX = scale;
309314
if (!std::signbit(width)) // Check if positive, works for checking against +0.0 and -0.0
310315
{
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+
}
313321

322+
float TextLengthScaled = intToFloat(static_cast<int32_t>(TextLength)) * scale;
314323
if (TextLengthScaled > width)
315324
{
316325
ScaleX = (width / TextLengthScaled) * scale;
317326

318327
// If aligning the text to the right, account for the new X scale
319-
if (alignBaseString)
328+
if (alignRight)
320329
{
321330
NewPosX += TextLengthScaled - width;
322331
}
@@ -340,24 +349,23 @@ void drawTextMain(const char *text, int32_t x, int32_t y, uint32_t color,
340349

341350
void drawText(const char *text, int32_t x, int32_t y, uint32_t color, float scale)
342351
{
343-
drawTextMain(text, x, y, color, nullptr, scale, -0.f);
352+
drawTextMain(text, x, y, color, false, scale, -0.f);
344353
}
345354

346355
void drawTextWidth(const char *text, int32_t x,
347356
int32_t y, uint32_t color, float scale, float width)
348357
{
349-
drawTextMain(text, x, y, color, nullptr, scale, width);
358+
drawTextMain(text, x, y, color, false, scale, width);
350359
}
351360

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)
354362
{
355-
drawTextMain(text, x, y, color, alignBaseString, scale, -0.f);
363+
drawTextMain(text, x, y, color, true, scale, -0.f);
356364
}
357365

358366
// Credits to Jdaster64 for writing the original code for this function
359367
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)
361369
{
362370
char LineBuffer[128];
363371
const char *CurrentLine = text;
@@ -390,7 +398,7 @@ void drawTextMultipleLinesMain(const char *text, int32_t x, int32_t y,
390398
char *tempBuffer = strncpy(LineBuffer, CurrentLine, LineLength);
391399
tempBuffer[LineLength] = '\0';
392400

393-
drawTextMain(tempBuffer, x, y, color, alignBaseString, scale, width);
401+
drawTextMain(tempBuffer, x, y, color, alignRight, scale, width);
394402
}
395403

396404
// Advance to the next line
@@ -399,18 +407,18 @@ void drawTextMultipleLinesMain(const char *text, int32_t x, int32_t y,
399407
}
400408

401409
// Draw the rest of the text
402-
drawTextMain(CurrentLine, x, y, color, alignBaseString, scale, width);
410+
drawTextMain(CurrentLine, x, y, color, alignRight, scale, width);
403411
}
404412

405413
void drawTextMultipleLines(const char *text, int32_t x, int32_t y, uint32_t color, float scale)
406414
{
407-
drawTextMultipleLinesMain(text, x, y, color, nullptr, scale, -0.f);
415+
drawTextMultipleLinesMain(text, x, y, color, false, scale, -0.f);
408416
}
409417

410418
void drawTextMultipleLinesWidth(const char *text, int32_t x,
411419
int32_t y, uint32_t color, float scale, float width)
412420
{
413-
drawTextMultipleLinesMain(text, x, y, color, nullptr, scale, width);
421+
drawTextMultipleLinesMain(text, x, y, color, false, scale, width);
414422
}
415423

416424
void drawTextInit(uint8_t alpha, bool drawFontEdge)
@@ -1193,13 +1201,7 @@ void drawMarioStats()
11931201
"%" PRId32,
11941202
MarioStatsArray[Counter]);
11951203

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);
12031205
Counter++;
12041206
}
12051207

@@ -2698,6 +2700,7 @@ void drawBattlesStatusesList()
26982700
int32_t Width = 362;
26992701
int32_t Height = 35;
27002702
int32_t Curve = 0;
2703+
27012704
drawWindow(WindowColor, WindowPosX, WindowPosY, Width, Height, Curve);
27022705
}
27032706

@@ -2764,13 +2767,13 @@ void drawBattlesStatusesList()
27642767
Color = 0xFFFFFFFF;
27652768
}
27662769

2770+
int32_t TextPosXIncrement = 291;
2771+
27672772
#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;
27712774
#endif
27722775

2773-
drawTextAlignRight(TextToDraw, TextPosX + 300, TextPosY, Color, AlignBase, TextScale);
2776+
drawTextAlignRight(TextToDraw, TextPosX + TextPosXIncrement, TextPosY, Color, TextScale);
27742777
TextPosY -= 30;
27752778
}
27762779
}
@@ -3764,16 +3767,10 @@ void drawVersionNumber(int32_t posX, int32_t posY)
37643767
// uint8_t Alpha = 0xFF;
37653768
float Scale = 0.6f;
37663769

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);
37743771
}
37753772

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)
37773774
{
37783775
uint32_t Color = 0xFFFFFFFF;
37793776
// uint8_t Alpha = 0xFF;
@@ -3784,25 +3781,17 @@ void drawPageNumberMain(int32_t posX, int32_t posY, uint32_t currentPage, const
37843781
"Page %" PRIu32,
37853782
currentPage + 1);
37863783

3787-
drawTextAlignRight(tempDisplayBuffer, posX, posY, Color, alignBase, Scale);
3784+
drawTextMain(tempDisplayBuffer, posX, posY, Color, alignRight, Scale, -0.f);
37883785
}
37893786

37903787
void drawPageNumberAlignLeft(int32_t posX, int32_t posY, uint32_t currentPage)
37913788
{
3792-
drawPageNumberMain(posX, posY, currentPage, nullptr);
3789+
drawPageNumberMain(posX, posY, currentPage, false);
37933790
}
37943791

37953792
void drawPageNumber(int32_t posX, int32_t posY, uint32_t currentPage)
37963793
{
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);
38063795
}
38073796

38083797
void drawBoolOnOrOff(bool tempBool, const char *currentLine, int32_t posY)
@@ -5243,10 +5232,7 @@ void Mod::drawSequenceInPauseMenu(ttyd::dispdrv::CameraId cameraId, void *winWor
52435232
"%" PRIu32,
52445233
getSequencePosition());
52455234

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
52505236
Scale = 0.9f;
52515237
#endif
52525238

@@ -5255,7 +5241,6 @@ void Mod::drawSequenceInPauseMenu(ttyd::dispdrv::CameraId cameraId, void *winWor
52555241
WindowPosX + 214,
52565242
WindowPosY + PosYIncrement,
52575243
Color,
5258-
AlignBase,
52595244
Scale);
52605245
}
52615246

ttyd-tools/rel/source/menu.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,8 +3827,13 @@ void drawMenu()
38273827
drawSingleColumnMain();
38283828

38293829
// Draw the version number
3830-
int32_t PosX = 223;
3830+
int32_t PosX = 205;
38313831
int32_t PosY = 180;
3832+
3833+
#ifdef TTYD_JP
3834+
PosX -= 3;
3835+
#endif
3836+
38323837
drawVersionNumber(PosX, PosY);
38333838

38343839
// Draw the error message if the player tried to use the battle menu while not in a battle
@@ -3970,8 +3975,13 @@ void drawMenu()
39703975
drawSingleColumn(PosY, MaxOptionsPerPage, tempCurrentPage, false);
39713976

39723977
// Draw the page number
3973-
int32_t PosX = 223;
3978+
int32_t PosX = 205;
39743979
// int32_t PosY = 180;
3980+
3981+
#ifdef TTYD_JP
3982+
PosX -= 3;
3983+
#endif
3984+
39753985
drawPageNumber(PosX, PosY, tempCurrentPage);
39763986
break;
39773987
}
@@ -4419,8 +4429,13 @@ void drawMenu()
44194429
drawSingleColumnMain();
44204430

44214431
// Draw the page number
4422-
int32_t PosX = 223;
4432+
int32_t PosX = 205;
44234433
int32_t PosY = 180;
4434+
4435+
#ifdef TTYD_JP
4436+
PosX -= 3;
4437+
#endif
4438+
44244439
drawPageNumber(PosX, PosY, tempCurrentPage);
44254440

44264441
// Draw each actor
@@ -4492,8 +4507,13 @@ void drawMenu()
44924507
drawBattlesStatusesList();
44934508

44944509
// Draw the page number
4495-
int32_t PosX = 223;
4510+
int32_t PosX = 208;
44964511
int32_t PosY = 180;
4512+
4513+
#ifdef TTYD_JP
4514+
PosX -= 2;
4515+
#endif
4516+
44974517
drawPageNumber(PosX, PosY, tempCurrentPage);
44984518

44994519
if (tempSelectedOption > 0)

0 commit comments

Comments
 (0)