ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::event::EventsManager Class Reference

Static helper class to handle ecstasy events. More...

#include <EventsManager.hpp>

Static Public Member Functions

static void handleEvent (Registry &registry, const Event &event)
 Handle an event in a given registry.
 

Private Member Functions

 EventsManager ()
 

Detailed Description

Static helper class to handle ecstasy events.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-06)

Definition at line 30 of file EventsManager.hpp.

Constructor & Destructor Documentation

◆ EventsManager()

ecstasy::integration::event::EventsManager::EventsManager ( )
private

Member Function Documentation

◆ handleEvent()

void ecstasy::integration::event::EventsManager::handleEvent ( Registry registry,
const Event event 
)
static

Handle an event in a given registry.

When an event is send, it update the associated input registry resources (if any) and then calls the associated event listeners in the registry (if any).

Parameters
[in]registryReference to the registry owning the input resources/event listeners components.
[in]eventEvent to handle.
Exceptions
std::invalid_argumentIf the event is 'corrupted' (ie invalid mouse button, invalid key, etc).
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-06)

Definition at line 85 of file EventsManager.cpp.

86 {
87 switch (event.type) {
90 callListeners(registry, event.mouseButton);
91
92 if (registry.hasResource<Mouse>())
93 registry.getResource<Mouse>().get().setButtonState(
94 event.mouseButton.button, event.mouseButton.pressed);
95 break;
96 case Event::Type::MouseWheelScrolled: callListeners(registry, event.mouseWheel); break;
98 callListeners(registry, event.mouseMove);
99
100 if (registry.hasResource<Mouse>()) {
101 RR<Mouse> mouse = registry.getResource<Mouse>();
102 mouse.get().setPosition(
103 event.mouseMove.x + mouse.get().getX(), event.mouseMove.y + mouse.get().getY());
104 }
105 break;
108 callKeyListeners(registry, event.key);
109
110 if (registry.hasResource<Keyboard>())
111 registry.getResource<Keyboard>().get().setKeyState(event.key.key, event.key.pressed);
112 break;
113 case Event::Type::TextEntered: callListeners(registry, event.text); break;
116 callGamepadListeners(registry, event.gamepadButton);
117
118 if (registry.hasResource<Gamepads>())
119 registry.getResource<Gamepads>()
120 .get()
121 .get(event.gamepadButton.id)
122 .setButtonState(event.gamepadButton.button, event.gamepadButton.pressed);
123 break;
126 callListeners(registry, event.gamepadConnected);
127
128 if (registry.hasResource<Gamepads>())
129 registry.getResource<Gamepads>()
130 .get()
131 .get(event.gamepadConnected.id)
132 .setConnected(event.gamepadConnected.connected);
133 break;
135 callListeners(registry, event.gamepadAxis);
136
137 if (registry.hasResource<Gamepads>())
138 registry.getResource<Gamepads>()
139 .get()
140 .get(event.gamepadAxis.id)
141 .setAxisValue(event.gamepadAxis.axis, event.gamepadAxis.value);
142 break;
143 default: break;
144 }
145
146#ifdef ECSTASY_INTEGRATIONS_USER_ACTION
147 if (registry.hasResource<user_action::Users>())
148 registry.getResource<const user_action::Users>().get().handleEvent(registry, event);
149#endif
150 }
Event integration.
Definition Event.hpp:25
static void callListeners(Registry &registry, const E &event)
static void callGamepadListeners(Registry &registry, const GamepadButtonEvent &event)
static void callKeyListeners(Registry &registry, const KeyEvent &event)
@ KeyReleased
One of the keyboard key has been released.
@ MouseButtonPressed
One of the mouse button has been pressed.
@ MouseButtonReleased
One of the mouse button has been released.
@ TextEntered
A character has been entered.
@ MouseWheelScrolled
The mouse wheel was scrolled.
@ GamepadAxis
One of the gamepads axis value changed.
@ KeyPressed
One of the keyboard key has been pressed.
@ GamepadDisconnected
One gamepad has been disconnected.
@ MouseMoved
The mouse cursor moved.
@ GamepadConnected
One gamepad has been connected.
@ GamepadButtonPressed
One of the gamepads button has been pressed.
@ GamepadButtonReleased
One of the gamepads button has been released.

The documentation for this class was generated from the following files: