From 7070f22d86057eafca3b82321d4146958c14a33e Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 27 Nov 2024 14:25:32 +0100 Subject: pr feedback --- src/crepe/system/InputSystem.cpp | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/crepe/system/InputSystem.cpp') diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 9690fec..590be8d 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -1,8 +1,8 @@ -#include "../api/Button.h" -#include "../api/EventManager.h" +#include "api/Button.h" +#include "api/EventManager.h" #include "ComponentManager.h" -#include "system/InputSystem.h" +#include "InputSystem.h" using namespace crepe; @@ -36,17 +36,15 @@ void InputSystem::update() { break; } case SDLContext::EventType::MOUSEUP: { - MouseReleaseEvent mouse_release_event = MouseReleaseEvent{ + event_mgr.queue_event(MouseReleaseEvent{ .mouse_x = event.mouse_position.first, .mouse_y = event.mouse_position.second, .button = event.mouse_button, - }; - event_mgr.queue_event(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) { @@ -96,10 +94,10 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data) { = mgr.get_components_by_type(); for (Button & button : buttons) { - Transform * transform = find_transform_for_button(button, transforms); + OptionalRef transform = find_transform_for_button(button, transforms); if (!transform) continue; - if (button.interactable && is_mouse_inside_button(event_data, button, *transform)) { + if (button.active && is_mouse_inside_button(event_data, button, transform)) { button.hover = true; } else { button.hover = false; @@ -111,29 +109,31 @@ void InputSystem::handle_click(const SDLContext::EventData & event_data) { ComponentManager & mgr = this->component_manager; std::vector> buttons = mgr.get_components_by_type