Skip to content

Engine → Platform

gamepad.h

Gamepad buttons and axes: the SDL game controller layout GLFW exposes as GLFW_GAMEPAD_BUTTON_* / GLFW_GAMEPAD_AXIS_*. Up to four gamepads are tracked; joysticks without a gamepad mapping are ignored.

Enumerations

gamepad_axis

enum class gamepad_axis : u8 {
    LEFT_X = 0,
    LEFT_Y,
    RIGHT_X,
    RIGHT_Y,
    LEFT_TRIGGER,       // reported in [0, 1] (GLFW's [-1, 1] is remapped by the backend)
    RIGHT_TRIGGER,      // reported in [0, 1]
    COUNT
};

gamepad_button

enum class gamepad_button : u8 {
    A = 0,
    B,
    X,
    Y,
    LEFT_BUMPER,
    RIGHT_BUMPER,
    BACK,
    START,
    GUIDE,
    LEFT_THUMB,
    RIGHT_THUMB,
    DPAD_UP,
    DPAD_RIGHT,
    DPAD_DOWN,
    DPAD_LEFT,
    COUNT
};

Constants

Name Type Value Description
GAMEPAD_AXIS_COUNT inline constexpr u32 6
GAMEPAD_BUTTON_COUNT inline constexpr u32 15
MAX_GAMEPADS inline constexpr u32 4

Functions

Public

is_valid_gamepad_axis

[[nodiscard]] constexpr bool is_valid_gamepad_axis(
    gamepad_axis axis) noexcept;

True when the value names one of the six axes.

is_valid_gamepad_button

[[nodiscard]] constexpr bool is_valid_gamepad_button(
    gamepad_button button) noexcept;

True when the value names one of the fifteen buttons.

parse_gamepad_axis

[[nodiscard]] CONJURE_API std::optional<gamepad_axis> parse_gamepad_axis(
    std::string_view name) noexcept;

Parses an axis name case-insensitively; nullopt for anything else.

parse_gamepad_button

[[nodiscard]] CONJURE_API std::optional<gamepad_button> parse_gamepad_button(
    std::string_view name) noexcept;

Parses a button name case-insensitively; nullopt for anything else.

to_string

[[nodiscard]] CONJURE_API std::string_view to_string(
    gamepad_button button) noexcept;

The enumerator name ("LEFT_BUMPER"), or "" for unknown values.

[[nodiscard]] CONJURE_API std::string_view to_string(
    gamepad_axis axis) noexcept;

The enumerator name ("RIGHT_TRIGGER"), or "" for unknown values.