|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
RAII wrapper for a raw SDL_Joystick device. More...
#include <joystick.hpp>
Public Member Functions | |
| Joystick () | |
| Default constructor — device not yet opened. | |
| ~Joystick () | |
| Destructor — closes the joystick if open. | |
| Joystick (const Joystick &)=delete | |
| Joystick & | operator= (const Joystick &)=delete |
| Joystick (Joystick &&)=delete | |
| Joystick & | operator= (Joystick &&)=delete |
| bool | open (int index) |
| Open the joystick at the given device index. | |
| std::string | name () const |
| Return the joystick's name as reported by SDL. | |
| void | close () |
| Close the joystick handle if open. | |
| std::optional< SDL_Joystick * > | handle () |
| Return the underlying SDL_Joystick handle as an optional. | |
| SDL_Joystick * | unwrap () const |
| Unwrap the SDL_Joystick pointer, asserting it is open. | |
| int | joystickIndex () const |
| Return the device index this joystick was opened with. | |
| int | numButtons () |
| int | numHats () |
| int | numAxes () |
| bool | getButton (int button) |
| Test whether a button is currently pressed. | |
| Uint8 | getHat (int hat) |
| Read the position of a POV hat. | |
| Sint16 | getAxis (int axis) |
| Read the current axis value. | |
| mx::Wrapper< SDL_Joystick * > | wrapper () const |
| Return a Wrapper around the SDL_Joystick handle. | |
Static Public Member Functions | |
| static int | joysticks () |
| Return the number of connected joysticks. | |
Protected Attributes | |
| SDL_Joystick * | stick = nullptr |
| Underlying SDL joystick handle. | |
| int | index = -1 |
| Device index (-1 if not open). | |
RAII wrapper for a raw SDL_Joystick device.
Opens an SDL joystick by index and provides axis, hat, and button read-back. The handle is automatically closed on destruction.
Definition at line 26 of file joystick.hpp.
| mx::Joystick::Joystick | ( | ) |
Default constructor — device not yet opened.
Definition at line 11 of file joystick.cpp.
Referenced by Joystick(), Joystick(), operator=(), and operator=().
| mx::Joystick::~Joystick | ( | ) |
Destructor — closes the joystick if open.
Definition at line 13 of file joystick.cpp.
References close().
|
delete |
References Joystick().
|
delete |
References Joystick().
| void mx::Joystick::close | ( | ) |
Close the joystick handle if open.
Definition at line 36 of file joystick.cpp.
Referenced by ~Joystick().
| Sint16 mx::Joystick::getAxis | ( | int | axis | ) |
Read the current axis value.
| axis | Axis index. |
Definition at line 77 of file joystick.cpp.
References stick.
| bool mx::Joystick::getButton | ( | int | button | ) |
Test whether a button is currently pressed.
| button | Button index. |
true if pressed. Definition at line 63 of file joystick.cpp.
References stick.
| Uint8 mx::Joystick::getHat | ( | int | hat | ) |
Read the position of a POV hat.
| hat | Hat index. |
Definition at line 70 of file joystick.cpp.
References stick.
| std::optional< SDL_Joystick * > mx::Joystick::handle | ( | ) |
Return the underlying SDL_Joystick handle as an optional.
Definition at line 44 of file joystick.cpp.
References stick.
| int mx::Joystick::joystickIndex | ( | ) | const |
Return the device index this joystick was opened with.
Definition at line 59 of file joystick.cpp.
References index.
|
inlinestatic |
Return the number of connected joysticks.
Definition at line 76 of file joystick.hpp.
| std::string mx::Joystick::name | ( | ) | const |
Return the joystick's name as reported by SDL.
Definition at line 29 of file joystick.cpp.
References stick.
| int mx::Joystick::numAxes | ( | ) |
Definition at line 95 of file joystick.cpp.
References stick.
| int mx::Joystick::numButtons | ( | ) |
Definition at line 84 of file joystick.cpp.
References stick.
| int mx::Joystick::numHats | ( | ) |
Definition at line 90 of file joystick.cpp.
References stick.
| bool mx::Joystick::open | ( | int | index | ) |
Open the joystick at the given device index.
| index | SDL joystick index (0-based). |
true on success. Definition at line 17 of file joystick.cpp.
References Joystick().
References index, and Joystick().
| SDL_Joystick * mx::Joystick::unwrap | ( | ) | const |
Unwrap the SDL_Joystick pointer, asserting it is open.
Definition at line 51 of file joystick.cpp.
References stick.
|
inline |
Return a Wrapper around the SDL_Joystick handle.
Definition at line 110 of file joystick.hpp.
References stick.
|
protected |
Device index (-1 if not open).
Definition at line 117 of file joystick.hpp.
Referenced by close(), Joystick(), joystickIndex(), open(), and operator=().
|
protected |
Underlying SDL joystick handle.
Definition at line 116 of file joystick.hpp.
Referenced by close(), getAxis(), getButton(), getHat(), handle(), Joystick(), name(), numAxes(), numButtons(), numHats(), open(), unwrap(), and wrapper().