DEADSOFTWARE

kos32: efficiently implement main loop
[flatwaifu.git] / src / menu.h
1 /* Copyright (C) 2020 SovietPony
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15 #ifndef MENU_H_INCLUDED
16 #define MENU_H_INCLUDED
18 #include "glob.h"
20 /* menu types */
21 #define GM_BIG 1
22 #define GM_SMALL 2
24 /* variant types */
25 #define GM_BUTTON 1
26 #define GM_SCROLLER 2
27 #define GM_TEXTFIELD 3
28 #define GM_SMALL_BUTTON 4
29 #define GM_TEXTFIELD_BUTTON 5
31 /* menu messages */
32 #define GM_GETINT 1
33 #define GM_SETINT 2
34 #define GM_GETSTR 3
35 #define GM_SETSTR 4
36 #define GM_SELECT 5 // buttons
37 #define GM_ENTER 6 // menu
38 #define GM_LEAVE 7 // menu
39 #define GM_BEGIN 8 // textfield
40 #define GM_END 9 // textfield
41 #define GM_CANCEL 10 // textfield
42 #define GM_QUERY 11 // menu
43 #define GM_GETTITLE 12 // menu
44 #define GM_GETENTRY 13 // entry
45 #define GM_GETCAPTION 14 // entry
46 #define GM_UP 15
47 #define GM_DOWN 16
48 #define GM_KEY 17
50 typedef struct menu_str_msg_t {
51 byte type;
52 char *s;
53 int maxlen;
54 } menu_str_msg_t;
56 typedef struct menu_int_msg_t {
57 byte type;
58 int i, a, b, s;
59 } menu_int_msg_t;
61 typedef union menu_msg_t {
62 byte type;
63 menu_str_msg_t string;
64 menu_int_msg_t integer;
65 } menu_msg_t;
67 typedef struct menu_t menu_t;
68 struct menu_t {
69 int (*handler)(menu_msg_t *msg, const menu_t *m, int i);
70 };
72 typedef struct simple_menu_t {
73 byte type;
74 char *title;
75 char *say;
76 struct simple_entry_t {
77 char *caption;
78 const menu_t *submenu;
79 } entries[];
80 } simple_menu_t;
82 extern byte _warp;
84 #define GM_MAX_INPUT 24
85 extern char ibuf[GM_MAX_INPUT];
86 extern byte input;
87 extern int icur;
88 extern int imax;
90 extern short lastkey;
92 #define GM_INIT_STRING(msg, str) GM_init_str(msg, str, sizeof str);
93 #define GM_CYCLE(i, m, n) ((i) < (m) ? (n) : (((i) > (n)) ? (m) : (i)))
94 int GM_init_int0 (menu_msg_t *msg, int i, int a, int b, int s);
95 int GM_init_int (menu_msg_t *msg, int i, int a, int b, int s);
96 int GM_init_str (menu_msg_t *msg, char *str, int maxlen);
97 int basic_menu_handler (menu_msg_t *msg, byte type, char *title, char *say, int n, int *cur);
98 int simple_menu_handler (menu_msg_t *msg, int i, int n, const simple_menu_t *m, int *cur);
100 int GM_push (const menu_t *m);
101 int GM_pop (void);
102 int GM_popall (void);
103 const menu_t *GM_get (void);
104 int GM_send_this (const menu_t *m, menu_msg_t *msg);
105 int GM_send (const menu_t *m, int i, menu_msg_t *msg);
107 void GM_key (int key, int down);
108 void GM_input (int ch);
109 void G_code (void);
110 int GM_act (void);
111 void GM_init (void);
113 #endif /* MENU_H_INCLUDED */