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

Utility functions relating to UI events. More...

Go to the source code of this file.

Data Structures

struct  keypress
 Struct holding all relevant info for keypresses. More...
 
struct  mouseclick
 Struct holding all relevant info for mouse clicks. More...
 
union  ui_event
 Union type to hold information about any given event. More...
 

Macros

#define KC_MOD_CONTROL   0x01
 Key modifiers. More...
 
#define KC_MOD_SHIFT   0x02
 
#define KC_MOD_ALT   0x04
 
#define KC_MOD_META   0x08
 
#define KC_MOD_KEYPAD   0x10
 
#define MODS_INCLUDE_CONTROL(v)   (((v) >= 0x01 && (v) <= 0x1F) ? false : true)
 The game assumes that in certain cases, the effect of a modifer key will be encoded in the keycode itself (e.g. More...
 
#define MODS_INCLUDE_SHIFT(v)
 
#define ENCODE_KTRL(v)   (((v) >= 0x40 && (v) <= 0x5F) ? true : false)
 If keycode you're trying to apply control to is between 0x40-0x5F inclusive, then you should take 0x40 from the keycode and leave KC_MOD_CONTROL unset. More...
 
#define KTRL(X)   ((X) & 0x1F)
 Given a character X, turn it into a control character. More...
 
#define UN_KTRL(X)   ((X) + 64)
 Given a control character X, turn it into its uppercase ASCII equivalent. More...
 
#define ARROW_DOWN   0x80
 Keyset mappings for various keys. More...
 
#define ARROW_LEFT   0x81
 
#define ARROW_RIGHT   0x82
 
#define ARROW_UP   0x83
 
#define KC_F1   0x84
 
#define KC_F2   0x85
 
#define KC_F3   0x86
 
#define KC_F4   0x87
 
#define KC_F5   0x88
 
#define KC_F6   0x89
 
#define KC_F7   0x8A
 
#define KC_F8   0x8B
 
#define KC_F9   0x8C
 
#define KC_F10   0x8D
 
#define KC_F11   0x8E
 
#define KC_F12   0x8F
 
#define KC_F13   0x90
 
#define KC_F14   0x91
 
#define KC_F15   0x92
 
#define KC_HELP   0x93
 
#define KC_HOME   0x94
 
#define KC_PGUP   0x95
 
#define KC_END   0x96
 
#define KC_PGDOWN   0x97
 
#define KC_INSERT   0x98
 
#define KC_PAUSE   0x99
 
#define KC_BREAK   0x9a
 
#define KC_BEGIN   0x9b
 
#define KC_ENTER   0x9c /* ASCII \r */
 
#define KC_TAB   0x9d /* ASCII \t */
 
#define KC_DELETE   0x9e
 
#define KC_BACKSPACE   0x9f /* ASCII \h */
 
#define ESCAPE   0xE000
 
#define isarrow(c)   ((c >= ARROW_DOWN) && (c <= ARROW_UP))
 Analogous to isdigit() etc in ctypes. More...
 
#define EVENT_EMPTY   { 0 }
 Easy way to initialise a ui_event without seeing the gory bits. More...
 

Typedefs

typedef u32b keycode_t
 Type capable of holding any input key we might want to use. More...
 

Enumerations

enum  ui_event_type {
  EVT_NONE = 0x0000, EVT_KBRD = 0x0001, EVT_MOUSE = 0x0002, EVT_RESIZE = 0x0004,
  EVT_BUTTON = 0x0008, EVT_ESCAPE = 0x0010, EVT_MOVE = 0x0020, EVT_SELECT = 0x0040,
  EVT_SWITCH = 0x0080
}
 The various UI events that can occur. More...
 

Functions

keycode_t keycode_find_code (const char *str, size_t len)
 Given a string (and that string's length), return the corresponding keycode. More...
 
const char * keycode_find_desc (keycode_t kc)
 Given a keycode, return its description. More...
 
void keypress_to_text (char *buf, size_t len, const struct keypress *src, bool expand_backslash)
 Convert a string of keypresses into their textual representation. More...
 
void keypress_from_text (struct keypress *buf, size_t len, const char *str)
 Convert a textual representation of keypresses into actual keypresses. More...
 
void keypress_to_readable (char *buf, size_t len, struct keypress src)
 Convert a keypress into something the user can read (not designed to be used internally. More...
 
bool char_matches_key (wchar_t c, keycode_t key)
 Return whether the given display char matches an entered symbol. More...
 

Variables

static struct keypress const KEYPRESS_NULL
 Null keypress constant, for safe initializtion. More...
 

Detailed Description

Utility functions relating to UI events.

Copyright (c) 2011 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

◆ ARROW_DOWN

#define ARROW_DOWN   0x80

Keyset mappings for various keys.

Referenced by do_cmd_messages(), edit_text(), history_display(), show_file(), target_dir_allow(), and textui_textblock_show().

◆ ARROW_LEFT

#define ARROW_LEFT   0x81

◆ ARROW_RIGHT

#define ARROW_RIGHT   0x82

◆ ARROW_UP

#define ARROW_UP   0x83

◆ ENCODE_KTRL

#define ENCODE_KTRL (   v)    (((v) >= 0x40 && (v) <= 0x5F) ? true : false)

If keycode you're trying to apply control to is between 0x40-0x5F inclusive, then you should take 0x40 from the keycode and leave KC_MOD_CONTROL unset.

Otherwise, leave the keycode alone and set KC_MOD_CONTROL in mods.

This macro returns true in the former case and false in the latter.

◆ ESCAPE

#define ESCAPE   0xE000

◆ EVENT_EMPTY

#define EVENT_EMPTY   { 0 }

◆ isarrow

#define isarrow (   c)    ((c >= ARROW_DOWN) && (c <= ARROW_UP))

Analogous to isdigit() etc in ctypes.

Referenced by target_dir_allow().

◆ KC_BACKSPACE

#define KC_BACKSPACE   0x9f /* ASCII \h */

◆ KC_BEGIN

#define KC_BEGIN   0x9b

◆ KC_BREAK

#define KC_BREAK   0x9a

◆ KC_DELETE

#define KC_DELETE   0x9e

◆ KC_END

#define KC_END   0x96

Referenced by edit_text(), and show_file().

◆ KC_ENTER

#define KC_ENTER   0x9c /* ASCII \r */

◆ KC_F1

#define KC_F1   0x84

◆ KC_F10

#define KC_F10   0x8D

◆ KC_F11

#define KC_F11   0x8E

◆ KC_F12

#define KC_F12   0x8F

◆ KC_F13

#define KC_F13   0x90

◆ KC_F14

#define KC_F14   0x91

◆ KC_F15

#define KC_F15   0x92

◆ KC_F2

#define KC_F2   0x85

◆ KC_F3

#define KC_F3   0x86

◆ KC_F4

#define KC_F4   0x87

◆ KC_F5

#define KC_F5   0x88

◆ KC_F6

#define KC_F6   0x89

◆ KC_F7

#define KC_F7   0x8A

◆ KC_F8

#define KC_F8   0x8B

◆ KC_F9

#define KC_F9   0x8C

◆ KC_HELP

#define KC_HELP   0x93

◆ KC_HOME

#define KC_HOME   0x94

Referenced by edit_text(), and show_file().

◆ KC_INSERT

#define KC_INSERT   0x98

◆ KC_MOD_ALT

#define KC_MOD_ALT   0x04

◆ KC_MOD_CONTROL

#define KC_MOD_CONTROL   0x01

◆ KC_MOD_KEYPAD

#define KC_MOD_KEYPAD   0x10

◆ KC_MOD_META

#define KC_MOD_META   0x08

◆ KC_MOD_SHIFT

#define KC_MOD_SHIFT   0x02

◆ KC_PAUSE

#define KC_PAUSE   0x99

◆ KC_PGDOWN

#define KC_PGDOWN   0x97

◆ KC_PGUP

#define KC_PGUP   0x95

◆ KC_TAB

#define KC_TAB   0x9d /* ASCII \t */

Referenced by Term_keypress().

◆ KTRL

#define KTRL (   X)    ((X) & 0x1F)

◆ MODS_INCLUDE_CONTROL

#define MODS_INCLUDE_CONTROL (   v)    (((v) >= 0x01 && (v) <= 0x1F) ? false : true)

The game assumes that in certain cases, the effect of a modifer key will be encoded in the keycode itself (e.g.

'A' is shift-'a'). In these cases (specified below), a keypress' 'mods' value should not encode them also.

If the character has come from the keypad: Include all mods Else if the character is in the range 0x01-0x1F, and the keypress was from a key that without modifiers would be in the range 0x40-0x5F: CONTROL is encoded in the keycode, and should not be in mods Else if the character is in the range 0x21-0x2F, 0x3A-0x60 or 0x7B-0x7E: SHIFT is often used to produce these should not be encoded in mods

(All ranges are inclusive.)

You can use these macros for part of the above conditions.

◆ MODS_INCLUDE_SHIFT

#define MODS_INCLUDE_SHIFT (   v)
Value:
((((v) >= 0x21 && (v) <= 0x2F) || \
((v) >= 0x3A && (v) <= 0x60) || \
((v) >= 0x7B && (v) <= 0x7E)) ? false : true)
false
Definition: list-summon-types.h:18

◆ UN_KTRL

#define UN_KTRL (   X)    ((X) + 64)

Given a control character X, turn it into its uppercase ASCII equivalent.

Referenced by cmd_lookup_key_unktrl(), get_item_allow(), get_tag(), keypress_to_readable(), keypress_to_text(), and show_command_list().

Typedef Documentation

◆ keycode_t

typedef u32b keycode_t

Type capable of holding any input key we might want to use.

Enumeration Type Documentation

◆ ui_event_type

The various UI events that can occur.

Enumerator
EVT_NONE 
EVT_KBRD 
EVT_MOUSE 
EVT_RESIZE 
EVT_BUTTON 
EVT_ESCAPE 
EVT_MOVE 
EVT_SELECT 
EVT_SWITCH 

Function Documentation

◆ char_matches_key()

bool char_matches_key ( wchar_t  c,
keycode_t  key 
)

Return whether the given display char matches an entered symbol.

Horrible hack. TODO UTF-8 find some way of entering mb chars

References text_mbstowcs().

Referenced by do_cmd_query_symbol(), and lookup_symbol().

◆ keycode_find_code()

keycode_t keycode_find_code ( const char *  str,
size_t  len 
)

Given a string (and that string's length), return the corresponding keycode.

Given a string (and that string's length), return the corresponding keycode.

References code, desc, i, mappings, and N_ELEMENTS.

Referenced by keypress_from_text().

◆ keycode_find_desc()

const char* keycode_find_desc ( keycode_t  kc)

Given a keycode, return its description.

Given a keycode, return its description.

References code, i, mappings, N_ELEMENTS, and NULL.

Referenced by keypress_to_readable(), and keypress_to_text().

◆ keypress_from_text()

void keypress_from_text ( struct keypress buf,
size_t  len,
const char *  str 
)

Convert a textual representation of keypresses into actual keypresses.

Convert a textual representation of keypresses into actual keypresses.

References dehex(), EVT_KBRD, EVT_NONE, KC_MOD_ALT, KC_MOD_CONTROL, KC_MOD_KEYPAD, KC_MOD_META, KC_MOD_SHIFT, keycode_find_code(), MIN, and STORE.

Referenced by parse_prefs_keymap_action(), and parse_prefs_keymap_input().

◆ keypress_to_readable()

void keypress_to_readable ( char *  buf,
size_t  len,
struct keypress  src 
)

Convert a keypress into something the user can read (not designed to be used internally.

Convert a keypress into something the user can read (not designed to be used internally.

References keypress::code, desc, i, KC_MOD_ALT, KC_MOD_CONTROL, KC_MOD_KEYPAD, KC_MOD_META, KC_MOD_SHIFT, keycode_find_desc(), keypress::mods, strnfcat(), and UN_KTRL.

Referenced by cmd_sub_entry().

◆ keypress_to_text()

void keypress_to_text ( char *  buf,
size_t  len,
const struct keypress src,
bool  expand_backslash 
)

Convert a string of keypresses into their textual representation.

Convert a string of keypresses into their textual representation.

References keypress::code, desc, EVT_KBRD, i, KC_MOD_ALT, KC_MOD_CONTROL, KC_MOD_KEYPAD, KC_MOD_META, KC_MOD_SHIFT, keycode_find_desc(), keypress::mods, strnfcat(), type, and UN_KTRL.

Referenced by do_cmd_keylog(), keymap_browse_hook(), keymap_dump(), keymap_get_trigger(), ui_keymap_create(), and ui_keymap_query().

Variable Documentation

◆ KEYPRESS_NULL

struct keypress const KEYPRESS_NULL
static
Initial value:
= {
.type = EVT_NONE,
.code = 0,
.mods = 0
}
Definition: ui-event.h:26

Null keypress constant, for safe initializtion.

Referenced by askfor_aux(), do_cmd_keylog(), do_cmd_locate(), keymap_dump(), keymap_get_trigger(), and textui_get_command().