X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fkeybindings.h;h=e0fdadb7a0818b9826f246d3e85c16e0862935cd;hb=ec5c4edd169be8fe8c778cabdfc7ada665629ffd;hp=ad8b3bb36be853e17d109b7a8e7f22574c0a3f67;hpb=47d7b87570ce3c79d3e0a6b8e765c74d065b6ba5;p=plomrogue diff --git a/src/keybindings.h b/src/keybindings.h index ad8b3bb..e0fdadb 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -1,25 +1,66 @@ +/* keybindings.h + * + * Retrieval and storage of keybindings. + */ + #ifndef KEYBINDINGS_H #define KEYBINDINGS_H -#include + +#include /* for uint16_t */ struct World; struct WinMeta; -struct KeyBinding { - char * name; - uint16_t key; }; - -struct KeysWinData { - uint16_t max; - char edit; - uint16_t select; }; - -void init_keybindings(struct World *); -void save_keybindings(struct World *); -uint16_t get_action_key (struct KeyBinding *, char *); -char * get_keyname(uint16_t); -void keyswin_mod_key (struct World *, struct WinMeta *); -void keyswin_move_selection (struct World *, char); + + +/* Individual keybinding. */ +struct KeyBinding +{ + char * name; /* name of functionality bound to keycode */ + uint16_t key; /* keycode */ +}; + + + +/* Metadata used by the keybinding editing window. */ +struct KeysWinData +{ + uint16_t max; /* index of last keybinding (= n of keybindings - 1) */ + char edit; /* 1 if currently editing a keybinding, else 0 */ + uint16_t select; /* index of keybinding selected for editing */ +}; + + + +/* Read keybindings data from / write them to the file "keybindings". */ +extern void init_keybindings(struct World * world); +extern void save_keybindings(struct World * world); + + + +/* Return keycode matching a key (functionality) name. */ +extern uint16_t get_action_key(struct KeyBinding * keybindings, char * name); + + + +/* Translate keycode to readable names of max 9 chars where possible. */ +extern char * get_keyname(struct World * world, uint16_t keycode); + + + +/* Mark selection in keybindings window modifiable, get user input to modify + * key. Ensure there are max. three digits in the keycode ASCII representation. + */ +extern void keyswin_mod_key(struct World * world, struct WinMeta * win_meta); + + + +/* Move selection in keybinding window upwards ("dir" = "u") or downwards ("dir" + * = "d") within the limits of the keybindings list length. + */ +extern void keyswin_move_selection(struct World * world, char dir); + + #endif