ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::event::Gamepad Class Reference

Current Gamepad state. More...

#include <Gamepad.hpp>

Collaboration diagram for ecstasy::integration::event::Gamepad:

Public Types

enum class  Button {
  Unknown = -1 , FaceUp , FaceRight , FaceDown ,
  FaceLeft , BumperLeft , BumperRight , MiddleLeft ,
  Middle , MiddleRight , ThumbLeft , ThumbRight ,
  Count
}
 Gamepad buttons. More...
 
enum class  Axis {
  Unknown = -1 , LeftX , LeftY , RightX ,
  RightY , TriggerLeft , TriggerRight , DPadX ,
  DPadY , Count
}
 Gamepad axis, associated value must be in range [-1, 1]. More...
 
enum class  Joystick { Unknown = -1 , Left = 0 , Right , Count }
 Gamepad joysticks (a joystick has 2 combined axis) More...
 

Public Member Functions

constexpr Gamepad (std::size_t id=0) noexcept
 Construct a new Gamepad object.
 
 ~Gamepad () noexcept=default
 Default destructor.
 
constexpr std::size_t getId () const noexcept
 Get the gamepad id.
 
constexpr void setId (std::size_t id) noexcept
 Change the gamepad id.
 
constexpr bool isConnected () const noexcept
 Check whether the gamepad is connected or not.
 
constexpr void setConnected (bool connected) noexcept
 Update the connected state of the gamepad.
 
constexpr bool isButtonDown (Button button) const
 Check whether a button is down.
 
constexpr bool isButtonUp (Button button) const
 Check whether a button is up.
 
constexpr void setButtonState (Button button, bool down)
 Update a given button state.
 
constexpr float getAxisValue (Axis axis) const
 Get the given axis value.
 
constexpr void setAxisValue (Axis axis, float value)
 Update an axis value.
 

Static Public Member Functions

static constexpr void assertButtonValid (Button button, bool allowUnknown=false)
 Check whether a button is valid.
 
static constexpr void assertAxisValid (Axis axis, bool allowUnknown=false)
 Check whether an axis is valid.
 

Private Attributes

std::size_t _id
 Gamepad id.
 
bool _connected
 Gamepad connection state.
 
std::array< bool, static_cast< std::size_t >(Button::Count)> _buttons
 Gamepad buttons state.
 
std::array< float, static_cast< std::size_t >(Axis::Count)> _axis
 Gamepad axis values.
 

Detailed Description

Current Gamepad state.

Used by Gamepads.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 30 of file Gamepad.hpp.

Member Enumeration Documentation

◆ Axis

Gamepad axis, associated value must be in range [-1, 1].

Enumerator
Unknown 

Unhandled axis.

LeftX 

Left joystick X axis (default: 0)

LeftY 

Left joystick Y axis (default: 0)

RightX 

Right joystick X axis (default: 0)

RightY 

Right joystick Y axis (default: 0)

TriggerLeft 

Left trigger (default: -1)

TriggerRight 

Right trigger (default: -1)

DPadX 

DPad X axis (default: 0)

DPadY 

DPad Y Axis (default: 0)

Count 

Keep last – the total number of gamepad axis.

Definition at line 66 of file Gamepad.hpp.

66 {
67 Unknown = -1,
68 LeftX,
69 LeftY,
70 RightX,
71 RightY,
74 DPadX,
75 DPadY,
76
77 Count
78
79 };
@ TriggerLeft
Left trigger (default: -1)
@ TriggerRight
Right trigger (default: -1)
@ LeftY
Left joystick Y axis (default: 0)
@ LeftX
Left joystick X axis (default: 0)
@ RightX
Right joystick X axis (default: 0)
@ RightY
Right joystick Y axis (default: 0)
@ Count
Keep last – the total number of gamepad buttons.

◆ Button

Gamepad buttons.

Enumerator
Unknown 

Unhandled button.

FaceUp 

Face Buttons.

Face button up (i.e. PS: Triangle, Xbox: Y)

FaceRight 

Face button right (i.e. PS: Square, Xbox: X)

FaceDown 

Face button down (i.e. PS: Cross, Xbox: A)

FaceLeft 

Face button left (i.e.

PS: Circle, Xbox: B)

BumperLeft 

Backward buttons.

Left bumper (LB / L1)

BumperRight 

Right bumper (RB / R1)

MiddleLeft 

Middle buttons.

Left center button (i.e. PS: Select, Xbox: back)

Middle 

Center buttons (i.e. PS: PS, Xbox: XBOX)

MiddleRight 

Right center button (i.e.

PS: Start, Xbox: Start)

ThumbLeft 

Joystick buttons.

Left joystick button

ThumbRight 

Right joystick button.

Count 

Keep last – the total number of gamepad buttons.

Definition at line 44 of file Gamepad.hpp.

44 {
45 Unknown = -1,
47 FaceUp,
48 FaceRight,
49 FaceDown,
50 FaceLeft,
56 Middle,
59 ThumbLeft,
61
62 Count
63 };
@ MiddleRight
Right center button (i.e.
@ FaceRight
Face button right (i.e. PS: Square, Xbox: X)
@ Middle
Center buttons (i.e. PS: PS, Xbox: XBOX)
@ FaceDown
Face button down (i.e. PS: Cross, Xbox: A)

◆ Joystick

Gamepad joysticks (a joystick has 2 combined axis)

Enumerator
Unknown 

Unhandled joystick.

Left 

Left joystick.

Right 

Right joystick.

Count 

Keep last – the total number of gamepad joysticks.

Definition at line 83 of file Gamepad.hpp.

83 {
84 Unknown = -1,
85 Left = 0,
86 Right,
87
88 Count
89 };

Constructor & Destructor Documentation

◆ Gamepad()

constexpr ecstasy::integration::event::Gamepad::Gamepad ( std::size_t  id = 0)
inlineconstexprnoexcept

Construct a new Gamepad object.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 97 of file Gamepad.hpp.

97 : _id(id), _connected(false), _buttons({false}), _axis({0.f})
98 {
101 }
std::array< float, static_cast< std::size_t >(Axis::Count)> _axis
Gamepad axis values.
Definition Gamepad.hpp:302
bool _connected
Gamepad connection state.
Definition Gamepad.hpp:298
std::array< bool, static_cast< std::size_t >(Button::Count)> _buttons
Gamepad buttons state.
Definition Gamepad.hpp:300
constexpr void setAxisValue(Axis axis, float value)
Update an axis value.
Definition Gamepad.hpp:252

◆ ~Gamepad()

ecstasy::integration::event::Gamepad::~Gamepad ( )
defaultnoexcept

Default destructor.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Member Function Documentation

◆ assertAxisValid()

static constexpr void ecstasy::integration::event::Gamepad::assertAxisValid ( Axis  axis,
bool  allowUnknown = false 
)
inlinestaticconstexpr

Check whether an axis is valid.

Parameters
[in]axisevaluated axis.
[in]allowUnknownWhether the Unknown axis is valid or not.
Exceptions
std::invalid_argumentIf the axis is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-13)

Definition at line 287 of file Gamepad.hpp.

288 {
289 if (static_cast<std::size_t>(axis) >= static_cast<std::size_t>(Axis::Count)
290 || (!allowUnknown && axis == Axis::Unknown)) [[unlikely]]
291 throw std::invalid_argument("Invalid axis");
292 }
@ Count
Keep last – the total number of gamepad axis.

◆ assertButtonValid()

static constexpr void ecstasy::integration::event::Gamepad::assertButtonValid ( Button  button,
bool  allowUnknown = false 
)
inlinestaticconstexpr

Check whether a button is valid.

Parameters
[in]buttonevaluated button.
[in]allowUnknownWhether the Unknown button is valid or not.
Exceptions
std::invalid_argumentIf the button is invalid
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-13)

Definition at line 269 of file Gamepad.hpp.

270 {
271 if (static_cast<std::size_t>(button) >= static_cast<std::size_t>(Button::Count)
272 || (!allowUnknown && button == Button::Unknown)) [[unlikely]]
273 throw std::invalid_argument("Invalid button");
274 }

◆ getAxisValue()

constexpr float ecstasy::integration::event::Gamepad::getAxisValue ( Axis  axis) const
inlineconstexpr

Get the given axis value.

Parameters
[in]axisevaluated axis.
Returns
float axis value.
Exceptions
std::invalid_argumentIf the axis is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 233 of file Gamepad.hpp.

234 {
235 assertAxisValid(axis);
236 return _axis[static_cast<std::size_t>(axis)];
237 }
static constexpr void assertAxisValid(Axis axis, bool allowUnknown=false)
Check whether an axis is valid.
Definition Gamepad.hpp:287

◆ getId()

constexpr std::size_t ecstasy::integration::event::Gamepad::getId ( ) const
inlineconstexprnoexcept

Get the gamepad id.

Returns
std::size_t id.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 118 of file Gamepad.hpp.

119 {
120 return _id;
121 }

◆ isButtonDown()

constexpr bool ecstasy::integration::event::Gamepad::isButtonDown ( Button  button) const
inlineconstexpr

Check whether a button is down.

Parameters
[in]buttonevaluated button.
Returns
bool Whether the button is down.
Exceptions
std::invalid_argumentIf the button is invalid
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 178 of file Gamepad.hpp.

179 {
180 assertButtonValid(button);
181 return _buttons[static_cast<std::size_t>(button)];
182 }
static constexpr void assertButtonValid(Button button, bool allowUnknown=false)
Check whether a button is valid.
Definition Gamepad.hpp:269

◆ isButtonUp()

constexpr bool ecstasy::integration::event::Gamepad::isButtonUp ( Button  button) const
inlineconstexpr

Check whether a button is up.

Parameters
[in]buttonevaluated button.
Returns
bool Whether the button is up.
Exceptions
std::invalid_argumentIf the button is invalid
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 196 of file Gamepad.hpp.

197 {
198 assertButtonValid(button);
199 return !isButtonDown(button);
200 }
constexpr bool isButtonDown(Button button) const
Check whether a button is down.
Definition Gamepad.hpp:178

◆ isConnected()

constexpr bool ecstasy::integration::event::Gamepad::isConnected ( ) const
inlineconstexprnoexcept

Check whether the gamepad is connected or not.

Returns
bool Whether the gamepad is connected or not.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 146 of file Gamepad.hpp.

147 {
148 return _connected;
149 }

◆ setAxisValue()

constexpr void ecstasy::integration::event::Gamepad::setAxisValue ( Axis  axis,
float  value 
)
inlineconstexpr

Update an axis value.

Warning
It only update the internal state, no event is called.
Parameters
[in]axismodified axis.
[in]valuenew value.
Exceptions
std::invalid_argumentIf the axis is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 252 of file Gamepad.hpp.

253 {
254 assertAxisValid(axis);
255 _axis[static_cast<std::size_t>(axis)] = value;
256 }

◆ setButtonState()

constexpr void ecstasy::integration::event::Gamepad::setButtonState ( Button  button,
bool  down 
)
inlineconstexpr

Update a given button state.

Warning
It only update the internal state, no event is called.
Parameters
[in]buttonbutton to update.
[in]downWhether the button must be set down or not.
Exceptions
std::invalid_argumentIf the button is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-16)

Definition at line 215 of file Gamepad.hpp.

216 {
217 assertButtonValid(button);
218 _buttons[static_cast<std::size_t>(button)] = down;
219 }

◆ setConnected()

constexpr void ecstasy::integration::event::Gamepad::setConnected ( bool  connected)
inlineconstexprnoexcept

Update the connected state of the gamepad.

Warning
It only update the internal state, no event is called.
Parameters
[in]connectedNew connected value (true if connected).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 161 of file Gamepad.hpp.

162 {
163 _connected = connected;
164 }

◆ setId()

constexpr void ecstasy::integration::event::Gamepad::setId ( std::size_t  id)
inlineconstexprnoexcept

Change the gamepad id.

Warning
It only update the internal state, no event is called.
Parameters
[in]idnew gamepad id.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-18)

Definition at line 133 of file Gamepad.hpp.

134 {
135 _id = id;
136 }

Member Data Documentation

◆ _axis

std::array<float, static_cast<std::size_t>(Axis::Count)> ecstasy::integration::event::Gamepad::_axis
private

Gamepad axis values.

Definition at line 302 of file Gamepad.hpp.

◆ _buttons

std::array<bool, static_cast<std::size_t>(Button::Count)> ecstasy::integration::event::Gamepad::_buttons
private

Gamepad buttons state.

Definition at line 300 of file Gamepad.hpp.

◆ _connected

bool ecstasy::integration::event::Gamepad::_connected
private

Gamepad connection state.

Definition at line 298 of file Gamepad.hpp.

◆ _id

std::size_t ecstasy::integration::event::Gamepad::_id
private

Gamepad id.

Definition at line 296 of file Gamepad.hpp.


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