aboutsummaryrefslogtreecommitdiffstats
path: root/src/text
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-04 10:30:53 +0200
committerBad Diode <bd@badd10de.dev>2021-06-04 10:30:53 +0200
commit76343003abd8bc686e6bb5ca4bcb77cb33b76e10 (patch)
treee3fbcd37b5697396ffea25f2fe4eac3b1f5f5433 /src/text
parent5ca4491aa46b7090189685fecf422ee7316de724 (diff)
downloadstepper-76343003abd8bc686e6bb5ca4bcb77cb33b76e10.tar.gz
stepper-76343003abd8bc686e6bb5ca4bcb77cb33b76e10.zip
Add text drawing support for framebuffer
Diffstat (limited to 'src/text')
-rw-r--r--src/text/text.h27
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
8typedef struct TextEngine { 9typedef 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.
110static inline
111void
112txt_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