-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbraille.c
212 lines (203 loc) · 9.39 KB
/
braille.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "global.h"
#include "main.h"
#include "window.h"
#include "text.h"
#include "sound.h"
// This file handles the braille font.
// For printing braille messages, see ScrCmd_braillemessage
ALIGNED(4)
static const u8 sScrollDistances[] = {
[OPTIONS_TEXT_SPEED_SLOW] = 1,
[OPTIONS_TEXT_SPEED_MID] = 2,
[OPTIONS_TEXT_SPEED_FAST] = 4,
};
static const u16 sFont_Braille[] = INCBIN_U16("graphics/fonts/braille.fwjpnfont");
static void DecompressGlyph_Braille(u16);
u16 FontFunc_Braille(struct TextPrinter *textPrinter)
{
u16 char_;
struct TextPrinterSubStruct *subStruct;
subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
switch (textPrinter->state)
{
case RENDER_STATE_HANDLE_CHAR:
if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp)
{
textPrinter->delayCounter = 0;
}
if (textPrinter->delayCounter && textPrinter->textSpeed)
{
textPrinter->delayCounter --;
if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON))
{
subStruct->hasPrintBeenSpedUp = TRUE;
textPrinter->delayCounter = 0;
}
return RENDER_UPDATE;
}
if (gTextFlags.autoScroll)
textPrinter->delayCounter = 3;
else
textPrinter->delayCounter = textPrinter->textSpeed;
char_ = *textPrinter->printerTemplate.currentChar++;
switch (char_)
{
case EOS:
return RENDER_FINISH;
case CHAR_NEWLINE:
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY += gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
return RENDER_REPEAT;
case PLACEHOLDER_BEGIN:
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_BEGIN:
char_ = *textPrinter->printerTemplate.currentChar++;
switch (char_)
{
case EXT_CTRL_CODE_COLOR:
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_HIGHLIGHT:
textPrinter->printerTemplate.bgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_SHADOW:
textPrinter->printerTemplate.shadowColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW:
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.bgColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.shadowColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_PALETTE:
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_FONT:
subStruct->fontId = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_RESET_FONT:
return RENDER_REPEAT;
case EXT_CTRL_CODE_PAUSE:
textPrinter->delayCounter = *textPrinter->printerTemplate.currentChar++;
textPrinter->state = RENDER_STATE_PAUSE;
return RENDER_REPEAT;
case EXT_CTRL_CODE_PAUSE_UNTIL_PRESS:
textPrinter->state = RENDER_STATE_WAIT;
if (gTextFlags.autoScroll)
subStruct->autoScrollDelay = 0;
return RENDER_UPDATE;
case EXT_CTRL_CODE_WAIT_SE:
textPrinter->state = RENDER_STATE_WAIT_SE;
return RENDER_UPDATE;
case EXT_CTRL_CODE_PLAY_BGM:
case EXT_CTRL_CODE_PLAY_SE:
textPrinter->printerTemplate.currentChar += 2;
return RENDER_REPEAT;
case EXT_CTRL_CODE_ESCAPE:
char_ = *++textPrinter->printerTemplate.currentChar;
break;
case EXT_CTRL_CODE_SHIFT_RIGHT:
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x + *textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_SHIFT_DOWN:
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y + *textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_FILL_WINDOW:
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
return RENDER_REPEAT;
}
break;
case CHAR_PROMPT_CLEAR:
textPrinter->state = RENDER_STATE_CLEAR;
TextPrinterInitDownArrowCounters(textPrinter);
return RENDER_UPDATE;
case CHAR_PROMPT_SCROLL:
textPrinter->state = RENDER_STATE_SCROLL_START;
TextPrinterInitDownArrowCounters(textPrinter);
return RENDER_UPDATE;
case CHAR_EXTRA_SYMBOL:
char_ = *textPrinter->printerTemplate.currentChar++| 0x100;
break;
case CHAR_KEYPAD_ICON:
textPrinter->printerTemplate.currentChar++;
return RENDER_PRINT;
}
DecompressGlyph_Braille(char_);
CopyGlyphToWindow(textPrinter);
textPrinter->printerTemplate.currentX += gCurGlyph.width + textPrinter->printerTemplate.letterSpacing;
return RENDER_PRINT;
case RENDER_STATE_WAIT:
if (TextPrinterWait(textPrinter))
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
case RENDER_STATE_CLEAR:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y;
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
}
return RENDER_UPDATE;
case RENDER_STATE_SCROLL_START:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
TextPrinterClearDownArrow(textPrinter);
textPrinter->scrollDistance = gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->state = RENDER_STATE_SCROLL;
}
return RENDER_UPDATE;
case RENDER_STATE_SCROLL:
if (textPrinter->scrollDistance)
{
if (textPrinter->scrollDistance < sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed])
{
ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->scrollDistance = 0;
}
else
{
ScrollWindow(textPrinter->printerTemplate.windowId, 0, sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed], PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->scrollDistance -= sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed];
}
CopyWindowToVram(textPrinter->printerTemplate.windowId, COPYWIN_GFX);
}
else
{
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
}
return RENDER_UPDATE;
case RENDER_STATE_WAIT_SE:
if (!IsSEPlaying())
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
case RENDER_STATE_PAUSE:
if (textPrinter->delayCounter)
textPrinter->delayCounter --;
else
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
}
return RENDER_FINISH;
}
static void DecompressGlyph_Braille(u16 glyph)
{
const u16 *glyphs = sFont_Braille + 0x100 * (glyph / 8) + 0x10 * (glyph % 8);
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x88, gCurGlyph.gfxBufferBottom + 8);
gCurGlyph.width = 16;
gCurGlyph.height = 16;
}
u32 GetGlyphWidth_Braille(u16 glyphId, bool32 isJapanese)
{
return 16;
}