7#include "../FastSignals/libfastsignals/include/signal.h"
21 template<
typename Ret,
typename... Args>
22 struct Delegate<Ret(Args...)>:
public is::signals::signal<Ret(Args...)> {
23 using callback_type =
typename is::signals::signal<Ret(Args...)>::slot_type;
25 Delegate& operator+=(callback_type callback) { this->connect(callback);
return *
this; }
27 void set(callback_type callback) {
28 this->disconnect_all_slots();
29 this->connect(callback);
31 Delegate& operator=(callback_type callback) { set(callback);
return *
this; }
76 static uint8_t
IsSetPressed(
const std::set<Button>& buttons);
93 static Button btn(MouseButton button) {
return { Type::Mouse, {.mouse = button}}; }
110 static Button pad(GamepadButton button,
int gamepad = 0) {
return { Type::Keyboard, {.gamepad = {gamepad, button}}}; }
119 static Button joy(GamepadButton button,
int gamepad = 0) {
return pad(button, gamepad); }
132 using ButtonSet = std::set<Button>;
163 Up, Down, Left, Right,
164 UpLeft, UpRight, DownLeft, DownRight
166 std::array<ButtonSet, N> directions;
167 std::array<uint8_t, N> lasts;
168 bool normalize =
true;
179 uint8_t last_state = 0;
190 float last_state = 0;
206 Vector2 last_state = { 0, 0 };
216 MultiButtonData<4>* quadButtons;
222 Delegate<void(
const std::string_view name, Vector2 state, Vector2 delta)> callback;
225 Action() : type(Type::Invalid), data({.button = {}}) {}
227 if(type == Type::Button && data.button.buttons)
delete data.button.buttons;
228 else if(type == Type::MultiButton && data.multi.quadButtons)
delete data.multi.quadButtons;
230 Action(Type t, Data d = {.button = {
nullptr,
false, 0}}) : type(t), data(d) {}
231 Action(
const Action&) =
delete;
232 Action(Action&& o) : Action() { *
this = std::move(o); }
233 Action& operator=(
const Action&) =
delete;
234 Action& operator=(Action&& o);
237 Action& AddVectorCallbackNamed(is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type callback) {
238 this->callback.connect(callback);
241 Action& SetVectorCallbackNamed(is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type callback) {
242 this->callback.disconnect_all_slots();
243 return AddVectorCallbackNamed(callback);
245 Action& AddVectorCallback(is::signals::signal<
void(Vector2 state, Vector2 delta)>::slot_type callback) {
246 return AddVectorCallbackNamed((is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
247 [callback = std::move(callback)](
const std::string_view name, Vector2 state, Vector2 delta){
248 callback(state, delta);
251 Action& SetVectorCallback(is::signals::signal<
void(Vector2 state, Vector2 delta)>::slot_type callback) {
252 return SetVectorCallbackNamed((is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
253 [callback = std::move(callback)](
const std::string_view name, Vector2 state, Vector2 delta){
254 callback(state, delta);
259 Action& AddFloatCallbackNamed(is::signals::signal<
void(
const std::string_view name,
float state,
float delta)>::slot_type callback) {
260 return AddVectorCallbackNamed(
261 (is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
262 [callback](
const std::string_view name, Vector2 state, Vector2 delta) {
263 callback(name, state.x, delta.x);
266 Action& SetFloatCallbackNamed(is::signals::signal<
void(
const std::string_view name,
float state,
float delta)>::slot_type callback) {
267 this->callback.disconnect_all_slots();
268 return AddFloatCallbackNamed(callback);
270 Action& AddFloatCallback(is::signals::signal<
void(
float state,
float delta)>::slot_type callback) {
271 return AddFloatCallbackNamed([callback = std::move(callback)](
const std::string_view name,
float state,
float delta){
272 callback(state, delta);
275 Action& SetFloatCallback(is::signals::signal<
void(
float state,
float delta)>::slot_type callback) {
276 return SetFloatCallbackNamed([callback = std::move(callback)](
const std::string_view name,
float state,
float delta){
277 callback(state, delta);
282 Action& AddCallbackNamed(is::signals::signal<
void(
const std::string_view name,
float state,
float delta)>::slot_type callback) {
283 return AddFloatCallbackNamed(callback);
285 Action& SetCallbackNamed(is::signals::signal<
void(
const std::string_view name,
float state,
float delta)>::slot_type callback) {
286 return SetFloatCallbackNamed(callback);
288 Action& AddCallback(is::signals::signal<
void(
float state,
float delta)>::slot_type callback) {
289 return AddFloatCallback(callback);
291 Action& SetCallback(is::signals::signal<
void(
float state,
float delta)>::slot_type callback) {
292 return SetFloatCallback(callback);
296 Action& AddPressedCallbackNamed(is::signals::signal<
void(
const std::string_view name)>::slot_type callback) {
297 return AddVectorCallbackNamed(
298 (is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
299 [callback](
const std::string_view name, Vector2 state, Vector2 delta) {
300 if(state.x) callback(name);
303 Action& SetPressedCallbackNamed(is::signals::signal<
void(
const std::string_view name)>::slot_type callback) {
304 this->callback.disconnect_all_slots();
305 return AddPressedCallbackNamed(callback);
307 Action& AddPressedCallback(is::signals::signal<
void()>::slot_type callback) {
308 return AddVectorCallbackNamed(
309 (is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
310 [callback](
const std::string_view name, Vector2 state, Vector2 delta) {
311 if(state.x) callback();
314 Action& SetPressedCallback(is::signals::signal<
void()>::slot_type callback) {
315 this->callback.disconnect_all_slots();
316 return AddPressedCallback(callback);
319 Action& AddReleasedCallbackNamed(is::signals::signal<
void(
const std::string_view name)>::slot_type callback) {
320 return AddVectorCallbackNamed(
321 (is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
322 [callback](
const std::string_view name, Vector2 state, Vector2 delta) {
323 if(!state.x) callback(name);
326 Action& SetReleasedCallbackNamed(is::signals::signal<
void(
const std::string_view name)>::slot_type callback) {
327 this->callback.disconnect_all_slots();
328 return AddReleasedCallbackNamed(callback);
330 Action& AddReleasedCallback(is::signals::signal<
void()>::slot_type callback) {
331 return AddVectorCallbackNamed(
332 (is::signals::signal<
void(
const std::string_view name, Vector2 state, Vector2 delta)>::slot_type)
333 [callback](
const std::string_view name, Vector2 state, Vector2 delta) {
334 if(!state.x) callback();
337 Action& SetReleasedCallback(is::signals::signal<
void()>::slot_type callback) {
338 this->callback.disconnect_all_slots();
339 return AddReleasedCallback(callback);
385 static Action pad(GamepadButton b,
int gamepad = 0,
bool combo =
false) {
return button({ Button::Type::Keyboard, {.gamepad = {gamepad, b}}}, combo); }
398 static Action joy(GamepadButton b,
int gamepad = 0,
bool combo =
false) {
return pad(b, gamepad, combo); }
423 static Action button_set(ButtonSet buttons = {},
bool combo =
false) {
return Action{Action::Type::Button, Action::Data{ .
button = {
new ButtonSet(buttons), combo }}}; }
434 return {Action::Type::Axis, {.axis = {Data::Axis::Type::Gamepad, {gamepad, axis}}}};
444 return {Action::Type::Axis, {.axis = { Data::Axis::Type::MouseWheel }}};
458 Action out{Action::Type::MultiButton};
459 out.data.multi.type = Data::MultiButton::Type::ButtonPair;
460 out.data.multi.quadButtons =
new MultiButtonData<4>{{ positive, negative }, {}, normalize};
485 return {Action::Type::Vector, {.vector = { Data::Vector::Type::MouseWheel }}};
495 return {Action::Type::Vector, {.vector = { Data::Vector::Type::MousePosition }}};
508 static Action gamepad_axes(GamepadAxis horizontal = GAMEPAD_AXIS_LEFT_X, GamepadAxis vertical = GAMEPAD_AXIS_LEFT_Y,
int gamepadHorizontal = 0,
int gamepadVertical = -1);
524 static Action quad(ButtonSet up, ButtonSet down, ButtonSet left, ButtonSet right,
bool normalized =
true) {
525 Action out{Action::Type::MultiButton};
526 out.data.multi.type = Data::MultiButton::Type::QuadButtons;
527 out.data.multi.quadButtons =
new MultiButtonData<4>{{ up, down, left, right }, {}, normalized};
550 bool normalized = true
551 ) {
return quad(up, down, left, right, normalized); }
562 Action&& move() {
return std::move(*
this); }
573 friend struct BufferedInput;
576 void PumpButton(std::string_view name);
577 void PumpAxis(std::string_view name);
578 void PumpVector(std::string_view name);
579 void PumpMultiButton(std::string_view name);
588 std::map<std::string, Action> actions;
591 Action& operator[](
const std::string& key) {
596 void PollEvents(
bool whileUnfocused =
false);
Input-related functions: gamepads.
All raylib-cpp classes and functions appear in the raylib namespace.
struct combining a gamepad and axis enum and id together
Represents various input action types, such as buttons, axes (controller trigger, mouse wheel),...
static Action button(Button button, bool combo=false)
Action that is invoked whenever the abstract button is pressed.
static Action gamepad_button(GamepadButton b, int gamepad=0, bool combo=false)
Action that is invoked whenever the gamepad button is pressed.
static Action key(KeyboardKey key, bool combo=false)
Action that is invoked whenever the keyboard key is pressed.
Action && Move()
Helper function which moves the action, equivalent to calling std::move but can be chained for conven...
static Action pad(GamepadButton b, int gamepad=0, bool combo=false)
Action that is invoked whenever the gamepad button is pressed.
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...
static Action mouse_wheel()
Action that is invoked whenever the mouse wheel is adjusted.
void PollEvents(std::string_view name)
Function which updates the state of the action and invokes the callback if a change occured.
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.
static Action joy(GamepadButton b, int gamepad=0, bool combo=false)
Action that is invoked whenever the gamepad button is pressed.
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 represen...
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.
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 represen...
static Action mouse_wheel_vector()
Action that is invoked whenever the mouse wheel is adjusted (also supports wheels that can tilt side ...
static Action mouse_button(MouseButton b, bool combo=false)
Action that is invoked whenever the mouse button is pressed.
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...
static Action mouse_position()
Action that is invoked whenever the mouse moves.
static Action button_set(ButtonSet buttons={}, bool combo=false)
Action that is invoked whenever the one of the collection of buttons are pressed.