Wed, 09 Apr 2014 18:11:51 +0200
tried to improve colors
src/Makefile | file | annotate | diff | comparison | revisions | |
src/colors.c | file | annotate | diff | comparison | revisions | |
src/colors.h | file | annotate | diff | comparison | revisions | |
src/game.c | file | annotate | diff | comparison | revisions | |
src/input.c | file | annotate | diff | comparison | revisions | |
src/input.h | file | annotate | diff | comparison | revisions | |
src/main.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/Makefile Wed Apr 09 12:07:47 2014 +0200 1.2 +++ b/src/Makefile Wed Apr 09 18:11:51 2014 +0200 1.3 @@ -29,6 +29,7 @@ 1.4 include ../conf.mk 1.5 1.6 SRC = main.c 1.7 +SRC += colors.c 1.8 SRC += network.c 1.9 SRC += input.c 1.10 SRC += server.c
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/colors.c Wed Apr 09 18:11:51 2014 +0200 2.3 @@ -0,0 +1,40 @@ 2.4 +/* 2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2.6 + * 2.7 + * Copyright 2014 Mike Becker. All rights reserved. 2.8 + * 2.9 + * Redistribution and use in source and binary forms, with or without 2.10 + * modification, are permitted provided that the following conditions are met: 2.11 + * 2.12 + * 1. Redistributions of source code must retain the above copyright 2.13 + * notice, this list of conditions and the following disclaimer. 2.14 + * 2.15 + * 2. Redistributions in binary form must reproduce the above copyright 2.16 + * notice, this list of conditions and the following disclaimer in the 2.17 + * documentation and/or other materials provided with the distribution. 2.18 + * 2.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2.29 + * POSSIBILITY OF SUCH DAMAGE. 2.30 + * 2.31 + */ 2.32 + 2.33 +#include "colors.h" 2.34 +#include <ncurses.h> 2.35 + 2.36 +void init_colorpairs() { 2.37 + init_pair(COL_APP, COLOR_WHITE, COLOR_BLACK); 2.38 + init_pair(COL_BW, COLOR_BLACK, COLOR_CYAN); 2.39 + init_pair(COL_BB, COLOR_BLACK, COLOR_BLUE); 2.40 + init_pair(COL_WB, COLOR_WHITE, COLOR_BLUE); 2.41 + init_pair(COL_WW, COLOR_WHITE, COLOR_CYAN); 2.42 +} 2.43 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/colors.h Wed Apr 09 18:11:51 2014 +0200 3.3 @@ -0,0 +1,42 @@ 3.4 +/* 3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3.6 + * 3.7 + * Copyright 2014 Mike Becker. All rights reserved. 3.8 + * 3.9 + * Redistribution and use in source and binary forms, with or without 3.10 + * modification, are permitted provided that the following conditions are met: 3.11 + * 3.12 + * 1. Redistributions of source code must retain the above copyright 3.13 + * notice, this list of conditions and the following disclaimer. 3.14 + * 3.15 + * 2. Redistributions in binary form must reproduce the above copyright 3.16 + * notice, this list of conditions and the following disclaimer in the 3.17 + * documentation and/or other materials provided with the distribution. 3.18 + * 3.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 3.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 3.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3.29 + * POSSIBILITY OF SUCH DAMAGE. 3.30 + * 3.31 + */ 3.32 + 3.33 +#ifndef COLORS_H 3.34 +#define COLORS_H 3.35 + 3.36 +#define COL_APP 1 3.37 +#define COL_BW 2 3.38 +#define COL_WB 3 3.39 +#define COL_BB 4 3.40 +#define COL_WW 5 3.41 + 3.42 +void init_colorpairs(); 3.43 + 3.44 +#endif /* COLORS_H */ 3.45 +
4.1 --- a/src/game.c Wed Apr 09 12:07:47 2014 +0200 4.2 +++ b/src/game.c Wed Apr 09 18:11:51 2014 +0200 4.3 @@ -30,6 +30,7 @@ 4.4 #include "game.h" 4.5 #include "network.h" 4.6 #include "input.h" 4.7 +#include "colors.h" 4.8 #include <ncurses.h> 4.9 #include <string.h> 4.10 #include <inttypes.h> 4.11 @@ -80,8 +81,13 @@ 4.12 piecec = ' '; 4.13 } 4.14 4.15 - attrset((col == WHITE ? A_BOLD : A_DIM) | 4.16 - COLOR_PAIR((y&1)==(x&1) ? COL_WB : COL_BW)); 4.17 + _Bool boardblack = (y&1)==(x&1); 4.18 + attrset((col==WHITE ? A_BOLD : A_DIM)| 4.19 + COLOR_PAIR(col == WHITE ? 4.20 + (boardblack ? COL_WB : COL_WW) : 4.21 + (boardblack ? COL_BB : COL_BW) 4.22 + ) 4.23 + ); 4.24 4.25 int cy = gamestate->mycolor == WHITE ? boardy-y : boardy-7+y; 4.26 int cx = gamestate->mycolor == WHITE ? boardx+x*3 : boardx+21-x*3; 4.27 @@ -433,6 +439,8 @@ 4.28 mvaddstr(getmaxy(stdscr)-1, 0, 4.29 "Game has ended. Press any key to leave..."); 4.30 refresh(); 4.31 + cbreak(); 4.32 + flushinp(); 4.33 getch(); 4.34 } 4.35
5.1 --- a/src/input.c Wed Apr 09 12:07:47 2014 +0200 5.2 +++ b/src/input.c Wed Apr 09 18:11:51 2014 +0200 5.3 @@ -31,12 +31,6 @@ 5.4 #include <string.h> 5.5 #include <ctype.h> 5.6 5.7 -void init_colorpairs() { 5.8 - init_pair(COL_YB, COLOR_YELLOW, COLOR_BLUE); 5.9 - init_pair(COL_BW, COLOR_BLACK, COLOR_WHITE); 5.10 - init_pair(COL_WB, COLOR_WHITE, COLOR_BLACK); 5.11 -} 5.12 - 5.13 int prompt_yesno(char *msg) { 5.14 printw("%s (y/n)? ", msg); 5.15 refresh();
6.1 --- a/src/input.h Wed Apr 09 12:07:47 2014 +0200 6.2 +++ b/src/input.h Wed Apr 09 18:11:51 2014 +0200 6.3 @@ -37,12 +37,6 @@ 6.4 extern "C" { 6.5 #endif 6.6 6.7 -#define COL_YB 1 6.8 -#define COL_BW 2 6.9 -#define COL_WB 3 6.10 - 6.11 -void init_colorpairs(); 6.12 - 6.13 int prompt_yesno(char *msg); 6.14 6.15
7.1 --- a/src/main.c Wed Apr 09 12:07:47 2014 +0200 7.2 +++ b/src/main.c Wed Apr 09 18:11:51 2014 +0200 7.3 @@ -30,6 +30,7 @@ 7.4 #include "terminal-chess.h" 7.5 #include "game.h" 7.6 #include "input.h" 7.7 +#include "colors.h" 7.8 #include <string.h> 7.9 #include <time.h> 7.10 #include <getopt.h> 7.11 @@ -170,7 +171,7 @@ 7.12 if (has_colors()) { 7.13 start_color(); 7.14 init_colorpairs(); 7.15 - bkgd(COLOR_PAIR(COL_YB)); 7.16 + bkgd(COLOR_PAIR(COL_APP)); 7.17 } else { 7.18 fprintf(stderr, "Non-colored terminals are not supported yet."); 7.19 endwin();