Angband
ui-event.h
Go to the documentation of this file.
1 
18 #ifndef INCLUDED_UI_EVENT_H
19 #define INCLUDED_UI_EVENT_H
20 
24 typedef enum
25 {
26  EVT_NONE = 0x0000,
27 
28  /* Basic events */
29  EVT_KBRD = 0x0001, /* Keypress */
30  EVT_MOUSE = 0x0002, /* Mousepress */
31  EVT_RESIZE = 0x0004, /* Display resize */
32 
33  EVT_BUTTON = 0x0008, /* Button press */
34 
35  /* 'Abstract' events */
36  EVT_ESCAPE = 0x0010, /* Get out of this menu */
37  EVT_MOVE = 0x0020, /* Menu movement */
38  EVT_SELECT = 0x0040, /* Menu selection */
39  EVT_SWITCH = 0x0080 /* Menu switch */
41 
42 
46 #define KC_MOD_CONTROL 0x01
47 #define KC_MOD_SHIFT 0x02
48 #define KC_MOD_ALT 0x04
49 #define KC_MOD_META 0x08
50 #define KC_MOD_KEYPAD 0x10
51 
52 
70 #define MODS_INCLUDE_CONTROL(v) \
71  (((v) >= 0x01 && (v) <= 0x1F) ? false : true)
72 
73 #define MODS_INCLUDE_SHIFT(v) \
74  ((((v) >= 0x21 && (v) <= 0x2F) || \
75  ((v) >= 0x3A && (v) <= 0x60) || \
76  ((v) >= 0x7B && (v) <= 0x7E)) ? false : true)
77 
78 
87 #define ENCODE_KTRL(v) \
88  (((v) >= 0x40 && (v) <= 0x5F) ? true : false)
89 
90 
94 #define KTRL(X) \
95  ((X) & 0x1F)
96 
97 
101 #define UN_KTRL(X) \
102  ((X) + 64)
103 
104 
108 #define ARROW_DOWN 0x80
109 #define ARROW_LEFT 0x81
110 #define ARROW_RIGHT 0x82
111 #define ARROW_UP 0x83
112 
113 #define KC_F1 0x84
114 #define KC_F2 0x85
115 #define KC_F3 0x86
116 #define KC_F4 0x87
117 #define KC_F5 0x88
118 #define KC_F6 0x89
119 #define KC_F7 0x8A
120 #define KC_F8 0x8B
121 #define KC_F9 0x8C
122 #define KC_F10 0x8D
123 #define KC_F11 0x8E
124 #define KC_F12 0x8F
125 #define KC_F13 0x90
126 #define KC_F14 0x91
127 #define KC_F15 0x92
128 
129 #define KC_HELP 0x93
130 #define KC_HOME 0x94
131 #define KC_PGUP 0x95
132 #define KC_END 0x96
133 #define KC_PGDOWN 0x97
134 #define KC_INSERT 0x98
135 #define KC_PAUSE 0x99
136 #define KC_BREAK 0x9a
137 #define KC_BEGIN 0x9b
138 #define KC_ENTER 0x9c /* ASCII \r */
139 #define KC_TAB 0x9d /* ASCII \t */
140 #define KC_DELETE 0x9e
141 #define KC_BACKSPACE 0x9f /* ASCII \h */
142 #define ESCAPE 0xE000
143 
144 /* we have up until 0x9F before we start edging into displayable Unicode */
145 /* then we could move into private use area 1, 0xE000 onwards */
146 
150 #define isarrow(c) ((c >= ARROW_DOWN) && (c <= ARROW_UP))
151 
152 
156 typedef u32b keycode_t;
157 
158 
162 struct keypress {
166 };
167 
171 static struct keypress const KEYPRESS_NULL = {
172  .type = EVT_NONE,
173  .code = 0,
174  .mods = 0
175 };
176 
180 struct mouseclick {
186 };
187 
191 typedef union {
193  struct mouseclick mouse;
194  struct keypress key;
195 } ui_event;
196 
200 #define EVENT_EMPTY { 0 }
201 
202 
203 /*** Functions ***/
204 
208 keycode_t keycode_find_code(const char *str, size_t len);
209 
213 const char *keycode_find_desc(keycode_t kc);
214 
218 void keypress_to_text(char *buf, size_t len, const struct keypress *src,
219  bool expand_backslash);
220 
224 void keypress_from_text(struct keypress *buf, size_t len, const char *str);
225 
230 void keypress_to_readable(char *buf, size_t len, struct keypress src);
231 
232 
233 extern bool char_matches_key(wchar_t c, keycode_t key);
234 
235 
236 #endif /* INCLUDED_UI_EVENT_H */
const char * keycode_find_desc(keycode_t kc)
Given a keycode, return its description.
Definition: ui-event.c:81
keycode_t code
Definition: ui-event.h:164
byte x
Definition: ui-event.h:182
uint32_t u32b
Definition: h-basic.h:172
byte mods
Definition: ui-event.h:165
keycode_t keycode_find_code(const char *str, size_t len)
Given a string (and that string's length), return the corresponding keycode.
Definition: ui-event.c:67
uint8_t byte
Definition: h-basic.h:167
ui_event_type type
Definition: ui-event.h:163
byte button
Definition: ui-event.h:184
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.
Definition: ui-event.c:287
Struct holding all relevant info for keypresses.
Definition: ui-event.h:162
Definition: ui-event.h:37
ui_event_type type
Definition: ui-event.h:181
png_bytep buf
Definition: libpng12/png.h:2815
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.
Definition: ui-event.c:219
Definition: ui-event.h:26
Definition: ui-event.h:30
Definition: ui-event.h:38
bool char_matches_key(wchar_t c, keycode_t key)
Return whether the given display char matches an entered symbol.
Definition: ui-event.c:331
Definition: ui-event.h:36
Definition: ui-event.h:29
ui_event_type
The various UI events that can occur.
Definition: ui-event.h:24
void keypress_from_text(struct keypress *buf, size_t len, const char *str)
Convert a textual representation of keypresses into actual keypresses.
Definition: ui-event.c:105
Struct holding all relevant info for mouse clicks.
Definition: ui-event.h:180
static struct keypress const KEYPRESS_NULL
Null keypress constant, for safe initializtion.
Definition: ui-event.h:171
byte y
Definition: ui-event.h:183
ui_event_type type
Definition: ui-event.h:192
byte mods
Definition: ui-event.h:185
Definition: ui-event.h:33
u32b keycode_t
Type capable of holding any input key we might want to use.
Definition: ui-event.h:156
#define const
Definition: zconf.h:124
Union type to hold information about any given event.
Definition: ui-event.h:191
Definition: ui-event.h:39
Definition: ui-event.h:31