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
action.h
Go to the documentation of this file.
1
20
21#ifndef ASW_ACTION_H
22#define ASW_ACTION_H
23
24#include <string>
25#include <string_view>
26#include <variant>
27
28#include "./input.h"
29
30namespace asw::input {
31
33struct KeyBinding {
35};
36
41
47
54 uint32_t controller_index { 0 };
55 float threshold { 0.5F };
56 bool positive_direction { true };
57};
58
61 = std::variant<KeyBinding, MouseButtonBinding, ControllerButtonBinding, ControllerAxisBinding>;
62
71void bind_action(std::string_view name, ActionBinding binding);
72
77void unbind_action(std::string_view name);
78
81void clear_actions();
82
88bool get_action_down(std::string_view name);
89
95bool get_action_up(std::string_view name);
96
102bool get_action(std::string_view name);
103
113float get_action_strength(std::string_view name);
114
120void update_actions();
121
122} // namespace asw::input
123
124#endif // ASW_ACTION_H
Input module for the ASW library.
bool get_action_down(std::string_view name)
Check if an action was triggered (first pressed) this frame.
Definition action.cpp:141
void bind_action(std::string_view name, ActionBinding binding)
Register a binding for a named action.
Definition action.cpp:126
Key
Enumeration of keys in the ASW library.
Definition input.h:37
void clear_actions()
Remove all registered actions and their bindings.
Definition action.cpp:136
ControllerButton
Mappings from SDL game controller buttons to ASW buttons.
Definition input.h:403
void update_actions()
Update cached action states from current raw input.
Definition action.cpp:165
bool get_action(std::string_view name)
Check if an action is currently held down.
Definition action.cpp:153
float get_action_strength(std::string_view name)
Get the analogue strength of an action (0.0 – 1.0).
Definition action.cpp:159
void unbind_action(std::string_view name)
Remove all bindings for a named action.
Definition action.cpp:131
MouseButton
Enumeration of mouse buttons in the ASW library.
Definition input.h:27
std::variant< KeyBinding, MouseButtonBinding, ControllerButtonBinding, ControllerAxisBinding > ActionBinding
A single input binding — keyboard, mouse button, controller button, or controller axis.
Definition action.h:60
bool get_action_up(std::string_view name)
Check if an action was released this frame.
Definition action.cpp:147
ControllerAxis
Mappings from SDL game controller axes to ASW axes.
Definition input.h:432
Binding to a controller axis, activated when the axis exceeds a threshold.
Definition action.h:52
Binding to a controller (gamepad) button.
Definition action.h:43
Binding to a keyboard key.
Definition action.h:33
Binding to a mouse button.
Definition action.h:38