From 76343003abd8bc686e6bb5ca4bcb77cb33b76e10 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 4 Jun 2021 10:30:53 +0200 Subject: Add text drawing support for framebuffer --- src/text/text.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/text') 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 @@ #ifndef TEXT_H #define TEXT_H -#include "bd-font.c" -#include "shorthand.h" #include "posprintf.h" +#include "renderer.h" + +#include "bd-font.c" typedef struct TextEngine { // 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) { text_engine.cursor_y = tile_y; } +// Draws a message where the first character's top-left corner begins at the +// given x and y position. The character spacing can be adjusted, but beware of +// color merging issues. +static inline +void +txt_draws(char *msg, size_t x, size_t y, size_t spacing) { + while (*msg) { + char c = *msg++; + Tile *tile = FONT_DATA; + tile += c; + draw_tile(x, y, tile, true); + x += spacing; + } +} + // Print text to the screen with formatting. #define txt_printf(msg, ...) \ { \ @@ -111,4 +127,11 @@ txt_position(size_t tile_x, size_t tile_y) { txt_puts(buf); \ } +#define txt_drawf(msg, x, y, s, ...) \ + { \ + char buf[256] = {0}; \ + posprintf(buf, msg, ##__VA_ARGS__); \ + txt_draws(buf, x, y, s); \ + } + #endif // TEXT_H -- cgit v1.2.1