-
Notifications
You must be signed in to change notification settings - Fork 4
/
displaytext.c
67 lines (55 loc) · 1.63 KB
/
displaytext.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <nusys.h>
#include "displaytext.h"
#include "graphic.h"
#include "segmentinfo.h"
u8 displayTextTexture[TMEM_SIZE_BYTES] __attribute__((aligned(8)));
void loadDisplayText() {
nuPiReadRom((u32)(_display_textSegmentRomStart), (void*)(displayTextTexture), TMEM_SIZE_BYTES);
}
int measureDisplayText(const char* text) {
int sum = 0;
int maxSum = 0;
for (int i = 0; text[i] != '\0'; i++) {
sum += DISPLAY_FONT_LETTER_WIDTH;
if (text[i] == 'I') {
sum -= 6;
} else if (text[i] == ' ') {
sum -= (DISPLAY_FONT_LETTER_WIDTH - 6);
} else if (text[i] == '\n') {
sum = 0;
}
if (sum > maxSum) {
maxSum = sum;
}
}
return maxSum;
}
void renderDisplayText(int x, int y, const char* text) {
int advance = x;
int ySpot = y;
for (int i = 0; text[i] != '\0'; i++) {
const char letter = text[i];
u32 s = 0;
if ((letter >= 65) && (letter <= 89)) {
s = ((letter - 65) + 2) * DISPLAY_FONT_LETTER_WIDTH;
} else if ((letter >= 48) && (letter <= 57)) {
s = (((letter - 48)) * DISPLAY_FONT_LETTER_WIDTH) + 364;
} else if (letter == '!') {
s = 13;
} else if (letter == '\n') {
ySpot += DISPLAY_FONT_LETTER_HEIGHT;
advance = x;
continue;
} else if (letter == ' ') {
advance += 6;
continue;
}
gSPScisTextureRectangle(glistp++, (advance) << 2, (ySpot) << 2, (advance + DISPLAY_FONT_LETTER_WIDTH) << 2, (ySpot + DISPLAY_FONT_LETTER_HEIGHT - 1) << 2, 0, s << 5, 0 << 5, 1 << 10, 1 << 10);
advance += DISPLAY_FONT_LETTER_WIDTH;
if (letter == 'I') {
advance -= 6;
} else if (s == 0) {
advance -= 8;
}
}
}