libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
mx::Input Class Reference

Convenience wrapper that queries controller buttons by logical name. More...

#include <input.hpp>

Inheritance diagram for mx::Input:
[legend]
Collaboration diagram for mx::Input:
[legend]

Public Member Functions

 Input ()=default
 Default constructor.
 ~Input ()=default
 Input (const Input &)=delete
Input & operator= (const Input &)=delete
 Input (Input &&)=delete
Input & operator= (Input &&)=delete
bool getButton (Input_Button b)
 Query whether a logical gamepad button is currently pressed.
Public Member Functions inherited from mx::Controller
 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.

Additional Inherited Members

Static Public Member Functions inherited from mx::Controller
static int joysticks ()
 Return the number of connected joysticks/controllers.
Protected Attributes inherited from mx::Controller
SDL_GameController * stick = nullptr
 Underlying SDL game controller handle.
int index = -1
 Device index (-1 if not open).

Detailed Description

Convenience wrapper that queries controller buttons by logical name.

Inherits Controller, adding getButton(Input_Button) to allow polling gamepad input without knowing the underlying SDL button codes.

Definition at line 41 of file input.hpp.

Constructor & Destructor Documentation

◆ Input() [1/3]

mx::Input::Input ( )
default

Default constructor.

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

◆ ~Input()

mx::Input::~Input ( )
default

◆ Input() [2/3]

mx::Input::Input ( const Input & )
delete

References Input().

◆ Input() [3/3]

mx::Input::Input ( Input && )
delete

References Input().

Member Function Documentation

◆ getButton()

bool mx::Input::getButton ( Input_Button b)

Query whether a logical gamepad button is currently pressed.

Parameters
bLogical button identifier.
Returns
true if the button is held down.

Definition at line 22 of file input.cpp.

References mx::Controller::active(), mx::ctrl, mx::Controller::getButton(), and mx::keys.

◆ operator=() [1/2]

Input & mx::Input::operator= ( const Input & )
delete

References Input().

◆ operator=() [2/2]

Input & mx::Input::operator= ( Input && )
delete

References Input().


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