textbuffer.h 1.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#ifndef TEXTBUFFER_H
#define TEXTBUFFER_H
#include "gfx.h"
#include "fonts.h"
#include <stdint.h>

#define TEXTBUFFER_MAX_WIDTH 40
#define TEXTBUFFER_MAX_HEIGHT 20

struct txt_glyph {
	char ch;
	Color fg_color;
	Color bg_color;
};

struct txt_buffer {
	struct gfx_region *reg;
	sFONT *font;
	int cursor_column;
	int cursor_row;
	Color fg_color;
	Color bg_color;
	int draw_cursor;
	int auto_update;
25
	int needs_redraw;
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

	struct txt_glyph text[TEXTBUFFER_MAX_HEIGHT][TEXTBUFFER_MAX_WIDTH];
};

enum txt_color {
	TEXT_FOREGROUND,
	TEXT_BACKGROUND
};

void txt_init(struct txt_buffer *txtb, struct gfx_region *reg, sFONT *f);
size_t txt_width(struct txt_buffer *tm);
size_t txt_height(struct txt_buffer *tm);
void txt_clear(struct txt_buffer *tm);
void txt_putchar(struct txt_buffer *tm, char ch);
void txt_puts(struct txt_buffer *tm, const char *str);
void txt_draw(struct txt_buffer *tm);
void txt_set_color_f(struct txt_buffer *tm, enum txt_color sw, float r, float g,
								     float b);
44 45 46
void txt_set_color_rgb(struct txt_buffer *tm, enum txt_color sw, int r, int g,
								       int b);
void txt_set_color(struct txt_buffer *tm, enum txt_color sw, Color c);
47 48
void txt_set_transparent(struct txt_buffer *tm);
void txt_set_cursor(struct txt_buffer *tm, int x, int y, int draw_cursor);
49
void txt_update(struct txt_buffer *tm, int force_redraw);
50 51

#endif