diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-16 15:26:48 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-16 15:26:48 +0100 |
commit | 8209678e20605936b2ce58331c1a65d8f23fee91 (patch) | |
tree | 6a8c1e236eb1cee716a6a17bc504af3ac29555b6 | |
parent | 027e67b32a9cca3cac4a186e73fdcc42faeab8c4 (diff) |
make format
-rw-r--r-- | src/crepe/api/EventManager.cpp | 13 | ||||
-rw-r--r-- | src/crepe/api/EventManager.h | 2 | ||||
-rw-r--r-- | src/crepe/api/EventManager.hpp | 15 | ||||
-rw-r--r-- | src/crepe/api/IKeyListener.cpp | 72 | ||||
-rw-r--r-- | src/crepe/api/IKeyListener.h | 4 | ||||
-rw-r--r-- | src/crepe/api/IMouseListener.cpp | 40 | ||||
-rw-r--r-- | src/crepe/api/IMouseListener.h | 4 | ||||
-rw-r--r-- | src/crepe/api/KeyCodes.h | 386 |
8 files changed, 295 insertions, 241 deletions
diff --git a/src/crepe/api/EventManager.cpp b/src/crepe/api/EventManager.cpp index a04f08b..7f47938 100644 --- a/src/crepe/api/EventManager.cpp +++ b/src/crepe/api/EventManager.cpp @@ -8,10 +8,12 @@ EventManager & EventManager::get_instance() { } void EventManager::dispatch_events() { - using HandlersMap = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap = std::unordered_map< + int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; - for (auto event_it = this->events_queue.begin(); event_it != this->events_queue.end();) { + for (auto event_it = this->events_queue.begin(); + event_it != this->events_queue.end();) { std::unique_ptr<Event> & event = std::get<0>(*event_it); int channel = std::get<1>(*event_it); std::type_index event_type = std::get<2>(*event_it); @@ -25,7 +27,8 @@ void EventManager::dispatch_events() { auto handlers = handlers_map.find(channel); if (handlers != handlers_map.end()) { HandlersVec & callbacks = handlers->second; - for (auto handler_it = callbacks.begin(); handler_it != callbacks.end(); ++handler_it) { + for (auto handler_it = callbacks.begin(); + handler_it != callbacks.end(); ++handler_it) { if ((*handler_it)->exec(*event)) { event_it = events_queue.erase(event_it); event_handled = true; @@ -39,7 +42,8 @@ void EventManager::dispatch_events() { auto handlers_it = this->subscribers.find(event_type); if (handlers_it != this->subscribers.end()) { HandlersVec & handlers = handlers_it->second; - for (auto handler_it = handlers.begin(); handler_it != handlers.end(); ++handler_it) { + for (auto handler_it = handlers.begin(); + handler_it != handlers.end(); ++handler_it) { // remove event from queue since and continue when callback returns true if ((*handler_it)->exec(*event)) { event_it = this->events_queue.erase(event_it); @@ -55,4 +59,3 @@ void EventManager::dispatch_events() { } } } - diff --git a/src/crepe/api/EventManager.h b/src/crepe/api/EventManager.h index 1ff4031..783db62 100644 --- a/src/crepe/api/EventManager.h +++ b/src/crepe/api/EventManager.h @@ -11,7 +11,7 @@ #include "EventHandler.h" namespace crepe { - + /** * \class EventManager * \brief The EventManager class is responsible for managing the subscription, triggering, diff --git a/src/crepe/api/EventManager.hpp b/src/crepe/api/EventManager.hpp index 1e505f4..d901492 100644 --- a/src/crepe/api/EventManager.hpp +++ b/src/crepe/api/EventManager.hpp @@ -4,7 +4,8 @@ namespace crepe { template <typename EventType> void EventManager::subscribe(EventHandler<EventType> && callback, int channel) { - using HandlersMap = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap = std::unordered_map< + int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; std::type_index event_type = typeid(EventType); @@ -29,7 +30,8 @@ template <typename EventType> void EventManager::queue_event(EventType && event, int channel) { std::type_index event_type = std::type_index(typeid(EventType)); - auto event_ptr = std::make_unique<EventType>(std::forward<EventType>(event)); + auto event_ptr + = std::make_unique<EventType>(std::forward<EventType>(event)); std::tuple<std::unique_ptr<Event>, int, std::type_index> tuple( std::move(event_ptr), channel, event_type); @@ -38,7 +40,8 @@ void EventManager::queue_event(EventType && event, int channel) { template <typename EventType> void EventManager::trigger_event(const EventType & event, int channel) { - using HandlersMap = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; + using HandlersMap = std::unordered_map< + int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; std::type_index event_type = std::type_index(typeid(EventType)); @@ -68,8 +71,10 @@ void EventManager::trigger_event(const EventType & event, int channel) { } template <typename EventType> -void EventManager::unsubscribe(const EventHandler<EventType> & callback, int channel) { - using HandlersMap = std::unordered_map<int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; +void EventManager::unsubscribe(const EventHandler<EventType> & callback, + int channel) { + using HandlersMap = std::unordered_map< + int, std::vector<std::unique_ptr<IEventHandlerWrapper>>>; using HandlersVec = std::vector<std::unique_ptr<IEventHandlerWrapper>>; std::type_index event_type(typeid(EventType)); diff --git a/src/crepe/api/IKeyListener.cpp b/src/crepe/api/IKeyListener.cpp index 81d30b8..cd255df 100644 --- a/src/crepe/api/IKeyListener.cpp +++ b/src/crepe/api/IKeyListener.cpp @@ -3,64 +3,68 @@ using namespace crepe; // Constructor with default channel -IKeyListener::IKeyListener() : channel(0), active(true), event_manager(EventManager::get_instance()) { - this->subscribe_events(); +IKeyListener::IKeyListener() + : channel(0), + active(true), + event_manager(EventManager::get_instance()) { + this->subscribe_events(); } // Constructor with specified channel -IKeyListener::IKeyListener(int channel) : channel(channel), active(true), event_manager(EventManager::get_instance()) { - this->subscribe_events(); +IKeyListener::IKeyListener(int channel) + : channel(channel), + active(true), + event_manager(EventManager::get_instance()) { + this->subscribe_events(); } // Destructor, unsubscribe events -IKeyListener::~IKeyListener() { - this->unsubscribe_events(); -} +IKeyListener::~IKeyListener() { this->unsubscribe_events(); } // Subscribe to key events void IKeyListener::subscribe_events() { - key_pressed_handler = [this](const KeyPressEvent& event) { - return this->on_key_pressed(event); - }; - key_released_handler = [this](const KeyReleaseEvent& event) { - return this->on_key_released(event); - }; + key_pressed_handler = [this](const KeyPressEvent & event) { + return this->on_key_pressed(event); + }; + key_released_handler = [this](const KeyReleaseEvent & event) { + return this->on_key_released(event); + }; - event_manager.subscribe<KeyPressEvent>( - std::move(this->key_pressed_handler), this->channel); - event_manager.subscribe<KeyReleaseEvent>( - std::move(this->key_released_handler), this->channel); + event_manager.subscribe<KeyPressEvent>(std::move(this->key_pressed_handler), + this->channel); + event_manager.subscribe<KeyReleaseEvent>( + std::move(this->key_released_handler), this->channel); } // Unsubscribe from key events void IKeyListener::unsubscribe_events() { - event_manager.unsubscribe<KeyPressEvent>( - this->key_pressed_handler, this->channel); - event_manager.unsubscribe<KeyReleaseEvent>( - this->key_released_handler, this->channel); + event_manager.unsubscribe<KeyPressEvent>(this->key_pressed_handler, + this->channel); + event_manager.unsubscribe<KeyReleaseEvent>(this->key_released_handler, + this->channel); } // Activate key listening void IKeyListener::activate_keys() { - if (this->active) { - return; - } - this->active = true; - this->subscribe_events(); + if (this->active) { + return; + } + this->active = true; + this->subscribe_events(); } // Deactivate key listening void IKeyListener::deactivate_keys() { - if (!this->active) { - return; - } - this->active = false; - this->unsubscribe_events(); + if (!this->active) { + return; + } + this->active = false; + this->unsubscribe_events(); } // Set a new channel for key events void IKeyListener::set_channel(int channel) { - this->unsubscribe_events(); - this->channel = channel; - this->subscribe_events(); + this->unsubscribe_events(); + this->channel = channel; + this->subscribe_events(); } diff --git a/src/crepe/api/IKeyListener.h b/src/crepe/api/IKeyListener.h index 77fbf1e..e170120 100644 --- a/src/crepe/api/IKeyListener.h +++ b/src/crepe/api/IKeyListener.h @@ -5,7 +5,7 @@ #include "EventManager.h" namespace crepe { - + /** * \class IKeyListener * \brief Interface for keyboard event handling in the application. @@ -78,7 +78,7 @@ private: EventHandler<KeyPressEvent> key_pressed_handler; //!< Key release event handler. EventHandler<KeyReleaseEvent> key_released_handler; - EventManager& event_manager; + EventManager & event_manager; }; } // namespace crepe diff --git a/src/crepe/api/IMouseListener.cpp b/src/crepe/api/IMouseListener.cpp index f49004a..bfa49f8 100644 --- a/src/crepe/api/IMouseListener.cpp +++ b/src/crepe/api/IMouseListener.cpp @@ -2,19 +2,17 @@ using namespace crepe; -IMouseListener::IMouseListener(int channel) - : event_manager(EventManager::get_instance()), channel(channel) { - this->subscribe_events(); +IMouseListener::IMouseListener(int channel) + : event_manager(EventManager::get_instance()), + channel(channel) { + this->subscribe_events(); } -IMouseListener::IMouseListener() - : event_manager(EventManager::get_instance()) { - this->subscribe_events(); +IMouseListener::IMouseListener() : event_manager(EventManager::get_instance()) { + this->subscribe_events(); } -IMouseListener::~IMouseListener() { - this->unsubscribe_events(); -} +IMouseListener::~IMouseListener() { this->unsubscribe_events(); } void IMouseListener::subscribe_events() { // Define handler lambdas and subscribe them @@ -32,18 +30,26 @@ void IMouseListener::subscribe_events() { }; // Subscribe event handlers (no need for std::move) - event_manager.subscribe<MouseClickEvent>(std::move(mouse_click_handler), this->channel); - event_manager.subscribe<MousePressEvent>(std::move(mouse_press_handler), this->channel); - event_manager.subscribe<MouseReleaseEvent>(std::move(mouse_release_handler), this->channel); - event_manager.subscribe<MouseMoveEvent>(std::move(mouse_move_handler), this->channel); + event_manager.subscribe<MouseClickEvent>(std::move(mouse_click_handler), + this->channel); + event_manager.subscribe<MousePressEvent>(std::move(mouse_press_handler), + this->channel); + event_manager.subscribe<MouseReleaseEvent>(std::move(mouse_release_handler), + this->channel); + event_manager.subscribe<MouseMoveEvent>(std::move(mouse_move_handler), + this->channel); } void IMouseListener::unsubscribe_events() { // Unsubscribe event handlers - event_manager.unsubscribe<MouseClickEvent>(mouse_click_handler, this->channel); - event_manager.unsubscribe<MousePressEvent>(mouse_press_handler, this->channel); - event_manager.unsubscribe<MouseReleaseEvent>(mouse_release_handler, this->channel); - event_manager.unsubscribe<MouseMoveEvent>(mouse_move_handler, this->channel); + event_manager.unsubscribe<MouseClickEvent>(mouse_click_handler, + this->channel); + event_manager.unsubscribe<MousePressEvent>(mouse_press_handler, + this->channel); + event_manager.unsubscribe<MouseReleaseEvent>(mouse_release_handler, + this->channel); + event_manager.unsubscribe<MouseMoveEvent>(mouse_move_handler, + this->channel); } void IMouseListener::activate_mouse() { diff --git a/src/crepe/api/IMouseListener.h b/src/crepe/api/IMouseListener.h index 3b9e317..37d2f00 100644 --- a/src/crepe/api/IMouseListener.h +++ b/src/crepe/api/IMouseListener.h @@ -5,7 +5,7 @@ #include "EventManager.h" namespace crepe { - + /** * \class IMouseListener * \brief Interface for mouse event handling in the application. @@ -116,7 +116,7 @@ private: EventHandler<MouseReleaseEvent> mouse_release_handler; //! Mouse move event handler. EventHandler<MouseMoveEvent> mouse_move_handler; - EventManager& event_manager; + EventManager & event_manager; }; } //namespace crepe diff --git a/src/crepe/api/KeyCodes.h b/src/crepe/api/KeyCodes.h index a326527..feed0b2 100644 --- a/src/crepe/api/KeyCodes.h +++ b/src/crepe/api/KeyCodes.h @@ -1,186 +1,222 @@ #pragma once -//! \file InputEnums.h -//! \brief Defines enums for mouse buttons and keyboard keycodes used in the application. - //! \enum MouseButton //! \brief Enumeration for mouse button inputs, including standard and extended buttons. enum class MouseButton { - //! No mouse button input. - NONE = 0, - //! Left mouse button. - LEFT_MOUSE = 1, - //! Right mouse button. - RIGHT_MOUSE = 2, - //! Middle mouse button (scroll wheel press). - MIDDLE_MOUSE = 3, - //! First extended mouse button. - X1_MOUSE = 4, - //! Second extended mouse button. - X2_MOUSE = 5, - //! Scroll wheel upward movement. - SCROLL_UP = 6, - //! Scroll wheel downward movement. - SCROLL_DOWN = 7 + //! No mouse button input. + NONE = 0, + //! Left mouse button. + LEFT_MOUSE = 1, + //! Right mouse button. + RIGHT_MOUSE = 2, + //! Middle mouse button (scroll wheel press). + MIDDLE_MOUSE = 3, + //! First extended mouse button. + X1_MOUSE = 4, + //! Second extended mouse button. + X2_MOUSE = 5, + //! Scroll wheel upward movement. + SCROLL_UP = 6, + //! Scroll wheel downward movement. + SCROLL_DOWN = 7 }; //! \enum Keycode //! \brief Enumeration for keyboard key inputs, including printable characters, function keys, and keypad keys. enum class Keycode : int { - //! No key input. - NONE = 0, - //! Spacebar. - SPACE = 32, - //! Apostrophe ('). - APOSTROPHE = 39, - //! Comma (,). - COMMA = 44, - //! Minus (-). - MINUS = 45, - //! Period (.). - PERIOD = 46, - //! Slash (/). - SLASH = 47, - //! Digit 0. - D0 = 48, - //! Digit 1. - D1 = 49, - //! Digit 2. - D2 = 50, - //! Digit 3. - D3 = 51, - //! Digit 4. - D4 = 52, - //! Digit 5. - D5 = 53, - //! Digit 6. - D6 = 54, - //! Digit 7. - D7 = 55, - //! Digit 8. - D8 = 56, - //! Digit 9. - D9 = 57, - //! Semicolon (;). - SEMICOLON = 59, - //! Equal sign (=). - EQUAL = 61, - //! Key 'A'. - A = 65, - //! Key 'B'. - B = 66, - //! Key 'C'. - C = 67, - //! Key 'D'. - D = 68, - //! Key 'E'. - E = 69, - //! Key 'F'. - F = 70, - //! Key 'G'. - G = 71, - //! Key 'H'. - H = 72, - //! Key 'I'. - I = 73, - //! Key 'J'. - J = 74, - //! Key 'K'. - K = 75, - //! Key 'L'. - L = 76, - //! Key 'M'. - M = 77, - //! Key 'N'. - N = 78, - //! Key 'O'. - O = 79, - //! Key 'P'. - P = 80, - //! Key 'Q'. - Q = 81, - //! Key 'R'. - R = 82, - //! Key 'S'. - S = 83, - //! Key 'T'. - T = 84, - //! Key 'U'. - U = 85, - //! Key 'V'. - V = 86, - //! Key 'W'. - W = 87, - //! Key 'X'. - X = 88, - //! Key 'Y'. - Y = 89, - //! Key 'Z'. - Z = 90, - //! Left bracket ([). - LEFT_BRACKET = 91, - //! Backslash (\). - BACKSLASH = 92, - //! Right bracket (]). - RIGHT_BRACKET = 93, - //! Grave accent (`). - GRAVE_ACCENT = 96, - //! Non-US key #1. - WORLD1 = 161, - //! Non-US key #2. - WORLD2 = 162, - //! Escape key. - ESCAPE = 256, - //! Enter key. - ENTER = 257, - //! Tab key. - TAB = 258, - //! Backspace key. - BACKSPACE = 259, - //! Insert key. - INSERT = 260, - //! Delete key. - DELETE = 261, - //! Right arrow key. - RIGHT = 262, - //! Left arrow key. - LEFT = 263, - //! Down arrow key. - DOWN = 264, - //! Up arrow key. - UP = 265, - //! Page Up key. - PAGE_UP = 266, - //! Page Down key. - PAGE_DOWN = 267, - //! Home key. - HOME = 268, - //! End key. - END = 269, - //! Caps Lock key. - CAPS_LOCK = 280, - //! Scroll Lock key. - SCROLL_LOCK = 281, - //! Num Lock key. - NUM_LOCK = 282, - //! Print Screen key. - PRINT_SCREEN = 283, - //! Pause key. - PAUSE = 284, - //! Function keys (F1-F25). - F1 = 290, F2 = 291, F3 = 292, F4 = 293, F5 = 294, - F6 = 295, F7 = 296, F8 = 297, F9 = 298, F10 = 299, - F11 = 300, F12 = 301, F13 = 302, F14 = 303, F15 = 304, - F16 = 305, F17 = 306, F18 = 307, F19 = 308, F20 = 309, - F21 = 310, F22 = 311, F23 = 312, F24 = 313, F25 = 314, - //! Keypad digits and operators. - KP0 = 320, KP1 = 321, KP2 = 322, KP3 = 323, KP4 = 324, - KP5 = 325, KP6 = 326, KP7 = 327, KP8 = 328, KP9 = 329, - KP_DECIMAL = 330, KP_DIVIDE = 331, KP_MULTIPLY = 332, - KP_SUBTRACT = 333, KP_ADD = 334, KP_ENTER = 335, KP_EQUAL = 336, - //! Modifier keys. - LEFT_SHIFT = 340, LEFT_CONTROL = 341, LEFT_ALT = 342, LEFT_SUPER = 343, - RIGHT_SHIFT = 344, RIGHT_CONTROL = 345, RIGHT_ALT = 346, RIGHT_SUPER = 347, - //! Menu key. - MENU = 348 + //! No key input. + NONE = 0, + //! Spacebar. + SPACE = 32, + //! Apostrophe ('). + APOSTROPHE = 39, + //! Comma (,). + COMMA = 44, + //! Minus (-). + MINUS = 45, + //! Period (.). + PERIOD = 46, + //! Slash (/). + SLASH = 47, + //! Digit 0. + D0 = 48, + //! Digit 1. + D1 = 49, + //! Digit 2. + D2 = 50, + //! Digit 3. + D3 = 51, + //! Digit 4. + D4 = 52, + //! Digit 5. + D5 = 53, + //! Digit 6. + D6 = 54, + //! Digit 7. + D7 = 55, + //! Digit 8. + D8 = 56, + //! Digit 9. + D9 = 57, + //! Semicolon (;). + SEMICOLON = 59, + //! Equal sign (=). + EQUAL = 61, + //! Key 'A'. + A = 65, + //! Key 'B'. + B = 66, + //! Key 'C'. + C = 67, + //! Key 'D'. + D = 68, + //! Key 'E'. + E = 69, + //! Key 'F'. + F = 70, + //! Key 'G'. + G = 71, + //! Key 'H'. + H = 72, + //! Key 'I'. + I = 73, + //! Key 'J'. + J = 74, + //! Key 'K'. + K = 75, + //! Key 'L'. + L = 76, + //! Key 'M'. + M = 77, + //! Key 'N'. + N = 78, + //! Key 'O'. + O = 79, + //! Key 'P'. + P = 80, + //! Key 'Q'. + Q = 81, + //! Key 'R'. + R = 82, + //! Key 'S'. + S = 83, + //! Key 'T'. + T = 84, + //! Key 'U'. + U = 85, + //! Key 'V'. + V = 86, + //! Key 'W'. + W = 87, + //! Key 'X'. + X = 88, + //! Key 'Y'. + Y = 89, + //! Key 'Z'. + Z = 90, + //! Left bracket ([). + LEFT_BRACKET = 91, + //! Backslash (\). + BACKSLASH = 92, + //! Right bracket (]). + RIGHT_BRACKET = 93, + //! Grave accent (`). + GRAVE_ACCENT = 96, + //! Non-US key #1. + WORLD1 = 161, + //! Non-US key #2. + WORLD2 = 162, + //! Escape key. + ESCAPE = 256, + //! Enter key. + ENTER = 257, + //! Tab key. + TAB = 258, + //! Backspace key. + BACKSPACE = 259, + //! Insert key. + INSERT = 260, + //! Delete key. + DELETE = 261, + //! Right arrow key. + RIGHT = 262, + //! Left arrow key. + LEFT = 263, + //! Down arrow key. + DOWN = 264, + //! Up arrow key. + UP = 265, + //! Page Up key. + PAGE_UP = 266, + //! Page Down key. + PAGE_DOWN = 267, + //! Home key. + HOME = 268, + //! End key. + END = 269, + //! Caps Lock key. + CAPS_LOCK = 280, + //! Scroll Lock key. + SCROLL_LOCK = 281, + //! Num Lock key. + NUM_LOCK = 282, + //! Print Screen key. + PRINT_SCREEN = 283, + //! Pause key. + PAUSE = 284, + //! Function keys (F1-F25). + F1 = 290, + F2 = 291, + F3 = 292, + F4 = 293, + F5 = 294, + F6 = 295, + F7 = 296, + F8 = 297, + F9 = 298, + F10 = 299, + F11 = 300, + F12 = 301, + F13 = 302, + F14 = 303, + F15 = 304, + F16 = 305, + F17 = 306, + F18 = 307, + F19 = 308, + F20 = 309, + F21 = 310, + F22 = 311, + F23 = 312, + F24 = 313, + F25 = 314, + //! Keypad digits and operators. + KP0 = 320, + KP1 = 321, + KP2 = 322, + KP3 = 323, + KP4 = 324, + KP5 = 325, + KP6 = 326, + KP7 = 327, + KP8 = 328, + KP9 = 329, + KP_DECIMAL = 330, + KP_DIVIDE = 331, + KP_MULTIPLY = 332, + KP_SUBTRACT = 333, + KP_ADD = 334, + KP_ENTER = 335, + KP_EQUAL = 336, + //! Modifier keys. + LEFT_SHIFT = 340, + LEFT_CONTROL = 341, + LEFT_ALT = 342, + LEFT_SUPER = 343, + RIGHT_SHIFT = 344, + RIGHT_CONTROL = 345, + RIGHT_ALT = 346, + RIGHT_SUPER = 347, + //! Menu key. + MENU = 348 }; |