/* * Curses UI for slide puzzle game * Copyright © 2022 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef RRACE_CURSESUI_H_ #define RRACE_CURSESUI_H_ #include "game.h" /* Array indices for gamewin and goalwin window sets. */ enum { PLAYWIN_TILEBORDER, PLAYWIN_TILEFILL, PLAYWIN_AREA, PLAYWIN_MAX }; /* Colour pair enumeration */ enum { /* Pairs 1-6 correspond to tile colours; use TILE_xxx enumerations. */ RR_COLOUR_SHADOW = TILE_MAX, /* black on black (use bold) */ RR_COLOUR_TOOLBAR, /* cyan on black (use reverse video) */ RR_COLOUR_MAX }; struct app_state { struct board board; WINDOW *gamewin[PLAYWIN_MAX], *goalwin[PLAYWIN_MAX]; WINDOW *toolbar, *timer; /* Previous input returned from getch, for 2-character sequences */ int last_input; /* Most recently displayed timer value, for screen redraw. */ uint_least32_t timer_ms; /* Location of the keyboard cursor */ int_least8_t cursor; /* If true, the goal will be displayed over the main play area. */ uint_least8_t view_goal_on_game; /* Clicked toolbar item */ uint_least8_t toolbar_click; /* Current state of the toolbar menu */ uint_least8_t toolbar_state; }; void curs_new_game(struct app_state *state); void curs_reenable_dialog(struct app_state *state, const char *heading); void curs_draw_toolbar(struct app_state *state); void curs_execute_function(struct app_state *state, int function); #if HAVE_CURSES_MOUSE_SUPPORT int curs_toolbar_mouse_func(struct app_state *state, int x, int y); #else static inline int curs_toolbar_mouse_func(struct app_state *state, int x, int y) { return 0; } #endif #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif