cpp-sdl2
C++ header-only SDL2 wrapper
|
Represent a gamepad (game controller) More...
#include <game_controller.hpp>
Public Member Functions | |
GameController (int joystick_index) | |
Construct a controller from a joystick index, throws if that index is not a game controller. More... | |
GameController (SDL_GameController *controller) | |
Construct a controller from a GameController pointer. This object will take ownership of the controller pointed. More... | |
GameController ()=default | |
Construct an empty controller. More... | |
GameController (GameController const &)=delete | |
Not copyable. More... | |
GameController & | operator= (GameController const &)=delete |
GameController (GameController &&other) noexcept | |
move ctor More... | |
GameController & | operator= (GameController &&other) noexcept |
move-assing operator More... | |
~GameController () | |
Close the opened controller pointer, unless this wrapper was created via GameController::non_owning() More... | |
SDL_GameController * | ptr () const |
Get the SDL pointer. More... | |
Haptic | open_haptic () const |
Open the haptic device from the controller. More... | |
bool | is_attached () const |
Return true if this controller is attached. More... | |
int16_t | get_axis (SDL_GameControllerAxis axis) const |
Get the current imediate value of the given axis. More... | |
int8_t | get_button (SDL_GameControllerButton button) const |
Get the current imedate value of the given button. More... | |
int | rumble (uint16_t low_freq, uint16_t high_freq, std::chrono::milliseconds duration) const |
Play a simple rumble. If the controller has 2 motors, the two values will control one of them. If the controller only has one, the values will be mixed together. More... | |
int | rumble (uint16_t low_freq, uint16_t high_freq, uint32_t millisec_duration) const |
Play a simple rumble. If the controller has 2 motors, the two values will control one of them. If the controller only has one, the values will be mixed together. More... | |
std::string | name () const |
Static Public Member Functions | |
static std::string | get_controller_name (int joystick_index) |
static int | load_mapping_database (std::string const &file_path) |
Load a file database. More... | |
static int | load_mapping_database (const char *file_path) |
Load a file database. More... | |
static int | add_mapping (std::string const &mapping_string) |
Add a mapping string. More... | |
static int | add_mapping (const char *mapping_string) |
Add a mapping string. More... | |
static std::vector< GameController > | open_all_available_controllers () |
Try to open all available controllers, and return an array of all controller sucessfully openned. More... | |
static GameController | non_owning (SDL_JoystickID joystick_id) |
Create a non_owning controller around a stick ID, to use the C++ API without managing the controller. More... | |
static GameController | non_owning (SDL_GameController *controller) |
Create a non_owning controller around an SDL controller pointer, to use the C++ aPI withiout managing the controller. More... | |
Private Member Functions | |
GameController (SDL_GameController *controller, bool non_owned) | |
Private controller for a non-onwer controller. The bool argument is expected to be false here. More... | |
Private Attributes | |
SDL_GameController * | controller_ = nullptr |
bool const | owned_ = true |
Represent a gamepad (game controller)
Definition at line 14 of file game_controller.hpp.
|
inline |
Construct a controller from a joystick index, throws if that index is not a game controller.
Definition at line 18 of file game_controller.hpp.
References controller_.
|
inline |
Construct a controller from a GameController pointer. This object will take ownership of the controller pointed.
Definition at line 27 of file game_controller.hpp.
References GameController(), and operator=().
|
default |
Construct an empty controller.
Referenced by GameController().
|
delete |
Not copyable.
|
inlinenoexcept |
move ctor
Definition at line 37 of file game_controller.hpp.
|
inline |
Close the opened controller pointer, unless this wrapper was created via GameController::non_owning()
Definition at line 61 of file game_controller.hpp.
References controller_, and owned_.
|
inlineprivate |
Private controller for a non-onwer controller. The bool argument is expected to be false here.
Definition at line 201 of file game_controller.hpp.
References owned_.
|
inlinestatic |
Add a mapping string.
Definition at line 147 of file game_controller.hpp.
|
inlinestatic |
Add a mapping string.
Definition at line 153 of file game_controller.hpp.
|
inline |
Get the current imediate value of the given axis.
Definition at line 76 of file game_controller.hpp.
References controller_.
|
inline |
Get the current imedate value of the given button.
Definition at line 82 of file game_controller.hpp.
References controller_, and rumble().
|
inlinestatic |
Definition at line 108 of file game_controller.hpp.
References name().
|
inline |
Return true if this controller is attached.
Definition at line 73 of file game_controller.hpp.
References controller_.
|
inlinestatic |
Load a file database.
Definition at line 129 of file game_controller.hpp.
|
inlinestatic |
Load a file database.
Definition at line 135 of file game_controller.hpp.
|
inline |
Definition at line 101 of file game_controller.hpp.
References controller_.
Referenced by get_controller_name().
|
inlinestatic |
Create a non_owning controller around a stick ID, to use the C++ API without managing the controller.
Definition at line 191 of file game_controller.hpp.
|
inlinestatic |
Create a non_owning controller around an SDL controller pointer, to use the C++ aPI withiout managing the controller.
Definition at line 197 of file game_controller.hpp.
|
inlinestatic |
Try to open all available controllers, and return an array of all controller sucessfully openned.
Definition at line 167 of file game_controller.hpp.
|
inline |
Open the haptic device from the controller.
Definition at line 70 of file game_controller.hpp.
References controller_.
|
delete |
Referenced by GameController().
|
inlinenoexcept |
move-assing operator
Definition at line 40 of file game_controller.hpp.
References controller_, and owned_.
|
inline |
|
inline |
Play a simple rumble. If the controller has 2 motors, the two values will control one of them. If the controller only has one, the values will be mixed together.
Definition at line 89 of file game_controller.hpp.
Referenced by get_button().
|
inline |
Play a simple rumble. If the controller has 2 motors, the two values will control one of them. If the controller only has one, the values will be mixed together.
Definition at line 95 of file game_controller.hpp.
References controller_.
|
private |
Definition at line 207 of file game_controller.hpp.
Referenced by GameController(), get_axis(), get_button(), is_attached(), name(), open_haptic(), operator=(), ptr(), rumble(), and ~GameController().
|
private |
Definition at line 208 of file game_controller.hpp.
Referenced by GameController(), operator=(), and ~GameController().