diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-25 11:48:39 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-25 11:48:39 +0100 |
commit | 48015cd425b26eb68eb07f4e4b1adf71e81e11b1 (patch) | |
tree | 95725bd476cf92c5749e27c44c5134902dedfc66 /src/crepe | |
parent | ea7d7ec301968f3a542de93f487f9501b70c0cd4 (diff) |
make format
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/api/Button.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Button.h | 28 | ||||
-rw-r--r-- | src/crepe/api/Event.h | 6 | ||||
-rw-r--r-- | src/crepe/api/KeyCodes.h | 284 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/UiObject.h | 16 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 357 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 16 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 259 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.h | 43 |
10 files changed, 504 insertions, 513 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp index 70f749d..547c0fc 100644 --- a/src/crepe/api/Button.cpp +++ b/src/crepe/api/Button.cpp @@ -2,4 +2,4 @@ using namespace crepe; -Button::Button(game_object_id_t id) : UiObject(id){} +Button::Button(game_object_id_t id) : UiObject(id) {} diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index f769d58..0056238 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -12,33 +12,33 @@ namespace crepe { */ class Button : public UiObject { public: - /** + /** * \brief Constructs a Button with the specified game object ID. * \param id The unique ID of the game object associated with this button. */ - Button(game_object_id_t id); + Button(game_object_id_t id); - //! Indicates if the button is interactable (can be clicked). - bool interactable = true; + //! Indicates if the button is interactable (can be clicked). + bool interactable = true; - //! Indicates if the button is a toggle button (can be pressed and released). - bool is_toggle = false; + //! Indicates if the button is a toggle button (can be pressed and released). + bool is_toggle = false; - //! Indicates whether the button is currently pressed. - bool is_pressed = false; + //! Indicates whether the button is currently pressed. + bool is_pressed = false; - //! Indicates whether the mouse is currently hovering over the button. - bool hover = false; + //! Indicates whether the mouse is currently hovering over the button. + bool hover = false; - //! The callback function to be executed when the button is clicked. - std::function<void()> on_click; + //! The callback function to be executed when the button is clicked. + std::function<void()> on_click; public: - /** + /** * \brief Retrieves the maximum number of instances allowed for this button type. * \return Always returns 1, as only a single instance is allowed. */ - virtual int get_instances_max() const override { return 1; } + virtual int get_instances_max() const override { return 1; } }; } // namespace crepe diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h index 46dd86b..2018d52 100644 --- a/src/crepe/api/Event.h +++ b/src/crepe/api/Event.h @@ -89,9 +89,9 @@ public: //! Y-coordinate of the mouse position at the time of the event. int mouse_y = 0; // Relative movement in x - int rel_x; + int rel_x; // Relative movement in y - int rel_y; + int rel_y; }; /** @@ -127,4 +127,4 @@ class ShutDownEvent : public Event { public: }; -} +} // namespace crepe diff --git a/src/crepe/api/KeyCodes.h b/src/crepe/api/KeyCodes.h index 4b026c5..fcfc080 100644 --- a/src/crepe/api/KeyCodes.h +++ b/src/crepe/api/KeyCodes.h @@ -1,154 +1,154 @@ #pragma once namespace crepe { - //! Enumeration for mouse button inputs, including standard and extended buttons. - enum class MouseButton { - NONE = 0, //!< No mouse button input. - LEFT_MOUSE = 1, //!< Left mouse button. - RIGHT_MOUSE = 2, //!< Right mouse button. - MIDDLE_MOUSE = 3, //!< Middle mouse button (scroll wheel press). - X1_MOUSE = 4, //!< First extended mouse button. - X2_MOUSE = 5, //!< Second extended mouse button. - SCROLL_UP = 6, //!< Scroll wheel upward movement. - SCROLL_DOWN = 7, //!< Scroll wheel downward movement. - }; +//! Enumeration for mouse button inputs, including standard and extended buttons. +enum class MouseButton { + NONE = 0, //!< No mouse button input. + LEFT_MOUSE = 1, //!< Left mouse button. + RIGHT_MOUSE = 2, //!< Right mouse button. + MIDDLE_MOUSE = 3, //!< Middle mouse button (scroll wheel press). + X1_MOUSE = 4, //!< First extended mouse button. + X2_MOUSE = 5, //!< Second extended mouse button. + SCROLL_UP = 6, //!< Scroll wheel upward movement. + SCROLL_DOWN = 7, //!< Scroll wheel downward movement. +}; - //! Enumeration for keyboard key inputs, including printable characters, function keys, and keypad keys. - enum class Keycode { - NONE = 0, //!< No key input. - SPACE = 32, //!< Spacebar. - APOSTROPHE = 39, //!< Apostrophe ('). - COMMA = 44, //!< Comma (,). - MINUS = 45, //!< Minus (-). - PERIOD = 46, //!< Period (.). - SLASH = 47, //!< Slash (/). - D0 = 48, //!< Digit 0. - D1 = 49, //!< Digit 1. - D2 = 50, //!< Digit 2. - D3 = 51, //!< Digit 3. - D4 = 52, //!< Digit 4. - D5 = 53, //!< Digit 5. - D6 = 54, //!< Digit 6. - D7 = 55, //!< Digit 7. - D8 = 56, //!< Digit 8. - D9 = 57, //!< Digit 9. - SEMICOLON = 59, //!< Semicolon (;). - EQUAL = 61, //!< Equal sign (=). - A = 65, //!< Key 'A'. - B = 66, //!< Key 'B'. - C = 67, //!< Key 'C'. - D = 68, //!< Key 'D'. - E = 69, //!< Key 'E'. - F = 70, //!< Key 'F'. - G = 71, //!< Key 'G'. - H = 72, //!< Key 'H'. - I = 73, //!< Key 'I'. - J = 74, //!< Key 'J'. - K = 75, //!< Key 'K'. - L = 76, //!< Key 'L'. - M = 77, //!< Key 'M'. - N = 78, //!< Key 'N'. - O = 79, //!< Key 'O'. - P = 80, //!< Key 'P'. - Q = 81, //!< Key 'Q'. - R = 82, //!< Key 'R'. - S = 83, //!< Key 'S'. - T = 84, //!< Key 'T'. - U = 85, //!< Key 'U'. - V = 86, //!< Key 'V'. - W = 87, //!< Key 'W'. - X = 88, //!< Key 'X'. - Y = 89, //!< Key 'Y'. - Z = 90, //!< Key 'Z'. - LEFT_BRACKET = 91, //!< Left bracket ([). - BACKSLASH = 92, //!< Backslash (\). - RIGHT_BRACKET = 93, //!< Right bracket (]). - GRAVE_ACCENT = 96, //!< Grave accent (`). - WORLD1 = 161, //!< Non-US key #1. - WORLD2 = 162, //!< Non-US key #2. - ESCAPE = 256, //!< Escape key. - ENTER = 257, //!< Enter key. - TAB = 258, //!< Tab key. - BACKSPACE = 259, //!< Backspace key. - INSERT = 260, //!< Insert key. - DELETE = 261, //!< Delete key. - RIGHT = 262, //!< Right arrow key. - LEFT = 263, //!< Left arrow key. - DOWN = 264, //!< Down arrow key. - UP = 265, //!< Up arrow key. - PAGE_UP = 266, //!< Page Up key. - PAGE_DOWN = 267, //!< Page Down key. - HOME = 268, //!< Home key. - END = 269, //!< End key. - CAPS_LOCK = 280, //!< Caps Lock key. - SCROLL_LOCK = 281, //!< Scroll Lock key. - NUM_LOCK = 282, //!< Num Lock key. - PRINT_SCREEN = 283, //!< Print Screen key. - PAUSE = 284, //!< Pause key. - /** +//! Enumeration for keyboard key inputs, including printable characters, function keys, and keypad keys. +enum class Keycode { + NONE = 0, //!< No key input. + SPACE = 32, //!< Spacebar. + APOSTROPHE = 39, //!< Apostrophe ('). + COMMA = 44, //!< Comma (,). + MINUS = 45, //!< Minus (-). + PERIOD = 46, //!< Period (.). + SLASH = 47, //!< Slash (/). + D0 = 48, //!< Digit 0. + D1 = 49, //!< Digit 1. + D2 = 50, //!< Digit 2. + D3 = 51, //!< Digit 3. + D4 = 52, //!< Digit 4. + D5 = 53, //!< Digit 5. + D6 = 54, //!< Digit 6. + D7 = 55, //!< Digit 7. + D8 = 56, //!< Digit 8. + D9 = 57, //!< Digit 9. + SEMICOLON = 59, //!< Semicolon (;). + EQUAL = 61, //!< Equal sign (=). + A = 65, //!< Key 'A'. + B = 66, //!< Key 'B'. + C = 67, //!< Key 'C'. + D = 68, //!< Key 'D'. + E = 69, //!< Key 'E'. + F = 70, //!< Key 'F'. + G = 71, //!< Key 'G'. + H = 72, //!< Key 'H'. + I = 73, //!< Key 'I'. + J = 74, //!< Key 'J'. + K = 75, //!< Key 'K'. + L = 76, //!< Key 'L'. + M = 77, //!< Key 'M'. + N = 78, //!< Key 'N'. + O = 79, //!< Key 'O'. + P = 80, //!< Key 'P'. + Q = 81, //!< Key 'Q'. + R = 82, //!< Key 'R'. + S = 83, //!< Key 'S'. + T = 84, //!< Key 'T'. + U = 85, //!< Key 'U'. + V = 86, //!< Key 'V'. + W = 87, //!< Key 'W'. + X = 88, //!< Key 'X'. + Y = 89, //!< Key 'Y'. + Z = 90, //!< Key 'Z'. + LEFT_BRACKET = 91, //!< Left bracket ([). + BACKSLASH = 92, //!< Backslash (\). + RIGHT_BRACKET = 93, //!< Right bracket (]). + GRAVE_ACCENT = 96, //!< Grave accent (`). + WORLD1 = 161, //!< Non-US key #1. + WORLD2 = 162, //!< Non-US key #2. + ESCAPE = 256, //!< Escape key. + ENTER = 257, //!< Enter key. + TAB = 258, //!< Tab key. + BACKSPACE = 259, //!< Backspace key. + INSERT = 260, //!< Insert key. + DELETE = 261, //!< Delete key. + RIGHT = 262, //!< Right arrow key. + LEFT = 263, //!< Left arrow key. + DOWN = 264, //!< Down arrow key. + UP = 265, //!< Up arrow key. + PAGE_UP = 266, //!< Page Up key. + PAGE_DOWN = 267, //!< Page Down key. + HOME = 268, //!< Home key. + END = 269, //!< End key. + CAPS_LOCK = 280, //!< Caps Lock key. + SCROLL_LOCK = 281, //!< Scroll Lock key. + NUM_LOCK = 282, //!< Num Lock key. + PRINT_SCREEN = 283, //!< Print Screen key. + PAUSE = 284, //!< Pause key. + /** * \name 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, - /// \} - /** + 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, + /// \} + /** * \name 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, - /// \} - /** + 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, + /// \} + /** * \name 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 = 348, //!< Menu key. - }; -} + 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 = 348, //!< Menu key. +}; +} // namespace crepe diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 9599943..b343250 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -2,11 +2,11 @@ #include "../system/AnimatorSystem.h" #include "../system/CollisionSystem.h" +#include "../system/InputSystem.h" #include "../system/ParticleSystem.h" #include "../system/PhysicsSystem.h" #include "../system/RenderSystem.h" #include "../system/ScriptSystem.h" -#include "../system/InputSystem.h" #include "LoopManager.h" #include "LoopTimer.h" @@ -24,9 +24,7 @@ LoopManager::LoopManager() { this->load_system<InputSystem>(); } -void LoopManager::process_input() { - this->get_system<InputSystem>().update(); -} +void LoopManager::process_input() { this->get_system<InputSystem>().update(); } void LoopManager::start() { this->setup(); diff --git a/src/crepe/api/UiObject.h b/src/crepe/api/UiObject.h index ae2e744..7bd1c2e 100644 --- a/src/crepe/api/UiObject.h +++ b/src/crepe/api/UiObject.h @@ -10,24 +10,24 @@ namespace crepe { */ class UiObject : public Component { public: - /** + /** * \brief Constructs a UiObject with the specified game object ID. * \param id The unique ID of the game object associated with this UI object. */ - UiObject(game_object_id_t id); + UiObject(game_object_id_t id); - //! The width of the UI object. - int width = 0; + //! The width of the UI object. + int width = 0; - //! The height of the UI object. - int height = 0; + //! The height of the UI object. + int height = 0; public: - /** + /** * \brief Retrieves the maximum number of instances allowed for this UI object type. * /return Always returns 1, as only a single instance is allowed. */ - virtual int get_instances_max() const override { return 1; } + virtual int get_instances_max() const override { return 1; } }; } // namespace crepe diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index a37392f..8ed3654 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -5,23 +5,22 @@ #include <SDL2/SDL_render.h> #include <SDL2/SDL_surface.h> #include <SDL2/SDL_video.h> +#include <array> #include <cmath> #include <cstddef> #include <functional> #include <memory> #include <stdexcept> #include <string> -#include <array> #include "../api/Camera.h" +#include "../api/EventManager.h" #include "../api/Sprite.h" #include "../api/Texture.h" #include "../api/Transform.h" -#include "../api/EventManager.h" #include "../api/Vector2.h" #include "../util/Log.h" - #include "SDLContext.h" using namespace crepe; @@ -77,138 +76,138 @@ SDLContext::~SDLContext() { } Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { - static const std::array<Keycode, SDL_NUM_SCANCODES> LOOKUP_TABLE = [] { - std::array<Keycode, SDL_NUM_SCANCODES> table{}; - table.fill(Keycode::NONE); - - table[SDL_SCANCODE_SPACE] = Keycode::SPACE; - table[SDL_SCANCODE_APOSTROPHE] = Keycode::APOSTROPHE; - table[SDL_SCANCODE_COMMA] = Keycode::COMMA; - table[SDL_SCANCODE_MINUS] = Keycode::MINUS; - table[SDL_SCANCODE_PERIOD] = Keycode::PERIOD; - table[SDL_SCANCODE_SLASH] = Keycode::SLASH; - table[SDL_SCANCODE_0] = Keycode::D0; - table[SDL_SCANCODE_1] = Keycode::D1; - table[SDL_SCANCODE_2] = Keycode::D2; - table[SDL_SCANCODE_3] = Keycode::D3; - table[SDL_SCANCODE_4] = Keycode::D4; - table[SDL_SCANCODE_5] = Keycode::D5; - table[SDL_SCANCODE_6] = Keycode::D6; - table[SDL_SCANCODE_7] = Keycode::D7; - table[SDL_SCANCODE_8] = Keycode::D8; - table[SDL_SCANCODE_9] = Keycode::D9; - table[SDL_SCANCODE_SEMICOLON] = Keycode::SEMICOLON; - table[SDL_SCANCODE_EQUALS] = Keycode::EQUAL; - table[SDL_SCANCODE_A] = Keycode::A; - table[SDL_SCANCODE_B] = Keycode::B; - table[SDL_SCANCODE_C] = Keycode::C; - table[SDL_SCANCODE_D] = Keycode::D; - table[SDL_SCANCODE_E] = Keycode::E; - table[SDL_SCANCODE_F] = Keycode::F; - table[SDL_SCANCODE_G] = Keycode::G; - table[SDL_SCANCODE_H] = Keycode::H; - table[SDL_SCANCODE_I] = Keycode::I; - table[SDL_SCANCODE_J] = Keycode::J; - table[SDL_SCANCODE_K] = Keycode::K; - table[SDL_SCANCODE_L] = Keycode::L; - table[SDL_SCANCODE_M] = Keycode::M; - table[SDL_SCANCODE_N] = Keycode::N; - table[SDL_SCANCODE_O] = Keycode::O; - table[SDL_SCANCODE_P] = Keycode::P; - table[SDL_SCANCODE_Q] = Keycode::Q; - table[SDL_SCANCODE_R] = Keycode::R; - table[SDL_SCANCODE_S] = Keycode::S; - table[SDL_SCANCODE_T] = Keycode::T; - table[SDL_SCANCODE_U] = Keycode::U; - table[SDL_SCANCODE_V] = Keycode::V; - table[SDL_SCANCODE_W] = Keycode::W; - table[SDL_SCANCODE_X] = Keycode::X; - table[SDL_SCANCODE_Y] = Keycode::Y; - table[SDL_SCANCODE_Z] = Keycode::Z; - table[SDL_SCANCODE_LEFTBRACKET] = Keycode::LEFT_BRACKET; - table[SDL_SCANCODE_BACKSLASH] = Keycode::BACKSLASH; - table[SDL_SCANCODE_RIGHTBRACKET] = Keycode::RIGHT_BRACKET; - table[SDL_SCANCODE_GRAVE] = Keycode::GRAVE_ACCENT; - table[SDL_SCANCODE_ESCAPE] = Keycode::ESCAPE; - table[SDL_SCANCODE_RETURN] = Keycode::ENTER; - table[SDL_SCANCODE_TAB] = Keycode::TAB; - table[SDL_SCANCODE_BACKSPACE] = Keycode::BACKSPACE; - table[SDL_SCANCODE_INSERT] = Keycode::INSERT; - table[SDL_SCANCODE_DELETE] = Keycode::DELETE; - table[SDL_SCANCODE_RIGHT] = Keycode::RIGHT; - table[SDL_SCANCODE_LEFT] = Keycode::LEFT; - table[SDL_SCANCODE_DOWN] = Keycode::DOWN; - table[SDL_SCANCODE_UP] = Keycode::UP; - table[SDL_SCANCODE_PAGEUP] = Keycode::PAGE_UP; - table[SDL_SCANCODE_PAGEDOWN] = Keycode::PAGE_DOWN; - table[SDL_SCANCODE_HOME] = Keycode::HOME; - table[SDL_SCANCODE_END] = Keycode::END; - table[SDL_SCANCODE_CAPSLOCK] = Keycode::CAPS_LOCK; - table[SDL_SCANCODE_SCROLLLOCK] = Keycode::SCROLL_LOCK; - table[SDL_SCANCODE_NUMLOCKCLEAR] = Keycode::NUM_LOCK; - table[SDL_SCANCODE_PRINTSCREEN] = Keycode::PRINT_SCREEN; - table[SDL_SCANCODE_PAUSE] = Keycode::PAUSE; - table[SDL_SCANCODE_F1] = Keycode::F1; - table[SDL_SCANCODE_F2] = Keycode::F2; - table[SDL_SCANCODE_F3] = Keycode::F3; - table[SDL_SCANCODE_F4] = Keycode::F4; - table[SDL_SCANCODE_F5] = Keycode::F5; - table[SDL_SCANCODE_F6] = Keycode::F6; - table[SDL_SCANCODE_F7] = Keycode::F7; - table[SDL_SCANCODE_F8] = Keycode::F8; - table[SDL_SCANCODE_F9] = Keycode::F9; - table[SDL_SCANCODE_F10] = Keycode::F10; - table[SDL_SCANCODE_F11] = Keycode::F11; - table[SDL_SCANCODE_F12] = Keycode::F12; - table[SDL_SCANCODE_KP_0] = Keycode::KP0; - table[SDL_SCANCODE_KP_1] = Keycode::KP1; - table[SDL_SCANCODE_KP_2] = Keycode::KP2; - table[SDL_SCANCODE_KP_3] = Keycode::KP3; - table[SDL_SCANCODE_KP_4] = Keycode::KP4; - table[SDL_SCANCODE_KP_5] = Keycode::KP5; - table[SDL_SCANCODE_KP_6] = Keycode::KP6; - table[SDL_SCANCODE_KP_7] = Keycode::KP7; - table[SDL_SCANCODE_KP_8] = Keycode::KP8; - table[SDL_SCANCODE_KP_9] = Keycode::KP9; - table[SDL_SCANCODE_LSHIFT] = Keycode::LEFT_SHIFT; - table[SDL_SCANCODE_LCTRL] = Keycode::LEFT_CONTROL; - table[SDL_SCANCODE_LALT] = Keycode::LEFT_ALT; - table[SDL_SCANCODE_LGUI] = Keycode::LEFT_SUPER; - table[SDL_SCANCODE_RSHIFT] = Keycode::RIGHT_SHIFT; - table[SDL_SCANCODE_RCTRL] = Keycode::RIGHT_CONTROL; - table[SDL_SCANCODE_RALT] = Keycode::RIGHT_ALT; - table[SDL_SCANCODE_RGUI] = Keycode::RIGHT_SUPER; - table[SDL_SCANCODE_MENU] = Keycode::MENU; - - return table; - }(); - - if (sdl_key < 0 || sdl_key >= SDL_NUM_SCANCODES) { - return Keycode::NONE; - } - - return LOOKUP_TABLE[sdl_key]; + static const std::array<Keycode, SDL_NUM_SCANCODES> LOOKUP_TABLE = [] { + std::array<Keycode, SDL_NUM_SCANCODES> table{}; + table.fill(Keycode::NONE); + + table[SDL_SCANCODE_SPACE] = Keycode::SPACE; + table[SDL_SCANCODE_APOSTROPHE] = Keycode::APOSTROPHE; + table[SDL_SCANCODE_COMMA] = Keycode::COMMA; + table[SDL_SCANCODE_MINUS] = Keycode::MINUS; + table[SDL_SCANCODE_PERIOD] = Keycode::PERIOD; + table[SDL_SCANCODE_SLASH] = Keycode::SLASH; + table[SDL_SCANCODE_0] = Keycode::D0; + table[SDL_SCANCODE_1] = Keycode::D1; + table[SDL_SCANCODE_2] = Keycode::D2; + table[SDL_SCANCODE_3] = Keycode::D3; + table[SDL_SCANCODE_4] = Keycode::D4; + table[SDL_SCANCODE_5] = Keycode::D5; + table[SDL_SCANCODE_6] = Keycode::D6; + table[SDL_SCANCODE_7] = Keycode::D7; + table[SDL_SCANCODE_8] = Keycode::D8; + table[SDL_SCANCODE_9] = Keycode::D9; + table[SDL_SCANCODE_SEMICOLON] = Keycode::SEMICOLON; + table[SDL_SCANCODE_EQUALS] = Keycode::EQUAL; + table[SDL_SCANCODE_A] = Keycode::A; + table[SDL_SCANCODE_B] = Keycode::B; + table[SDL_SCANCODE_C] = Keycode::C; + table[SDL_SCANCODE_D] = Keycode::D; + table[SDL_SCANCODE_E] = Keycode::E; + table[SDL_SCANCODE_F] = Keycode::F; + table[SDL_SCANCODE_G] = Keycode::G; + table[SDL_SCANCODE_H] = Keycode::H; + table[SDL_SCANCODE_I] = Keycode::I; + table[SDL_SCANCODE_J] = Keycode::J; + table[SDL_SCANCODE_K] = Keycode::K; + table[SDL_SCANCODE_L] = Keycode::L; + table[SDL_SCANCODE_M] = Keycode::M; + table[SDL_SCANCODE_N] = Keycode::N; + table[SDL_SCANCODE_O] = Keycode::O; + table[SDL_SCANCODE_P] = Keycode::P; + table[SDL_SCANCODE_Q] = Keycode::Q; + table[SDL_SCANCODE_R] = Keycode::R; + table[SDL_SCANCODE_S] = Keycode::S; + table[SDL_SCANCODE_T] = Keycode::T; + table[SDL_SCANCODE_U] = Keycode::U; + table[SDL_SCANCODE_V] = Keycode::V; + table[SDL_SCANCODE_W] = Keycode::W; + table[SDL_SCANCODE_X] = Keycode::X; + table[SDL_SCANCODE_Y] = Keycode::Y; + table[SDL_SCANCODE_Z] = Keycode::Z; + table[SDL_SCANCODE_LEFTBRACKET] = Keycode::LEFT_BRACKET; + table[SDL_SCANCODE_BACKSLASH] = Keycode::BACKSLASH; + table[SDL_SCANCODE_RIGHTBRACKET] = Keycode::RIGHT_BRACKET; + table[SDL_SCANCODE_GRAVE] = Keycode::GRAVE_ACCENT; + table[SDL_SCANCODE_ESCAPE] = Keycode::ESCAPE; + table[SDL_SCANCODE_RETURN] = Keycode::ENTER; + table[SDL_SCANCODE_TAB] = Keycode::TAB; + table[SDL_SCANCODE_BACKSPACE] = Keycode::BACKSPACE; + table[SDL_SCANCODE_INSERT] = Keycode::INSERT; + table[SDL_SCANCODE_DELETE] = Keycode::DELETE; + table[SDL_SCANCODE_RIGHT] = Keycode::RIGHT; + table[SDL_SCANCODE_LEFT] = Keycode::LEFT; + table[SDL_SCANCODE_DOWN] = Keycode::DOWN; + table[SDL_SCANCODE_UP] = Keycode::UP; + table[SDL_SCANCODE_PAGEUP] = Keycode::PAGE_UP; + table[SDL_SCANCODE_PAGEDOWN] = Keycode::PAGE_DOWN; + table[SDL_SCANCODE_HOME] = Keycode::HOME; + table[SDL_SCANCODE_END] = Keycode::END; + table[SDL_SCANCODE_CAPSLOCK] = Keycode::CAPS_LOCK; + table[SDL_SCANCODE_SCROLLLOCK] = Keycode::SCROLL_LOCK; + table[SDL_SCANCODE_NUMLOCKCLEAR] = Keycode::NUM_LOCK; + table[SDL_SCANCODE_PRINTSCREEN] = Keycode::PRINT_SCREEN; + table[SDL_SCANCODE_PAUSE] = Keycode::PAUSE; + table[SDL_SCANCODE_F1] = Keycode::F1; + table[SDL_SCANCODE_F2] = Keycode::F2; + table[SDL_SCANCODE_F3] = Keycode::F3; + table[SDL_SCANCODE_F4] = Keycode::F4; + table[SDL_SCANCODE_F5] = Keycode::F5; + table[SDL_SCANCODE_F6] = Keycode::F6; + table[SDL_SCANCODE_F7] = Keycode::F7; + table[SDL_SCANCODE_F8] = Keycode::F8; + table[SDL_SCANCODE_F9] = Keycode::F9; + table[SDL_SCANCODE_F10] = Keycode::F10; + table[SDL_SCANCODE_F11] = Keycode::F11; + table[SDL_SCANCODE_F12] = Keycode::F12; + table[SDL_SCANCODE_KP_0] = Keycode::KP0; + table[SDL_SCANCODE_KP_1] = Keycode::KP1; + table[SDL_SCANCODE_KP_2] = Keycode::KP2; + table[SDL_SCANCODE_KP_3] = Keycode::KP3; + table[SDL_SCANCODE_KP_4] = Keycode::KP4; + table[SDL_SCANCODE_KP_5] = Keycode::KP5; + table[SDL_SCANCODE_KP_6] = Keycode::KP6; + table[SDL_SCANCODE_KP_7] = Keycode::KP7; + table[SDL_SCANCODE_KP_8] = Keycode::KP8; + table[SDL_SCANCODE_KP_9] = Keycode::KP9; + table[SDL_SCANCODE_LSHIFT] = Keycode::LEFT_SHIFT; + table[SDL_SCANCODE_LCTRL] = Keycode::LEFT_CONTROL; + table[SDL_SCANCODE_LALT] = Keycode::LEFT_ALT; + table[SDL_SCANCODE_LGUI] = Keycode::LEFT_SUPER; + table[SDL_SCANCODE_RSHIFT] = Keycode::RIGHT_SHIFT; + table[SDL_SCANCODE_RCTRL] = Keycode::RIGHT_CONTROL; + table[SDL_SCANCODE_RALT] = Keycode::RIGHT_ALT; + table[SDL_SCANCODE_RGUI] = Keycode::RIGHT_SUPER; + table[SDL_SCANCODE_MENU] = Keycode::MENU; + + return table; + }(); + + if (sdl_key < 0 || sdl_key >= SDL_NUM_SCANCODES) { + return Keycode::NONE; + } + + return LOOKUP_TABLE[sdl_key]; } MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { - static const std::array<MouseButton, 5> MOUSE_BUTTON_LOOKUP_TABLE = [] { - std::array<MouseButton, 5> table{}; - table.fill(MouseButton::NONE); - - table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE; - table[SDL_BUTTON_RIGHT] = MouseButton::RIGHT_MOUSE; - table[SDL_BUTTON_MIDDLE] = MouseButton::MIDDLE_MOUSE; - table[SDL_BUTTON_X1] = MouseButton::X1_MOUSE; - table[SDL_BUTTON_X2] = MouseButton::X2_MOUSE; - - return table; - }(); - - if (sdl_button >= MOUSE_BUTTON_LOOKUP_TABLE.size()) { - // Return NONE for invalid or unmapped button - return MouseButton::NONE; - } + static const std::array<MouseButton, 5> MOUSE_BUTTON_LOOKUP_TABLE = [] { + std::array<MouseButton, 5> table{}; + table.fill(MouseButton::NONE); + + table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE; + table[SDL_BUTTON_RIGHT] = MouseButton::RIGHT_MOUSE; + table[SDL_BUTTON_MIDDLE] = MouseButton::MIDDLE_MOUSE; + table[SDL_BUTTON_X1] = MouseButton::X1_MOUSE; + table[SDL_BUTTON_X2] = MouseButton::X2_MOUSE; + + return table; + }(); + + if (sdl_button >= MOUSE_BUTTON_LOOKUP_TABLE.size()) { + // Return NONE for invalid or unmapped button + return MouseButton::NONE; + } - return MOUSE_BUTTON_LOOKUP_TABLE[sdl_button]; + return MOUSE_BUTTON_LOOKUP_TABLE[sdl_button]; } void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer.get()); } void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer.get()); } @@ -310,73 +309,63 @@ int SDLContext::get_height(const Texture & ctx) const { } void SDLContext::delay(int ms) const { SDL_Delay(ms); } -std::vector<SDLContext::EventData> SDLContext::get_events(){ +std::vector<SDLContext::EventData> SDLContext::get_events() { std::vector<SDLContext::EventData> event_list; SDL_Event event; while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - event_list.push_back(EventData{ + switch (event.type) { + case SDL_QUIT: + event_list.push_back(EventData{ .event_type = SDLContext::Event::SHUTDOWN, }); break; - case SDL_KEYDOWN: + case SDL_KEYDOWN: event_list.push_back(EventData{ .event_type = SDLContext::Event::KEYDOWN, .key = sdl_to_keycode(event.key.keysym.scancode), .key_repeat = (event.key.repeat != 0), }); break; - case SDL_KEYUP: + case SDL_KEYUP: event_list.push_back(EventData{ .event_type = SDLContext::Event::KEYUP, .key = sdl_to_keycode(event.key.keysym.scancode), }); - break; - case SDL_MOUSEBUTTONDOWN: - { - int x,y; - SDL_GetMouseState(&x, &y); - event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEDOWN, - .mouse_button = sdl_to_mousebutton(event.button.button), - .mouse_position = {event.button.x,event.button.y}, - }); - } - break; - case SDL_MOUSEBUTTONUP: - { - int x,y; - SDL_GetMouseState(&x, &y); - event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEUP, - .mouse_button = sdl_to_mousebutton(event.button.button), - .mouse_position = {event.button.x,event.button.y}, - }); - } - break; - - case SDL_MOUSEMOTION: - { - event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEMOVE, - .mouse_position = {event.motion.x,event.motion.y}, - .rel_mouse_move = {event.motion.xrel,event.motion.yrel} - }); - } - break; - - case SDL_MOUSEWHEEL: - { - event_list.push_back(EventData{ - .event_type = SDLContext::Event::MOUSEWHEEL, - .mouse_position = {event.motion.x,event.motion.y}, - .wheel_delta = event.wheel.y, - }); - } - break; - } - } + break; + case SDL_MOUSEBUTTONDOWN: { + int x, y; + SDL_GetMouseState(&x, &y); + event_list.push_back(EventData{ + .event_type = SDLContext::Event::MOUSEDOWN, + .mouse_button = sdl_to_mousebutton(event.button.button), + .mouse_position = {event.button.x, event.button.y}, + }); + } break; + case SDL_MOUSEBUTTONUP: { + int x, y; + SDL_GetMouseState(&x, &y); + event_list.push_back(EventData{ + .event_type = SDLContext::Event::MOUSEUP, + .mouse_button = sdl_to_mousebutton(event.button.button), + .mouse_position = {event.button.x, event.button.y}, + }); + } break; + + case SDL_MOUSEMOTION: { + event_list.push_back( + EventData{.event_type = SDLContext::Event::MOUSEMOVE, + .mouse_position = {event.motion.x, event.motion.y}, + .rel_mouse_move = {event.motion.xrel, event.motion.yrel}}); + } break; + + case SDL_MOUSEWHEEL: { + event_list.push_back(EventData{ + .event_type = SDLContext::Event::MOUSEWHEEL, + .mouse_position = {event.motion.x, event.motion.y}, + .wheel_delta = event.wheel.y, + }); + } break; + } + } return event_list; } - diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 1b881d1..7ec11fd 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -6,15 +6,15 @@ #include <SDL2/SDL_video.h> #include <cmath> #include <functional> -#include <utility> #include <memory> #include <string> +#include <utility> -#include "../api/Sprite.h" +#include "../api/Event.h" #include "../api/KeyCodes.h" +#include "../api/Sprite.h" #include "../api/Transform.h" #include "../api/Vector2.h" -#include "../api/Event.h" #include "api/Camera.h" #include "types.h" @@ -36,7 +36,7 @@ class InputSystem; class SDLContext { public: - enum Event{ + enum Event { NONE = 0, MOUSEDOWN, MOUSEUP, @@ -52,9 +52,9 @@ public: Keycode key = Keycode::NONE; bool key_repeat = false; MouseButton mouse_button = MouseButton::NONE; - std::pair<int,int> mouse_position = {-1,-1}; + std::pair<int, int> mouse_position = {-1, -1}; int wheel_delta = -1; - std::pair<int,int> rel_mouse_move = {-1,-1}; + std::pair<int, int> rel_mouse_move = {-1, -1}; }; /** * \brief Gets the singleton instance of SDLContext. @@ -75,11 +75,12 @@ private: * \param running Reference to a boolean flag that controls the main loop. */ std::vector<SDLContext::EventData> get_events(); - + Keycode get_key(); Keycode get_mouse(); Keycode sdl_to_keycode(SDL_Keycode sdlKey); MouseButton sdl_to_mousebutton(Uint8 sdl_button); + private: //! Will only use get_ticks friend class AnimatorSystem; @@ -197,5 +198,4 @@ private: SDL_Rect viewport = {0, 0, 640, 480}; }; - } // namespace crepe diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 1b455cd..7f7f9ec 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -1,154 +1,155 @@ -#include "ComponentManager.h" -#include "../api/EventManager.h" #include "../api/Event.h" - +#include "../api/EventManager.h" +#include "ComponentManager.h" #include "system/InputSystem.h" using namespace crepe; void InputSystem::update() { - EventManager &event_mgr = EventManager::get_instance(); - std::vector<SDLContext::EventData> event_list = SDLContext::get_instance().get_events(); - - for (const SDLContext::EventData &event : event_list) { - switch (event.event_type) { - case SDLContext::Event::KEYDOWN: { - event_mgr.queue_event<KeyPressEvent>(KeyPressEvent{ - .repeat = event.key_repeat, - .key = event.key, - }); - break; - } - case SDLContext::Event::KEYUP: { - event_mgr.queue_event<KeyReleaseEvent>(KeyReleaseEvent{ - .key = event.key, - }); - break; - } - case SDLContext::Event::MOUSEDOWN: { - event_mgr.queue_event<MousePressEvent>(MousePressEvent{ - .mouse_x = event.mouse_position.first, - .mouse_y = event.mouse_position.second, - .button = event.mouse_button, - }); - last_mouse_down_position = event.mouse_position; - last_mouse_button = event.mouse_button; - break; - } - case SDLContext::Event::MOUSEUP: { - MouseReleaseEvent mouse_release_event = MouseReleaseEvent{ - .mouse_x = event.mouse_position.first, - .mouse_y = event.mouse_position.second, - .button = event.mouse_button, - }; - event_mgr.queue_event<MouseReleaseEvent>(mouse_release_event); - - // Calculate deltas for click detection - int delta_x = event.mouse_position.first - last_mouse_down_position.first; - int delta_y = event.mouse_position.second - last_mouse_down_position.second; - - if (last_mouse_button == event.mouse_button && - std::abs(delta_x) <= click_tolerance && - std::abs(delta_y) <= click_tolerance) { - event_mgr.queue_event<MouseClickEvent>(MouseClickEvent{ - .mouse_x = event.mouse_position.first, - .mouse_y = event.mouse_position.second, - .button = event.mouse_button, - }); - - handle_click(event); - } - break; - } - case SDLContext::Event::MOUSEMOVE: { - event_mgr.queue_event<MouseMoveEvent>(MouseMoveEvent{ - .mouse_x = event.mouse_position.first, - .mouse_y = event.mouse_position.second, - .rel_x = event.rel_mouse_move.first, - .rel_y = event.rel_mouse_move.second, - }); - handle_move(event); - break; - } - case SDLContext::Event::MOUSEWHEEL: { - event_mgr.queue_event<MouseScrollEvent>(MouseScrollEvent{ - .scroll_x = event.wheel_delta, - .scroll_y = 0, - .direction = event.wheel_delta, - }); - break; - } - case SDLContext::Event::SHUTDOWN: { - event_mgr.queue_event<ShutDownEvent>(ShutDownEvent{}); - break; - } - default: - break; - } - } + EventManager & event_mgr = EventManager::get_instance(); + std::vector<SDLContext::EventData> event_list = SDLContext::get_instance().get_events(); + + for (const SDLContext::EventData & event : event_list) { + switch (event.event_type) { + case SDLContext::Event::KEYDOWN: { + event_mgr.queue_event<KeyPressEvent>(KeyPressEvent{ + .repeat = event.key_repeat, + .key = event.key, + }); + break; + } + case SDLContext::Event::KEYUP: { + event_mgr.queue_event<KeyReleaseEvent>(KeyReleaseEvent{ + .key = event.key, + }); + break; + } + case SDLContext::Event::MOUSEDOWN: { + event_mgr.queue_event<MousePressEvent>(MousePressEvent{ + .mouse_x = event.mouse_position.first, + .mouse_y = event.mouse_position.second, + .button = event.mouse_button, + }); + last_mouse_down_position = event.mouse_position; + last_mouse_button = event.mouse_button; + break; + } + case SDLContext::Event::MOUSEUP: { + MouseReleaseEvent mouse_release_event = MouseReleaseEvent{ + .mouse_x = event.mouse_position.first, + .mouse_y = event.mouse_position.second, + .button = event.mouse_button, + }; + event_mgr.queue_event<MouseReleaseEvent>(mouse_release_event); + + // Calculate deltas for click detection + int delta_x = event.mouse_position.first - last_mouse_down_position.first; + int delta_y = event.mouse_position.second - last_mouse_down_position.second; + + if (last_mouse_button == event.mouse_button + && std::abs(delta_x) <= click_tolerance + && std::abs(delta_y) <= click_tolerance) { + event_mgr.queue_event<MouseClickEvent>(MouseClickEvent{ + .mouse_x = event.mouse_position.first, + .mouse_y = event.mouse_position.second, + .button = event.mouse_button, + }); + + handle_click(event); + } + break; + } + case SDLContext::Event::MOUSEMOVE: { + event_mgr.queue_event<MouseMoveEvent>(MouseMoveEvent{ + .mouse_x = event.mouse_position.first, + .mouse_y = event.mouse_position.second, + .rel_x = event.rel_mouse_move.first, + .rel_y = event.rel_mouse_move.second, + }); + handle_move(event); + break; + } + case SDLContext::Event::MOUSEWHEEL: { + event_mgr.queue_event<MouseScrollEvent>(MouseScrollEvent{ + .scroll_x = event.wheel_delta, + .scroll_y = 0, + .direction = event.wheel_delta, + }); + break; + } + case SDLContext::Event::SHUTDOWN: { + event_mgr.queue_event<ShutDownEvent>(ShutDownEvent{}); + break; + } + default: + break; + } + } } -void InputSystem::handle_move(const SDLContext::EventData &event_data) { - ComponentManager &mgr = this->component_manager; +void InputSystem::handle_move(const SDLContext::EventData & event_data) { + ComponentManager & mgr = this->component_manager; - std::vector<std::reference_wrapper<Button>> buttons = mgr.get_components_by_type<Button>(); - std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>(); + std::vector<std::reference_wrapper<Button>> buttons = mgr.get_components_by_type<Button>(); + std::vector<std::reference_wrapper<Transform>> transforms + = mgr.get_components_by_type<Transform>(); - for (Button &button : buttons) { - Transform *transform = find_transform_for_button(button, transforms); - if (!transform) - continue; + for (Button & button : buttons) { + Transform * transform = find_transform_for_button(button, transforms); + if (!transform) continue; - if (button.interactable && is_mouse_inside_button(event_data, button, *transform)) { - button.hover = true; - } else { - button.hover = false; - } - } + if (button.interactable && is_mouse_inside_button(event_data, button, *transform)) { + button.hover = true; + } else { + button.hover = false; + } + } } -void InputSystem::handle_click(const SDLContext::EventData &event_data) { - ComponentManager &mgr = this->component_manager; +void InputSystem::handle_click(const SDLContext::EventData & event_data) { + ComponentManager & mgr = this->component_manager; - std::vector<std::reference_wrapper<Button>> buttons = mgr.get_components_by_type<Button>(); - std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>(); + std::vector<std::reference_wrapper<Button>> buttons = mgr.get_components_by_type<Button>(); + std::vector<std::reference_wrapper<Transform>> transforms + = mgr.get_components_by_type<Transform>(); - for (Button &button : buttons) { - Transform *transform = find_transform_for_button(button, transforms); - if (!transform) - continue; + for (Button & button : buttons) { + Transform * transform = find_transform_for_button(button, transforms); + if (!transform) continue; - if (button.interactable && is_mouse_inside_button(event_data, button, *transform)) { - handle_button_press(button); - } - } + if (button.interactable && is_mouse_inside_button(event_data, button, *transform)) { + handle_button_press(button); + } + } } -Transform *InputSystem::find_transform_for_button(Button &button, std::vector<std::reference_wrapper<Transform>> &transforms) { - for (Transform &transform : transforms) { - if (button.game_object_id == transform.game_object_id) { - return &transform; - } - } - return nullptr; +Transform * InputSystem::find_transform_for_button( + Button & button, std::vector<std::reference_wrapper<Transform>> & transforms) { + for (Transform & transform : transforms) { + if (button.game_object_id == transform.game_object_id) { + return &transform; + } + } + return nullptr; } -bool InputSystem::is_mouse_inside_button(const SDLContext::EventData &event_data, const Button &button, const Transform &transform) { - return event_data.mouse_position.first >= transform.position.x && - event_data.mouse_position.first <= transform.position.x + button.width && - event_data.mouse_position.second >= transform.position.y && - event_data.mouse_position.second <= transform.position.y + button.height; +bool InputSystem::is_mouse_inside_button(const SDLContext::EventData & event_data, + const Button & button, const Transform & transform) { + return event_data.mouse_position.first >= transform.position.x + && event_data.mouse_position.first <= transform.position.x + button.width + && event_data.mouse_position.second >= transform.position.y + && event_data.mouse_position.second <= transform.position.y + button.height; } -void InputSystem::handle_button_press(Button &button) { - if (button.is_toggle) { - if (!button.is_pressed && button.on_click) { - button.on_click(); - } - button.is_pressed = !button.is_pressed; - } else if (button.on_click) { - button.on_click(); - } +void InputSystem::handle_button_press(Button & button) { + if (button.is_toggle) { + if (!button.is_pressed && button.on_click) { + button.on_click(); + } + button.is_pressed = !button.is_pressed; + } else if (button.on_click) { + button.on_click(); + } } diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 672f225..5f94446 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -2,8 +2,8 @@ #include "System.h" -#include "../api/Event.h" #include "../api/Button.h" +#include "../api/Event.h" #include "../api/Transform.h" #include "../facade/SDLContext.h" @@ -19,64 +19,67 @@ namespace crepe { */ class InputSystem : public System { public: - using System::System; + using System::System; - /** + /** * \brief Updates the system, processing all input events. * This method processes all events and triggers corresponding actions. */ - void update() override; + void update() override; private: - //! Stores the last position of the mouse when the button was pressed. - std::pair<int, int> last_mouse_down_position{-1, -1}; + //! Stores the last position of the mouse when the button was pressed. + std::pair<int, int> last_mouse_down_position{-1, -1}; - //! Stores the last mouse button pressed. - MouseButton last_mouse_button = MouseButton::NONE; + //! Stores the last mouse button pressed. + MouseButton last_mouse_button = MouseButton::NONE; - //! The tolerance in pixels for detecting a mouse click. - const int click_tolerance = 5; + //! The tolerance in pixels for detecting a mouse click. + const int click_tolerance = 5; - /** + /** * \brief Handles the click event. * \param eventData The event data containing information about the mouse click. * * This method processes the mouse click event and triggers the corresponding button action. */ - void handle_click(const SDLContext::EventData &eventData); + void handle_click(const SDLContext::EventData & eventData); - /** + /** * \brief Handles the mouse movement event. * \param eventData The event data containing information about the mouse movement. * * This method processes the mouse movement event and updates the button hover state. */ - void handle_move(const SDLContext::EventData &eventData); + void handle_move(const SDLContext::EventData & eventData); - /** + /** * \brief Finds the transform component associated with a button. * \param button The button to find the associated transform for. * \param transforms A list of transforms to search through. * \return A pointer to the transform of the button, or nullptr if not found. */ - Transform* find_transform_for_button(Button &button, std::vector<std::reference_wrapper<Transform>> &transforms); + Transform * + find_transform_for_button(Button & button, + std::vector<std::reference_wrapper<Transform>> & transforms); - /** + /** * \brief Checks if the mouse position is inside the bounds of the button. * \param eventData The event data containing the mouse position. * \param button The button to check. * \param transform The transform component of the button. * \return True if the mouse is inside the button, false otherwise. */ - bool is_mouse_inside_button(const SDLContext::EventData &eventData, const Button &button, const Transform &transform); + bool is_mouse_inside_button(const SDLContext::EventData & eventData, const Button & button, + const Transform & transform); - /** + /** * \brief Handles the button press event, calling the on_click callback if necessary. * \param button The button being pressed. * * This method triggers the on_click action for the button when it is pressed. */ - void handle_button_press(Button &button); + void handle_button_press(Button & button); }; } // namespace crepe |