ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::sfml::PollEvents Class Reference

Poll events system, polling the events from the RenderWindow resource if present. More...

#include <PollEvents.hpp>

Inheritance diagram for ecstasy::integration::sfml::PollEvents:
Collaboration diagram for ecstasy::integration::sfml::PollEvents:

Public Member Functions

void run (ecstasy::Registry &registry) override final
 Run the system.
 
- Public Member Functions inherited from ecstasy::ISystem
virtual ~ISystem ()=default
 Default destructor.
 
virtual void run (Registry &registry)=0
 Run the system.
 
constexpr TimergetTimer () noexcept
 Get the system timer.
 
constexpr const TimergetTimer () const noexcept
 Get the system timer.
 
constexpr bool enabled () const noexcept
 Whether the system is enabled.
 
constexpr void disable () noexcept
 Disable the system.
 
constexpr void enable () noexcept
 Enable the system.
 

Detailed Description

Poll events system, polling the events from the RenderWindow resource if present.

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-16)

Definition at line 30 of file PollEvents.hpp.

Member Function Documentation

◆ run()

void ecstasy::integration::sfml::PollEvents::run ( ecstasy::Registry registry)
finaloverridevirtual

Run the system.

Mouse events

Keyboard events

Gamepad events

Implements ecstasy::ISystem.

Definition at line 63 of file PollEvents.cpp.

64 {
65 if (!registry.hasResource<RenderWindow>()) [[unlikely]]
66 return;
67 RR<RenderWindow> windowWrapper = registry.getResource<RenderWindow>();
68
69 sf::Event event;
70 while (windowWrapper.get().pollEvent(event)) {
71 switch (event.type) {
73 case sf::Event::MouseButtonPressed:
74 case sf::Event::MouseButtonReleased:
76 event::MouseButtonEvent(static_cast<event::Mouse::Button>(event.mouseButton.button),
77 event.type == sf::Event::MouseButtonPressed));
78 break;
79 case sf::Event::MouseWheelScrolled:
81 event::MouseWheelScrollEvent(event.mouseWheelScroll.delta,
82 static_cast<event::Mouse::Wheel>(event.mouseWheelScroll.wheel)));
83 break;
84 case sf::Event::MouseMoved:
86 registry, event::MouseMoveEvent(event.mouseMove.x, event.mouseMove.y));
87 break;
88
90 case sf::Event::KeyPressed:
91 case sf::Event::KeyReleased:
94 static_cast<event::Keyboard::Key>(event.key.code), event.type == sf::Event::KeyPressed));
95 break;
96 case sf::Event::TextEntered:
98 break;
99
101 case sf::Event::JoystickButtonPressed:
102 case sf::Event::JoystickButtonReleased:
104 event::GamepadButtonEvent(event.joystickButton.joystickId,
105 getGamepadButton(event.joystickButton.button),
106 event.type == sf::Event::JoystickButtonPressed));
107 break;
108 case sf::Event::JoystickConnected:
109 case sf::Event::JoystickDisconnected:
112 event.joystickConnect.joystickId, event.type == sf::Event::JoystickConnected));
113 break;
114 case sf::Event::JoystickMoved:
116 event::GamepadAxisEvent(event.joystickMove.joystickId, getGamepadAxis(event.joystickMove.axis),
117 event.joystickMove.position / 100.f));
118 break;
119
120 case sf::Event::Closed: windowWrapper.get()->close(); break;
121 default: break;
122 }
123 }
124 }
ResourceReference< const R, Locked > getResource() const
Get the Resource of type R.
Definition Registry.hpp:937
bool hasResource() const
Check whether the registry has the resource of type R.
Definition Registry.hpp:918
static void handleEvent(Registry &registry, const Event &event)
Handle an event in a given registry.
Event integration.
Definition Event.hpp:25
static event::Gamepad::Axis getGamepadAxis(int sfmlAxis)
static event::Gamepad::Button getGamepadButton(unsigned int sfmlButton)
Event describing a gamepad axis value change.
Event describing a gamepad button pressed or released.
Event describing a gamepad connection or disconnection.
Event describing a key pressed or released.
Definition KeyEvent.hpp:25
Event describing when a mouse button is pressed or released.
Event describing when the mouse move.
Event describing when a mouse wheel is scrolled.
Event describing a text (character) entered.

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