18 :
EntityNode(entityId), _mouse(entityId), _mapper(entityId)
26 return _mouse.getPositionX();
31 return _mouse.getPositionY();
36 return _mouse.getMousePosition();
46 processEvents(window, screen);
68 std::string indentation =
"";
69 for (
unsigned int i = 0; i < indent; ++i) {
72 std::string result = indentation +
"Event Manager:\n";
76 result += indentation +
"- Mouse info: {\n" + _mouse.getInfo(indent + 1) + indentation +
"}\n";
77 result += indentation +
"- Key Mapper: {\n" + _mapper.getInfo(indent + 1) + indentation +
"}\n";
78 result += indentation +
"- keys: {\n";
79 for (
unsigned int i = 0; i < _keys.size(); i++) {
80 result += indentation +
"\t" +
Recoded::myToString(i) +
": " + _mapper.stringKey(_keys[i]) +
"\n";
82 result += indentation +
"}\n";
89 return _mouse.isMouseInFocus();
94 return _mouse.isMouseLeftButtonClicked();
99 return _mouse.isMouseRightButtonClicked();
104 for (
const auto &keyNodes : _keys) {
105 if (keyNodes == key) {
114 if (_resetIndex >= _resetDelay) {
126 PRETTY_DEBUG <<
"Setting the counter to the reset delay value" << std::endl;
127 _resetIndex = _resetDelay;
128 PRETTY_DEBUG <<
"Calling the clearEvents function" << std::endl;
130 PRETTY_DEBUG <<
"The events have been flushed" << std::endl;
137 std::any eventCapsule = windowItem.
pollEvent();
138 while (eventCapsule.has_value()) {
139 sf::Event
event = std::any_cast<sf::Event>(eventCapsule);
140 if (event.is<sf::Event::Closed>()) {
141 PRETTY_INFO <<
"The window's cross has been clicked." << std::endl;
143 }
else if (
const auto *keyPressed = event.getIf<sf::Event::KeyPressed>()) {
144 sf::Keyboard::Scancode code = keyPressed->scancode;
145 PRETTY_DEBUG <<
"A key was pressed, it's code is: '" << _mapper.stringKey(code) <<
"'." << std::endl;
146 if (code == sf::Keyboard::Scancode::Escape) {
147 PRETTY_INFO <<
"The escape key was pressed." << std::endl;
151 _keys.push_back(_mapper.mapKey(code));
154 _keys.push_back(_mapper.mapKey(code));
157 event.is<sf::Event::MouseButtonPressed>() || event.is<sf::Event::MouseMoved>() ||
158 event.is<sf::Event::MouseWheelScrolled>() || event.is<sf::Event::TouchBegan>() ||
159 event.is<sf::Event::TouchEnded>() || event.is<sf::Event::TouchMoved>()
161 PRETTY_DEBUG <<
"Begin processing the mouse Event." << std::endl;
162 _mouse.update(eventCapsule);
163 PRETTY_DEBUG <<
"End processing the mouse Event." << std::endl;
ActiveScreen
This is the enum class in charge of the window switcher code. This enum allows the mainloop of the pr...
Header file for the EventManager class, responsible for managing input events.
#define PRETTY_DEBUG
Debug log with details and colour.
#define PRETTY_INFO
Info log with details and colour.
Manages input events such as mouse movements, key presses, and window interactions.
const bool isLeftButtonClicked() const
Checks if the left mouse button is clicked.
const std::pair< int, int > getMousePosition() const
Retrieves the current position of the mouse as a pair (x, y).
const bool isRightButtonClicked() const
Checks if the right mouse button is clicked.
const bool isKeyPressed(const GUI::ECS::Systems::Key &key) const
Checks if a specific key is currently pressed.
EventManager & operator=(const GUI::ECS::Systems::EventManager ©)
Assignment operator for the EventManager.
void clearEvents()
Clears all currently stored events if the counter has reached the delay, otherwise,...
const float getPositionY() const
Retrieves the current Y position of the mouse.
const std::vector< GUI::ECS::Systems::Key > getKeys() const
Retrieves all currently pressed keys.
const bool isMouseInFocus() const
Checks if the mouse is in focus within the window.
const GUI::ECS::Systems::MouseInfo getMouseInfo() const
Retrieves the current state of the mouse.
const float getPositionX() const
Retrieves the current X position of the mouse.
void flushEvents()
Forcefully clear all the stored events.
~EventManager()
Destroys the EventManager instance.
EventManager(const std::uint32_t entityId=0)
Constructs an EventManager with an optional entity ID.
const std::string getInfo(const unsigned int indent=0) const
This is a function meant for debugging purposes It will dump the current state of the variables upon ...
void update(GUI::ECS::Systems::Window &window, const ActiveScreen &screen=ActiveScreen::UNKNOWN)
Updates the EventManager with events from a window.
void processEvents(GUI::ECS::Systems::Window &window, const ActiveScreen ¤tScreen=ActiveScreen::UNKNOWN)
Processes events from the specified window.
Manages an SFML-based graphical window and handles rendering of ECS components.
void close()
Closes the window.
std::any pollEvent()
Polls for the next event in the window's event queue.
std::ostream & operator<<(std::ostream &os, const Clock &item)
Outputs the clock's info to a stream.
const std::string myToString(const Rect< RectType > &rectangle)
Converts a Rect<T> object to its string representation.