X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=src%2Fkeybindings.h;h=d400414b33c62183b628357a7a9683141a651589;hb=140cadf8f8dc73a1756169dbfa7cb5f05e3b8b8c;hp=85c33c781bf38581a627a66e1eb42ca002f64ec1;hpb=f222ace2f2441b21a3c29741483d8018294820a4;p=plomrogue diff --git a/src/keybindings.h b/src/keybindings.h index 85c33c7..d400414 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -1,19 +1,72 @@ +/* keybindings.h + * + * Retrieval and storage of keybindings. + */ + #ifndef KEYBINDINGS_H +#define KEYBINDINGS_H + + + +#include /* for uint16_t */ +struct World; +struct WinMeta; + + + +/* Individual keybinding. */ +struct KeyBinding +{ + struct KeyBinding * next; + uint16_t key; /* keycode */ + char * name; /* name of functionality bound to keycode */ +}; + + + +/* Metadata used by the keybinding editing window. */ +struct KeysWinData +{ + char edit; /* 1 if currently editing a keybinding, else 0 */ + uint16_t select; /* list index of keybinding selected for editing */ +}; + + + +/* Return keycode matched by keybinding to command of "name". */ +extern uint16_t get_keycode_to_action(struct KeyBinding * keybindings, char * name); + +/* Return human-readable name (of maximum 9 chars) for "keycode" as matched by + * ncurses.h; if none is found, return "UNKNOWN". */ +extern char * get_name_to_keycode(struct World * world, uint16_t keycode); + +/* Return number of keybindings in keybindings chain. */ +extern uint16_t get_n_of_keybs(struct World * world); + +/* Return "n"-th keybinding in keybindings chain. */ +extern struct KeyBinding * get_keyb_of_n(struct World * world, uint16_t n); + + + +/* Initialize keybindings data (by reading from file "keybindings"), save it (by + * writing to the same file) and free it. + */ +extern void init_keybindings(struct World * world); +extern void save_keybindings(struct World * world); +extern void free_keybindings(struct KeyBinding * kb_start); + + + +/* 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 move_keys_mod_selection(struct World * world, char dir); + -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); #endif