Angband
Data Structures | Functions | Variables
ui-menu.c File Reference

Generic menu interaction functions. More...

#include "angband.h"
#include "cave.h"
#include "ui-target.h"
#include "ui-event.h"
#include "ui-input.h"
#include "ui-menu.h"

Data Structures

struct  menu_entry

Functions

static void display_menu_row (struct menu *menu, int pos, int top, bool cursor, int row, int col, int width)
static bool menu_calc_size (struct menu *menu)
static bool is_valid_row (struct menu *menu, int cursor)
static void display_action_aux (menu_action *act, byte color, int row, int col, int wid)
static char menu_action_tag (struct menu *m, int oid)
static int menu_action_valid (struct menu *m, int oid)
static void menu_action_display (struct menu *m, int oid, bool cursor, int row, int col, int width)
static bool menu_action_handle (struct menu *m, const ui_event *event, int oid)
static void display_string (struct menu *m, int oid, bool cursor, int row, int col, int width)
static int scrolling_get_cursor (int row, int col, int n, int top, region *loc)
static void display_scrolling (struct menu *menu, int cursor, int *top, region *loc)
static char scroll_get_tag (struct menu *menu, int pos)
static ui_event scroll_process_direction (struct menu *m, int dir)
static int columns_get_cursor (int row, int col, int n, int top, region *loc)
static void display_columns (struct menu *menu, int cursor, int *top, region *loc)
static char column_get_tag (struct menu *menu, int pos)
static ui_event column_process_direction (struct menu *m, int dir)
static int get_cursor_key (struct menu *menu, int top, struct keypress key)
static menu_row_style_t menu_row_style_for_validity (menu_row_validity_t row_valid)
void menu_refresh (struct menu *menu, bool reset_screen)
 Display a menu.
bool menu_handle_mouse (struct menu *menu, const ui_event *in, ui_event *out)
static bool menu_handle_action (struct menu *m, const ui_event *in)
 Handle any menu command keys / SELECT events.
bool menu_handle_keypress (struct menu *menu, const ui_event *in, ui_event *out)
 Handle navigation keypresses.
ui_event menu_select (struct menu *menu, int notify, bool popup)
 Run a menu.
const menu_itermenu_find_iter (menu_iter_id id)
 Return the menu iter struct for a given iter ID.
static const menu_skinmenu_find_skin (skin_id id)
void menu_set_filter (struct menu *menu, const int filter_list[], int n)
void menu_release_filter (struct menu *menu)
 Remove any filters set on a menu by menu_set_filer().
void menu_ensure_cursor_valid (struct menu *m)
 Set the menu cursor to the next valid row.
bool menu_layout (struct menu *m, const region *loc)
 Ready a menu for display in the region specified.
void menu_setpriv (struct menu *menu, int count, void *data)
 Set menu private data and the number of menu items.
voidmenu_priv (struct menu *menu)
 Return menu private data, set with menu_setpriv().
void menu_init (struct menu *menu, skin_id skin_id, const menu_iter *iter)
 Initialise a menu, using the skin and iter functions specified.
struct menumenu_new (skin_id skin_id, const menu_iter *iter)
 Allocate and return a new, initialised, menu.
struct menumenu_new_action (menu_action *acts, size_t n)
void menu_set_cursor_x_offset (struct menu *m, int offset)
 Allow adjustment of the cursor's default x offset.
static int dynamic_valid (struct menu *m, int oid)
static void dynamic_display (struct menu *m, int oid, bool cursor, int row, int col, int width)
struct menumenu_dynamic_new (void)
void menu_dynamic_add_valid (struct menu *m, const char *text, int value, menu_row_validity_t valid)
void menu_dynamic_add (struct menu *m, const char *text, int value)
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)
void menu_dynamic_add_label (struct menu *m, const char *text, const char label, int value, char *label_list)
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)

Variables

const byte curs_attrs [2][2]
const char lower_case [] = "abcdefghijklmnopqrstuvwxyz"
const char upper_case [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const char all_letters [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
static const menu_iter menu_iter_actions
static const menu_iter menu_iter_strings
static const menu_skin menu_skin_scroll
static const menu_skin menu_skin_column
static const menu_iter dynamic_iter

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.

Function Documentation

static char column_get_tag ( struct menu menu,
int  pos 
)
static

References menu::selections.

static ui_event column_process_direction ( struct menu m,
int  dir 
)
static
static int columns_get_cursor ( int  row,
int  col,
int  n,
int  top,
region loc 
)
static
static void display_action_aux ( menu_action act,
byte  color,
int  row,
int  col,
int  wid 
)
static
static void display_columns ( struct menu menu,
int  cursor,
int top,
region loc 
)
static
static void display_menu_row ( struct menu menu,
int  pos,
int  top,
bool  cursor,
int  row,
int  col,
int  width 
)
static
static void display_scrolling ( struct menu menu,
int  cursor,
int top,
region loc 
)
static
static void display_string ( struct menu m,
int  oid,
bool  cursor,
int  row,
int  col,
int  width 
)
static
static void dynamic_display ( struct menu m,
int  oid,
bool  cursor,
int  row,
int  col,
int  width 
)
static
static int dynamic_valid ( struct menu m,
int  oid 
)
static
static int get_cursor_key ( struct menu menu,
int  top,
struct keypress  key 
)
static
static bool is_valid_row ( struct menu menu,
int  cursor 
)
static
static void menu_action_display ( struct menu m,
int  oid,
bool  cursor,
int  row,
int  col,
int  width 
)
static
static bool menu_action_handle ( struct menu m,
const ui_event event,
int  oid 
)
static
static char menu_action_tag ( struct menu m,
int  oid 
)
static

References menu_priv(), and menu_action::tag.

static int menu_action_valid ( struct menu m,
int  oid 
)
static
static bool menu_calc_size ( struct menu menu)
static
void menu_dynamic_add ( struct menu m,
const char *  text,
int  value 
)
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 
)
void menu_dynamic_add_valid ( struct menu m,
const char *  text,
int  value,
menu_row_validity_t  valid 
)
void menu_dynamic_calc_location ( struct menu m,
int  mx,
int  my 
)
void menu_dynamic_free ( struct menu m)
size_t menu_dynamic_longest_entry ( struct menu m)
struct menu* menu_dynamic_new ( void  )
read
int menu_dynamic_select ( struct menu m)
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().

const menu_iter* menu_find_iter ( menu_iter_id  id)

Return the menu iter struct for a given iter ID.

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().

static const menu_skin* menu_find_skin ( skin_id  id)
static
static bool menu_handle_action ( struct menu m,
const ui_event in 
)
static

Handle any menu command keys / SELECT events.

Returns TRUE if the key was handled at all (including if it's not handled and just ignored).

References menu::cursor, FALSE, menu::filter_list, menu::row_funcs, and menu_iter::row_handler.

Referenced by menu_select().

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, FALSE, menu::filter_count, menu::filter_list, menu::flags, get_cursor_key(), is_valid_row(), KC_ENTER, ui_event::key, MN_DBL_TAP, region::page_rows, menu_skin::process_dir, menu::skin, target_dir(), menu::top, TRUE, and ui_event::type.

Referenced by display_knowledge(), and menu_select().

bool menu_handle_mouse ( struct menu menu,
const ui_event in,
ui_event out 
)
void menu_init ( struct menu menu,
skin_id  skin_id,
const menu_iter iter 
)
bool menu_layout ( struct menu menu,
const region loc 
)
struct menu* menu_new ( skin_id  skin_id,
const menu_iter iter 
)
read
struct menu* menu_new_action ( menu_action acts,
size_t  n 
)
read
void* menu_priv ( struct menu menu)
void menu_refresh ( struct menu menu,
bool  reset_screen 
)
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().

static menu_row_style_t menu_row_style_for_validity ( menu_row_validity_t  row_valid)
static
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.

References menu::active, menu::cmd_keys, keypress::code, EVENT_EMPTY, EVT_ESCAPE, EVT_KBRD, EVT_MOUSE, EVT_RESIZE, EVT_SELECT, FALSE, 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(), TRUE, ui_event::type, and region::width.

Referenced by cmd_menu(), death_screen(), do_cmd_colors(), do_cmd_keymaps(), do_cmd_options(), do_cmd_options_item(), do_cmd_spoilers(), do_cmd_visuals(), ego_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_enter_store(), textui_store_knowledge(), wiz_create_item(), wiz_create_item_action(), and wiz_gf_demo().

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().

void menu_set_filter ( struct menu menu,
const int  filter_list[],
int  n 
)
void menu_setpriv ( struct menu menu,
int  count,
void data 
)
static char scroll_get_tag ( struct menu menu,
int  pos 
)
static

References menu::selections, and menu::top.

static ui_event scroll_process_direction ( struct menu m,
int  dir 
)
static
static int scrolling_get_cursor ( int  row,
int  col,
int  n,
int  top,
region loc 
)
static

References region::row.

Variable Documentation

const char all_letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const byte curs_attrs[2][2]
const menu_iter dynamic_iter
static
Initial value:
{
NULL,
NULL,
NULL
}
const char lower_case[] = "abcdefghijklmnopqrstuvwxyz"
const menu_iter menu_iter_actions
static
const menu_iter menu_iter_strings
static
Initial value:
{
NULL,
NULL,
NULL,
NULL
}

Referenced by menu_find_iter().

const menu_skin menu_skin_column
static
const menu_skin menu_skin_scroll
static
const char upper_case[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"