]> git.draconx.ca Git - rrace.git/blob - src/cursesui.h
Use gen-tree.awk to produce curses menu labels.
[rrace.git] / src / cursesui.h
1 /*
2  * Curses UI for slide puzzle game
3  * Copyright © 2022 Nick Bowler
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #ifndef RRACE_CURSESUI_H_
20 #define RRACE_CURSESUI_H_
21
22 #include "game.h"
23
24 /* Array indices for gamewin and goalwin window sets. */
25 enum {
26         PLAYWIN_TILEBORDER,
27         PLAYWIN_TILEFILL,
28         PLAYWIN_AREA,
29         PLAYWIN_MAX
30 };
31
32 /* Colour pair enumeration */
33 enum {
34         /* Pairs 1-6 correspond to tile colours; use TILE_xxx enumerations. */
35         RR_COLOUR_SHADOW = TILE_MAX, /* black on black (use bold) */
36         RR_COLOUR_TOOLBAR,           /* cyan on black (use reverse video) */
37         RR_COLOUR_MAX
38 };
39
40 struct app_state {
41         struct board board;
42
43         WINDOW *gamewin[PLAYWIN_MAX], *goalwin[PLAYWIN_MAX];
44         WINDOW *toolbar, *timer;
45
46         /* Previous input returned from getch, for 2-character sequences */
47         int last_input;
48
49         /* Most recently displayed timer value, for screen redraw. */
50         uint_least32_t timer_ms;
51
52         /* Location of the keyboard cursor */
53         int_least8_t cursor;
54
55         /* If true, the goal will be displayed over the main play area. */
56         uint_least8_t view_goal_on_game;
57
58         /* Clicked toolbar item */
59         uint_least8_t toolbar_click;
60
61         /* Current state of the toolbar menu */
62         uint_least8_t toolbar_state;
63 };
64
65 void curs_new_game(struct app_state *state);
66
67 void curs_reenable_dialog(struct app_state *state, const char *heading);
68
69 void curs_draw_toolbar(struct app_state *state);
70 void curs_execute_function(struct app_state *state, int function);
71
72 #if HAVE_CURSES_MOUSE_SUPPORT
73 int curs_toolbar_mouse_func(struct app_state *state, int x, int y);
74 #else
75 static inline int
76 curs_toolbar_mouse_func(struct app_state *state, int x, int y)
77 {
78         return 0;
79 }
80 #endif
81
82 #define MIN(a, b) ((a) < (b) ? (a) : (b))
83 #define MAX(a, b) ((a) > (b) ? (a) : (b))
84
85 #endif