Manages keyboard and joystick input bindings for application actions. More...
#include <keybind_manager.h>
Public Member Functions | |
KeybindManager () | |
Constructs a KeybindManager instance. | |
~KeybindManager () override=default | |
Destroys the KeybindManager instance. | |
std::string | getActionForKey (const std::string &key) const override |
SDL_Keycode | getKey (const std::string &action) const override |
Gets the keyboard keycode for an action. | |
void | setKey (const std::string &action, SDL_Keycode key) override |
Sets the keyboard keycode for an action. | |
std::vector< std::string > | getActions () const override |
Gets the list of supported actions. | |
void | setJoystickButton (const std::string &action, int joystickId, uint8_t button) override |
Sets a joystick button binding for an action. | |
void | setJoystickHat (const std::string &action, int joystickId, uint8_t hat, uint8_t direction) override |
Sets a joystick hat binding for an action. | |
void | setJoystickAxis (const std::string &action, int joystickId, uint8_t axis, bool positiveDirection) override |
Sets a joystick axis binding for an action. | |
std::string | eventToString (const SDL_Event &event) const override |
Converts an SDL event to a string representation. | |
bool | isAction (const SDL_KeyboardEvent &event, const std::string &action) const override |
Checks if a keyboard event matches an action. | |
bool | isJoystickAction (const SDL_JoyButtonEvent &event, const std::string &action) const override |
Checks if a joystick button event matches an action. | |
bool | isJoystickHatAction (const SDL_JoyHatEvent &event, const std::string &action) const override |
Checks if a joystick hat event matches an action. | |
bool | isJoystickAxisAction (const SDL_JoyAxisEvent &event, const std::string &action) const override |
Checks if a joystick axis event matches an action. | |
void | loadKeybinds (const std::map< std::string, std::string > &keybindData) override |
Loads keybind configurations from a data map. | |
void | saveKeybinds (std::map< std::string, std::string > &keybinds) const override |
Saves keybind configurations to a map. | |
![]() | |
virtual | ~IKeybindProvider ()=default |
Virtual destructor for proper cleanup of derived classes. | |
Manages keyboard and joystick input bindings for application actions.
This class implements the IKeybindProvider interface to store, retrieve, and validate input bindings (keyboard keys, joystick buttons, hats, and axes) for user-defined actions. It supports loading and saving keybind configurations and provides tooltip descriptions.
KeybindManager::KeybindManager | ( | ) |
Constructs a KeybindManager instance.
Initializes the keybind manager with default bindings for application actions.
|
overridedefault |
Destroys the KeybindManager instance.
Default destructor, no special cleanup required.
|
overridevirtual |
Converts an SDL event to a string representation.
Generates a human-readable string describing the input event (key, button, hat, or axis).
event | The SDL event to convert. |
Implements IKeybindProvider.
|
overridevirtual |
Implements IKeybindProvider.
|
overridevirtual |
Gets the list of supported actions.
Returns a vector of action identifiers that can be bound to inputs.
Implements IKeybindProvider.
|
overridevirtual |
Gets the keyboard keycode for an action.
Retrieves the SDL keycode associated with the specified action.
action | The action identifier (e.g., "LaunchTable"). |
Implements IKeybindProvider.
|
overridevirtual |
Checks if a keyboard event matches an action.
Determines if the keyboard event corresponds to the specified action's keybinding.
event | The SDL keyboard event. |
action | The action identifier. |
Implements IKeybindProvider.
|
overridevirtual |
Checks if a joystick button event matches an action.
Determines if the joystick button event corresponds to the specified action's binding.
event | The SDL joystick button event. |
action | The action identifier. |
Implements IKeybindProvider.
|
overridevirtual |
Checks if a joystick axis event matches an action.
Determines if the joystick axis event corresponds to the specified action's binding.
event | The SDL joystick axis event. |
action | The action identifier. |
Implements IKeybindProvider.
|
overridevirtual |
Checks if a joystick hat event matches an action.
Determines if the joystick hat event corresponds to the specified action's binding.
event | The SDL joystick hat event. |
action | The action identifier. |
Implements IKeybindProvider.
|
overridevirtual |
Loads keybind configurations from a data map.
Populates the keybind mappings from a provided map of action-to-input strings.
keybindData | A map of action identifiers to input configuration strings. |
Implements IKeybindProvider.
|
overridevirtual |
Saves keybind configurations to a map.
Populates a map with the current keybind mappings for JSON serialization.
keybinds | The map to populate with action-to-input string pairs. |
Implements IKeybindProvider.
|
overridevirtual |
Sets a joystick axis binding for an action.
Assigns a joystick axis direction to the specified action.
action | The action identifier. |
joystickId | The ID of the joystick. |
axis | The joystick axis index. |
positiveDirection | True for positive axis direction, false for negative. |
Implements IKeybindProvider.
|
overridevirtual |
Sets a joystick button binding for an action.
Assigns a joystick button to the specified action.
action | The action identifier. |
joystickId | The ID of the joystick. |
button | The joystick button index. |
Implements IKeybindProvider.
|
overridevirtual |
Sets a joystick hat binding for an action.
Assigns a joystick hat direction to the specified action.
action | The action identifier. |
joystickId | The ID of the joystick. |
hat | The joystick hat index. |
direction | The hat direction (e.g., SDL_HAT_UP). |
Implements IKeybindProvider.
|
overridevirtual |
Sets the keyboard keycode for an action.
Assigns a new SDL keycode to the specified action.
action | The action identifier. |
key | The SDL keycode to assign. |
Implements IKeybindProvider.