9 static struct cpair *colors;
10 static int num_colors;
12 static int fgcol, bgcol;
15 static int cur_x, cur_y;
17 static int curses_color(int col);
18 static void upd_color(void);
25 nodelay(stdscr, TRUE);
30 fgcol = curses_color(TGFX_WHITE);
31 bgcol = curses_color(TGFX_BLACK);
34 colors = malloc_nf(COLORS * sizeof *colors);
55 void tg_fgcolor(int col)
57 fgcol = curses_color(col);
60 void tg_bgcolor(int col)
62 bgcol = curses_color(col);
65 void tg_color(int col)
67 fgcol = curses_color(col & 0xf);
68 bgcol = curses_color((col >> 4) & 0xf);
77 void tg_setcursor(int x, int y)
85 void tg_text(int x, int y, const char *fmt, ...)
90 tg_vtext(x, y, fmt, ap);
94 void tg_vtext(int x, int y, const char *fmt, va_list ap)
97 attron(COLOR_PAIR(cur_pair));
99 vw_printw(stdscr, fmt, ap);
100 attroff(COLOR_PAIR(cur_pair));
104 void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags)
109 attron(COLOR_PAIR(cur_pair));
111 for(i=0; i<ysz; i++) {
116 if(flags & TGFX_FRAME) {
118 hline(ACS_HLINE, xsz - 2);
119 move(y + ysz - 1, x + 1);
120 hline(ACS_HLINE, xsz - 2);
122 vline(ACS_VLINE, ysz - 2);
123 move(y + 1, x + xsz - 1);
124 vline(ACS_VLINE, ysz - 2);
126 mvaddch(y, x, ACS_ULCORNER);
127 mvaddch(y, x + xsz - 1, ACS_URCORNER);
128 mvaddch(y + ysz - 1, x, ACS_LLCORNER);
129 mvaddch(y + ysz - 1, x + xsz - 1, ACS_LRCORNER);
133 tg_text(x + 2, y, "%s", label);
136 attroff(COLOR_PAIR(cur_pair));
140 int tg_gchar(int gchar)
153 static int curses_color(int col)
170 static void upd_color(void)
174 for(i=0; i<num_colors; i++) {
175 if(fgcol == colors[i].fg && bgcol == colors[i].bg) {
176 cur_pair = colors[i].pair;
181 /* not found, allocate a new color pair */
182 if(num_colors >= COLORS) {
186 cur_pair = num_colors;
188 colors[i].fg = fgcol;
189 colors[i].bg = bgcol;
190 colors[i].pair = cur_pair;
191 init_pair(cur_pair, fgcol, bgcol);