From 210ff1309aa545aa3574d991acc7734a1f268b8e Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 18 Nov 2024 16:12:12 +0100 Subject: added keycode conversion --- src/crepe/facade/SDLContext.cpp | 126 ++++++++++++++++++++++++++++++++++++++- src/crepe/facade/SDLContext.h | 2 + src/crepe/system/InputSystem.cpp | 0 src/crepe/system/InputSystem.h | 14 +++++ 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/crepe/system/InputSystem.cpp create mode 100644 src/crepe/system/InputSystem.h diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 83e91f8..bd2d33b 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -10,12 +10,15 @@ #include #include #include +#include #include "../api/Sprite.h" #include "../api/Texture.h" #include "../api/Transform.h" +#include "../api/EventManager.h" #include "../util/Log.h" + #include "SDLContext.h" using namespace crepe; @@ -80,8 +83,8 @@ SDLContext::~SDLContext() { } void SDLContext::handle_events(bool & running) { + EventManager& event_manager = EventManager::get_instance(); //TODO: wouter i need events - /* SDL_Event event; SDL_PollEvent(&event); switch (event.type) { @@ -89,7 +92,10 @@ void SDLContext::handle_events(bool & running) { running = false; break; case SDL_KEYDOWN: - triggerEvent(KeyPressedEvent(getCustomKey(event.key.keysym.sym))); + event_manager.trigger_event(KeyPressEvent{ + .key = this->sdl_to_keycode(event.key.keysym.sym), + .repeat = event.key.repeat + }); break; case SDL_MOUSEBUTTONDOWN: int x, y; @@ -97,7 +103,121 @@ void SDLContext::handle_events(bool & running) { triggerEvent(MousePressedEvent(x, y)); break; } - */ +} + + +Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { + static const std::array LOOKUP_TABLE = [] { + std::array table{}; + table.fill(Keycode::NONE); // Default to NONE for unmapped keys + + 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]; } void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer.get()); } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 007092b..ef7161b 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -8,6 +8,7 @@ #include #include "../api/Sprite.h" +#include "../api/KeyCodes.h" #include "../api/Transform.h" #include "api/Camera.h" @@ -53,6 +54,7 @@ private: * \param running Reference to a boolean flag that controls the main loop. */ void handle_events(bool & running); + Keycode sdl_to_keycode(SDL_Keycode sdlKey); private: //! Will only use get_ticks diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h new file mode 100644 index 0000000..642035f --- /dev/null +++ b/src/crepe/system/InputSystem.h @@ -0,0 +1,14 @@ +#pragma once + +#include "System.h" + +namespace crepe { + +class InputSystem : public System { +public: + using System::System; + void update() override; + void +}; + +} // namespace crepe -- cgit v1.2.3 From 92e83ded2b6afb26082d7661c28af1d9d4e950a2 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 18 Nov 2024 16:55:21 +0100 Subject: added mouse and key event triggering --- src/crepe/api/Event.h | 16 ++++++ src/crepe/api/LoopManager.h | 13 ++--- src/crepe/facade/SDLContext.cpp | 114 ++++++++++++++++++++++++++++++++-------- src/crepe/facade/SDLContext.h | 1 + src/example/events.cpp | 4 +- src/example/gameloop.cpp | 33 ++++++++++++ 6 files changed, 151 insertions(+), 30 deletions(-) diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h index d5ddf0a..ef6a791 100644 --- a/src/crepe/api/Event.h +++ b/src/crepe/api/Event.h @@ -87,6 +87,10 @@ public: //! Y-coordinate of the mouse position at the time of the event. int mouse_y = 0; + // Relative movement in x + int rel_x; + // Relative movement in y + int rel_y; }; /** @@ -113,3 +117,15 @@ public: class ShutDownEvent : public Event { public: }; + +class MouseScrollEvent : public Event { +public: + //! X-coordinate of the mouse position at the time of the event. + int scroll_x = 0; + + //! Y-coordinate of the mouse position at the time of the event. + int scroll_y = 0; + + int direction = 0; +}; + diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index f6904be..b18c9d1 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -10,6 +10,12 @@ namespace crepe { class LoopManager { public: void start(); + /** + * \brief Set game running variable + * + * \param running running (false = game shutdown, true = game running) + */ + void set_running(bool running); LoopManager(); private: @@ -53,12 +59,7 @@ private: * This function updates physics and game logic based on LoopTimer's fixed_delta_time. */ void fixed_update(); - /** - * \brief Set game running variable - * - * \param running running (false = game shutdown, true = game running) - */ - void set_running(bool running); + /** * \brief Function for executing render-related systems. * diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index bd2d33b..8a02f4c 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -82,34 +82,84 @@ SDLContext::~SDLContext() { SDL_Quit(); } -void SDLContext::handle_events(bool & running) { - EventManager& event_manager = EventManager::get_instance(); - //TODO: wouter i need events - SDL_Event event; - SDL_PollEvent(&event); - switch (event.type) { - case SDL_QUIT: - running = false; - break; - case SDL_KEYDOWN: - event_manager.trigger_event(KeyPressEvent{ - .key = this->sdl_to_keycode(event.key.keysym.sym), - .repeat = event.key.repeat - }); - break; - case SDL_MOUSEBUTTONDOWN: - int x, y; - SDL_GetMouseState(&x, &y); - triggerEvent(MousePressedEvent(x, y)); - break; - } +void SDLContext::handle_events(bool &running) { + EventManager& event_manager = EventManager::get_instance(); + SDL_Event event; + + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_QUIT: + running = false; + event_manager.trigger_event(ShutDownEvent{}); + break; + + case SDL_KEYDOWN: + std::cout << "keyDown: " << event.key.keysym.sym << std::endl; + event_manager.trigger_event(KeyPressEvent{ + .repeat = event.key.repeat, + .key = this->sdl_to_keycode(event.key.keysym.scancode) + }); + break; + + case SDL_KEYUP: + event_manager.trigger_event(KeyReleaseEvent{ + .key = this->sdl_to_keycode(event.key.keysym.scancode), + }); + break; + + case SDL_MOUSEBUTTONDOWN: + { + int x, y; + SDL_GetMouseState(&x, &y); + event_manager.trigger_event(MousePressEvent{ + .mouse_x = x, + .mouse_y = y, + .button = this->sdl_to_mousebutton(event.button.button) + }); + } + break; + + case SDL_MOUSEBUTTONUP: + { + int x, y; + SDL_GetMouseState(&x, &y); + event_manager.trigger_event(MouseReleaseEvent{ + .mouse_x = x, + .mouse_y = y, + .button = this->sdl_to_mousebutton(event.button.button) + }); + } + break; + + case SDL_MOUSEMOTION: + event_manager.trigger_event(MouseMoveEvent{ + .mouse_x = event.motion.x, + .mouse_y = event.motion.y, + .rel_x = event.motion.xrel, + .rel_y = event.motion.yrel + }); + break; + + case SDL_MOUSEWHEEL: + event_manager.trigger_event(MouseScrollEvent{ + .scroll_x = event.wheel.x, + .scroll_y = event.wheel.y, + .direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1) + }); + break; + + // Add more events as needed for your application. + } + } } + Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { static const std::array LOOKUP_TABLE = [] { std::array table{}; - table.fill(Keycode::NONE); // Default to NONE for unmapped keys + // Default to NONE for unmapped keys + table.fill(Keycode::NONE); table[SDL_SCANCODE_SPACE] = Keycode::SPACE; table[SDL_SCANCODE_APOSTROPHE] = Keycode::APOSTROPHE; @@ -219,7 +269,27 @@ Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { return LOOKUP_TABLE[sdl_key]; } +MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { + static const std::array MOUSE_BUTTON_LOOKUP_TABLE = [] { + std::array table{}; + table.fill(MouseButton::NONE); // Default to NONE for unmapped buttons + + 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 mapped button +} void SDLContext::clear_screen() { SDL_RenderClear(this->game_renderer.get()); } void SDLContext::present_screen() { SDL_RenderPresent(this->game_renderer.get()); } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index ef7161b..cce2fb6 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -55,6 +55,7 @@ private: */ void handle_events(bool & running); Keycode sdl_to_keycode(SDL_Keycode sdlKey); + MouseButton sdl_to_mousebutton(Uint8 sdl_button); private: //! Will only use get_ticks diff --git a/src/example/events.cpp b/src/example/events.cpp index 6431c67..1b9ea45 100644 --- a/src/example/events.cpp +++ b/src/example/events.cpp @@ -56,12 +56,12 @@ public: bool on_key_pressed(const KeyPressEvent & event) override { std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast(event.key) << std::endl; - return true; // Return true if the listener should remain active + return false; } bool on_key_released(const KeyReleaseEvent & event) override { std::cout << "TestKeyListener: Key Released - Code: " << static_cast(event.key) << std::endl; - return true; + return false; } }; int main() { diff --git a/src/example/gameloop.cpp b/src/example/gameloop.cpp index a676f20..d45b3ce 100644 --- a/src/example/gameloop.cpp +++ b/src/example/gameloop.cpp @@ -1,7 +1,40 @@ +#include #include "crepe/api/LoopManager.h" +#include +#include +#include +#include using namespace crepe; +class TestKeyListener : public IKeyListener { +public: + bool on_key_pressed(const KeyPressEvent & event) override { + std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast(event.key) + << std::endl; + if(event.key == Keycode::ESCAPE){ + + } + return false; + } + bool on_key_released(const KeyReleaseEvent & event) override { + std::cout << "TestKeyListener: Key Released - Code: " << static_cast(event.key) + << std::endl; + return false; + } +}; +bool on_key_pressed(const KeyPressEvent & event){ + std::cout << "TestKeyListener: Key Pressed - Code: " << static_cast(event.key) + << std::endl; + if(event.key == Keycode::ESCAPE){ + return true; + } + return false; + } int main() { LoopManager gameloop; + TestKeyListener key_listener; + EventManager::get_instance().subscribe(on_key_pressed); gameloop.start(); + + return 1; } -- cgit v1.2.3 From 60cbc3d649775053ac1d333716c9f5fda651a643 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 18 Nov 2024 20:30:54 +0100 Subject: sdl changes --- src/crepe/facade/SDLContext.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 8a02f4c..d0977cb 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -148,7 +148,6 @@ void SDLContext::handle_events(bool &running) { }); break; - // Add more events as needed for your application. } } } -- cgit v1.2.3 From 6c2fc3716c9c6c68e982b243af5f7ed04fb35e86 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Tue, 19 Nov 2024 15:16:16 +0100 Subject: button handling --- src/crepe/api/Button.cpp | 0 src/crepe/api/Button.h | 17 +++++++++++++ src/crepe/api/UiObject.h | 14 +++++++++++ src/crepe/facade/SDLContext.cpp | 6 ++--- src/crepe/system/InputSystem.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ src/crepe/system/InputSystem.h | 8 +++++-- 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/crepe/api/Button.cpp create mode 100644 src/crepe/api/Button.h create mode 100644 src/crepe/api/UiObject.h diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h new file mode 100644 index 0000000..5035729 --- /dev/null +++ b/src/crepe/api/Button.h @@ -0,0 +1,17 @@ +#include + +#include "Component.h" +#include "api/EventHandler.h" +#include "api/UiObject.h" +namespace crepe { +class Button : public UiObject{ +public: + ~Button(){}; + bool interactable = true; + bool is_toggle = false; + bool is_pressed = false; + std::function on_click; +public: +virtual int get_instances_max() const { return 1; } +}; +} diff --git a/src/crepe/api/UiObject.h b/src/crepe/api/UiObject.h new file mode 100644 index 0000000..f57f7ef --- /dev/null +++ b/src/crepe/api/UiObject.h @@ -0,0 +1,14 @@ +#include + +#include "Component.h" +#include "api/EventHandler.h" +namespace crepe { +class UiObject : public Component{ +public: + ~UiObject(){}; + int width = 0; + int height = 0; +public: +virtual int get_instances_max() const { return 1; } +}; +} diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index d0977cb..43ef3f1 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -94,7 +94,6 @@ void SDLContext::handle_events(bool &running) { break; case SDL_KEYDOWN: - std::cout << "keyDown: " << event.key.keysym.sym << std::endl; event_manager.trigger_event(KeyPressEvent{ .repeat = event.key.repeat, .key = this->sdl_to_keycode(event.key.keysym.scancode) @@ -157,7 +156,6 @@ void SDLContext::handle_events(bool &running) { Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { static const std::array LOOKUP_TABLE = [] { std::array table{}; - // Default to NONE for unmapped keys table.fill(Keycode::NONE); table[SDL_SCANCODE_SPACE] = Keycode::SPACE; @@ -271,7 +269,7 @@ Keycode SDLContext::sdl_to_keycode(SDL_Keycode sdl_key) { MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { static const std::array MOUSE_BUTTON_LOOKUP_TABLE = [] { std::array table{}; - table.fill(MouseButton::NONE); // Default to NONE for unmapped buttons + table.fill(MouseButton::NONE); table[SDL_BUTTON_LEFT] = MouseButton::LEFT_MOUSE; table[SDL_BUTTON_RIGHT] = MouseButton::RIGHT_MOUSE; @@ -287,7 +285,7 @@ MouseButton SDLContext::sdl_to_mousebutton(Uint8 sdl_button) { return MouseButton::NONE; } - return MOUSE_BUTTON_LOOKUP_TABLE[sdl_button]; // Return mapped 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()); } diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index e69de29..b7a86f4 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -0,0 +1,52 @@ +#include "ComponentManager.h" +#include "../api/Button.h" +#include "../api/EventManager.h" +#include "../api/Transform.h" +#include "../api/Event.h" + +#include "system/InputSystem.h" + +using namespace crepe; + +InputSystem::InputSystem(ComponentManager &component_manager) + : System(component_manager) { + auto &event_manager = EventManager::get_instance(); + + event_manager.subscribe([this](const MouseClickEvent &event) { + return this->handle_click(event); + }); + + event_manager.subscribe([this](const MouseMoveEvent &event) { + return this->handle_move(event); + }); +} + +void InputSystem::update() { +} + +bool InputSystem::handle_click(const MouseClickEvent &event) { + ComponentManager &mgr = this->component_manager; + + std::vector> buttons = + mgr.get_components_by_type