Skip to content

Commit ea2ab83

Browse files
committed
Use FontGetMessageWidth with more windows
Used FontGetMessageWidth with more windows that have text inside of them, to calculate the width of the window.
1 parent c87989b commit ea2ab83

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

ttyd-tools/rel/include/draw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void startDrawString(uint8_t alpha, uint32_t color, float scale);
2020
void drawText(const char *text, int32_t x, int32_t y, uint8_t alpha,
2121
uint32_t color, float scale);
2222

23+
uint16_t getMessageWidth(const char *text, float scale);
24+
2325
void drawTextWithWindow(const char *text, int32_t textPosX, int32_t textPosY, uint8_t alpha,
2426
uint32_t textColor, float textScale, int32_t windowWidth, uint32_t windowColor, float windowCurve);
2527

@@ -60,7 +62,6 @@ void drawWarpsErrorMessage();
6062
void drawPartnerFollowerMessage(const char *message);
6163
void drawPartnerErrorMessage();
6264
void drawFollowersErrorMessage();
63-
void drawMemoryErrorMessage(const char *message);
6465
void drawNotInBattleErrorMessage();
6566
void drawConfirmationWindow(const char *message);
6667

ttyd-tools/rel/source/draw.cpp

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ void drawText(const char *text, int32_t x, int32_t y, uint8_t alpha, uint32_t co
259259
}
260260
}
261261

262+
uint16_t getMessageWidth(const char *text, float scale)
263+
{
264+
uint16_t LineLength = ttyd::fontmgr::FontGetMessageWidth(text);
265+
float Width = static_cast<float>(LineLength + 15) * (scale + 0.05);
266+
return static_cast<uint16_t>(Width);
267+
}
268+
262269
void drawTextWithWindow(const char *text, int32_t textPosX, int32_t textPosY, uint8_t alpha,
263270
uint32_t textColor, float textScale, int32_t windowWidth, uint32_t windowColor, float windowCurve)
264271
{
@@ -1490,14 +1497,15 @@ void drawMemoryChangeWatchPosition()
14901497
}
14911498

14921499
// Draw the help window
1493-
int32_t Width = 293;
14941500
int32_t Curve = 20;
14951501
uint32_t WindowColor = 0x151515F6;
14961502
int32_t TextPosX = -135;
14971503
int32_t TextPosY = 100;
14981504
Scale = 0.6;
14991505

15001506
const char *HelpText = "Press/Hold the D-Pad directions\nto move the watch\n\nHold Y to hide this window\n\nPress B to cancel";
1507+
int32_t Width = static_cast<int32_t>(getMessageWidth(HelpText, Scale));
1508+
15011509
drawTextWithWindow(HelpText, TextPosX, TextPosY, Alpha, TextColor,
15021510
Scale, Width, WindowColor, Curve);
15031511
}
@@ -1832,10 +1840,10 @@ void drawErrorMessage(const char *line)
18321840
return;
18331841
}
18341842

1835-
int32_t TextPosX = -130;
1836-
// int32_t WindowWidth = 305;
1837-
uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(line);
1838-
int32_t WindowWidth = 80 + (LineLength >> 1) - (LineLength % 10);
1843+
int32_t TextPosX = -130;
1844+
float Scale = 0.6;
1845+
int32_t WindowWidth = static_cast<int32_t>(getMessageWidth(line, Scale));
1846+
18391847
drawErrorWindow(line, TextPosX, WindowWidth);
18401848
}
18411849
else
@@ -1875,22 +1883,6 @@ void drawFollowersErrorMessage()
18751883
drawPartnerFollowerMessage(CurrentLine);
18761884
}
18771885

1878-
void drawMemoryErrorMessage(const char *message)
1879-
{
1880-
uint32_t tempTimer = Timer;
1881-
if ((FunctionReturnCode < 0) && (tempTimer > 0))
1882-
{
1883-
if (checkForClosingErrorMessage())
1884-
{
1885-
return;
1886-
}
1887-
1888-
int32_t PosX = -140;
1889-
int32_t WindowWidth = 275;
1890-
drawErrorWindow(message, PosX, WindowWidth);
1891-
}
1892-
}
1893-
18941886
void drawNotInBattleErrorMessage()
18951887
{
18961888
uint32_t tempTimer = Timer;
@@ -3485,13 +3477,10 @@ void drawPalaceSkipDetails()
34853477
}
34863478

34873479
uint32_t TextColor = 0xFFFFFFFF;
3488-
// uint32_t WindowColor = 0x000000C0;
34893480
uint8_t Alpha = 0xFF;
34903481
int32_t PosX = -232;
34913482
int32_t PosY = -70;
34923483
float Scale = 0.75;
3493-
// int32_t WindowWidth = 440;
3494-
// float WindowCurve = 0;
34953484

34963485
// Move the text up if the input display is active
34973486
if (Displays[BUTTON_INPUT_DISPLAY])
@@ -3514,12 +3503,6 @@ void drawPalaceSkipDetails()
35143503
PhantomEmberPosY,
35153504
PartnerPosY);
35163505

3517-
// uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(tempDisplayBuffer);
3518-
// int32_t WindowWidth = 245 + (LineLength >> 1) - (LineLength % 10);
3519-
3520-
/*drawTextWithWindow(tempDisplayBuffer, PosX, PosY, Alpha, TextColor,
3521-
Scale, WindowWidth, WindowColor, WindowCurve);*/
3522-
35233506
drawText(tempDisplayBuffer, PosX, PosY, Alpha, TextColor, Scale);
35243507

35253508
// Draw Mario's coordinates if they're not already drawn
@@ -3574,7 +3557,6 @@ void drawActionCommandsTiming()
35743557

35753558
uint32_t TypeToDraw = DisplayActionCommands.TypeToDraw;
35763559
char *tempDisplayBuffer = DisplayBuffer;
3577-
uint32_t IncrementWindowWidth = 129;
35783560
const char *TextToDraw;
35793561

35803562
const uint32_t SuccessfulTiming = 1;
@@ -3659,7 +3641,6 @@ void drawActionCommandsTiming()
36593641
case CannotBeSuperguarded:
36603642
{
36613643
TextToDraw = "Cannot superguard this attack";
3662-
IncrementWindowWidth += 7;
36633644
break;
36643645
}
36653646
default:
@@ -3678,8 +3659,7 @@ void drawActionCommandsTiming()
36783659
int32_t WindowCurve = 10;
36793660
float Scale = 0.75;
36803661

3681-
uint32_t LineLength = ttyd::fontmgr::FontGetMessageWidth(TextToDraw);
3682-
int32_t WindowWidth = IncrementWindowWidth + (LineLength >> 1) - (LineLength % 10);
3662+
int32_t WindowWidth = static_cast<int32_t>(getMessageWidth(TextToDraw, Scale));
36833663

36843664
drawTextWithWindow(TextToDraw, TextPosX, TextPosY, Alpha, TextColor,
36853665
Scale, WindowWidth, WindowColor, WindowCurve);

ttyd-tools/rel/source/menu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3284,13 +3284,13 @@ void drawMenu()
32843284
case ALL_SLOTS_EMPTY:
32853285
{
32863286
const char *CurrentLine = "All slots are currently empty.";
3287-
drawMemoryErrorMessage(CurrentLine);
3287+
drawErrorMessage(CurrentLine);
32883288
break;
32893289
}
32903290
case NO_SLOTS_LEFT:
32913291
{
32923292
const char *CurrentLine = "There are no more free slots.";
3293-
drawMemoryErrorMessage(CurrentLine);
3293+
drawErrorMessage(CurrentLine);
32943294
break;
32953295
}
32963296
default:

0 commit comments

Comments
 (0)