cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Joystick Class Reference

#include <joystick.hpp>

Public Member Functions

 Joystick ()
 Default ctor, create a non-valid (empty) joystick object. More...
 
 Joystick (int device_index)
 Create a joystick by opening a joystick device. More...
 
 Joystick (SDL_Joystick *joystick)
 Create a joystick from an SDL joystick. More...
 
 Joystick (Joystick const &)=delete
 
Joystickoperator= (Joystick const &)=delete
 
 Joystick (Joystick &&other) noexcept
 move ctor More...
 
Joystickoperator= (Joystick &&other) noexcept
 move assign operator More...
 
 ~Joystick ()
 Will automatically close the joystick when going out of scope if this object owns the pointer. More...
 
Haptic open_haptic () const
 Open haptics for this device. More...
 
SDL_JoystickPowerLevel power_level () const
 Get the power level of the joystick. Will throw if unknown. More...
 
bool attached () const
 Return true if device is currently attached. More...
 
int16_t get_axis (int axis) const
 Get the current immediate value of the given axis. More...
 
sdl::Vec2i get_ball (int ball) const
 Get the current immediate value of the given trackball. More...
 
uint8_t get_button (int button) const
 Get the current immediate value of the given button. More...
 
uint8_t get_hat (int hat) const
 Get the current immediate value of the given hat. More...
 
std::string name () const
 Get the name of the joystick. More...
 
int num_hats () const
 Get how many hats. More...
 
int num_buttons () const
 Get how many buttons. More...
 
int num_balls () const
 Get how many balls. More...
 
int num_axes () const
 Get how many axes. More...
 
SDL_JoystickID instance_id () const
 Get this joystick instance id. More...
 
bool operator== (Joystick const &other) const
 
bool operator== (SDL_Joystick *other) const
 
bool operator== (SDL_JoystickID other) const
 

Static Public Member Functions

static Joystick non_owning (SDL_Joystick *stick)
 construct a non-owning wrapper around this joystick More...
 
static Joystick non_joystick (SDL_JoystickID joyid)
 construct a non-owning wrapper around this joystick id More...
 

Private Member Functions

 Joystick (SDL_Joystick *stick, bool owning_state)
 Construct a non-owning joystick object. More...
 

Private Attributes

SDL_Joystick * joystick_ = nullptr
 
const bool owner_ = true
 

Detailed Description

Definition at line 11 of file joystick.hpp.

Constructor & Destructor Documentation

◆ Joystick() [1/6]

sdl::Joystick::Joystick ( SDL_Joystick *  stick,
bool  owning_state 
)
inlineprivate

Construct a non-owning joystick object.

Definition at line 17 of file joystick.hpp.

◆ Joystick() [2/6]

sdl::Joystick::Joystick ( )
inline

Default ctor, create a non-valid (empty) joystick object.

Definition at line 24 of file joystick.hpp.

Referenced by Joystick(), and non_joystick().

◆ Joystick() [3/6]

sdl::Joystick::Joystick ( int  device_index)
inline

Create a joystick by opening a joystick device.

Definition at line 27 of file joystick.hpp.

◆ Joystick() [4/6]

sdl::Joystick::Joystick ( SDL_Joystick *  joystick)
inline

Create a joystick from an SDL joystick.

Definition at line 33 of file joystick.hpp.

References Joystick(), and operator=().

◆ Joystick() [5/6]

sdl::Joystick::Joystick ( Joystick const &  )
delete

◆ Joystick() [6/6]

sdl::Joystick::Joystick ( Joystick &&  other)
inlinenoexcept

move ctor

Definition at line 39 of file joystick.hpp.

◆ ~Joystick()

sdl::Joystick::~Joystick ( )
inline

Will automatically close the joystick when going out of scope if this object owns the pointer.

Definition at line 59 of file joystick.hpp.

Member Function Documentation

◆ attached()

bool sdl::Joystick::attached ( ) const
inline

Return true if device is currently attached.

Definition at line 78 of file joystick.hpp.

◆ get_axis()

int16_t sdl::Joystick::get_axis ( int  axis) const
inline

Get the current immediate value of the given axis.

Definition at line 81 of file joystick.hpp.

◆ get_ball()

sdl::Vec2i sdl::Joystick::get_ball ( int  ball) const
inline

Get the current immediate value of the given trackball.

Definition at line 84 of file joystick.hpp.

◆ get_button()

uint8_t sdl::Joystick::get_button ( int  button) const
inline

Get the current immediate value of the given button.

Definition at line 95 of file joystick.hpp.

◆ get_hat()

uint8_t sdl::Joystick::get_hat ( int  hat) const
inline

Get the current immediate value of the given hat.

Definition at line 98 of file joystick.hpp.

◆ instance_id()

SDL_JoystickID sdl::Joystick::instance_id ( ) const
inline

Get this joystick instance id.

Definition at line 144 of file joystick.hpp.

Referenced by operator==().

◆ name()

std::string sdl::Joystick::name ( ) const
inline

Get the name of the joystick.

Definition at line 101 of file joystick.hpp.

◆ non_joystick()

static Joystick sdl::Joystick::non_joystick ( SDL_JoystickID  joyid)
inlinestatic

construct a non-owning wrapper around this joystick id

Definition at line 157 of file joystick.hpp.

References Joystick().

◆ non_owning()

static Joystick sdl::Joystick::non_owning ( SDL_Joystick *  stick)
inlinestatic

construct a non-owning wrapper around this joystick

Definition at line 154 of file joystick.hpp.

◆ num_axes()

int sdl::Joystick::num_axes ( ) const
inline

Get how many axes.

Definition at line 134 of file joystick.hpp.

◆ num_balls()

int sdl::Joystick::num_balls ( ) const
inline

Get how many balls.

Definition at line 124 of file joystick.hpp.

◆ num_buttons()

int sdl::Joystick::num_buttons ( ) const
inline

Get how many buttons.

Definition at line 114 of file joystick.hpp.

◆ num_hats()

int sdl::Joystick::num_hats ( ) const
inline

Get how many hats.

Definition at line 104 of file joystick.hpp.

◆ open_haptic()

Haptic sdl::Joystick::open_haptic ( ) const
inline

Open haptics for this device.

Definition at line 65 of file joystick.hpp.

◆ operator=() [1/2]

Joystick& sdl::Joystick::operator= ( Joystick const &  )
delete

Referenced by Joystick().

◆ operator=() [2/2]

Joystick& sdl::Joystick::operator= ( Joystick &&  other)
inlinenoexcept

move assign operator

Definition at line 42 of file joystick.hpp.

References joystick_, and owner_.

◆ operator==() [1/3]

bool sdl::Joystick::operator== ( Joystick const &  other) const
inline

Definition at line 166 of file joystick.hpp.

References joystick_.

◆ operator==() [2/3]

bool sdl::Joystick::operator== ( SDL_Joystick *  other) const
inline

Definition at line 168 of file joystick.hpp.

◆ operator==() [3/3]

bool sdl::Joystick::operator== ( SDL_JoystickID  other) const
inline

Definition at line 170 of file joystick.hpp.

References instance_id().

◆ power_level()

SDL_JoystickPowerLevel sdl::Joystick::power_level ( ) const
inline

Get the power level of the joystick. Will throw if unknown.

Definition at line 68 of file joystick.hpp.

Member Data Documentation

◆ joystick_

SDL_Joystick* sdl::Joystick::joystick_ = nullptr
private

Definition at line 13 of file joystick.hpp.

Referenced by operator=(), and operator==().

◆ owner_

const bool sdl::Joystick::owner_ = true
private

Definition at line 14 of file joystick.hpp.

Referenced by operator=().


The documentation for this class was generated from the following file: