aboutsummaryrefslogtreecommitdiff
path: root/frontend/common/menu.h
blob: 79b827837ca1cee4f93a6479a6288deb4ffb5034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * (C) Gražvydas "notaz" Ignotas, 2006-2010
 *
 * This work is licensed under the terms of any of these licenses
 * (at your option):
 *  - GNU GPL, version 2 or later.
 *  - GNU LGPL, version 2.1 or later.
 * See the COPYING file in the top-level directory.
 */

typedef enum
{
	MB_NONE = 1,		/* no auto processing */
	MB_OPT_ONOFF,		/* ON/OFF setting */
	MB_OPT_RANGE,		/* [min-max] setting */
	MB_OPT_CUSTOM,		/* custom value */
	MB_OPT_CUSTONOFF,
	MB_OPT_CUSTRANGE,
	MB_OPT_ENUM,
} menu_behavior;

typedef struct
{
	const char *name;
	menu_behavior beh;
	int id;
	void *var;		/* for on-off/range settings */
	int mask;		/* bit to toggle for on/off */
	signed short min;	/* for ranged integer settings, to be sign-extended */
	signed short max;
	unsigned int enabled:1;
	unsigned int need_to_save:1;
	unsigned int selectable:1;
	int (*handler)(int id, int keys);
	const char * (*generate_name)(int id, int *offs);
	const void *data;
	const char *help;
} menu_entry;

#define mee_handler_id_h(name, id, handler, help) \
	{ name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, NULL, NULL, help }

#define mee_handler_id(name, id, handler) \
	mee_handler_id_h(name, id, handler, NULL)

#define mee_handler(name, handler) \
	mee_handler_id(name, MA_NONE, handler)

#define mee_handler_h(name, handler, help) \
	mee_handler_id_h(name, MA_NONE, handler, help)

#define mee_label(name) \
	{ name, MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0, 0, NULL, NULL, NULL, NULL }

#define mee_label_mk(id, name_func) \
	{ "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 0, NULL, name_func, NULL, NULL }

#define mee_onoff_h(name, id, var, mask, help) \
	{ name, MB_OPT_ONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, NULL, NULL, help }

#define mee_onoff(name, id, var, mask) \
	mee_onoff_h(name, id, var, mask, NULL)

#define mee_range_h(name, id, var, min, max, help) \
	{ name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, help }

#define mee_range(name, id, var, min, max) \
	mee_range_h(name, id, var, min, max, NULL)

#define mee_range_hide(name, id, var, min, max) \
	{ name, MB_OPT_RANGE, id, &(var), 0, min, max, 0, 1, 0, NULL, NULL, NULL, NULL }

#define mee_cust_s_h(name, id, need_save, handler, name_func, help) \
	{ name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, need_save, 1, handler, name_func, NULL, help }

#define mee_cust_h(name, id, handler, name_func, help) \
	mee_cust_s_h(name, id, 1, handler, name_func, help)

#define mee_cust(name, id, handler, name_func) \
	mee_cust_h(name, id, handler, name_func, NULL)

#define mee_cust_nosave(name, id, handler, name_func) \
	mee_cust_s_h(name, id, 0, handler, name_func, NULL)

#define mee_onoff_cust(name, id, var, mask, name_func) \
	{ name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func, NULL, NULL }

#define mee_range_cust(name, id, var, min, max, name_func) \
	{ name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func, NULL, NULL }

#define mee_enum_h(name, id, var, names_list, help) \
	{ name, MB_OPT_ENUM, id, &(var), 0, 0, 0, 1, 1, 1, NULL, NULL, names_list, help }

#define mee_enum(name, id, var, names_list) \
	mee_enum_h(name, id, var, names_list, NULL)

#define mee_end \
	{ NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }

typedef struct
{
	char *name;
	int mask;
} me_bind_action;

extern me_bind_action me_ctrl_actions[];
extern me_bind_action emuctrl_actions[];	// platform code

extern void *g_menubg_src_ptr;
extern void *g_menubg_ptr;
extern void *g_menuscreen_ptr;
#if MSCREEN_SIZE_FIXED
#define g_menuscreen_w MSCREEN_WIDTH
#define g_menuscreen_h MSCREEN_HEIGHT
#else
extern int g_menuscreen_w;
extern int g_menuscreen_h;
#endif

void menu_init(void);
void text_out16(int x, int y, const char *texto, ...);
void me_update_msg(const char *msg);

void menu_romload_prepare(const char *rom_name);
void menu_romload_end(void);

void menu_loop(void);
int  menu_loop_tray(void);

menu_entry *me_list_get_first(void);
menu_entry *me_list_get_next(void);