Kohi Game Engine
keymap.h
Go to the documentation of this file.
1 
23 #pragma once
24 
25 #include "defines.h"
26 #include "input.h"
27 
33 typedef enum keymap_modifier_bits {
43 
46 
52 typedef enum keymap_entry_bind_type {
64 
66 typedef void (*PFN_keybind_callback)(keys key, keymap_entry_bind_type type, keymap_modifier modifiers, void* user_data);
67 
74 typedef struct keymap_binding {
82  void* user_data;
86 
91 typedef struct keymap_entry {
97 
103 typedef struct keymap {
112 
117 
128 KAPI void keymap_binding_add(keymap* map, keys key, keymap_entry_bind_type type, keymap_modifier modifiers, void* user_data, PFN_keybind_callback callback);
129 
142 
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:177
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
This file contains everything having to do with input on deskop environments from keyboards and mice....
keys
Represents available keyboard keys.
Definition: input.h:36
@ KEYS_MAX_KEYS
Definition: input.h:308
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...
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.
u32 keymap_modifier
A typedef for combined keymap modifiers.
Definition: keymap.h:45
KAPI keymap keymap_create(void)
Creates and returns a new keymap.
keymap_entry_bind_type
A collection of keymap binding types, which correspond to various types of key input events such as p...
Definition: keymap.h:52
@ KEYMAP_BIND_TYPE_UNDEFINED
An undefined mapping that can be overridden.
Definition: keymap.h:54
@ KEYMAP_BIND_TYPE_UNSET
Used to disable a key binding on a lower-level map.
Definition: keymap.h:62
@ KEYMAP_BIND_TYPE_PRESS
Callback is made when key is initially pressed.
Definition: keymap.h:56
@ KEYMAP_BIND_TYPE_RELEASE
Callback is made when key is released.
Definition: keymap.h:58
@ KEYMAP_BIND_TYPE_HOLD
Callback is made continuously while key is held.
Definition: keymap.h:60
keymap_modifier_bits
An enumeration of modifier keys required by a keymap's keybinding to be activated....
Definition: keymap.h:33
@ KEYMAP_MODIFIER_NONE_BIT
The default modifier, means that no modifiers are required.
Definition: keymap.h:35
@ KEYMAP_MODIFIER_CONTROL_BIT
A control(ctrl)/cmd key must be pressed for the binding to fire.
Definition: keymap.h:39
@ KEYMAP_MODIFIER_ALT_BIT
A alt/option key must be pressed for the binding to fire.
Definition: keymap.h:41
@ KEYMAP_MODIFIER_SHIFT_BIT
A shift key must be pressed for the binding to fire.
Definition: keymap.h:37
KAPI void keymap_clear(keymap *map)
Clears all bindings from the given keymap.
struct keymap keymap
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an in...
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.
Definition: keymap.h:66
struct keymap_binding keymap_binding
Represents an individual binding, containing the keybind type, modifiers, callback,...
struct keymap_entry keymap_entry
An individual entry for a keymap, which contains the key to be bound and a linked list of bindings.
Represents an individual binding, containing the keybind type, modifiers, callback,...
Definition: keymap.h:74
void * user_data
User data, if supplied. Otherwise 0.
Definition: keymap.h:82
keymap_modifier modifiers
Required modifiers, if any. Default: KEYMAP_MODIFIER_NONE_BIT.
Definition: keymap.h:78
PFN_keybind_callback callback
A function pointer to be invoked when this binding is triggered.
Definition: keymap.h:80
keymap_entry_bind_type type
The keybind type (i.e. press, release, hold). Default: KEYMAP_BIND_TYPE_UNDEFINED.
Definition: keymap.h:76
struct keymap_binding * next
A pointer to the next binding in the linked list, or 0 if the tail.
Definition: keymap.h:84
An individual entry for a keymap, which contains the key to be bound and a linked list of bindings.
Definition: keymap.h:91
keys key
The bound key.
Definition: keymap.h:93
keymap_binding * bindings
Linked list of bindings. Default: 0.
Definition: keymap.h:95
A keymap, which holds a list of keymap entries, each with a list of bindings. These are held in an in...
Definition: keymap.h:103
keymap_entry entries[KEYS_MAX_KEYS]
An array of keymap entries, indexed by keycode for quick lookups.
Definition: keymap.h:110
b8 overrides_all
Indicates that all entries are overridden, even ones not defined (effectively blanking them out until...
Definition: keymap.h:108