21 std::array<bool, GamepadButtonCount>
Buttons{};
22 std::array<float, GamepadAxisCount>
Axes{};
119 bool Connected =
false;
125 const Slot* FindConnected(
GamepadId gamepad)
const;
130 std::array<Slot, MaxGamepads> m_Slots{};
Base class of all events, with their types and categories.
Codes of the gamepads, of their buttons and of their axes, independent from GLFW.
Base class of all events.
Definition Event.h:111
void SetReader(Reader reader)
Replaces the function that reads the gamepads, for example to simulate gamepads in the tests.
std::function< std::optional< GamepadReading >(GamepadId)> Reader
Function that reads a gamepad: the reading, or no value when no gamepad has this id.
Definition Gamepads.h:70
void Update(const EventCallback &send)
Reads every gamepad, keeps its new state, and sends the events of the changes since the last call.
Gamepads(Reader reader)
Creates the gamepads, read with another function, for example by the tests.
GamepadSettings & GetSettings()
Returns the settings of the dead zones and of the events, which can be changed at any time.
Definition Gamepads.h:108
Gamepads()
Creates the gamepads, read with GLFW. GLFW must be started before the first call to Update().
bool IsConnected(GamepadId gamepad) const
Returns true if a gamepad is connected with this id.
bool IsButtonPressed(GamepadId gamepad, GamepadButton button) const
Returns true if the button of the gamepad is held down. False when the gamepad is not connected.
float GetAxis(GamepadId gamepad, GamepadAxis axis) const
Returns the value of the axis of the gamepad, after the dead zones.
const std::string & GetName(GamepadId gamepad) const
Returns the name of the gamepad, or an empty string if no gamepad is connected with this id.
std::function< void(Event &)> EventCallback
Function that receives the events of the gamepads.
Definition Gamepads.h:67
const GamepadSettings & GetSettings() const
Returns the settings of the dead zones and of the events.
Definition Gamepads.h:111
Contains all the engine code.
GamepadButton
Button of a gamepad, at the position of the buttons of an Xbox controller.
Definition GamepadCodes.h:34
GamepadId
Identifies a connected gamepad, from 0 to MaxGamepads - 1.
Definition GamepadCodes.h:26
GamepadAxis
Axis of a gamepad.
Definition GamepadCodes.h:57
What is read from a connected gamepad, before the dead zones are applied.
Definition Gamepads.h:33
std::string Name
Name of the gamepad, for example "Xbox Controller".
Definition Gamepads.h:34
GamepadState State
Raw state: the stick axes go from -1 to 1, and the triggers too, -1 being at rest.
Definition Gamepads.h:35
Settings that filter the axes of the gamepads.
Definition Gamepads.h:40
float TriggerDeadZone
Value under which a trigger reads as 0, on its range from 0 to 1.
Definition Gamepads.h:47
float AxisEventThreshold
Change needed to send a GamepadAxisMovedEvent, so that a moving stick does not send an event every fr...
Definition Gamepads.h:51
float StickDeadZone
Distance from the center under which a stick reads as 0.
Definition Gamepads.h:43
State of the buttons and axes of a gamepad.
Definition Gamepads.h:20
std::array< float, GamepadAxisCount > Axes
Value of each axis, indexed by GamepadAxis.
Definition Gamepads.h:22
float GetAxis(GamepadAxis axis) const
Returns the value of the axis.
Definition Gamepads.h:28
bool IsPressed(GamepadButton button) const
Returns true if the button is held down.
Definition Gamepads.h:25
std::array< bool, GamepadButtonCount > Buttons
True for each button held down, indexed by GamepadButton.
Definition Gamepads.h:21