aboutsummaryrefslogtreecommitdiffstats
path: root/src/text.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-19 16:29:20 +0200
committerBad Diode <bd@badd10de.dev>2021-05-19 16:29:20 +0200
commit9911609e8fff312c406e3407a519b39db79bdb97 (patch)
treebbef38c5eaac06e6658ec93c2e07c571166a836d /src/text.h
parent60684bb15f5c68eb8248673da48cc4469537ffc9 (diff)
downloaduxngba-9911609e8fff312c406e3407a519b39db79bdb97.tar.gz
uxngba-9911609e8fff312c406e3407a519b39db79bdb97.zip
Implement double buffering drawing
Diffstat (limited to 'src/text.h')
-rw-r--r--src/text.h31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/text.h b/src/text.h
index b3bb601..b90c160 100644
--- a/src/text.h
+++ b/src/text.h
@@ -131,9 +131,9 @@ txt_putc_hybrid(char c) {
131 unpack_tiles(packed_char, &tile, 1); 131 unpack_tiles(packed_char, &tile, 1);
132 int x = text_engine.cursor_x; 132 int x = text_engine.cursor_x;
133 int y = text_engine.cursor_y; 133 int y = text_engine.cursor_y;
134 // DEBUG: should be on the text struct. 134 Tile *buf = text_engine.memory;
135 Tile *buf = &TILE_MEM[0];
136 buf[x + y * 30] = tile; 135 buf[x + y * 30] = tile;
136 dirty_tiles[y][x] = 1;
137 text_engine.cursor_x += 1; 137 text_engine.cursor_x += 1;
138 if (text_engine.cursor_x >= 30) { 138 if (text_engine.cursor_x >= 30) {
139 text_engine.cursor_x = 0; 139 text_engine.cursor_x = 0;
@@ -222,6 +222,33 @@ txt_init_bitmap(TextMode mode, Font font) {
222 text_engine.mode = mode; 222 text_engine.mode = mode;
223} 223}
224 224
225void
226txt_init_hybrid(TextMode mode, Font font, u32 *buf) {
227 // If font_map is NULL, initialize the standard 0-255 character map.
228 if (font.char_map == NULL) {
229 for (size_t i = 0; i < 256; ++i) {
230 default_char_map[i] = i;
231 }
232 font.char_map = &default_char_map;
233 }
234
235 // Initialize default values if set to zero.
236 if (font.char_width == 0) {
237 font.char_width = 8;
238 }
239 if (font.char_height == 0) {
240 font.char_height = 8;
241 }
242 if (font.color == 0) {
243 font.color = COLOR_WHITE;
244 }
245
246 // Prepare text engine.
247 text_engine.font = font;
248 text_engine.mode = mode;
249 text_engine.memory = *buf;
250}
251
225// Print text to the screen with formatting. 252// Print text to the screen with formatting.
226void 253void
227txt_printf(char *msg, ...) { 254txt_printf(char *msg, ...) {