diff options
Diffstat (limited to 'src/text/text.h')
-rw-r--r-- | src/text/text.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/text/text.h b/src/text/text.h index 65003c5..630f04f 100644 --- a/src/text/text.h +++ b/src/text/text.h | |||
@@ -1,9 +1,10 @@ | |||
1 | #ifndef TEXT_H | 1 | #ifndef TEXT_H |
2 | #define TEXT_H | 2 | #define TEXT_H |
3 | 3 | ||
4 | #include "bd-font.c" | ||
5 | #include "shorthand.h" | ||
6 | #include "posprintf.h" | 4 | #include "posprintf.h" |
5 | #include "renderer.h" | ||
6 | |||
7 | #include "bd-font.c" | ||
7 | 8 | ||
8 | typedef struct TextEngine { | 9 | typedef struct TextEngine { |
9 | // Cursor for tiled text mode The X and Y positions correspond to the tile | 10 | // Cursor for tiled text mode The X and Y positions correspond to the tile |
@@ -103,6 +104,21 @@ txt_position(size_t tile_x, size_t tile_y) { | |||
103 | text_engine.cursor_y = tile_y; | 104 | text_engine.cursor_y = tile_y; |
104 | } | 105 | } |
105 | 106 | ||
107 | // Draws a message where the first character's top-left corner begins at the | ||
108 | // given x and y position. The character spacing can be adjusted, but beware of | ||
109 | // color merging issues. | ||
110 | static inline | ||
111 | void | ||
112 | txt_draws(char *msg, size_t x, size_t y, size_t spacing) { | ||
113 | while (*msg) { | ||
114 | char c = *msg++; | ||
115 | Tile *tile = FONT_DATA; | ||
116 | tile += c; | ||
117 | draw_tile(x, y, tile, true); | ||
118 | x += spacing; | ||
119 | } | ||
120 | } | ||
121 | |||
106 | // Print text to the screen with formatting. | 122 | // Print text to the screen with formatting. |
107 | #define txt_printf(msg, ...) \ | 123 | #define txt_printf(msg, ...) \ |
108 | { \ | 124 | { \ |
@@ -111,4 +127,11 @@ txt_position(size_t tile_x, size_t tile_y) { | |||
111 | txt_puts(buf); \ | 127 | txt_puts(buf); \ |
112 | } | 128 | } |
113 | 129 | ||
130 | #define txt_drawf(msg, x, y, s, ...) \ | ||
131 | { \ | ||
132 | char buf[256] = {0}; \ | ||
133 | posprintf(buf, msg, ##__VA_ARGS__); \ | ||
134 | txt_draws(buf, x, y, s); \ | ||
135 | } | ||
136 | |||
114 | #endif // TEXT_H | 137 | #endif // TEXT_H |