ASAPCabinetFE
 
Loading...
Searching...
No Matches
KeybindManager Class Reference

Manages keyboard and joystick input bindings for application actions. More...

#include <keybind_manager.h>

+ Inheritance diagram for KeybindManager:
+ Collaboration diagram for KeybindManager:

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.
 
- Public Member Functions inherited from IKeybindProvider
virtual ~IKeybindProvider ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ KeybindManager()

KeybindManager::KeybindManager ( )

Constructs a KeybindManager instance.

Initializes the keybind manager with default bindings for application actions.

◆ ~KeybindManager()

KeybindManager::~KeybindManager ( )
overridedefault

Destroys the KeybindManager instance.

Default destructor, no special cleanup required.

Member Function Documentation

◆ eventToString()

std::string KeybindManager::eventToString ( const SDL_Event &  event) const
overridevirtual

Converts an SDL event to a string representation.

Generates a human-readable string describing the input event (key, button, hat, or axis).

Parameters
eventThe SDL event to convert.
Returns
A string describing the event.

Implements IKeybindProvider.

◆ getActionForKey()

std::string KeybindManager::getActionForKey ( const std::string &  key) const
overridevirtual

Implements IKeybindProvider.

◆ getActions()

std::vector< std::string > KeybindManager::getActions ( ) const
overridevirtual

Gets the list of supported actions.

Returns a vector of action identifiers that can be bound to inputs.

Returns
A vector of action identifier strings.

Implements IKeybindProvider.

◆ getKey()

SDL_Keycode KeybindManager::getKey ( const std::string &  action) const
overridevirtual

Gets the keyboard keycode for an action.

Retrieves the SDL keycode associated with the specified action.

Parameters
actionThe action identifier (e.g., "LaunchTable").
Returns
The SDL keycode for the action, or SDLK_UNKNOWN if not found.

Implements IKeybindProvider.

◆ isAction()

bool KeybindManager::isAction ( const SDL_KeyboardEvent &  event,
const std::string &  action 
) const
overridevirtual

Checks if a keyboard event matches an action.

Determines if the keyboard event corresponds to the specified action's keybinding.

Parameters
eventThe SDL keyboard event.
actionThe action identifier.
Returns
True if the event matches the action's keybinding, false otherwise.

Implements IKeybindProvider.

◆ isJoystickAction()

bool KeybindManager::isJoystickAction ( const SDL_JoyButtonEvent &  event,
const std::string &  action 
) const
overridevirtual

Checks if a joystick button event matches an action.

Determines if the joystick button event corresponds to the specified action's binding.

Parameters
eventThe SDL joystick button event.
actionThe action identifier.
Returns
True if the event matches the action's binding, false otherwise.

Implements IKeybindProvider.

◆ isJoystickAxisAction()

bool KeybindManager::isJoystickAxisAction ( const SDL_JoyAxisEvent &  event,
const std::string &  action 
) const
overridevirtual

Checks if a joystick axis event matches an action.

Determines if the joystick axis event corresponds to the specified action's binding.

Parameters
eventThe SDL joystick axis event.
actionThe action identifier.
Returns
True if the event matches the action's binding, false otherwise.

Implements IKeybindProvider.

◆ isJoystickHatAction()

bool KeybindManager::isJoystickHatAction ( const SDL_JoyHatEvent &  event,
const std::string &  action 
) const
overridevirtual

Checks if a joystick hat event matches an action.

Determines if the joystick hat event corresponds to the specified action's binding.

Parameters
eventThe SDL joystick hat event.
actionThe action identifier.
Returns
True if the event matches the action's binding, false otherwise.

Implements IKeybindProvider.

◆ loadKeybinds()

void KeybindManager::loadKeybinds ( const std::map< std::string, std::string > &  keybindData)
overridevirtual

Loads keybind configurations from a data map.

Populates the keybind mappings from a provided map of action-to-input strings.

Parameters
keybindDataA map of action identifiers to input configuration strings.

Implements IKeybindProvider.

+ Here is the call graph for this function:

◆ saveKeybinds()

void KeybindManager::saveKeybinds ( std::map< std::string, std::string > &  keybinds) const
overridevirtual

Saves keybind configurations to a map.

Populates a map with the current keybind mappings for JSON serialization.

Parameters
keybindsThe map to populate with action-to-input string pairs.

Implements IKeybindProvider.

◆ setJoystickAxis()

void KeybindManager::setJoystickAxis ( const std::string &  action,
int  joystickId,
uint8_t  axis,
bool  positiveDirection 
)
overridevirtual

Sets a joystick axis binding for an action.

Assigns a joystick axis direction to the specified action.

Parameters
actionThe action identifier.
joystickIdThe ID of the joystick.
axisThe joystick axis index.
positiveDirectionTrue for positive axis direction, false for negative.

Implements IKeybindProvider.

+ Here is the caller graph for this function:

◆ setJoystickButton()

void KeybindManager::setJoystickButton ( const std::string &  action,
int  joystickId,
uint8_t  button 
)
overridevirtual

Sets a joystick button binding for an action.

Assigns a joystick button to the specified action.

Parameters
actionThe action identifier.
joystickIdThe ID of the joystick.
buttonThe joystick button index.

Implements IKeybindProvider.

+ Here is the caller graph for this function:

◆ setJoystickHat()

void KeybindManager::setJoystickHat ( const std::string &  action,
int  joystickId,
uint8_t  hat,
uint8_t  direction 
)
overridevirtual

Sets a joystick hat binding for an action.

Assigns a joystick hat direction to the specified action.

Parameters
actionThe action identifier.
joystickIdThe ID of the joystick.
hatThe joystick hat index.
directionThe hat direction (e.g., SDL_HAT_UP).

Implements IKeybindProvider.

+ Here is the caller graph for this function:

◆ setKey()

void KeybindManager::setKey ( const std::string &  action,
SDL_Keycode  key 
)
overridevirtual

Sets the keyboard keycode for an action.

Assigns a new SDL keycode to the specified action.

Parameters
actionThe action identifier.
keyThe SDL keycode to assign.

Implements IKeybindProvider.

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: