Skip to content

Commit 1528b53

Browse files
committed
Update printMsg function for RTL support
1 parent baf7d21 commit 1528b53

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

retail/cardenginei/arm9_igm/source/inGameMenu.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,40 @@ void printRight(int x, int y, const unsigned char *str, FontPalette palette, boo
108108

109109
void printMsg(int y, const unsigned char *str, FontPalette palette, bool main) {
110110
u16 *dst = main ? BG_MAP_RAM(15) : BG_MAP_RAM_SUB(15);
111-
int x = 0;
112-
while(1) {
113-
bool spaceFound = false;
111+
while(*str) {
114112
bool endFound = false;
115-
int wordLen = 0;
113+
int lineLen = 0;
114+
if (str[0] == 0x20) {
115+
str++;
116+
}
116117
for (int i = 0; i < 0x20; i++) {
117-
spaceFound = str[i] == 0x20;
118118
endFound = str[i] == 0;
119-
if ((spaceFound && (x + i) > 0) || endFound) {
119+
if (endFound) {
120120
break;
121-
} else if (!spaceFound) {
122-
wordLen++;
123-
if (x > 0 && ((x + i) % 0x20) == 0) {
124-
x = 0;
125-
y++;
126-
if (y == 0x18) return;
127-
}
128121
}
122+
lineLen++;
129123
}
130-
if (wordLen == 0 && endFound) break;
131-
for (int i = 0; i < wordLen; i++) {
132-
dst[(y * 0x20) + x + i] = *(str++) | palette << 12;
133-
}
134-
if (spaceFound) {
135-
str++;
136-
wordLen++;
124+
if (!endFound) {
125+
for (int i = 0x20; i >= 0; i--) {
126+
if (str[i] == 0x20) {
127+
lineLen = i;
128+
break;
129+
}
130+
}
137131
}
138-
x += wordLen;
139-
if (x >= 0x20) {
140-
x = 0;
132+
if (lineLen > 0) {
133+
if (igmText.rtl) {
134+
for (int i = 0; i < lineLen; i++) {
135+
dst[(y * 0x20) + (0x20 - lineLen) + i] = *(str++) | palette << 12;
136+
}
137+
} else {
138+
for (int i = 0; i < lineLen; i++) {
139+
dst[(y * 0x20) + i] = *(str++) | palette << 12;
140+
}
141+
}
141142
y++;
142143
}
143-
if (y == 0x18 || endFound) break;
144+
if (y == 0x18) break;
144145
}
145146
}
146147

0 commit comments

Comments
 (0)