ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
anonymous_namespace{input.cpp} Namespace Reference

Typedefs

using ControllerState
 Data structure for controller state, including button states and axis values.
 

Functions

float rescale_dead_zone (float magnitude, float dead_zone)
 Rescale a value past the dead zone so it starts from zero.
 
asw::Vec2< float > read_stick (const ControllerState &cont, asw::input::ControllerStick stick)
 Read a stick with a radial dead zone.
 
float read_axis (const ControllerState &cont, asw::input::ControllerAxis axis)
 Read one axis with the dead zone applied.
 
template<typename Pred >
bool any_controller (uint32_t index, Pred pred)
 Check a button on one controller, or on any when index is ANY_CONTROLLER.
 
template<typename Action >
bool each_controller (uint32_t index, Action action)
 Run an action on one controller, or on all when index is ANY_CONTROLLER.
 
uint16_t to_motor_intensity (float intensity)
 Convert an intensity between 0 and 1 to SDL's motor range.
 
bool has_capability (const ControllerState &cont, const char *property)
 Read a boolean capability from a controller's properties.
 
std::string pad_identity (SDL_JoystickID id, SDL_Gamepad *pad)
 What tells a pad apart when it is plugged back in: its serial number, or its model when it has none. Two pads of one model with no serial look the same.
 
bool slot_empty (std::size_t index)
 
std::size_t pick_slot (const std::string &identity)
 Pick the slot for a pad that just connected.
 
SDL_WindowID simulated_window_id ()
 
void push_simulated_key (asw::input::Key key, bool down)
 
void push_simulated_mouse_button (asw::input::MouseButton button, bool down)
 

Variables

std::array< SDL_Cursor *, asw::input::NUM_CURSORS > cursors { nullptr }
 Active cursor stores the current active cursor. It is updated by the core.
 
std::vector< ControllerState > controller { }
 Global controller state. A slot stays at its index while its pad is unplugged, and the pad gets it back when plugged in again, so bindings keep reading the same physical pad.
 
std::vector< std::string > slot_owner { }
 The pad each slot last held, by pad_identity(). Kept after the pad is unplugged and after its slot is dropped from the end of controller, so the pad can get its slot back.
 
float default_dead_zone { 0.25F }
 Dead zone given to pads when they connect.
 
std::unordered_map< SDL_JoystickID, uint32_t > controller_id_map { }
 Map of SDL_JoystickID to controller index in the controller vector.
 
asw::input::KeyState keyboard { }
 
asw::input::MouseState mouse { }
 
std::string text_input
 
asw::input::InputDevice last_device { asw::input::InputDevice::KeyboardMouse }
 

Typedef Documentation

◆ ControllerState

using anonymous_namespace{input.cpp}::ControllerState
Initial value:
struct ControllerState {
std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> pressed { false };
std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> released { false };
std::array<bool, asw::input::NUM_CONTROLLER_BUTTONS> down { false };
bool any_pressed { false };
int last_pressed { -1 };
float dead_zone { 0.25F };
std::array<float, asw::input::NUM_CONTROLLER_AXES> axis { 0 };
SDL_Gamepad* gamepad { nullptr };
std::string name;
}
struct ControllerState { std::array< bool, asw::input::NUM_CONTROLLER_BUTTONS > pressed { false }; std::array< bool, asw::input::NUM_CONTROLLER_BUTTONS > released { false }; std::array< bool, asw::input::NUM_CONTROLLER_BUTTONS > down { false }; bool any_pressed { false }; int last_pressed { -1 }; float dead_zone { 0.25F }; std::array< float, asw::input::NUM_CONTROLLER_AXES > axis { 0 }; SDL_Gamepad *gamepad { nullptr }; std::string name;} ControllerState
Data structure for controller state, including button states and axis values.
Definition input.cpp:15

Data structure for controller state, including button states and axis values.

Definition at line 15 of file input.cpp.

Function Documentation

◆ any_controller()

template<typename Pred >
bool anonymous_namespace{input.cpp}::any_controller ( uint32_t index,
Pred pred )

Check a button on one controller, or on any when index is ANY_CONTROLLER.

Definition at line 109 of file input.cpp.

◆ each_controller()

template<typename Action >
bool anonymous_namespace{input.cpp}::each_controller ( uint32_t index,
Action action )

Run an action on one controller, or on all when index is ANY_CONTROLLER.

Returns
true if the action succeeded on at least one controller.

Definition at line 120 of file input.cpp.

◆ has_capability()

bool anonymous_namespace{input.cpp}::has_capability ( const ControllerState & cont,
const char * property )

Read a boolean capability from a controller's properties.

Definition at line 146 of file input.cpp.

◆ pad_identity()

std::string anonymous_namespace{input.cpp}::pad_identity ( SDL_JoystickID id,
SDL_Gamepad * pad )

What tells a pad apart when it is plugged back in: its serial number, or its model when it has none. Two pads of one model with no serial look the same.

Definition at line 154 of file input.cpp.

◆ pick_slot()

std::size_t anonymous_namespace{input.cpp}::pick_slot ( const std::string & identity)

Pick the slot for a pad that just connected.

Definition at line 171 of file input.cpp.

◆ push_simulated_key()

void anonymous_namespace{input.cpp}::push_simulated_key ( asw::input::Key key,
bool down )

Definition at line 335 of file input.cpp.

◆ push_simulated_mouse_button()

void anonymous_namespace{input.cpp}::push_simulated_mouse_button ( asw::input::MouseButton button,
bool down )

Definition at line 349 of file input.cpp.

◆ read_axis()

float anonymous_namespace{input.cpp}::read_axis ( const ControllerState & cont,
asw::input::ControllerAxis axis )

Read one axis with the dead zone applied.

Definition at line 87 of file input.cpp.

◆ read_stick()

asw::Vec2< float > anonymous_namespace{input.cpp}::read_stick ( const ControllerState & cont,
asw::input::ControllerStick stick )

Read a stick with a radial dead zone.

Definition at line 66 of file input.cpp.

◆ rescale_dead_zone()

float anonymous_namespace{input.cpp}::rescale_dead_zone ( float magnitude,
float dead_zone )

Rescale a value past the dead zone so it starts from zero.

Definition at line 56 of file input.cpp.

◆ simulated_window_id()

SDL_WindowID anonymous_namespace{input.cpp}::simulated_window_id ( )

Definition at line 326 of file input.cpp.

◆ slot_empty()

bool anonymous_namespace{input.cpp}::slot_empty ( std::size_t index)

Definition at line 165 of file input.cpp.

◆ to_motor_intensity()

uint16_t anonymous_namespace{input.cpp}::to_motor_intensity ( float intensity)

Convert an intensity between 0 and 1 to SDL's motor range.

Definition at line 135 of file input.cpp.

Variable Documentation

◆ controller

std::vector<ControllerState> anonymous_namespace{input.cpp}::controller { }

Global controller state. A slot stays at its index while its pad is unplugged, and the pad gets it back when plugged in again, so bindings keep reading the same physical pad.

Definition at line 37 of file input.cpp.

◆ controller_id_map

std::unordered_map<SDL_JoystickID, uint32_t> anonymous_namespace{input.cpp}::controller_id_map { }

Map of SDL_JoystickID to controller index in the controller vector.

Definition at line 48 of file input.cpp.

◆ cursors

std::array<SDL_Cursor*, asw::input::NUM_CURSORS> anonymous_namespace{input.cpp}::cursors { nullptr }

Active cursor stores the current active cursor. It is updated by the core.

Definition at line 32 of file input.cpp.

◆ default_dead_zone

float anonymous_namespace{input.cpp}::default_dead_zone { 0.25F }

Dead zone given to pads when they connect.

Definition at line 45 of file input.cpp.

◆ keyboard

asw::input::KeyState anonymous_namespace{input.cpp}::keyboard { }

Definition at line 50 of file input.cpp.

◆ last_device

asw::input::InputDevice anonymous_namespace{input.cpp}::last_device { asw::input::InputDevice::KeyboardMouse }

Definition at line 53 of file input.cpp.

◆ mouse

asw::input::MouseState anonymous_namespace{input.cpp}::mouse { }

Definition at line 51 of file input.cpp.

◆ slot_owner

std::vector<std::string> anonymous_namespace{input.cpp}::slot_owner { }

The pad each slot last held, by pad_identity(). Kept after the pad is unplugged and after its slot is dropped from the end of controller, so the pad can get its slot back.

Definition at line 42 of file input.cpp.

◆ text_input

std::string anonymous_namespace{input.cpp}::text_input

Definition at line 52 of file input.cpp.