Angband
ui-menu.h
Go to the documentation of this file.
1 
20 #ifndef INCLUDED_UI_MENU_H
21 #define INCLUDED_UI_MENU_H
22 
23 #include "ui-output.h"
24 
25 /*** Constants ***/
26 
27 /* Colors for interactive menus */
28 enum
29 {
30  CURS_UNKNOWN = 0, /* Use gray / dark blue for cursor */
31  CURS_KNOWN = 1 /* Use white / light blue for cursor */
32 };
33 
37 typedef enum _menu_row_style_t {
41 
45 typedef enum _menu_row_validity_t {
50 
51 /* Cursor colours for different states */
52 extern const byte curs_attrs[2][2];
53 
54 /* Standard menu orderings */
55 extern const char lower_case[]; /* abc..z */
56 extern const char upper_case[]; /* ABC..Z */
57 extern const char all_letters[]; /* abc..zABC..Z */
58 
59 
60 /*
61  Together, these classes define the constant properties of
62  the various menu classes.
63 
64  A menu consists of:
65  - menu_iter, which describes how to handle the type of "list" that's
66  being displayed as a menu
67  - a menu_skin, which describes the layout of the menu on the screen.
68  - various bits and bobs of other data (e.g. the actual list of entries)
69  */
70 struct menu;
71 
72 
73 
74 /*** Predefined menu "skins" ***/
75 
79 typedef enum
80 {
81  /*
82  * A simple list of actions with an associated name and id.
83  * Private data: an array of menu_action
84  */
86 
87  /*
88  * A list of strings to be selected from - no associated actions.
89  * Private data: an array of const char *
90  */
92 } menu_iter_id;
93 
94 
98 typedef struct
99 {
100  int flags;
101  char tag;
102  const char *name;
103  void (*action)(const char *title, int row);
104 } menu_action;
105 
106 
110 #define MN_ACT_GRAYED 0x0001 /* Allows selection but no action */
111 #define MN_ACT_HIDDEN 0x0002 /* Row is hidden, but may be selected via tag */
112 
113 
117 typedef struct
118 {
119  /* Returns menu item tag (optional) */
120  char (*get_tag)(struct menu *menu, int oid);
121 
122  /*
123  * Validity checker (optional--all rows are assumed valid if not present)
124  * Return values will be interpreted as: 0 = no, 1 = yes, 2 = hide.
125  */
126  int (*valid_row)(struct menu *menu, int oid);
127 
128  /* Displays a menu row */
129  void (*display_row)(struct menu *menu, int oid, bool cursor,
130  int row, int col, int width);
131 
132  /* Handle 'positive' events (selections or cmd_keys) */
133  /* XXX split out into a select handler and a cmd_key handler */
134  bool (*row_handler)(struct menu *menu, const ui_event *event, int oid);
135 
136  /* Called when the screen resizes */
137  void (*resize)(struct menu *m);
138 } menu_iter;
139 
140 
141 
142 /*** Menu skins ***/
143 
147 typedef enum
148 {
152 } skin_id;
153 
154 
155 /* Class functions for menu layout */
156 typedef struct
157 {
158  /* Determines the cursor index given a (mouse) location */
159  int (*get_cursor)(int row, int col, int n, int top, region *loc);
160 
161  /* Displays the current list of visible menu items */
162  void (*display_list)(struct menu *menu, int cursor, int *top, region *);
163 
164  /* Specifies the relative menu item given the state of the menu */
165  char (*get_tag)(struct menu *menu, int pos);
166 
167  /* Process a direction */
168  ui_event (*process_dir)(struct menu *menu, int dir);
169 } menu_skin;
170 
171 
172 
173 /*** Base menu structure ***/
174 
178 enum
179 {
180  /* Tags are associated with the view, not the element */
181  MN_REL_TAGS = 0x01,
182 
183  /* No tags -- movement key and mouse browsing only */
184  MN_NO_TAGS = 0x02,
185 
186  /* Tags to be generated by the display function */
187  MN_PVT_TAGS = 0x04,
188 
189  /* Tag selections can be made regardless of the case of the key pressed.
190  * i.e. 'a' activates the line tagged 'A'. */
192 
193  /* double tap (or keypress) for selection; single tap is cursor movement */
194  MN_DBL_TAP = 0x10,
195 
196  /* no select events to be triggered */
197  MN_NO_ACTION = 0x20,
198 
199  /* Tags can be selected via an inscription */
201 };
202 
203 
204 /* Base menu type */
205 struct menu
206 {
208  const char *header;
209  const char *title;
210  const char *prompt;
211 
212  /* Keyboard shortcuts for menu selection-- shouldn't overlap cmd_keys */
213  const char *selections;
214 
215  /* Menu selections corresponding to inscriptions */
216  char *inscriptions;
217 
218  /* String of characters that when pressed, menu handler should be called */
219  /* Mustn't overlap with 'selections' or some items may be unselectable */
220  const char *cmd_keys;
221 
222  /* String of characters that when pressed, return an EVT_SWITCH */
223  /* Mustn't overlap with previous blah blah */
224  const char *switch_keys;
225 
226  /* auxiliary browser help function */
227  void (*browse_hook)(int oid, void *db, const region *loc);
228 
229  /* Flags specifying the behavior of this menu (from struct menu_flags) */
230  int flags;
231 
232 
235  /* Stored boundary, set by menu_layout(). This is used to calculate
236  * where the menu should be displayed on display & resize */
238 
239  int filter_count; /* number of rows in current view */
240  const int *filter_list; /* optional filter (view) of menu objects */
241 
242  int count; /* number of rows in underlying data set */
243  void *menu_data; /* the data used to access rows. */
244 
245  const menu_skin *skin; /* menu display style functions */
246  const menu_iter *row_funcs; /* menu skin functions */
247 
248  /* State variables */
249  int cursor; /* Currently selected row */
250  int top; /* Position in list for partial display */
251  region active; /* Subregion actually active for selection */
252  int cursor_x_offset; /* Adjustment to the default position of the cursor on a line. */
253 };
254 
255 
256 
257 /*** Menu API ***/
258 
262 struct menu *menu_new(skin_id, const menu_iter *iter);
263 struct menu *menu_new_action(menu_action *acts, size_t n);
264 void menu_free(struct menu *m);
265 
266 
270 void menu_init(struct menu *menu, skin_id skin, const menu_iter *iter);
271 
272 
276 const menu_iter *menu_find_iter(menu_iter_id iter_id);
277 
278 
285 void menu_setpriv(struct menu *menu, int count, void *data);
286 
287 
291 void *menu_priv(struct menu *menu);
292 
293 
294 /*
295  * Set a filter on what items a menu can display.
296  *
297  * Use this if your menu private data has 100 items, but you want to choose
298  * which ones of those to display at any given time, e.g. in an inventory menu.
299  * object_list[] should be an array of indexes to display, and n should be its
300  * length.
301  */
302 void menu_set_filter(struct menu *menu, const int object_list[], int n);
303 
304 
308 void menu_release_filter(struct menu *menu);
309 
310 
316 bool menu_layout(struct menu *menu, const region *loc);
317 
318 
324 void menu_refresh(struct menu *menu, bool reset_screen);
325 
326 
352 ui_event menu_select(struct menu *menu, int notify, bool popup);
353 
357 void menu_ensure_cursor_valid(struct menu *m);
358 
359 
360 /* Interal menu stuff that cmd-know needs because it's quite horrible */
361 bool menu_handle_mouse(struct menu *menu, const ui_event *in, ui_event *out);
362 bool menu_handle_keypress(struct menu *menu, const ui_event *in, ui_event *out);
363 
367 void menu_set_cursor_x_offset(struct menu *m, int offset);
368 
369 /*** Dynamic menu handling ***/
370 
371 struct menu *menu_dynamic_new(void);
372 void menu_dynamic_add(struct menu *m, const char *text, int value);
373 void menu_dynamic_add_valid(struct menu *m, const char *text, int value, menu_row_validity_t valid);
374 void menu_dynamic_add_label(struct menu *m, const char *text, const char label, int value, char *label_list);
375 void menu_dynamic_add_label_valid(struct menu *m, const char *text, const char label, int value, char *label_list, menu_row_validity_t valid);
376 size_t menu_dynamic_longest_entry(struct menu *m);
377 void menu_dynamic_calc_location(struct menu *m, int mx, int my);
378 int menu_dynamic_select(struct menu *m);
379 void menu_dynamic_free(struct menu *m);
380 
381 #endif /* INCLUDED_UI_MENU_H */
png_bytepp row
Definition: libpng12/png.h:1784
Ordinary scrollable single-column list.
Definition: ui-menu.h:149
const char all_letters[]
Definition: ui-menu.c:40
const char upper_case[]
Definition: ui-menu.c:39
region active
Definition: ui-menu.h:251
int filter_count
Definition: ui-menu.h:239
enum _menu_row_validity_t menu_row_validity_t
Type wrapper for row validity.
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
const menu_iter * row_funcs
Definition: ui-menu.h:246
void menu_set_cursor_x_offset(struct menu *m, int offset)
Allow adjustment of the cursor's default x offset.
Definition: ui-menu.c:973
bool menu_handle_keypress(struct menu *menu, const ui_event *in, ui_event *out)
Handle navigation keypresses.
Definition: ui-menu.c:674
int menu_dynamic_select(struct menu *m)
Definition: ui-menu.c:1125
Primitive menu item with bound action.
Definition: ui-menu.h:98
Definition: z-type.h:24
const byte curs_attrs[2][2]
Cursor colours.
Definition: ui-menu.c:29
const int * filter_list
Definition: ui-menu.h:240
Multicolumn view.
Definition: ui-menu.h:151
void menu_release_filter(struct menu *menu)
Remove any filters set on a menu by menu_set_filer().
Definition: ui-menu.c:862
void(* browse_hook)(int oid, void *db, const region *loc)
Definition: ui-menu.h:227
skin_id
Identifiers for the kind of layout to use.
Definition: ui-menu.h:147
int cursor_x_offset
Definition: ui-menu.h:252
void menu_dynamic_free(struct menu *m)
Definition: ui-menu.c:1142
static term_data data[MAX_TERM_DATA]
Definition: main-nds.c:156
Definition: ui-menu.h:46
const char * switch_keys
Definition: ui-menu.h:224
typedef int
Definition: libpng12/png.h:1135
void(* action)()
Definition: ui-options.c:1669
enum _menu_row_style_t menu_row_style_t
Type wrapper for various row styles.
uint8_t byte
Definition: h-basic.h:167
const char * header
Public variables.
Definition: ui-menu.h:208
png_bytepp png_bytepp display_row
Definition: libpng12/png.h:1784
bool menu_handle_mouse(struct menu *menu, const ui_event *in, ui_event *out)
Handle mouse input in a menu.
Definition: ui-menu.c:616
void * menu_data
Definition: ui-menu.h:243
char tag
Definition: ui-menu.h:101
const menu_skin * skin
Definition: ui-menu.h:245
void menu_dynamic_calc_location(struct menu *m, int mx, int my)
Definition: ui-menu.c:1098
void menu_dynamic_add_label(struct menu *m, const char *text, const char label, int value, char *label_list)
Definition: ui-menu.c:1077
const char * title
Definition: ui-menu.h:209
Definition: ui-menu.h:91
Definition: ui-menu.h:38
void menu_set_filter(struct menu *menu, const int object_list[], int n)
Definition: ui-menu.c:854
Definition: ui-menu.h:187
Definition: ui-menu.h:30
Definition: ui-menu.h:39
void menu_ensure_cursor_valid(struct menu *m)
Set the menu cursor to the next valid row.
Definition: ui-menu.c:871
size_t menu_dynamic_longest_entry(struct menu *m)
Definition: ui-menu.c:1082
Definition: ui-menu.h:191
void menu_dynamic_add_label_valid(struct menu *m, const char *text, const char label, int value, char *label_list, menu_row_validity_t valid)
Definition: ui-menu.c:1069
region boundary
Private variables.
Definition: ui-menu.h:237
Definition: ui-menu.h:31
Definition: ui-menu.h:156
Definition: ui-menu.h:200
_menu_row_validity_t
Type wrapper for row validity.
Definition: ui-menu.h:45
char * inscriptions
Definition: ui-menu.h:216
int flags
Definition: ui-menu.h:100
Definition: ui-menu.h:181
void menu_free(struct menu *m)
Definition: ui-menu.c:968
Definition: ui-menu.h:47
Underlying function set for displaying lists in a certain kind of way.
Definition: ui-menu.h:117
const char * cmd_keys
Definition: ui-menu.h:220
static bool get_tag(struct object **tagged_obj, char tag, cmd_code cmd, bool quiver_tags)
Find the first object in the object list with the given "tag".
Definition: ui-object.c:651
struct loc loc(int x, int y)
Definition: z-type.c:22
bool menu_layout(struct menu *menu, const region *loc)
Ready a menu for display in the region specified.
Definition: ui-menu.c:919
Definition: ui-menu.h:48
void menu_setpriv(struct menu *menu, int count, void *data)
Set menu private data and the number of menu items.
Definition: ui-menu.c:925
static int iter
Definition: obj-power.c:56
void menu_refresh(struct menu *menu, bool reset_screen)
Display a menu.
Definition: ui-menu.c:576
static sqlite3 * db
Module state variables.
Definition: db.c:31
int count
Definition: ui-menu.h:242
struct menu * menu_new(skin_id, const menu_iter *iter)
Allocate and return a new, initialised, menu.
Definition: ui-menu.c:954
Special single-column list for object choice.
Definition: ui-menu.h:150
_menu_row_style_t
Type wrapper for various row styles.
Definition: ui-menu.h:37
const menu_iter * menu_find_iter(menu_iter_id iter_id)
Given a predefined menu kind, return its iter functions.
Definition: ui-menu.c:819
const char lower_case[]
Some useful constants.
Definition: ui-menu.c:38
struct menu * menu_dynamic_new(void)
Definition: ui-menu.c:1030
int flags
Definition: ui-menu.h:230
void menu_init(struct menu *menu, skin_id skin, const menu_iter *iter)
Initialise a menu, using the skin and iter functions specified.
Definition: ui-menu.c:938
Definition: ui-menu.h:197
png_infop png_uint_32 * width
Definition: libpng12/png.h:2341
void menu_dynamic_add_valid(struct menu *m, const char *text, int value, menu_row_validity_t valid)
Definition: ui-menu.c:1037
int cursor
Definition: ui-menu.h:249
struct menu * menu_new_action(menu_action *acts, size_t n)
Definition: ui-menu.c:961
void * menu_priv(struct menu *menu)
Return menu private data, set with menu_setpriv().
Definition: ui-menu.c:933
Definition: ui-menu.h:194
menu_iter_id
Types of predefined skins available.
Definition: ui-menu.h:79
Definition: ui-menu.h:184
const char * prompt
Definition: ui-menu.h:210
Union type to hold information about any given event.
Definition: ui-event.h:191
Putting text on the screen, screen saving and loading, panel handling.
Definition: ui-menu.h:205
Definition: ui-output.h:35
const char * selections
Definition: ui-menu.h:213
png_voidp int value
Definition: libpng12/png.h:2145
int top
Definition: ui-menu.h:250
ui_event menu_select(struct menu *menu, int notify, bool popup)
Run a menu.
Definition: ui-menu.c:747
const char * name
Definition: ui-menu.h:102
void menu_dynamic_add(struct menu *m, const char *text, int value)
Definition: ui-menu.c:1064
Definition: ui-menu.h:85