mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[qwaq] Implement basic color support
This commit is contained in:
parent
ec4e9b326d
commit
ae532870c4
3 changed files with 110 additions and 0 deletions
21
tools/qwaq/color.h
Normal file
21
tools/qwaq/color.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef __qwaq_color_h
|
||||
#define __qwaq_color_h
|
||||
|
||||
#ifndef COLOR_PAIR
|
||||
// double protection in case this header is included in a C file
|
||||
|
||||
#define COLOR_PAIR(cp) ((cp) << 8)
|
||||
|
||||
// taken from ncurses.h
|
||||
#define COLOR_BLACK 0
|
||||
#define COLOR_RED 1
|
||||
#define COLOR_GREEN 2
|
||||
#define COLOR_YELLOW 3
|
||||
#define COLOR_BLUE 4
|
||||
#define COLOR_MAGENTA 5
|
||||
#define COLOR_CYAN 6
|
||||
#define COLOR_WHITE 7
|
||||
|
||||
#endif
|
||||
|
||||
#endif//__qwaq_color_h
|
|
@ -1,3 +1,4 @@
|
|||
#include "color.h"
|
||||
#include "event.h"
|
||||
|
||||
typedef struct window_s *window_t;
|
||||
|
@ -11,6 +12,10 @@ void mvwprintf (window_t win, int x, int y, string fmt, ...) = #0;
|
|||
void wrefresh (window_t win) = #0;
|
||||
|
||||
int get_event (qwaq_event_t *event) = #0;
|
||||
int max_colors (void) = #0;
|
||||
int max_color_pairs (void) = #0;
|
||||
int init_pair (int pair, int f, int b) = #0;
|
||||
void wbkgd (window_t win, int ch) = #0;
|
||||
|
||||
int main (int argc, string *argv)
|
||||
{
|
||||
|
@ -18,10 +23,15 @@ int main (int argc, string *argv)
|
|||
qwaq_event_t event = { };
|
||||
|
||||
initialize ();
|
||||
init_pair (1, COLOR_WHITE, COLOR_BLUE);
|
||||
wbkgd (stdscr, COLOR_PAIR(1));
|
||||
wrefresh (stdscr);
|
||||
window_t win = create_window (20, 5, 50, 10);
|
||||
wbkgd (win, COLOR_PAIR(0));
|
||||
mvwprintf (win, 0, 0, "Hi there! (q to quit)");
|
||||
mvwprintf (win, 1, 1, "(?)Oo.");
|
||||
mvwprintf (win, 1, 2, " \\_O>");
|
||||
mvwprintf (win, 1, 3, " %d %d", max_colors (), max_color_pairs ());
|
||||
wrefresh (win);
|
||||
do {
|
||||
if (get_event (&event)) {
|
||||
|
|
|
@ -63,6 +63,8 @@ typedef enum qwaq_commands_e {
|
|||
qwaq_cmd_move_panel,
|
||||
qwaq_cmd_mvwaddstr,
|
||||
qwaq_cmd_wrefresh,
|
||||
qwaq_cmd_init_pair,
|
||||
qwaq_cmd_wbkgd,
|
||||
} qwaq_commands;
|
||||
|
||||
#define RING_BUFFER(type, size) \
|
||||
|
@ -396,6 +398,26 @@ cmd_wrefresh (qwaq_resources_t *res)
|
|||
wrefresh (window->win);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_init_pair (qwaq_resources_t *res)
|
||||
{
|
||||
int pair = RB_PEEK_DATA (res->command_queue, 2);
|
||||
int f = RB_PEEK_DATA (res->command_queue, 3);
|
||||
int b = RB_PEEK_DATA (res->command_queue, 4);
|
||||
|
||||
init_pair (pair, f, b);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_wbkgd (qwaq_resources_t *res)
|
||||
{
|
||||
int window_id = RB_PEEK_DATA (res->command_queue, 2);
|
||||
int ch = RB_PEEK_DATA (res->command_queue, 3);
|
||||
|
||||
window_t *window = get_window (res, __FUNCTION__, window_id);
|
||||
wbkgd (window->win, ch);
|
||||
}
|
||||
|
||||
static void
|
||||
process_commands (qwaq_resources_t *res)
|
||||
{
|
||||
|
@ -434,6 +456,12 @@ process_commands (qwaq_resources_t *res)
|
|||
case qwaq_cmd_wrefresh:
|
||||
cmd_wrefresh (res);
|
||||
break;
|
||||
case qwaq_cmd_init_pair:
|
||||
cmd_init_pair (res);
|
||||
break;
|
||||
case qwaq_cmd_wbkgd:
|
||||
cmd_wbkgd (res);
|
||||
break;
|
||||
}
|
||||
RB_DROP_DATA (res->command_queue, RB_PEEK_DATA (res->command_queue, 1));
|
||||
}
|
||||
|
@ -698,6 +726,52 @@ bi_get_event (progs_t *pr)
|
|||
R_INT (pr) = get_event (res, event);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_max_colors (progs_t *pr)
|
||||
{
|
||||
R_INT (pr) = COLORS;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_max_color_pairs (progs_t *pr)
|
||||
{
|
||||
R_INT (pr) = COLOR_PAIRS;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_init_pair (progs_t *pr)
|
||||
{
|
||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
||||
int pair = P_INT (pr, 0);
|
||||
int f = P_INT (pr, 1);
|
||||
int b = P_INT (pr, 2);
|
||||
|
||||
int command[] = { qwaq_cmd_init_pair, 0, pair, f, b, };
|
||||
command[1] = CMD_SIZE(command);
|
||||
|
||||
if (RB_SPACE_AVAILABLE (res->command_queue) >= CMD_SIZE(command)) {
|
||||
RB_WRITE_DATA (res->command_queue, command, CMD_SIZE(command));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bi_wbkgd (progs_t *pr)
|
||||
{
|
||||
qwaq_resources_t *res = PR_Resources_Find (pr, "qwaq");
|
||||
int window_id = P_INT (pr, 0);
|
||||
int ch = P_INT (pr, 1);
|
||||
|
||||
if (get_window (res, __FUNCTION__, window_id)) {
|
||||
int command[] = { qwaq_cmd_wbkgd, 0, window_id, ch, };
|
||||
|
||||
command[1] = CMD_SIZE(command);
|
||||
|
||||
if (RB_SPACE_AVAILABLE (res->command_queue) >= CMD_SIZE(command)) {
|
||||
RB_WRITE_DATA (res->command_queue, command, CMD_SIZE(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bi_initialize (progs_t *pr)
|
||||
{
|
||||
|
@ -706,6 +780,7 @@ bi_initialize (progs_t *pr)
|
|||
initscr ();
|
||||
need_endwin = 1;
|
||||
res->initialized = 1;
|
||||
start_color ();
|
||||
raw ();
|
||||
keypad (stdscr, TRUE);
|
||||
noecho ();
|
||||
|
@ -745,6 +820,10 @@ static builtin_t builtins[] = {
|
|||
{"mvwprintf", bi_mvwprintf, -1},
|
||||
{"wrefresh", bi_wrefresh, -1},
|
||||
{"get_event", bi_get_event, -1},
|
||||
{"max_colors", bi_max_colors, -1},
|
||||
{"max_color_pairs", bi_max_color_pairs, -1},
|
||||
{"init_pair", bi_init_pair, -1},
|
||||
{"wbkgd", bi_wbkgd, -1},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue