11#ifndef KEYBIND_MANAGER_H
12#define KEYBIND_MANAGER_H
43 std::string getActionForKey(
const std::string& key)
const override;
53 SDL_Keycode
getKey(
const std::string& action)
const override;
63 void setKey(
const std::string& action, SDL_Keycode key)
override;
72 std::vector<std::string>
getActions()
const override;
83 void setJoystickButton(
const std::string& action,
int joystickId, uint8_t button)
override;
95 void setJoystickHat(
const std::string& action,
int joystickId, uint8_t hat, uint8_t direction)
override;
107 void setJoystickAxis(
const std::string& action,
int joystickId, uint8_t axis,
bool positiveDirection)
override;
117 std::string
eventToString(
const SDL_Event& event)
const override;
128 bool isAction(
const SDL_KeyboardEvent& event,
const std::string& action)
const override;
139 bool isJoystickAction(
const SDL_JoyButtonEvent& event,
const std::string& action)
const override;
150 bool isJoystickHatAction(
const SDL_JoyHatEvent& event,
const std::string& action)
const override;
161 bool isJoystickAxisAction(
const SDL_JoyAxisEvent& event,
const std::string& action)
const override;
170 void loadKeybinds(
const std::map<std::string, std::string>& keybindData)
override;
179 void saveKeybinds(std::map<std::string, std::string>& keybinds)
const override;
186 struct JoystickInput {
195 struct JoystickHatInput {
205 struct JoystickAxisInput {
208 bool positiveDirection;
218 std::variant<SDL_Keycode, JoystickInput, JoystickHatInput, JoystickAxisInput> input;
221 std::map<std::string, Keybind> keybinds_;
228 void initializeDefaults();
Interface for keybind providers (forward declaration).
Definition ikeybind_provider.h:30
Manages keyboard and joystick input bindings for application actions.
Definition keybind_manager.h:27
void setJoystickHat(const std::string &action, int joystickId, uint8_t hat, uint8_t direction) override
Sets a joystick hat binding for an action.
Definition keybind_manager.cpp:89
void loadKeybinds(const std::map< std::string, std::string > &keybindData) override
Loads keybind configurations from a data map.
Definition keybind_manager.cpp:212
std::string eventToString(const SDL_Event &event) const override
Converts an SDL event to a string representation.
Definition keybind_manager.cpp:177
KeybindManager()
Constructs a KeybindManager instance.
Definition keybind_manager.cpp:12
void setJoystickAxis(const std::string &action, int joystickId, uint8_t axis, bool positiveDirection) override
Sets a joystick axis binding for an action.
Definition keybind_manager.cpp:109
void setKey(const std::string &action, SDL_Keycode key) override
Sets the keyboard keycode for an action.
Definition keybind_manager.cpp:65
SDL_Keycode getKey(const std::string &action) const override
Gets the keyboard keycode for an action.
Definition keybind_manager.cpp:56
void saveKeybinds(std::map< std::string, std::string > &keybinds) const override
Saves keybind configurations to a map.
Definition keybind_manager.cpp:260
bool isJoystickAction(const SDL_JoyButtonEvent &event, const std::string &action) const override
Checks if a joystick button event matches an action.
Definition keybind_manager.cpp:143
std::vector< std::string > getActions() const override
Gets the list of supported actions.
Definition keybind_manager.cpp:121
~KeybindManager() override=default
Destroys the KeybindManager instance.
void setJoystickButton(const std::string &action, int joystickId, uint8_t button) override
Sets a joystick button binding for an action.
Definition keybind_manager.cpp:77
bool isJoystickHatAction(const SDL_JoyHatEvent &event, const std::string &action) const override
Checks if a joystick hat event matches an action.
Definition keybind_manager.cpp:153
bool isAction(const SDL_KeyboardEvent &event, const std::string &action) const override
Checks if a keyboard event matches an action.
Definition keybind_manager.cpp:130
bool isJoystickAxisAction(const SDL_JoyAxisEvent &event, const std::string &action) const override
Checks if a joystick axis event matches an action.
Definition keybind_manager.cpp:163
Defines the IKeybindProvider interface for managing input bindings in ASAPCabinetFE.