Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
ui-menu.h File Reference

Generic menu interaction functions. More...

#include "ui-output.h"

Go to the source code of this file.

Data Structures

struct  menu_action
 Primitive menu item with bound action. More...
struct  menu_iter
 Underlying function set for displaying lists in a certain kind of way. More...
struct  menu_skin
struct  menu


#define MN_ACT_GRAYED   0x0001 /* Allows selection but no action */
 Flags for menu_actions. More...
#define MN_ACT_HIDDEN   0x0002 /* Row is hidden, but may be selected via tag */


typedef enum _menu_row_style_t menu_row_style_t
 Type wrapper for various row styles. More...
typedef enum _menu_row_validity_t menu_row_validity_t
 Type wrapper for row validity. More...


enum  { CURS_UNKNOWN = 0, CURS_KNOWN = 1 }
 Type wrapper for various row styles. More...
enum  _menu_row_validity_t { MN_ROW_INVALID = 0, MN_ROW_VALID = 1, MN_ROW_HIDDEN = 2 }
 Type wrapper for row validity. More...
enum  menu_iter_id { MN_ITER_ACTIONS = 1, MN_ITER_STRINGS = 2 }
 Types of predefined skins available. More...
enum  skin_id { MN_SKIN_SCROLL = 1, MN_SKIN_OBJECT = 2, MN_SKIN_COLUMNS = 3 }
 Identifiers for the kind of layout to use. More...
enum  {
  MN_REL_TAGS = 0x01, MN_NO_TAGS = 0x02, MN_PVT_TAGS = 0x04, MN_CASELESS_TAGS = 0x08,
  MN_DBL_TAP = 0x10, MN_NO_ACTION = 0x20, MN_INSCRIP_TAGS = 0x40
 Flags for menu appearance & behaviour. More...


struct menumenu_new (skin_id, const menu_iter *iter)
 Allocate and return a new, initialised, menu. More...
struct menumenu_new_action (menu_action *acts, size_t n)
void menu_free (struct menu *m)
void menu_init (struct menu *menu, skin_id skin, const menu_iter *iter)
 Initialise a menu, using the skin and iter functions specified. More...
const menu_itermenu_find_iter (menu_iter_id iter_id)
 Given a predefined menu kind, return its iter functions. More...
void menu_setpriv (struct menu *menu, int count, void *data)
 Set menu private data and the number of menu items. More...
voidmenu_priv (struct menu *menu)
 Return menu private data, set with menu_setpriv(). More...
void menu_set_filter (struct menu *menu, const int object_list[], int n)
void menu_release_filter (struct menu *menu)
 Remove any filters set on a menu by menu_set_filer(). More...
bool menu_layout (struct menu *menu, const region *loc)
 Ready a menu for display in the region specified. More...
void menu_refresh (struct menu *menu, bool reset_screen)
 Display a menu. More...
ui_event menu_select (struct menu *menu, int notify, bool popup)
 Run a menu. More...
void menu_ensure_cursor_valid (struct menu *m)
 Set the menu cursor to the next valid row. More...
bool menu_handle_mouse (struct menu *menu, const ui_event *in, ui_event *out)
 Handle mouse input in a menu. More...
bool menu_handle_keypress (struct menu *menu, const ui_event *in, ui_event *out)
 Handle navigation keypresses. More...
void menu_set_cursor_x_offset (struct menu *m, int offset)
 Allow adjustment of the cursor's default x offset. More...
struct menumenu_dynamic_new (void)
void menu_dynamic_add (struct menu *m, const char *text, int value)
void menu_dynamic_add_valid (struct menu *m, const char *text, int value, menu_row_validity_t valid)
void menu_dynamic_add_label (struct menu *m, const char *text, const char label, int value, char *label_list)
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)
size_t menu_dynamic_longest_entry (struct menu *m)
void menu_dynamic_calc_location (struct menu *m, int mx, int my)
int menu_dynamic_select (struct menu *m)
void menu_dynamic_free (struct menu *m)


const byte curs_attrs [2][2]
 Cursor colours. More...
const char lower_case []
 Some useful constants. More...
const char upper_case []
const char all_letters []

Detailed Description

Generic menu interaction functions.

Copyright (c) 2007 Pete Mack Copyright (c) 2010 Andi Sidwell

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation


#define MN_ACT_GRAYED   0x0001 /* Allows selection but no action */

Flags for menu_actions.

Referenced by menu_action_display(), menu_action_handle(), and textui_browse_knowledge().


#define MN_ACT_HIDDEN   0x0002 /* Row is hidden, but may be selected via tag */

Referenced by menu_action_valid().

Typedef Documentation

◆ menu_row_style_t

Type wrapper for various row styles.

◆ menu_row_validity_t

Type wrapper for row validity.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum

Flags for menu appearance & behaviour.


◆ _menu_row_style_t

Type wrapper for various row styles.


◆ _menu_row_validity_t

Type wrapper for row validity.


◆ menu_iter_id

Types of predefined skins available.


◆ skin_id

enum skin_id

Identifiers for the kind of layout to use.


Ordinary scrollable single-column list.


Special single-column list for object choice.


Multicolumn view.

Function Documentation

◆ menu_dynamic_add()

void menu_dynamic_add ( struct menu m,
const char *  text,
int  value 

◆ menu_dynamic_add_label()

void menu_dynamic_add_label ( struct menu m,
const char *  text,
const char  label,
int  value,
char *  label_list 

◆ menu_dynamic_add_label_valid()

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 

◆ menu_dynamic_add_valid()

void menu_dynamic_add_valid ( struct menu m,
const char *  text,
int  value,
menu_row_validity_t  valid 

◆ menu_dynamic_calc_location()

void menu_dynamic_calc_location ( struct menu m,
int  mx,
int  my 

◆ menu_dynamic_free()

void menu_dynamic_free ( struct menu m)

◆ menu_dynamic_longest_entry()

size_t menu_dynamic_longest_entry ( struct menu m)

◆ menu_dynamic_new()

struct menu* menu_dynamic_new ( void  )

◆ menu_dynamic_select()

int menu_dynamic_select ( struct menu m)

◆ menu_ensure_cursor_valid()

void menu_ensure_cursor_valid ( struct menu m)

Set the menu cursor to the next valid row.

References menu::count, menu::cursor, menu::filter_count, menu::filter_list, is_valid_row(), and row.

Referenced by menu_release_filter(), menu_set_filter(), and menu_setpriv().

◆ menu_find_iter()

const menu_iter* menu_find_iter ( menu_iter_id  id)

Given a predefined menu kind, return its iter functions.

Given a predefined menu kind, return its iter functions.

References menu_iter_actions, menu_iter_strings, MN_ITER_ACTIONS, and MN_ITER_STRINGS.

Referenced by display_knowledge(), menu_new_action(), and textui_knowledge_init().

◆ menu_free()

void menu_free ( struct menu m)

References mem_free().

Referenced by cleanup_options(), and death_screen().

◆ menu_handle_keypress()

bool menu_handle_keypress ( struct menu menu,
const ui_event in,
ui_event out 

Handle navigation keypresses.

Returns true if they key was intelligible as navigation, regardless of whether any action was taken.

References menu::active, keypress::code, menu::count, menu::cursor, ddy, ESCAPE, EVT_ESCAPE, EVT_MOVE, EVT_SELECT, menu::filter_count, menu::filter_list, menu::flags, get_cursor_key(), is_valid_row(), KC_ENTER, ui_event::key, MN_DBL_TAP, no_valid_row(), region::page_rows, menu_skin::process_dir, menu::skin, target_dir(), menu::top, and ui_event::type.

Referenced by display_knowledge(), and menu_select().

◆ menu_handle_mouse()

bool menu_handle_mouse ( struct menu menu,
const ui_event in,
ui_event out 

Handle mouse input in a menu.

Mouse output is either moving, selecting, escaping, or nothing. Returns true if something changes as a result of the click.

References menu::active, mouseclick::button, region::col, menu::count, menu::cursor, EVT_ESCAPE, EVT_MOVE, EVT_NONE, EVT_SELECT, menu::filter_count, menu::filter_list, menu::flags, menu_skin::get_cursor, is_valid_row(), MN_DBL_TAP, ui_event::mouse, region_inside(), menu::skin, menu::top, ui_event::type, mouseclick::x, and mouseclick::y.

Referenced by display_knowledge(), and menu_select().

◆ menu_init()

void menu_init ( struct menu menu,
skin_id  skin,
const menu_iter iter 

◆ menu_layout()

bool menu_layout ( struct menu menu,
const region loc 

◆ menu_new()

struct menu* menu_new ( skin_id  ,
const menu_iter iter 

◆ menu_new_action()

struct menu* menu_new_action ( menu_action acts,
size_t  n 

◆ menu_priv()

void* menu_priv ( struct menu menu)

◆ menu_refresh()

void menu_refresh ( struct menu menu,
bool  reset_screen 

◆ menu_release_filter()

void menu_release_filter ( struct menu menu)

Remove any filters set on a menu by menu_set_filer().

References menu::filter_count, menu::filter_list, and menu_ensure_cursor_valid().

◆ menu_select()

ui_event menu_select ( struct menu menu,
int  notify,
bool  popup 

Run a menu.

'notify' is a bitwise OR of ui_event_type events that you want to menu_select to return to you if they're not handled inside the menu loop. e.g. if you want to handle key events without specifying a menu_iter->handle function, you can set notify to EVT_KBRD, and any non-navigation keyboard events will stop the menu loop and return them to you.

Some events are returned by default, and else are EVT_ESCAPE and EVT_SELECT.

Event types that can be returned: EVT_ESCAPE: no selection; go back (by default) EVT_SELECT: menu->cursor is the selected menu item (by default) EVT_MOVE: the cursor has moved EVT_KBRD: unhandled keyboard events EVT_MOUSE: unhandled mouse events EVT_RESIZE: resize events

XXX remove 'notify'

If popup is true, the screen background is saved before starting the menu, and restored before each redraw. This allows variably-sized information at the bottom of the menu.

If popup is true, the screen is saved before the menu is drawn, and restored afterwards. Each time a popup menu is redrawn, it resets the screen before redrawing.

References menu::active, menu::cmd_keys, keypress::code, menu::cursor, EVENT_EMPTY, EVT_ESCAPE, EVT_KBRD, EVT_MOUSE, EVT_RESIZE, EVT_SELECT, EVT_SWITCH, menu::flags, inkey_ex(), ui_event::key, menu_calc_size(), menu_handle_action(), menu_handle_keypress(), menu_handle_mouse(), menu_refresh(), MN_NO_ACTION, region::page_rows, menu_iter::resize, menu::row_funcs, screen_load(), screen_save(), menu::switch_keys, ui_event::type, and region::width.

Referenced by cmd_menu(), curse_menu(), death_screen(), do_cmd_colors(), do_cmd_keymaps(), do_cmd_options(), do_cmd_options_item(), do_cmd_spoilers(), do_cmd_visuals(), ego_menu(), item_menu(), menu_dynamic_select(), menu_question(), option_toggle_menu(), quality_action(), quality_menu(), spell_menu_browse(), spell_menu_select(), store_get_stock(), sval_menu(), textui_action_menu_choose(), textui_browse_knowledge(), textui_store_knowledge(), use_store(), view_ability_menu(), wiz_create_item(), wiz_create_item_action(), and wiz_proj_demo().

◆ menu_set_cursor_x_offset()

void menu_set_cursor_x_offset ( struct menu m,
int  offset 

Allow adjustment of the cursor's default x offset.

References menu::cursor_x_offset.

Referenced by sval_menu().

◆ menu_set_filter()

void menu_set_filter ( struct menu menu,
const int  object_list[],
int  n 

◆ menu_setpriv()

void menu_setpriv ( struct menu menu,
int  count,
void data 

Variable Documentation

◆ all_letters

const char all_letters[]

◆ curs_attrs

const byte curs_attrs[2][2]

◆ lower_case

const char lower_case[]

◆ upper_case

const char upper_case[]