]> git.draconx.ca Git - rrace.git/commitdiff
curses: Parameterize vertical position of the game.
authorNick Bowler <nbowler@draconx.ca>
Sat, 11 Jun 2022 22:42:21 +0000 (18:42 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sat, 11 Jun 2022 22:43:37 +0000 (18:43 -0400)
Move a bunch of magic constants into a single definition so that the
game's vertical position on the screen can be adjusted more easily.

src/curses.c

index 986e7de09e409a913e7a78f79bd579aed9ccb1cb..d5b1cc4be149681d9a383183adb3493c97f4bd79 100644 (file)
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 
+enum {
+       GAME_YPOS = 1 // top row of game and goal areas.
+};
+
 static const char *progname = "rrace";
 static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
 
@@ -104,7 +108,7 @@ static void draw_tile(WINDOW **win, unsigned colour, unsigned selected,
        getmaxyx(border, h, w);
        w = 2*(w+1)/2;
 
-       if (mvwin(border, 2+h*y, start_column+w*x) == ERR)
+       if (mvwin(border, 1+GAME_YPOS+h*y, start_column+w*x) == ERR)
                return;
 
        if (colour != TILE_EMPTY) {
@@ -147,9 +151,9 @@ static void redraw_area_border(WINDOW **win, unsigned x, unsigned sz)
 
        getmaxyx(stdscr, h, w);
 
-       if (h <= 2) {
+       if (h <= GAME_YPOS+1) {
                bl = ACS_ULCORNER, br = ACS_URCORNER;
-       } else if (h <= 3*sz+2) {
+       } else if (h <= 3*sz+GAME_YPOS+1) {
                bl = br = ACS_VLINE, bs = ' ';
        }
 
@@ -277,13 +281,13 @@ static void setup_mainwin(struct app_state *state)
 
        /* Frame for game area */
        w = MIN(scr_w-2, 3+10*gamesz);
-       h = MIN(scr_h-1, 2+5*gamesz);
-       realloc_area(&state->gamewin[WINDOW_AREA], h, w, 1, 2);
+       h = MIN(scr_h-GAME_YPOS, 2+5*gamesz);
+       realloc_area(&state->gamewin[WINDOW_AREA], h, w, GAME_YPOS, 2);
 
        /* Frame for goal area */
        w = MIN(scr_w-split, 3+6*goalsz);
-       h = MIN(scr_h-1, 2+3*goalsz);
-       realloc_area(&state->goalwin[WINDOW_AREA], h, w, 1, split);
+       h = MIN(scr_h-GAME_YPOS, 2+3*goalsz);
+       realloc_area(&state->goalwin[WINDOW_AREA], h, w, GAME_YPOS, split);
 }
 
 static void app_initialize(int argc, char **argv)
@@ -396,7 +400,7 @@ static void do_mouse(struct app_state *state)
                w = 2*(w+1)/2;
 
                if (x < 4 || (x -= 4)/5 >= w) return;
-               if (y < 2 || (y -= 2)/5 >= h) return;
+               if (y <= GAME_YPOS || (y -= GAME_YPOS+1)/5 >= h) return;
 
                /* Turn off the keyboard cursor when using the mouse */
                cursor_mask = state->cursor < 0 ? -1 : 1ul << state->cursor;