Buttons held down, and those pressed or released since the start of the frame, with the position of the sticks and triggers.
More...
#include <aegis2d/platform/gamepad.hpp>
|
| void | begin_frame () noexcept |
| | Starts a frame: forgets the presses and releases of the previous one.
|
| |
| void | press (GamepadButton button) noexcept |
| | Records that a button went down.
|
| |
| void | release (GamepadButton button) noexcept |
| | Records that a button went up.
|
| |
| void | set_axis (GamepadAxis axis, float value) noexcept |
| | Records the position of a stick or a trigger, and presses or releases its button directions.
|
| |
| void | release_all () noexcept |
| | Releases every button and centers the sticks and triggers, as when the pad is unplugged or the window loses the focus.
|
| |
| void | merge (const Gamepad &other) noexcept |
| | Adds the state of another pad, for a player who may use any of several pads.
|
| |
| void | connect (GamepadStyle style) noexcept |
| | Marks the pad as plugged in.
|
| |
| void | disconnect () noexcept |
| | Marks the pad as unplugged and releases everything (release_all()).
|
| |
| bool | connected () const noexcept |
| | Tells whether a pad is plugged in.
|
| |
| GamepadStyle | style () const noexcept |
| | Family of the pad, for button_label().
|
| |
| bool | held (GamepadButton button) const noexcept |
| | Tells whether a button is down.
|
| |
| bool | pressed (GamepadButton button) const noexcept |
| | Tells whether a button went down during the frame.
|
| |
| bool | released (GamepadButton button) const noexcept |
| | Tells whether a button went up during the frame.
|
| |
| float | axis (GamepadAxis axis) const noexcept |
| | Position of a stick or a trigger.
|
| |
| std::span< const GamepadButton > | pressed_buttons () const noexcept |
| | Buttons pressed during the frame, in the order they went down.
|
| |
|
| static constexpr float | press_threshold = 0.5F |
| | Position past which a stick direction or a trigger counts as pressed.
|
| |
| static constexpr float | release_threshold = 0.35F |
| | Position below which a pressed stick direction or trigger is released.
|
| |
Buttons held down, and those pressed or released since the start of the frame, with the position of the sticks and triggers.
The window feeds it in Window::poll_events(), like the Keyboard: a button pressed and released within one frame is still seen as pressed. Moving a stick or a trigger with set_axis() also presses its button directions: a stick direction is pressed past press_threshold and released below release_threshold, so a stick resting near the threshold does not flicker between the two.
◆ axis()
| float aegis2d::platform::Gamepad::axis |
( |
GamepadAxis |
axis | ) |
const |
|
noexcept |
Position of a stick or a trigger.
Raw values: a game reading the sticks as analog applies its own dead zone.
- Parameters
-
| axis | Stick axis or trigger. |
- Returns
- From -1 to 1 for a stick, 0 to 1 for a trigger; 0 at rest.
◆ begin_frame()
| void aegis2d::platform::Gamepad::begin_frame |
( |
| ) |
|
|
noexcept |
Starts a frame: forgets the presses and releases of the previous one.
◆ connect()
| void aegis2d::platform::Gamepad::connect |
( |
GamepadStyle |
style | ) |
|
|
noexcept |
Marks the pad as plugged in.
- Parameters
-
◆ connected()
| bool aegis2d::platform::Gamepad::connected |
( |
| ) |
const |
|
noexcept |
◆ disconnect()
| void aegis2d::platform::Gamepad::disconnect |
( |
| ) |
|
|
noexcept |
Marks the pad as unplugged and releases everything (release_all()).
◆ held()
| bool aegis2d::platform::Gamepad::held |
( |
GamepadButton |
button | ) |
const |
|
noexcept |
Tells whether a button is down.
- Parameters
-
- Returns
true if it was pressed and not released yet.
◆ merge()
| void aegis2d::platform::Gamepad::merge |
( |
const Gamepad & |
other | ) |
|
|
noexcept |
Adds the state of another pad, for a player who may use any of several pads.
A button held, pressed or released on other is also on this one, and each axis keeps the position furthest from rest; this pad is connected if either is, with the style of the first one connected.
- Parameters
-
| other | State of another pad, for the same frame. |
◆ press()
Records that a button went down.
- Parameters
-
| button | Button pressed; ignored if it is already held. |
◆ pressed()
| bool aegis2d::platform::Gamepad::pressed |
( |
GamepadButton |
button | ) |
const |
|
noexcept |
Tells whether a button went down during the frame.
- Parameters
-
- Returns
true if it was pressed since begin_frame(), even if it is released again.
◆ pressed_buttons()
| std::span< const GamepadButton > aegis2d::platform::Gamepad::pressed_buttons |
( |
| ) |
const |
|
noexcept |
Buttons pressed during the frame, in the order they went down.
- Returns
- A view valid until the next call of a non-const function.
◆ release()
Records that a button went up.
- Parameters
-
| button | Button released; ignored if it is not held. |
◆ release_all()
| void aegis2d::platform::Gamepad::release_all |
( |
| ) |
|
|
noexcept |
Releases every button and centers the sticks and triggers, as when the pad is unplugged or the window loses the focus.
◆ released()
| bool aegis2d::platform::Gamepad::released |
( |
GamepadButton |
button | ) |
const |
|
noexcept |
Tells whether a button went up during the frame.
- Parameters
-
- Returns
true if it was released since begin_frame().
◆ set_axis()
| void aegis2d::platform::Gamepad::set_axis |
( |
GamepadAxis |
axis, |
|
|
float |
value |
|
) |
| |
|
noexcept |
Records the position of a stick or a trigger, and presses or releases its button directions.
- Parameters
-
| axis | Stick axis or trigger. |
| value | Position, clamped to [-1, 1] for a stick and [0, 1] for a trigger. |
◆ style()
◆ press_threshold
| constexpr float aegis2d::platform::Gamepad::press_threshold = 0.5F |
|
staticconstexpr |
Position past which a stick direction or a trigger counts as pressed.
◆ release_threshold
| constexpr float aegis2d::platform::Gamepad::release_threshold = 0.35F |
|
staticconstexpr |
Position below which a pressed stick direction or trigger is released.
The documentation for this class was generated from the following file: