X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Funix%2Ftgfx.c;h=f36eccedd9bc5119b265f40c2d2a4a4d2664ab1d;hb=8b4d2adf48213f2bf74ca1a423b1ac3dc8066f95;hp=4c8955da1f46d3f38613ed75db5a29f9878173f6;hpb=5363ed21fccc528965a8482b3b71fe0133595499;p=oftp diff --git a/src/unix/tgfx.c b/src/unix/tgfx.c index 4c8955d..f36ecce 100644 --- a/src/unix/tgfx.c +++ b/src/unix/tgfx.c @@ -1,38 +1,192 @@ #include #include "tgfx.h" +#include "util.h" + +struct cpair { + int pair; + int fg, bg; +}; +static struct cpair *colors; +static int num_colors; + +static int fgcol, bgcol; +static int bgchar; +static int cur_pair; +static int cur_x, cur_y; + +static int curses_color(int col); +static void upd_color(void); + +void tg_init(void) +{ + initscr(); + cbreak(); + keypad(stdscr, TRUE); + nodelay(stdscr, TRUE); + noecho(); + curs_set(0); + start_color(); + + fgcol = curses_color(TGFX_WHITE); + bgcol = curses_color(TGFX_BLACK); + bgchar = ' '; + + colors = malloc_nf(COLORS * sizeof *colors); + num_colors = 0; +} + +void tg_cleanup(void) +{ + endwin(); +} + +void tg_redraw(void) +{ + move(cur_y, cur_x); + refresh(); +} void tg_clear(void) { + clear(); } void tg_fgcolor(int col) { + fgcol = curses_color(col); } void tg_bgcolor(int col) { + bgcol = curses_color(col); } void tg_color(int col) { + fgcol = curses_color(col & 0xf); + bgcol = curses_color((col >> 4) & 0xf); } void tg_bgchar(int c) { + bgchar = c; } void tg_setcursor(int x, int y) { + move(y, x); + cur_x = x; + cur_y = y; } void tg_text(int x, int y, const char *fmt, ...) { + va_list ap; + + va_start(ap, fmt); + tg_vtext(x, y, fmt, ap); + va_end(ap); +} + +void tg_vtext(int x, int y, const char *fmt, va_list ap) +{ + upd_color(); + attron(COLOR_PAIR(cur_pair)); + move(y, x); + vw_printw(stdscr, fmt, ap); + attroff(COLOR_PAIR(cur_pair)); } void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags) { + int i; + + upd_color(); + attron(COLOR_PAIR(cur_pair)); + + for(i=0; i= COLORS) { + return; + } + i = num_colors++; + cur_pair = num_colors; + + colors[i].fg = fgcol; + colors[i].bg = bgcol; + colors[i].pair = cur_pair; + init_pair(cur_pair, fgcol, bgcol); }