DEADSOFTWARE

update copyrights
[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
49 typedef struct menu_str_msg_t {
50 byte type;
51 char *s;
52 int maxlen;
53 } menu_str_msg_t;
55 typedef struct menu_int_msg_t {
56 byte type;
57 int i, a, b, s;
58 } menu_int_msg_t;
60 typedef union menu_msg_t {
61 byte type;
62 menu_str_msg_t string;
63 menu_int_msg_t integer;
64 } menu_msg_t;
66 typedef struct menu_t menu_t;
67 struct menu_t {
68 int (*handler)(menu_msg_t *msg, const menu_t *m, int i);
69 };
71 typedef struct simple_menu_t {
72 byte type;
73 char *title;
74 char *say;
75 struct simple_entry_t {
76 char *caption;
77 const menu_t *submenu;
78 } entries[];
79 } simple_menu_t;
81 extern byte _warp;
83 #define GM_MAX_INPUT 24
84 extern char ibuf[GM_MAX_INPUT];
85 extern byte input;
86 extern int icur;
87 extern int imax;
89 extern short lastkey;
91 #define GM_INIT_STRING(msg, str) GM_init_str(msg, str, sizeof str);
92 #define GM_CYCLE(i, m, n) ((i) < (m) ? (n) : (((i) > (n)) ? (m) : (i)))
93 int GM_init_int0 (menu_msg_t *msg, int i, int a, int b, int s);
94 int GM_init_int (menu_msg_t *msg, int i, int a, int b, int s);
95 int GM_init_str (menu_msg_t *msg, char *str, int maxlen);
96 int basic_menu_handler (menu_msg_t *msg, byte type, char *title, char *say, int n, int *cur);
97 int simple_menu_handler (menu_msg_t *msg, int i, int n, const simple_menu_t *m, int *cur);
99 int GM_push (const menu_t *m);
100 int GM_pop (void);
101 int GM_popall (void);
102 const menu_t *GM_get (void);
103 int GM_send_this (const menu_t *m, menu_msg_t *msg);
104 int GM_send (const menu_t *m, int i, menu_msg_t *msg);
106 void GM_key (int key, int down);
107 void GM_input (int ch);
108 void G_code (void);
109 int GM_act (void);
110 void GM_init (void);
112 #endif /* MENU_H_INCLUDED */