From 596358ffea72aec48b389609349f717e76396ae2 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 25 Nov 2024 11:17:20 +0100 Subject: button test working --- src/crepe/api/Button.h | 1 + src/crepe/facade/SDLContext.cpp | 2 +- src/crepe/system/InputSystem.cpp | 31 ++++++++++++----- src/crepe/system/InputSystem.h | 2 +- src/test/inputTest.cpp | 75 +++++++++++++++++++++++++++++++++++----- 5 files changed, 92 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index 709854a..f533452 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -11,6 +11,7 @@ public: bool interactable = true; bool is_toggle = false; bool is_pressed = false; + bool hover = false; std::function on_click; public: virtual int get_instances_max() const { return 1; } diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index f87cc61..6371a51 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -361,6 +361,7 @@ std::vector SDLContext::get_events(){ event_list.push_back(EventData{ .event_type = SDLContext::Event::MOUSEMOVE, .mouse_position = {event.button.x,event.button.y}, + .rel_mouse_move = {event.motion.yrel,event.motion.xrel} }); } break; @@ -371,7 +372,6 @@ std::vector SDLContext::get_events(){ .event_type = SDLContext::Event::MOUSEWHEEL, .mouse_position = {event.motion.x,event.motion.y}, .wheel_delta = event.wheel.y, - .rel_mouse_move = {event.motion.yrel,event.motion.xrel}, }); } break; diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 4560411..a3e28e4 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -56,10 +56,6 @@ void InputSystem::update() { if (last_mouse_button == event.mouse_button && std::abs(delta_x) <= click_tolerance && std::abs(delta_y) <= click_tolerance) { - std::cout << "Click registered at (" << event.mouse_position.first - << ", " << event.mouse_position.second << ") with button " - << static_cast(event.mouse_button) << std::endl; - event_mgr.queue_event(MouseClickEvent{ .mouse_x = event.mouse_position.first, .mouse_y = event.mouse_position.second, @@ -67,8 +63,6 @@ void InputSystem::update() { }); this->handle_click(mouse_release_event); - } else { - std::cout << "Mouse release did not register as a click." << std::endl; } break; @@ -101,6 +95,25 @@ void InputSystem::update() { } } +void InputSystem::handle_move(const MouseMoveEvent){ + ComponentManager &mgr = this->component_manager; + + // Get the buttons and transforms + std::vector> buttons = mgr.get_components_by_type