RAII wrapper for SDL_Gamepad (standard layout mapping). More...
#include <mxvk/include/mxvk/mxvk_controller.hpp>
Public Member Functions | |
| bool | active () const |
| Check whether the controller is currently usable. | |
| void | close () |
| Close the controller handle if open. | |
| bool | connectEvent (SDL_Event &e) |
| Handle a device-added/removed event to maintain connection state. | |
| int | controllerIndex () const |
| Return the device index this controller was opened with. | |
| Sint16 | getAxis (SDL_GamepadAxis axis) const |
| Read the current axis value. | |
| bool | getButton (SDL_GamepadButton button) const |
| Test whether a mapped button is currently pressed. | |
| Uint8 | getHat (int hat) const |
| Read the position of a POV hat. | |
| std::optional< SDL_Gamepad * > | handle () const |
| Return the underlying SDL_Gamepad handle as an optional. | |
| std::string | name () const |
| Return the controller's name as reported by SDL. | |
| bool | open (int index) |
| Open a gamepad by device index. | |
| VK_Controller & | operator= (const VK_Controller &)=delete |
| VK_Controller & | operator= (VK_Controller &&)=delete |
| SDL_Gamepad * | unwrap () const |
| Unwrap the SDL_Gamepad pointer, asserting it is open. | |
| VK_Controller () | |
| Default constructor — device not yet opened. | |
| VK_Controller (const VK_Controller &)=delete | |
| VK_Controller (VK_Controller &&)=delete | |
| ~VK_Controller () noexcept | |
| Destructor — closes the controller if open. | |
Static Public Member Functions | |
| static int | joysticks () |
| Return the number of connected joysticks/controllers. | |
Protected Member Functions | |
| bool | openByInstanceId (SDL_JoystickID instanceId, int index_hint=-1) |
Protected Attributes | |
| int | deviceIndex = -1 |
| Open index in the current gamepad list. | |
| SDL_JoystickID | instanceId = 0 |
| Stable SDL gamepad instance identifier. | |
| SDL_Gamepad * | stick = nullptr |
| Underlying SDL gamepad handle. | |
RAII wrapper for SDL_Gamepad (standard layout mapping).
Provides button, hat, and axis queries using SDL's gamepad API, which normalizes button layouts across different physical devices.
Definition at line 114 of file mxvk_controller.hpp.
|
default |
Default constructor — device not yet opened.
|
noexcept |
Destructor — closes the controller if open.
Definition at line 140 of file mxvk_controller.cpp.
|
delete |
|
delete |
|
nodiscard |
Check whether the controller is currently usable.
true if the controller is open and has a valid index. Definition at line 246 of file mxvk_controller.cpp.
| void mxvk::VK_Controller::close | ( | ) |
Close the controller handle if open.
Definition at line 192 of file mxvk_controller.cpp.
| bool mxvk::VK_Controller::connectEvent | ( | SDL_Event & | e | ) |
Handle a device-added/removed event to maintain connection state.
| e | SDL event to inspect. |
true if the event was a controller connect/disconnect. Definition at line 250 of file mxvk_controller.cpp.
| int mxvk::VK_Controller::controllerIndex | ( | ) | const |
Return the device index this controller was opened with.
Definition at line 216 of file mxvk_controller.cpp.
|
nodiscard |
Read the current axis value.
| axis | SDL_GamepadAxis constant. |
Definition at line 239 of file mxvk_controller.cpp.
|
nodiscard |
Test whether a mapped button is currently pressed.
| button | SDL_GamepadButton constant. |
true if pressed. Definition at line 220 of file mxvk_controller.cpp.
|
nodiscard |
Read the position of a POV hat.
| hat | Hat index. |
Definition at line 227 of file mxvk_controller.cpp.
|
nodiscard |
Return the underlying SDL_Gamepad handle as an optional.
Definition at line 202 of file mxvk_controller.cpp.
|
static |
Return the number of connected joysticks/controllers.
Definition at line 144 of file mxvk_controller.cpp.
| std::string mxvk::VK_Controller::name | ( | ) | const |
Return the controller's name as reported by SDL.
Definition at line 182 of file mxvk_controller.cpp.
| bool mxvk::VK_Controller::open | ( | int | index | ) |
Open a gamepad by device index.
| index | SDL gamepad index (0-based) within the current device list. |
true on success. Definition at line 167 of file mxvk_controller.cpp.
|
protected |
Definition at line 153 of file mxvk_controller.cpp.
|
delete |
|
delete |
|
nodiscard |
Unwrap the SDL_Gamepad pointer, asserting it is open.
Definition at line 209 of file mxvk_controller.cpp.
|
protected |
Open index in the current gamepad list.
Definition at line 204 of file mxvk_controller.hpp.
|
protected |
Stable SDL gamepad instance identifier.
Definition at line 205 of file mxvk_controller.hpp.
|
protected |
Underlying SDL gamepad handle.
Definition at line 203 of file mxvk_controller.hpp.