From 6225515f53bba92dabb673385795566c385d4078 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 11 Jun 2022 18:42:21 -0400 Subject: [PATCH] curses: Parameterize vertical position of the game. 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 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/curses.c b/src/curses.c index 986e7de..d5b1cc4 100644 --- a/src/curses.c +++ b/src/curses.c @@ -31,6 +31,10 @@ #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; -- 2.43.2