le2d v0.4.7
2D game engine framework
 
Loading...
Searching...
No Matches
le::input::Gamepad Class Reference

Snapshot of gamepad / game controller state. More...

#include <le2d/input/gamepad.hpp>

Classes

struct  FirstUsed
 Selector for first used gamepad. More...
 
struct  LastUsed
 Selector for last used gamepad. More...
 
class  Manager
 Stores and maintains Gamepad states. More...
 

Public Types

enum struct  Id : std::int8_t
 Strong type wrapper for Gamepad ID. More...
 
using Binding = std::variant< FirstUsed, LastUsed, Id >
 Variant of selectors.
 

Public Member Functions

auto get_id () const -> Id
 
auto is_connected () const -> bool
 
auto get_name () const -> klib::CString
 
auto any_button_pressed () const -> bool
 
auto any_axis_nonzero (float dead_zone=nonzero_dead_zone_v) const -> bool
 
auto is_pressed (int button) const -> bool
 
auto get_axis (int axis, float dead_zone=dead_zone_v) const -> float
 

Static Public Attributes

static constexpr float dead_zone_v = 0.08f
 
static constexpr float nonzero_dead_zone_v = 0.2f
 

Detailed Description

Snapshot of gamepad / game controller state.

Note: Use le::Gamepad::get_active() or le::Gamepad::get_by_id() every frame, to get the latest snapshot.

Member Typedef Documentation

◆ Binding

Variant of selectors.

Member Enumeration Documentation

◆ Id

enum struct le::input::Gamepad::Id : std::int8_t
strong

Strong type wrapper for Gamepad ID.

Member Function Documentation

◆ any_axis_nonzero()

auto le::input::Gamepad::any_axis_nonzero ( float  dead_zone = nonzero_dead_zone_v) const -> bool
Parameters
dead_zoneMagnitude floor.
Returns
true if any axis value is above dead_zone.

◆ any_button_pressed()

auto le::input::Gamepad::any_button_pressed ( ) const -> bool
Returns
true if any button is pressed.

◆ get_axis()

auto le::input::Gamepad::get_axis ( int  axis,
float  dead_zone = dead_zone_v 
) const -> float
Parameters
axisGLFW_GAMEPAD_AXIS_<ID>.
dead_zoneMagnitude floor.
Returns
(corrected) current value of axis. Sticks: [-1, +1], triggers: [0, 1]. All 0 at rest.

◆ get_id()

auto le::input::Gamepad::get_id ( ) const -> Id
inline
Returns
ID of this Gamepad instance.

◆ get_name()

auto le::input::Gamepad::get_name ( ) const -> klib::CString
Returns
Name of this Gamepad, as reported by GLFW.

◆ is_connected()

auto le::input::Gamepad::is_connected ( ) const -> bool
inline
Returns
true if this Gamepad instance is connected.

◆ is_pressed()

auto le::input::Gamepad::is_pressed ( int  button) const -> bool
Parameters
buttonGLFW_GAMEPAD_BUTTON_<ID>.
Returns
true if button is pressed.

Member Data Documentation

◆ dead_zone_v

constexpr float le::input::Gamepad::dead_zone_v = 0.08f
staticconstexpr

◆ nonzero_dead_zone_v

constexpr float le::input::Gamepad::nonzero_dead_zone_v = 0.2f
staticconstexpr

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