|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
RAII wrapper for SDL_GameController (standard layout mapping). More...
#include <joystick.hpp>
Public Member Functions | |
| Controller () | |
| Default constructor — device not yet opened. | |
| ~Controller () | |
| Destructor — closes the controller if open. | |
| Controller (const Controller &)=delete | |
| Controller & | operator= (const Controller &)=delete |
| Controller (Controller &&)=delete | |
| Controller & | operator= (Controller &&)=delete |
| bool | open (int index) |
| Open a game controller by device index. | |
| bool | connectEvent (SDL_Event &e) |
| Handle a device-added/removed event to maintain connection state. | |
| std::string | name () const |
| Return the controller's name as reported by SDL. | |
| void | close () |
| Close the controller handle if open. | |
| std::optional< SDL_GameController * > | handle () |
| Return the underlying SDL_GameController handle as an optional. | |
| SDL_GameController * | unwrap () const |
| Unwrap the SDL_GameController pointer, asserting it is open. | |
| int | controllerIndex () const |
| Return the device index this controller was opened with. | |
| bool | getButton (SDL_GameControllerButton button) |
| Test whether a mapped button is currently pressed. | |
| Uint8 | getHat (int hat) |
| Read the position of a POV hat. | |
| Sint16 | getAxis (SDL_GameControllerAxis axis) |
| Read the current axis value. | |
| mx::Wrapper< SDL_GameController * > | wrapper () const |
| Return a Wrapper around the SDL_GameController handle. | |
| bool | active () const |
| Check whether the controller is currently usable. | |
Static Public Member Functions | |
| static int | joysticks () |
| Return the number of connected joysticks/controllers. | |
Protected Attributes | |
| SDL_GameController * | stick = nullptr |
| Underlying SDL game controller handle. | |
| int | index = -1 |
| Device index (-1 if not open). | |
RAII wrapper for SDL_GameController (standard layout mapping).
Provides button, hat, and axis queries using SDL's gamecontroller API, which normalises button layouts across different physical devices.
Definition at line 127 of file joystick.hpp.
| mx::Controller::Controller | ( | ) |
Default constructor — device not yet opened.
Definition at line 101 of file joystick.cpp.
Referenced by Controller(), Controller(), operator=(), and operator=().
| mx::Controller::~Controller | ( | ) |
Destructor — closes the controller if open.
Definition at line 103 of file joystick.cpp.
References close().
|
delete |
References Controller().
|
delete |
References Controller().
|
inline |
Check whether the controller is currently usable.
true if the controller is open and has a valid index. Definition at line 221 of file joystick.hpp.
Referenced by mx::Input::getButton().
| void mx::Controller::close | ( | ) |
Close the controller handle if open.
Definition at line 126 of file joystick.cpp.
Referenced by connectEvent(), and ~Controller().
| bool mx::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 176 of file joystick.cpp.
References close(), name(), open(), and mx::system_out.
| int mx::Controller::controllerIndex | ( | ) | const |
Return the device index this controller was opened with.
Definition at line 149 of file joystick.cpp.
References index.
| Sint16 mx::Controller::getAxis | ( | SDL_GameControllerAxis | axis | ) |
Read the current axis value.
| axis | SDL_GameControllerAxis constant. |
Definition at line 169 of file joystick.cpp.
References stick.
| bool mx::Controller::getButton | ( | SDL_GameControllerButton | button | ) |
Test whether a mapped button is currently pressed.
| button | SDL_GameControllerButton constant. |
true if pressed. Definition at line 153 of file joystick.cpp.
References stick.
Referenced by mx::Input::getButton().
| Uint8 mx::Controller::getHat | ( | int | hat | ) |
Read the position of a POV hat.
| hat | Hat index. |
Definition at line 159 of file joystick.cpp.
References stick.
| std::optional< SDL_GameController * > mx::Controller::handle | ( | ) |
Return the underlying SDL_GameController handle as an optional.
Definition at line 134 of file joystick.cpp.
References stick.
|
inlinestatic |
Return the number of connected joysticks/controllers.
Definition at line 184 of file joystick.hpp.
| std::string mx::Controller::name | ( | ) | const |
Return the controller's name as reported by SDL.
Definition at line 119 of file joystick.cpp.
References stick.
Referenced by connectEvent().
| bool mx::Controller::open | ( | int | index | ) |
Open a game controller by device index.
| index | SDL joystick index of the controller. |
true on success. Definition at line 107 of file joystick.cpp.
Referenced by connectEvent().
|
delete |
References Controller().
|
delete |
References Controller(), and index.
| SDL_GameController * mx::Controller::unwrap | ( | ) | const |
Unwrap the SDL_GameController pointer, asserting it is open.
Definition at line 141 of file joystick.cpp.
References stick.
|
inline |
Return a Wrapper around the SDL_GameController handle.
Definition at line 211 of file joystick.hpp.
References stick.
|
protected |
Device index (-1 if not open).
Definition at line 224 of file joystick.hpp.
Referenced by active(), close(), Controller(), controllerIndex(), open(), and operator=().
|
protected |
Underlying SDL game controller handle.
Definition at line 223 of file joystick.hpp.
Referenced by active(), close(), Controller(), getAxis(), getButton(), getHat(), handle(), name(), open(), unwrap(), and wrapper().