X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Funix%2Ftgfx.c;fp=src%2Funix%2Ftgfx.c;h=f88fd153e796327fbcbc9afd48c704f3817a8cfe;hb=2ba6401e39bcfaaccaa45e6b7ef780a7a15b0c48;hp=4c8955da1f46d3f38613ed75db5a29f9878173f6;hpb=2f4fb7c15c5017546238241ea318b16b9a032c52;p=oftp diff --git a/src/unix/tgfx.c b/src/unix/tgfx.c index 4c8955d..f88fd15 100644 --- a/src/unix/tgfx.c +++ b/src/unix/tgfx.c @@ -1,6 +1,38 @@ #include #include "tgfx.h" +static int fgcol, bgcol; +static int bgchar; +static int cur_x, cur_y; + +static int curses_color(int col); + +void tg_init(void) +{ + initscr(); + raw(); + keypad(stdscr, TRUE); + noecho(); + start_color(); + + fgcol = curses_color(TGFX_WHITE); + bgcol = curses_color(TGFX_BLACK); + bgchar = ' '; + + tg_color(fgcol | (bgcol << 4)); +} + +void tg_cleanup(void) +{ + endwin(); +} + +void tg_redraw(void) +{ + move(cur_y, cur_x); + refresh(); +} + void tg_clear(void) { } @@ -8,31 +40,102 @@ void tg_clear(void) void tg_fgcolor(int col) { + fgcol = curses_color(col); + init_pair(1, fgcol, bgcol); } void tg_bgcolor(int col) { + bgcol = curses_color(col); + init_pair(1, fgcol, bgcol); } void tg_color(int col) { + fgcol = curses_color(col & 0xf); + bgcol = curses_color((col >> 4) & 0xf); + init_pair(1, fgcol, bgcol); } 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) +{ + attron(COLOR_PAIR(1)); + move(y, x); + vw_printw(stdscr, fmt, ap); + attroff(COLOR_PAIR(1)); } void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags) { + int i; + + attron(COLOR_PAIR(1)); + + for(i=0; i