diff options
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 25 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.h | 6 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index bb67e5f..070f804 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -1,6 +1,6 @@ +#include "ComponentManager.h" #include "api/Button.h" #include "api/EventManager.h" -#include "ComponentManager.h" #include "InputSystem.h" @@ -41,7 +41,7 @@ void InputSystem::update() { 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) { @@ -53,8 +53,7 @@ void InputSystem::update() { handle_click(event); } - } - break; + } break; case SDLContext::EventType::MOUSEMOVE: event_mgr.queue_event<MouseMoveEvent>(MouseMoveEvent{ .mouse_x = event.mouse_position.first, @@ -113,20 +112,18 @@ void InputSystem::handle_click(const SDLContext::EventData & event_data) { } } +OptionalRef<Transform> +InputSystem::find_transform_for_button(Button & button, RefVector<Transform> & transforms) { -OptionalRef<Transform> InputSystem::find_transform_for_button( - Button & button, RefVector<Transform>& transforms) { - - for (auto& transform : transforms) { - if (button.game_object_id == transform.get().game_object_id) { - return OptionalRef<Transform>(transform); - } - } + for (auto & transform : transforms) { + if (button.game_object_id == transform.get().game_object_id) { + return OptionalRef<Transform>(transform); + } + } - return OptionalRef<Transform>(); + return OptionalRef<Transform>(); } - 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 diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 13c3fc1..b648144 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -1,8 +1,8 @@ #pragma once #include "facade/SDLContext.h" -#include "util/OptionalRef.h" #include "types.h" +#include "util/OptionalRef.h" #include "System.h" @@ -61,8 +61,8 @@ private: * \param transforms A list of transforms to search through. * \return A pointer to the transform of the button, or nullptr if not found. */ - OptionalRef<Transform> - find_transform_for_button(Button & button, RefVector<Transform>& transforms); + OptionalRef<Transform> find_transform_for_button(Button & button, + RefVector<Transform> & transforms); /** * \brief Checks if the mouse position is inside the bounds of the button. |