diff --git a/debug b/debug index 4670304..956bc2a 100755 --- a/debug +++ b/debug @@ -1,2 +1,2 @@ -gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncursesw -o bin/mahou +gcc src/*.c src/server/*.c src/client/*.c -g -iquotesrc/ -lpthread -lncursesw -lm -o bin/mahou chmod +x bin/mahou diff --git a/release b/release index 7438405..1929735 100755 --- a/release +++ b/release @@ -1,2 +1,2 @@ -gcc src/*.c src/server/*.c src/client/*.c -iquotesrc/ -lpthread -lncurses -o bin/mahou +gcc src/*.c src/server/*.c src/client/*.c -iquotesrc/ -lpthread -lncursesw -lm -o bin/mahou chmod +x bin/mahou diff --git a/src/client/client.c b/src/client/client.c index 1b0527c..b36408d 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -52,6 +52,7 @@ void client() { initscr(); start_color(); + scr_ctx_init(); keypad(stdscr, TRUE); while(running == TRUE) { @@ -89,32 +90,35 @@ static int main_menu() { BOOL polling = TRUE; int i, j, selected = 0, color, ch; - clear(); + erase(); noecho(); cbreak(); -#ifdef WORK - init_pair(1, COLOR_WHITE, COLOR_BLACK); -#else - init_pair(1, COLOR_WHITE, COLOR_BLUE); -#endif - init_pair(2, COLOR_BLACK, COLOR_CYAN); - - attron(COLOR_PAIR(1) | A_BOLD); + #ifdef WORK + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK) | A_BOLD); + #else + attron(SCR_PAIR(SCR_WHITE, SCR_BLUE) | A_BOLD); + #endif scr_fill(); draw_banner(); - attroff(COLOR_PAIR(1) | A_BOLD); + attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK) | A_BOLD); while(polling == TRUE) { for(i = 0; i < MM_OPT_COUNT; ++i) { - color = selected == i ? 2 : 1; + color = selected == i + ? SCR_PAIR(SCR_BLACK, SCR_CYAN) + #ifdef WORK + : SCR_PAIR(SCR_WHITE, SCR_BLACK); + #else + : SCR_PAIR(SCR_WHITE, SCR_BLUE); + #endif - attron(COLOR_PAIR(color)); + attron(color); mvprintw(AFTER_BANNER + 3 + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2, "* %s", MM_OPTIONS[i]); - attroff(COLOR_PAIR(color)); + attroff(color); } refresh(); @@ -153,9 +157,9 @@ void create_account() { scr_alert(20, "this prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of prompt box is a test of"); - int a = 0; + /*int a = 0; while(a != KEY_LF) - printw("%i ", (a = getch())); + printw("%i ", (a = getch()));*/ } void client_loop() { diff --git a/src/client/screen.c b/src/client/screen.c index 2c81d26..1f1d3e5 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -1,5 +1,19 @@ #include "screen.h" +void scr_ctx_init() { + short i, j, val; + short colors[] = {COLOR_BLACK, COLOR_BLUE, COLOR_GREEN, COLOR_CYAN, + COLOR_RED, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE}; + + for(i = 0; i < 8; ++i) { + for(j = 0; j < 8; ++j) { + val = i * 8 + j; + __SCR_PAIRS[i][j] = val; + init_pair(val, colors[i], colors[j]); + } + } +} + void scr_char_fill(char c) { int i, j; for(i = 0; i < LINES; ++i) @@ -44,32 +58,216 @@ void scr_box(int top, int left, int width, int height) { addstr("\u2551"); } - mvaddstr(top, left, "\u255A"); + mvaddstr(top + height - 1, left, "\u255A"); for(i = 0; i < width - 2; ++i) addstr("\u2550"); addstr("\u255D"); } -static int calculate_height(int width, int length) { - return (int)ciel((float)length / (float)width); +WINDOW* scr_win_box(int top, int left, int width, int height) { + WINDOW *win = newwin(height - 2, width - 2, top + 1, left + 1); + scr_box(top, left, width, height); + refresh(); + + return win; } -void scr_alert(int width, char *text) { - clear(); - noecho(); - cbreak(); - - int text_height = calculate_height(width, strlen(text)); - +static int calculate_height(int width, int length) { + return (int)ceil((float)length / (float)width); +} + +/*static void init_prompt_pairs() { + #ifdef WORK + init_pair(1, COLOR_WHITE, COLOR_BLACK); + init_pair(2, COLOR_BLACK, COLOR_CYAN); + init_pair(3, COLOR_WHITE, COLOR_BLACK); + #else init_pair(1, COLOR_WHITE, COLOR_BLUE); init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(3, COLOR_WHITE, COLOR_BLACK); + #endif +}*/ + +void scr_alert(int width, char *text) { + erase(); + noecho(); + cbreak(); - attron(COLOR_PAIR(3)); + short pair; + WINDOW *win; + int text_height = calculate_height(width, strlen(text)); + + #ifdef WORK + pair = SCR_PAIR(SCR_WHITE, SCR_BLACK); + #else + pair = SCR_PAIR(SCR_WHITE, SCR_BLUE); + #endif + + attron(pair); scr_fill(); - attroff(COLOR_PAIR(3)); + attron(pair); - attron(COLOR_PAIR(1)); - scr_box(1, 1, 10, 10); - attroff(COLOR_PAIR(1)); + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4); + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + wprintw(win, text); + wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + wattron(win, SCR_PAIR(SCR_BLACK, SCR_CYAN)); + mvwprintw(win, text_height + 1, (width - 6) / 2, "[ OK ]"); + wrefresh(win); + wattroff(win, SCR_PAIR(SCR_BLACK, SCR_CYAN)); + + scr_hide_cursor(); + getch(); + delwin(win); +} + +BOOL scr_prompt(int width, char *text) { + erase(); + noecho(); + cbreak(); + + int ch; + short pair; + BOOL retval = TRUE, loop = TRUE; + char check[] = "[ \u2714 ]"; + char cross[] = "[ \u2718 ]"; + WINDOW *win; + int text_height = calculate_height(width, strlen(text)); + + #ifdef WORK + pair = SCR_PAIR(SCR_WHITE, SCR_BLACK); + #else + pair = SCR_PAIR(SCR_WHITE, SCR_BLUE); + #endif + + attron(pair); + scr_fill(); + attron(pair); + + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4); + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + wprintw(win, text); + wrefresh(win); + wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + while(loop) { + wmove(win, text_height + 1, (width - 12) / 2); + + pair = retval == TRUE + ? SCR_PAIR(SCR_BLACK, SCR_CYAN) + : SCR_PAIR(SCR_WHITE, SCR_BLACK); + + wattron(win, pair); + wprintw(win, check); + wattroff(win, pair); + + wprintw(win, " "); + + pair = retval == FALSE + ? SCR_PAIR(SCR_BLACK, SCR_CYAN) + : SCR_PAIR(SCR_WHITE, SCR_BLACK); + + wattron(win, pair); + wprintw(win, cross); + wattroff(win, pair); + + wrefresh(win); + + scr_hide_cursor(); + ch = getch(); + switch(ch) { + case KEY_LEFT: + retval = TRUE; + break; + case KEY_RIGHT: + retval = FALSE; + break; + case KEY_LF: + case KEY_ENTER: + loop = FALSE; + break; + } + } + + delwin(win); +} + +BOOL scr_prompt_string(int width, char *text, char *out, int outlen) { + erase(); + noecho(); + cbreak(); + + int ch, curlen = 0; + short pair; + BOOL retval = TRUE, loop = TRUE; + WINDOW *win; + int text_height = calculate_height(width, strlen(text)); + + #ifdef WORK + pair = SCR_PAIR(SCR_WHITE, SCR_BLACK); + #else + pair = SCR_PAIR(SCR_WHITE, SCR_BLUE); + #endif + + attron(pair); + scr_fill(); + attron(pair); + + attron(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + win = scr_win_box(1, (COLS - (width + 2)) / 2, width + 2, text_height + 4); + attroff(SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + wattron(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + wprintw(win, text); + wrefresh(win); + wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK)); + + out[0] = '\0'; + while(loop) { + wmove(win, text_height + 1, (width - (outlen + 3)) / 2); + + pair = retval == TRUE + ? SCR_PAIR(SCR_BLACK, SCR_CYAN) + : SCR_PAIR(SCR_WHITE, SCR_BLACK); + + wattron(win, pair); + wprintw(win, check); + wattroff(win, pair); + + wprintw(win, " "); + + pair = retval == FALSE + ? SCR_PAIR(SCR_BLACK, SCR_CYAN) + : SCR_PAIR(SCR_WHITE, SCR_BLACK); + + wattron(win, pair); + wprintw(win, cross); + wattroff(win, pair); + + wrefresh(win); + + scr_hide_cursor(); + ch = getch(); + switch(ch) { + case KEY_LEFT: + retval = TRUE; + break; + case KEY_RIGHT: + retval = FALSE; + break; + case KEY_LF: + case KEY_ENTER: + loop = FALSE; + break; + } + } + + delwin(win); } \ No newline at end of file diff --git a/src/client/screen.h b/src/client/screen.h index 86705a2..09991c2 100644 --- a/src/client/screen.h +++ b/src/client/screen.h @@ -7,16 +7,31 @@ #include #include "common.h" +#define SCR_BLACK 0 +#define SCR_BLUE 1 +#define SCR_GREEN 2 +#define SCR_CYAN 3 +#define SCR_RED 4 +#define SCR_MAGENTA 5 +#define SCR_YELLOW 6 +#define SCR_WHITE 7 + +#define SCR_PAIR(X, Y) COLOR_PAIR(__SCR_PAIRS[X][Y]) + +short __SCR_PAIRS[8][8]; +void scr_ctx_init(); + void scr_fill(); void scr_char_fill(char); void scr_wchar_fill(wchar_t); void scr_hide_cursor(); - void scr_center_write(char*, int, int); void scr_box(int, int, int, int); +WINDOW* scr_win_box(int, int, int, int); void scr_alert(int, char*); +BOOL scr_prompt(int, char*); BOOL scr_prompt_string(int, char*, char*, int); BOOL scr_prompt_int(int, char*, int*); BOOL scr_prompt_options(int, char*, char**, int, int*);