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 File Reference

Action binding system for the ASW library. More...

#include <string>
#include <string_view>
#include <variant>
#include "./input.h"
Include dependency graph for action.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  asw::input::KeyBinding
 Binding to a keyboard key. More...
 
struct  asw::input::MouseButtonBinding
 Binding to a mouse button. More...
 
struct  asw::input::ControllerButtonBinding
 Binding to a controller (gamepad) button. More...
 
struct  asw::input::ControllerAxisBinding
 Binding to a controller axis, activated when the axis exceeds a threshold. More...
 

Namespaces

namespace  asw
 
namespace  asw::input
 

Typedefs

using asw::input::ActionBinding = std::variant<KeyBinding, MouseButtonBinding, ControllerButtonBinding, ControllerAxisBinding>
 A single input binding — keyboard, mouse button, controller button, or controller axis.
 

Functions

void asw::input::bind_action (std::string_view name, ActionBinding binding)
 Register a binding for a named action.
 
void asw::input::unbind_action (std::string_view name)
 Remove all bindings for a named action.
 
void asw::input::clear_actions ()
 Remove all registered actions and their bindings.
 
bool asw::input::get_action_down (std::string_view name)
 Check if an action was triggered (first pressed) this frame.
 
bool asw::input::get_action_up (std::string_view name)
 Check if an action was released this frame.
 
bool asw::input::get_action (std::string_view name)
 Check if an action is currently held down.
 
float asw::input::get_action_strength (std::string_view name)
 Get the analogue strength of an action (0.0 – 1.0).
 
void asw::input::update_actions ()
 Update cached action states from current raw input.
 

Detailed Description

Action binding system for the ASW library.

Author
Allan Legemaate (alege.nosp@m.maat.nosp@m.e@gma.nosp@m.il.c.nosp@m.om)
Date
2026-03-14

Allows registering named actions backed by one or more mouse, keyboard or controller bindings. Any binding that is active will satisfy the action.

Example:

// In game loop:
if (asw::input::get_action_down("jump")) { /* ... */ }
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
Binding to a controller (gamepad) button.
Definition action.h:43
Binding to a keyboard key.
Definition action.h:33

Definition in file action.h.