summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framebuffer.c23
-rw-r--r--framebuffer.h7
2 files changed, 30 insertions, 0 deletions
diff --git a/framebuffer.c b/framebuffer.c
index 01d169c..1b8439d 100644
--- a/framebuffer.c
+++ b/framebuffer.c
@@ -80,6 +80,29 @@ void fb_vert_line(Framebuffer fb, size_t x, size_t y1, size_t y2, Pixel pixel) {
}
}
+void fb_text(Framebuffer fb, long x, size_t y, char *s, Colour fg, Colour bg) {
+ if (x >= (long)term_width || y >= term_height) return; /* OOB */
+
+ while (x < 0 && *s != '\0') { x++, s++; }
+
+ Pixel p = {fg, bg, '\0'};
+ for(; *s != '\0' && x < (long)term_width; s++, x++) {
+ p.ch = *s;
+ fb.fb[y][x] = p;
+ }
+}
+
+void fb_text_no_bg(Framebuffer fb, long x, size_t y, char *s, Colour fg) {
+ if (x >= (long)term_width || y >= term_height) return; /* OOB */
+
+ while (x < 0 && *s != '\0') { x++, s++; }
+
+ for(; *s != '\0' && x < (long)term_width; s++, x++) {
+ fb.fb[y][x].ch = *s;
+ fb.fb[y][x].fg = fg;
+ }
+}
+
void term_init(void) {
tcgetattr(0, &initial_terminal_state);
diff --git a/framebuffer.h b/framebuffer.h
index 7571294..6191f2c 100644
--- a/framebuffer.h
+++ b/framebuffer.h
@@ -65,6 +65,13 @@ void fb_put(Framebuffer fb, size_t row, size_t col, Pixel pixel);
/* Draws a vertical line to fb on col x, from y1 to y2 */
void fb_vert_line(Framebuffer fb, size_t x, size_t y1, size_t y2, Pixel pixel);
+/* Puts s onto fb in position (x, y) with given colour. s has to be null-terminated.
+ * x is of type long to handle text 'origin' being lefter than the left edge when x < 0 */
+void fb_text(Framebuffer fb, long x, size_t y, char *s, Colour fg, Colour bg);
+
+/* Same as above, but the background is 'transparent' */
+void fb_text_no_bg(Framebuffer fb, long x, size_t y, char *s, Colour fg);
+
/* Initializes the terminal and sets TERM_WIDTH and TERM_HEIGHT */
void term_init(void);