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);
29 fgcol = curses_color(TGFX_WHITE);
30 bgcol = curses_color(TGFX_BLACK);
33 colors = malloc_nf(COLORS * sizeof *colors);
54 void tg_fgcolor(int col)
56 fgcol = curses_color(col);
59 void tg_bgcolor(int col)
61 bgcol = curses_color(col);
64 void tg_color(int col)
66 fgcol = curses_color(col & 0xf);
67 bgcol = curses_color((col >> 4) & 0xf);
76 void tg_setcursor(int x, int y)
84 void tg_text(int x, int y, const char *fmt, ...)
89 tg_vtext(x, y, fmt, ap);
93 void tg_vtext(int x, int y, const char *fmt, va_list ap)
96 attron(COLOR_PAIR(cur_pair));
98 vw_printw(stdscr, fmt, ap);
99 attroff(COLOR_PAIR(cur_pair));
103 void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags)
108 attron(COLOR_PAIR(cur_pair));
110 for(i=0; i<ysz; i++) {
115 if(flags & TGFX_FRAME) {
117 hline(ACS_HLINE, xsz - 2);
118 move(y + ysz - 1, x + 1);
119 hline(ACS_HLINE, xsz - 2);
121 vline(ACS_VLINE, ysz - 2);
122 move(y + 1, x + xsz - 1);
123 vline(ACS_VLINE, ysz - 2);
125 mvaddch(y, x, ACS_ULCORNER);
126 mvaddch(y, x + xsz - 1, ACS_URCORNER);
127 mvaddch(y + ysz - 1, x, ACS_LLCORNER);
128 mvaddch(y + ysz - 1, x + xsz - 1, ACS_LRCORNER);
132 tg_text(x + 2, y, "%s", label);
135 attroff(COLOR_PAIR(cur_pair));
138 static int curses_color(int col)
155 static void upd_color(void)
159 for(i=0; i<num_colors; i++) {
160 if(fgcol == colors[i].fg && bgcol == colors[i].bg) {
161 cur_pair = colors[i].pair;
166 /* not found, allocate a new color pair */
167 if(num_colors >= COLORS) {
171 cur_pair = num_colors;
173 colors[i].fg = fgcol;
174 colors[i].bg = bgcol;
175 colors[i].pair = cur_pair;
176 init_pair(cur_pair, fgcol, bgcol);