raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Friends | List of all members
raylib::Action Struct Reference

Represents various input action types, such as buttons, axes (controller trigger, mouse wheel), vectors (mouse, thumb stick), and multi-button combinations. More...

#include <BufferedRaylib.hpp>

Classes

struct  Gamepad
 struct combining a gamepad and axis enum and id together More...
 
struct  MultiButtonData
 Struct holding configuration data for multibutton actions. More...
 

Public Types

enum class  Type {
  Invalid = 0 , Button , Axis , Vector ,
  MultiButton
}
 

Public Member Functions

 Action (Action &&o)
 
 Action (const Action &)=delete
 
 Action (Type t, Data d={.button={nullptr, false, 0}})
 
ActionAddCallback (is::signals::signal< void(float state, float delta)>::slot_type callback)
 
ActionAddCallbackNamed (is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type callback)
 
ActionAddFloatCallback (is::signals::signal< void(float state, float delta)>::slot_type callback)
 
ActionAddFloatCallbackNamed (is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type callback)
 
ActionAddPressedCallback (is::signals::signal< void()>::slot_type callback)
 
ActionAddPressedCallbackNamed (is::signals::signal< void(const std::string_view name)>::slot_type callback)
 
ActionAddReleasedCallback (is::signals::signal< void()>::slot_type callback)
 
ActionAddReleasedCallbackNamed (is::signals::signal< void(const std::string_view name)>::slot_type callback)
 
ActionAddVectorCallback (is::signals::signal< void(Vector2 state, Vector2 delta)>::slot_type callback)
 
ActionAddVectorCallbackNamed (is::signals::signal< void(const std::string_view name, Vector2 state, Vector2 delta)>::slot_type callback)
 
Action && Move ()
 Helper function which moves the action, equivalent to calling std::move but can be chained for convenience. More...
 
Action && move ()
 
Actionoperator= (Action &&o)
 
Actionoperator= (const Action &)=delete
 
void PollEvents (std::string_view name)
 Function which updates the state of the action and invokes the callback if a change occured. More...
 
ActionSetCallback (is::signals::signal< void(float state, float delta)>::slot_type callback)
 
ActionSetCallbackNamed (is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type callback)
 
ActionSetFloatCallback (is::signals::signal< void(float state, float delta)>::slot_type callback)
 
ActionSetFloatCallbackNamed (is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type callback)
 
ActionSetPressedCallback (is::signals::signal< void()>::slot_type callback)
 
ActionSetPressedCallbackNamed (is::signals::signal< void(const std::string_view name)>::slot_type callback)
 
ActionSetReleasedCallback (is::signals::signal< void()>::slot_type callback)
 
ActionSetReleasedCallbackNamed (is::signals::signal< void(const std::string_view name)>::slot_type callback)
 
ActionSetVectorCallback (is::signals::signal< void(Vector2 state, Vector2 delta)>::slot_type callback)
 
ActionSetVectorCallbackNamed (is::signals::signal< void(const std::string_view name, Vector2 state, Vector2 delta)>::slot_type callback)
 

Static Public Member Functions

static Action button (Button button, bool combo=false)
 Action that is invoked whenever the abstract button is pressed. More...
 
static Action button_axis (ButtonSet positive, ButtonSet negative, bool normalize=true)
 Action that combines button sets pointing in 2 opposing directions into a signed value which represents the direction of the currently pressed buttons. More...
 
static Action button_pair (ButtonSet left, ButtonSet right, bool normalize=true)
 Action that combines button sets pointing in 2 opposing directions into a signed value which represents the direction of the currently pressed buttons. More...
 
static Action button_set (ButtonSet buttons={}, bool combo=false)
 Action that is invoked whenever the one of the collection of buttons are pressed. More...
 
static Action gamepad_axes (GamepadAxis horizontal=GAMEPAD_AXIS_LEFT_X, GamepadAxis vertical=GAMEPAD_AXIS_LEFT_Y, int gamepadHorizontal=0, int gamepadVertical=-1)
 Action that merges two seperate gamepad axis into a single vector. More...
 
static Action gamepad_axis (GamepadAxis axis=GAMEPAD_AXIS_LEFT_X, int gamepad=0)
 Action that is invoked whenever the gamepad axis (usually triggers) is de/pressed. More...
 
static Action gamepad_button (GamepadButton b, int gamepad=0, bool combo=false)
 Action that is invoked whenever the gamepad button is pressed. More...
 
static Action joy (GamepadButton b, int gamepad=0, bool combo=false)
 Action that is invoked whenever the gamepad button is pressed. More...
 
static Action key (KeyboardKey key, bool combo=false)
 Action that is invoked whenever the keyboard key is pressed. More...
 
static Action mouse_button (MouseButton b, bool combo=false)
 Action that is invoked whenever the mouse button is pressed. More...
 
static Action mouse_position ()
 Action that is invoked whenever the mouse moves. More...
 
static Action mouse_wheel ()
 Action that is invoked whenever the mouse wheel is adjusted. More...
 
static Action mouse_wheel_vector ()
 Action that is invoked whenever the mouse wheel is adjusted (also supports wheels that can tilt side to side). More...
 
static Action pad (GamepadButton b, int gamepad=0, bool combo=false)
 Action that is invoked whenever the gamepad button is pressed. More...
 
static Action quad (ButtonSet up, ButtonSet down, ButtonSet left, ButtonSet right, bool normalized=true)
 Action that combines button sets pointing in 4 cardinal directions into a vector which represents the direction of the currently pressed buttons. More...
 
static Action wasd (ButtonSet up={Button::key(KEY_W), Button::key(KEY_UP)}, ButtonSet left={Button::key(KEY_A), Button::key(KEY_LEFT)}, ButtonSet down={Button::key(KEY_S), Button::key(KEY_DOWN)}, ButtonSet right={Button::key(KEY_D), Button::key(KEY_RIGHT)}, bool normalized=true)
 Action that combines button sets pointing in 4 cardinal directions into a vector which represents the direction of the currently pressed buttons. More...
 

Public Attributes

Delegate< void(const std::string_view name, Vector2 state, Vector2 delta)> callback
 
union raylib::Action::Data data
 
enum raylib::Action::Type type
 

Protected Member Functions

void PumpAxis (std::string_view name)
 
void PumpButton (std::string_view name)
 
void PumpMultiButton (std::string_view name)
 
void PumpVector (std::string_view name)
 

Friends

struct BufferedInput
 

Detailed Description

Represents various input action types, such as buttons, axes (controller trigger, mouse wheel), vectors (mouse, thumb stick), and multi-button combinations.

Definition at line 137 of file BufferedRaylib.hpp.

Member Enumeration Documentation

◆ Type

enum class raylib::Action::Type
strong

Definition at line 139 of file BufferedRaylib.hpp.

Constructor & Destructor Documentation

◆ Action() [1/3]

raylib::Action::Action ( )
inline

Definition at line 225 of file BufferedRaylib.hpp.

◆ ~Action()

raylib::Action::~Action ( )
inline

Definition at line 226 of file BufferedRaylib.hpp.

◆ Action() [2/3]

raylib::Action::Action ( Type  t,
Data  d = {.button = {nullptr, false, 0}} 
)
inline

Definition at line 230 of file BufferedRaylib.hpp.

◆ Action() [3/3]

raylib::Action::Action ( Action &&  o)
inline

Definition at line 232 of file BufferedRaylib.hpp.

Member Function Documentation

◆ AddCallback()

Action & raylib::Action::AddCallback ( is::signals::signal< void(float state, float delta)>::slot_type  callback)
inline

Definition at line 288 of file BufferedRaylib.hpp.

◆ AddCallbackNamed()

Action & raylib::Action::AddCallbackNamed ( is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type  callback)
inline

Definition at line 282 of file BufferedRaylib.hpp.

◆ AddFloatCallback()

Action & raylib::Action::AddFloatCallback ( is::signals::signal< void(float state, float delta)>::slot_type  callback)
inline

Definition at line 270 of file BufferedRaylib.hpp.

◆ AddFloatCallbackNamed()

Action & raylib::Action::AddFloatCallbackNamed ( is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type  callback)
inline

Definition at line 259 of file BufferedRaylib.hpp.

◆ AddPressedCallback()

Action & raylib::Action::AddPressedCallback ( is::signals::signal< void()>::slot_type  callback)
inline

Definition at line 307 of file BufferedRaylib.hpp.

◆ AddPressedCallbackNamed()

Action & raylib::Action::AddPressedCallbackNamed ( is::signals::signal< void(const std::string_view name)>::slot_type  callback)
inline

Definition at line 296 of file BufferedRaylib.hpp.

◆ AddReleasedCallback()

Action & raylib::Action::AddReleasedCallback ( is::signals::signal< void()>::slot_type  callback)
inline

Definition at line 330 of file BufferedRaylib.hpp.

◆ AddReleasedCallbackNamed()

Action & raylib::Action::AddReleasedCallbackNamed ( is::signals::signal< void(const std::string_view name)>::slot_type  callback)
inline

Definition at line 319 of file BufferedRaylib.hpp.

◆ AddVectorCallback()

Action & raylib::Action::AddVectorCallback ( is::signals::signal< void(Vector2 state, Vector2 delta)>::slot_type  callback)
inline

Definition at line 245 of file BufferedRaylib.hpp.

◆ AddVectorCallbackNamed()

Action & raylib::Action::AddVectorCallbackNamed ( is::signals::signal< void(const std::string_view name, Vector2 state, Vector2 delta)>::slot_type  callback)
inline

Definition at line 237 of file BufferedRaylib.hpp.

◆ button()

static Action raylib::Action::button ( Button  button,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the abstract button is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
buttonthe button to listen for
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action

Definition at line 351 of file BufferedRaylib.hpp.

References button().

Referenced by button(), key(), mouse_button(), and pad().

◆ button_axis()

static Action raylib::Action::button_axis ( ButtonSet  positive,
ButtonSet  negative,
bool  normalize = true 
)
inlinestatic

Action that combines button sets pointing in 2 opposing directions into a signed value which represents the direction of the currently pressed buttons.

Callback signature: [](const std::string_view name, float dir, float delta) -> void

Parameters
positiveset of keys to represent the positive direction
negativeset of keys to represent the negative direction
normalizednormally if there is more than one button in a set, the value will grow to reflect how many buttons are pushed. While true the absolute value will never excede 1.
Returns
Action

Definition at line 457 of file BufferedRaylib.hpp.

Referenced by button_pair().

◆ button_pair()

static Action raylib::Action::button_pair ( ButtonSet  left,
ButtonSet  right,
bool  normalize = true 
)
inlinestatic

Action that combines button sets pointing in 2 opposing directions into a signed value which represents the direction of the currently pressed buttons.

Callback signature: [](const std::string_view name, float dir, float delta) -> void

Parameters
leftset of keys to represent left (negative) axis
rightset of keys to represent right (positive) axis
normalizednormally if there is more than one button in a set, the value will grow to reflect how many buttons are pushed. While true the absolute value will never excede 1.
Returns
Action

Definition at line 474 of file BufferedRaylib.hpp.

References button_axis().

◆ button_set()

static Action raylib::Action::button_set ( ButtonSet  buttons = {},
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the one of the collection of buttons are pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
buttonsthe set of buttons to listen for
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action
Note
same as pad

Definition at line 423 of file BufferedRaylib.hpp.

◆ gamepad_axes()

Action raylib::Action::gamepad_axes ( GamepadAxis  horizontal = GAMEPAD_AXIS_LEFT_X,
GamepadAxis  vertical = GAMEPAD_AXIS_LEFT_Y,
int  gamepadHorizontal = 0,
int  gamepadVertical = -1 
)
static

Action that merges two seperate gamepad axis into a single vector.

Callback signature: [](const std::string_view name, Vector2 dir, Vector2 delta) -> void

Parameters
horizontalthe id of axis to listen for horizontal (x) data
verticalthe id of axis to listen for vertical (y) data
gamepadHorizontalid of the gamepad to listen for in the horizontal axis (default 0)
gamepadVerticalid of the gamepad to listen for in the vertical axis. If its value is less than 0, it will copy the horizontal axis (default -1)
Returns
Action

Definition at line 103 of file BufferedRaylib.cpp.

◆ gamepad_axis()

static Action raylib::Action::gamepad_axis ( GamepadAxis  axis = GAMEPAD_AXIS_LEFT_X,
int  gamepad = 0 
)
inlinestatic

Action that is invoked whenever the gamepad axis (usually triggers) is de/pressed.

Callback signature: [](const std::string_view name, float value, float delta) -> void

Parameters
axisthe id of axis to listen for
gamepadid of the gamepad to listen for (default 0)
Returns
Action

Definition at line 433 of file BufferedRaylib.hpp.

◆ gamepad_button()

static Action raylib::Action::gamepad_button ( GamepadButton  b,
int  gamepad = 0,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the gamepad button is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
bthe button to listen for
gamepadid of the gamepad to listen for (default 0)
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action
Note
same as pad

Definition at line 411 of file BufferedRaylib.hpp.

References pad().

◆ joy()

static Action raylib::Action::joy ( GamepadButton  b,
int  gamepad = 0,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the gamepad button is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
bthe button to listen for
gamepadid of the gamepad to listen for (default 0)
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action
Note
same as pad

Definition at line 398 of file BufferedRaylib.hpp.

References pad().

◆ key()

static Action raylib::Action::key ( KeyboardKey  key,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the keyboard key is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
keythe key to listen for
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action

Definition at line 362 of file BufferedRaylib.hpp.

References button(), and key().

Referenced by key().

◆ mouse_button()

static Action raylib::Action::mouse_button ( MouseButton  b,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the mouse button is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
bthe button to listen for
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action

Definition at line 373 of file BufferedRaylib.hpp.

References button().

◆ mouse_position()

static Action raylib::Action::mouse_position ( )
inlinestatic

Action that is invoked whenever the mouse moves.

Callback signature: [](const std::string_view name, Vector2 dir, Vector2 delta) -> void

Returns
Action

Definition at line 494 of file BufferedRaylib.hpp.

◆ mouse_wheel()

static Action raylib::Action::mouse_wheel ( )
inlinestatic

Action that is invoked whenever the mouse wheel is adjusted.

Callback signature: [](const std::string_view name, float value, float delta) -> void

Returns
Action

Definition at line 443 of file BufferedRaylib.hpp.

◆ mouse_wheel_vector()

static Action raylib::Action::mouse_wheel_vector ( )
inlinestatic

Action that is invoked whenever the mouse wheel is adjusted (also supports wheels that can tilt side to side).

Callback signature: [](const std::string_view name, Vector2 dir, Vector2 delta) -> void

Returns
Action

Definition at line 484 of file BufferedRaylib.hpp.

◆ Move()

Action && raylib::Action::Move ( )
inline

Helper function which moves the action, equivalent to calling std::move but can be chained for convenience.

This function is nessicary since delegates (and thus actions) can't be copied, only moved.

Note
After calling this function "this" will have been moved into the reciever and shouldn't be accessed anymore!
Returns
Action&& moveable reference to the action

Definition at line 561 of file BufferedRaylib.hpp.

◆ move()

Action && raylib::Action::move ( )
inline

Definition at line 562 of file BufferedRaylib.hpp.

◆ operator=()

Action & raylib::Action::operator= ( Action &&  o)

Definition at line 42 of file BufferedRaylib.cpp.

◆ pad()

static Action raylib::Action::pad ( GamepadButton  b,
int  gamepad = 0,
bool  combo = false 
)
inlinestatic

Action that is invoked whenever the gamepad button is pressed.

Callback signature: [](const std::string_view name, uint8_t pressed, bool wasPressed) -> void; The value in pressed represents how many buttons in the set are currently pressed

Parameters
bthe button to listen for
gamepadid of the gamepad to listen for (default 0)
combowether all of the buttons in the set need to be pressed for a trigger (defaults to only a single button needing to be pressed)
Returns
Action

Definition at line 385 of file BufferedRaylib.hpp.

References button().

Referenced by gamepad_button(), and joy().

◆ PollEvents()

void raylib::Action::PollEvents ( std::string_view  name)

Function which updates the state of the action and invokes the callback if a change occured.

Note
Automatically called by BufferedInput so there usually isn't a need to manually call this function!
Parameters
namethe name of this action to pass through to the callback

Definition at line 134 of file BufferedRaylib.cpp.

◆ PumpAxis()

void raylib::Action::PumpAxis ( std::string_view  name)
protected

Definition at line 63 of file BufferedRaylib.cpp.

◆ PumpButton()

void raylib::Action::PumpButton ( std::string_view  name)
protected

Definition at line 51 of file BufferedRaylib.cpp.

◆ PumpMultiButton()

void raylib::Action::PumpMultiButton ( std::string_view  name)
protected

Definition at line 111 of file BufferedRaylib.cpp.

◆ PumpVector()

void raylib::Action::PumpVector ( std::string_view  name)
protected

Definition at line 82 of file BufferedRaylib.cpp.

◆ quad()

static Action raylib::Action::quad ( ButtonSet  up,
ButtonSet  down,
ButtonSet  left,
ButtonSet  right,
bool  normalized = true 
)
inlinestatic

Action that combines button sets pointing in 4 cardinal directions into a vector which represents the direction of the currently pressed buttons.

ex. If the up and left buttons are pressed, the resulting vector will be pointing upward and leftward. Callback signature: [](const std::string_view name, Vector2 dir, Vector2 delta) -> void

Parameters
upset of keys to represent up (+y) axis
downset of keys to represent down (-y) axis
leftset of keys to represent left (-x) axis
rightset of keys to represent right (+x) axis
normalizednormally if there is more than one button in a set, the vector's length will grow to reflect how many buttons are pushed. While true none of the vector's axis will ever excede 1.
Note
The resulting vector itself will not be normalized! If you need it to have a length of 1 you will be on your own...
Returns
Action

Definition at line 524 of file BufferedRaylib.hpp.

◆ SetCallback()

Action & raylib::Action::SetCallback ( is::signals::signal< void(float state, float delta)>::slot_type  callback)
inline

Definition at line 291 of file BufferedRaylib.hpp.

◆ SetCallbackNamed()

Action & raylib::Action::SetCallbackNamed ( is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type  callback)
inline

Definition at line 285 of file BufferedRaylib.hpp.

◆ SetFloatCallback()

Action & raylib::Action::SetFloatCallback ( is::signals::signal< void(float state, float delta)>::slot_type  callback)
inline

Definition at line 275 of file BufferedRaylib.hpp.

◆ SetFloatCallbackNamed()

Action & raylib::Action::SetFloatCallbackNamed ( is::signals::signal< void(const std::string_view name, float state, float delta)>::slot_type  callback)
inline

Definition at line 266 of file BufferedRaylib.hpp.

◆ SetPressedCallback()

Action & raylib::Action::SetPressedCallback ( is::signals::signal< void()>::slot_type  callback)
inline

Definition at line 314 of file BufferedRaylib.hpp.

◆ SetPressedCallbackNamed()

Action & raylib::Action::SetPressedCallbackNamed ( is::signals::signal< void(const std::string_view name)>::slot_type  callback)
inline

Definition at line 303 of file BufferedRaylib.hpp.

◆ SetReleasedCallback()

Action & raylib::Action::SetReleasedCallback ( is::signals::signal< void()>::slot_type  callback)
inline

Definition at line 337 of file BufferedRaylib.hpp.

◆ SetReleasedCallbackNamed()

Action & raylib::Action::SetReleasedCallbackNamed ( is::signals::signal< void(const std::string_view name)>::slot_type  callback)
inline

Definition at line 326 of file BufferedRaylib.hpp.

◆ SetVectorCallback()

Action & raylib::Action::SetVectorCallback ( is::signals::signal< void(Vector2 state, Vector2 delta)>::slot_type  callback)
inline

Definition at line 251 of file BufferedRaylib.hpp.

◆ SetVectorCallbackNamed()

Action & raylib::Action::SetVectorCallbackNamed ( is::signals::signal< void(const std::string_view name, Vector2 state, Vector2 delta)>::slot_type  callback)
inline

Definition at line 241 of file BufferedRaylib.hpp.

◆ wasd()

static Action raylib::Action::wasd ( ButtonSet  up = {Button::key(KEY_W), Button::key(KEY_UP)},
ButtonSet  left = {Button::key(KEY_A), Button::key(KEY_LEFT)},
ButtonSet  down = {Button::key(KEY_S), Button::key(KEY_DOWN)},
ButtonSet  right = {Button::key(KEY_D), Button::key(KEY_RIGHT)},
bool  normalized = true 
)
inlinestatic

Action that combines button sets pointing in 4 cardinal directions into a vector which represents the direction of the currently pressed buttons.

ex. If the up and left buttons are pressed, the resulting vector will be pointing upward and leftward. Callback signature: [](const std::string_view name, Vector2 dir, Vector2 delta) -> void

Note
This function is the same as quad, but the parameter order is changed to represent the common wasd convetion (and defaults are set to support it)
Parameters
upset of keys to represent up (+y) axis (default up arrow and w)
leftset of keys to represent left (-x) axis (default left arrow and a)
downset of keys to represent down (-y) axis (default down arrow and s)
rightset of keys to represent right (+x) axis (default right arrow and d)
normalizedwhen true the resulting vector is normalized so that it always has a length of one (default true)
Returns
Action

Definition at line 545 of file BufferedRaylib.hpp.

References raylib::Button::key().

Friends And Related Function Documentation

◆ BufferedInput

friend struct BufferedInput
friend

Definition at line 573 of file BufferedRaylib.hpp.

Member Data Documentation

◆ callback

Delegate<void(const std::string_view name, Vector2 state, Vector2 delta)> raylib::Action::callback

Definition at line 222 of file BufferedRaylib.hpp.