Kohi Game Engine
|
This file contains the structures and functions required to implement keymaps and keybindings, used to translate keyboard input events to events and/or call bound functions automatically. Keymaps replace the need for checks of key states in that they will instead invoke callback functions instead. Maps will be added onto a stack, where bindings are replaced along the way. For example, if the base keymap defines the "escape" key as an application quit, then another keymap added on re-defines the key to nothing while adding a new binding for "a", then "a"'s binding will work, and "escape" will do nothing. If "escape" were left undefined in the second keymap, the original mapping is left unchanged. Maps are pushed/popped as expected on a stack. More...
Go to the source code of this file.
Data Structures | |
struct | keymap_binding |
Represents an individual binding, containing the keybind type, modifiers, callback, potential user data. Doubles as a linked-list node, as keys can have multiple bindings associated with them on the same map. More... | |
struct | keymap_entry |
An individual entry for a keymap, which contains the key to be bound and a linked list of bindings. More... | |
struct | keymap |
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an internal stack, and override entries of the keymaps below it in the stack. More... | |
Typedefs | |
typedef enum keymap_modifier_bits | keymap_modifier_bits |
An enumeration of modifier keys required by a keymap's keybinding to be activated. These may be combined (ORed) together to require multiple modifiers. More... | |
typedef u32 | keymap_modifier |
A typedef for combined keymap modifiers. More... | |
typedef enum keymap_entry_bind_type | keymap_entry_bind_type |
A collection of keymap binding types, which correspond to various types of key input events such as press, release or hold. More... | |
typedef void(* | PFN_keybind_callback) (keys key, keymap_entry_bind_type type, keymap_modifier modifiers, void *user_data) |
A typedef of a keybinding callback to be made when a keybinding is activated. More... | |
typedef struct keymap_binding | keymap_binding |
Represents an individual binding, containing the keybind type, modifiers, callback, potential user data. Doubles as a linked-list node, as keys can have multiple bindings associated with them on the same map. More... | |
typedef struct keymap_entry | keymap_entry |
An individual entry for a keymap, which contains the key to be bound and a linked list of bindings. More... | |
typedef struct keymap | keymap |
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an internal stack, and override entries of the keymaps below it in the stack. More... | |
Enumerations | |
enum | keymap_modifier_bits { KEYMAP_MODIFIER_NONE_BIT = 0x0 , KEYMAP_MODIFIER_SHIFT_BIT = 0x1 , KEYMAP_MODIFIER_CONTROL_BIT = 0x2 , KEYMAP_MODIFIER_ALT_BIT = 0x4 } |
An enumeration of modifier keys required by a keymap's keybinding to be activated. These may be combined (ORed) together to require multiple modifiers. More... | |
enum | keymap_entry_bind_type { KEYMAP_BIND_TYPE_UNDEFINED = 0x0 , KEYMAP_BIND_TYPE_PRESS = 0x1 , KEYMAP_BIND_TYPE_RELEASE = 0x2 , KEYMAP_BIND_TYPE_HOLD = 0x4 , KEYMAP_BIND_TYPE_UNSET = 0x8 } |
A collection of keymap binding types, which correspond to various types of key input events such as press, release or hold. More... | |
Functions | |
KAPI keymap | keymap_create (void) |
Creates and returns a new keymap. More... | |
KAPI void | keymap_binding_add (keymap *map, keys key, keymap_entry_bind_type type, keymap_modifier modifiers, void *user_data, PFN_keybind_callback callback) |
Adds a binding to the keymap provided. More... | |
KAPI void | keymap_binding_remove (keymap *map, keys key, keymap_entry_bind_type type, keymap_modifier modifiers, PFN_keybind_callback callback) |
Removes the binding from the given keymap that also matches on key, bind type, modifiers and callback. If no match is found, nothing is done. More... | |
KAPI void | keymap_clear (keymap *map) |
Clears all bindings from the given keymap. More... | |
This file contains the structures and functions required to implement keymaps and keybindings, used to translate keyboard input events to events and/or call bound functions automatically. Keymaps replace the need for checks of key states in that they will instead invoke callback functions instead. Maps will be added onto a stack, where bindings are replaced along the way. For example, if the base keymap defines the "escape" key as an application quit, then another keymap added on re-defines the key to nothing while adding a new binding for "a", then "a"'s binding will work, and "escape" will do nothing. If "escape" were left undefined in the second keymap, the original mapping is left unchanged. Maps are pushed/popped as expected on a stack.
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an internal stack, and override entries of the keymaps below it in the stack.
typedef struct keymap_binding keymap_binding |
Represents an individual binding, containing the keybind type, modifiers, callback, potential user data. Doubles as a linked-list node, as keys can have multiple bindings associated with them on the same map.
typedef struct keymap_entry keymap_entry |
An individual entry for a keymap, which contains the key to be bound and a linked list of bindings.
typedef enum keymap_entry_bind_type keymap_entry_bind_type |
A collection of keymap binding types, which correspond to various types of key input events such as press, release or hold.
typedef u32 keymap_modifier |
A typedef for combined keymap modifiers.
typedef enum keymap_modifier_bits keymap_modifier_bits |
An enumeration of modifier keys required by a keymap's keybinding to be activated. These may be combined (ORed) together to require multiple modifiers.
typedef void(* PFN_keybind_callback) (keys key, keymap_entry_bind_type type, keymap_modifier modifiers, void *user_data) |
A typedef of a keybinding callback to be made when a keybinding is activated.
A collection of keymap binding types, which correspond to various types of key input events such as press, release or hold.
enum keymap_modifier_bits |
An enumeration of modifier keys required by a keymap's keybinding to be activated. These may be combined (ORed) together to require multiple modifiers.
KAPI void keymap_binding_add | ( | keymap * | map, |
keys | key, | ||
keymap_entry_bind_type | type, | ||
keymap_modifier | modifiers, | ||
void * | user_data, | ||
PFN_keybind_callback | callback | ||
) |
Adds a binding to the keymap provided.
map | A pointer to the keymap to add a binding to. Required. |
key | The key to bind to. |
type | The type of binding. |
modifiers | Required modifier keys, if any (OR them together). |
user_data | User data, if any. Optional. |
callback | The callback function pointer. Required. |
KAPI void keymap_binding_remove | ( | keymap * | map, |
keys | key, | ||
keymap_entry_bind_type | type, | ||
keymap_modifier | modifiers, | ||
PFN_keybind_callback | callback | ||
) |
Removes the binding from the given keymap that also matches on key, bind type, modifiers and callback. If no match is found, nothing is done.
map | A pointer to the keymap to remove the binding from. Required. |
key | The key to bind to. |
type | The type of binding. |
modifiers | The modifiers required for the binding. |
callback | The callback to be made from the biding. Required. |
Clears all bindings from the given keymap.
map | A pointer to the map to be cleared. |