10#define __JOYSTICK__H__
49 std::string
name()
const;
58 std::optional<SDL_Joystick*>
handle();
64 SDL_Joystick *
unwrap()
const;
76 static int joysticks() {
return SDL_NumJoysticks(); }
157 std::string
name()
const;
166 std::optional<SDL_GameController*>
handle();
172 SDL_GameController *
unwrap()
const;
191 bool getButton(SDL_GameControllerButton button);
205 Sint16
getAxis(SDL_GameControllerAxis axis);
223 SDL_GameController *
stick =
nullptr;
Controller & operator=(Controller &&)=delete
std::string name() const
Return the controller's name as reported by SDL.
int controllerIndex() const
Return the device index this controller was opened with.
int index
Device index (-1 if not open).
SDL_GameController * unwrap() const
Unwrap the SDL_GameController pointer, asserting it is open.
bool getButton(SDL_GameControllerButton button)
Test whether a mapped button is currently pressed.
bool connectEvent(SDL_Event &e)
Handle a device-added/removed event to maintain connection state.
mx::Wrapper< SDL_GameController * > wrapper() const
Return a Wrapper around the SDL_GameController handle.
Sint16 getAxis(SDL_GameControllerAxis axis)
Read the current axis value.
~Controller()
Destructor — closes the controller if open.
std::optional< SDL_GameController * > handle()
Return the underlying SDL_GameController handle as an optional.
void close()
Close the controller handle if open.
Controller(Controller &&)=delete
Controller & operator=(const Controller &)=delete
Uint8 getHat(int hat)
Read the position of a POV hat.
Controller()
Default constructor — device not yet opened.
Controller(const Controller &)=delete
bool open(int index)
Open a game controller by device index.
static int joysticks()
Return the number of connected joysticks/controllers.
SDL_GameController * stick
Underlying SDL game controller handle.
bool active() const
Check whether the controller is currently usable.
Joystick(const Joystick &)=delete
~Joystick()
Destructor — closes the joystick if open.
void close()
Close the joystick handle if open.
Joystick(Joystick &&)=delete
Joystick()
Default constructor — device not yet opened.
Sint16 getAxis(int axis)
Read the current axis value.
Joystick & operator=(const Joystick &)=delete
int joystickIndex() const
Return the device index this joystick was opened with.
std::string name() const
Return the joystick's name as reported by SDL.
SDL_Joystick * unwrap() const
Unwrap the SDL_Joystick pointer, asserting it is open.
SDL_Joystick * stick
Underlying SDL joystick handle.
std::optional< SDL_Joystick * > handle()
Return the underlying SDL_Joystick handle as an optional.
static int joysticks()
Return the number of connected joysticks.
bool getButton(int button)
Test whether a button is currently pressed.
bool open(int index)
Open the joystick at the given device index.
Joystick & operator=(Joystick &&)=delete
int index
Device index (-1 if not open).
Uint8 getHat(int hat)
Read the position of a POV hat.
mx::Wrapper< SDL_Joystick * > wrapper() const
Return a Wrapper around the SDL_Joystick handle.
A nullable smart wrapper around a raw pointer.
Type-safe nullable pointer wrapper inspired by Rust's Option<T>.