diff options
Diffstat (limited to 'src/text')
-rw-r--r-- | src/text/text.h | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/src/text/text.h b/src/text/text.h index 630f04f..3b7921d 100644 --- a/src/text/text.h +++ b/src/text/text.h | |||
@@ -25,6 +25,7 @@ typedef struct TextEngine { | |||
25 | 25 | ||
26 | static TextEngine text_engine = {0}; | 26 | static TextEngine text_engine = {0}; |
27 | 27 | ||
28 | // Initializes the text engine. | ||
28 | static inline | 29 | static inline |
29 | void | 30 | void |
30 | txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) { | 31 | txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) { |
@@ -43,38 +44,35 @@ txt_init(u32 *font_data, u16 *font_tilemap, u16 font_offset) { | |||
43 | text_engine.font_tilemap = font_tilemap; | 44 | text_engine.font_tilemap = font_tilemap; |
44 | } | 45 | } |
45 | 46 | ||
47 | // Writes a message to the tile text background. | ||
46 | static inline | 48 | static inline |
47 | void | 49 | void |
48 | txt_putc(char c) { | 50 | txt_puts(char *msg) { |
49 | if (c == '\0') { | 51 | while (*msg) { |
50 | return; | 52 | char c = *msg++; |
51 | } | 53 | if (c == '\0') { |
52 | if (c == '\n') { | 54 | continue; |
53 | text_engine.cursor_x = 0; | 55 | } |
54 | text_engine.cursor_y++; | 56 | if (c == '\n') { |
55 | } else { | ||
56 | int x = text_engine.cursor_x; | ||
57 | int y = text_engine.cursor_y; | ||
58 | text_engine.font_tilemap[x + 32 * y] = text_engine.font_map[(u16)c]; | ||
59 | text_engine.cursor_x += 1; | ||
60 | if (text_engine.cursor_x >= 30) { | ||
61 | text_engine.cursor_x = 0; | 57 | text_engine.cursor_x = 0; |
62 | text_engine.cursor_y++; | 58 | text_engine.cursor_y++; |
59 | } else { | ||
60 | int x = text_engine.cursor_x; | ||
61 | int y = text_engine.cursor_y; | ||
62 | text_engine.font_tilemap[x + 32 * y] = text_engine.font_map[(u16)c]; | ||
63 | text_engine.cursor_x += 1; | ||
64 | if (text_engine.cursor_x >= 30) { | ||
65 | text_engine.cursor_x = 0; | ||
66 | text_engine.cursor_y++; | ||
67 | } | ||
68 | } | ||
69 | if (text_engine.cursor_y >= 20) { | ||
70 | text_engine.cursor_y = 0; | ||
63 | } | 71 | } |
64 | } | ||
65 | if (text_engine.cursor_y >= 20) { | ||
66 | text_engine.cursor_y = 0; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static inline | ||
71 | void | ||
72 | txt_puts(char *msg) { | ||
73 | while (*msg) { | ||
74 | txt_putc(*msg++); | ||
75 | } | 72 | } |
76 | } | 73 | } |
77 | 74 | ||
75 | // Clears the current line on the tile text mode. | ||
78 | static inline | 76 | static inline |
79 | void | 77 | void |
80 | txt_clear_line(void) { | 78 | txt_clear_line(void) { |
@@ -86,6 +84,7 @@ txt_clear_line(void) { | |||
86 | text_engine.cursor_x = 0; | 84 | text_engine.cursor_x = 0; |
87 | } | 85 | } |
88 | 86 | ||
87 | // Clears the screen on the tile text mode. | ||
89 | static inline | 88 | static inline |
90 | void | 89 | void |
91 | txt_clear_screen(void) { | 90 | txt_clear_screen(void) { |
@@ -97,6 +96,7 @@ txt_clear_screen(void) { | |||
97 | text_engine.cursor_y = 0; | 96 | text_engine.cursor_y = 0; |
98 | } | 97 | } |
99 | 98 | ||
99 | // Moves the tile mode cursor to the specified position. | ||
100 | static inline | 100 | static inline |
101 | void | 101 | void |
102 | txt_position(size_t tile_x, size_t tile_y) { | 102 | txt_position(size_t tile_x, size_t tile_y) { |
@@ -127,6 +127,8 @@ txt_draws(char *msg, size_t x, size_t y, size_t spacing) { | |||
127 | txt_puts(buf); \ | 127 | txt_puts(buf); \ |
128 | } | 128 | } |
129 | 129 | ||
130 | // Draws text to the screen with formatting starting on the x and y position and | ||
131 | // with custom character spacing. | ||
130 | #define txt_drawf(msg, x, y, s, ...) \ | 132 | #define txt_drawf(msg, x, y, s, ...) \ |
131 | { \ | 133 | { \ |
132 | char buf[256] = {0}; \ | 134 | char buf[256] = {0}; \ |