From 66fdcffaddb0ab31d12b6b1d7892a8edaa31af65 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 4 Dec 2024 20:13:09 +0100 Subject: make format --- src/crepe/system/InputSystem.cpp | 25 +++++++++++-------------- src/crepe/system/InputSystem.h | 6 +++--- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src/crepe/system') diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index bbf2547..21ec24b 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -152,7 +152,7 @@ void InputSystem::handle_click(const MouseButton & mouse_button, const int world for (Button & button : buttons) { RefVector transform_vec = mgr.get_components_by_id(button.game_object_id); - Transform& transform(transform_vec.front().get()); + Transform & transform(transform_vec.front().get()); if (button.active && this->is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) { @@ -162,20 +162,17 @@ void InputSystem::handle_click(const MouseButton & mouse_button, const int world } bool InputSystem::is_mouse_inside_button(const int mouse_x, const int mouse_y, - const Button &button, const Transform &transform) { - int actual_x = transform.position.x + button.offset.x; - int actual_y = transform.position.y + button.offset.y; - - int half_width = button.dimensions.x / 2; - int half_height = button.dimensions.y / 2; - - // Check if the mouse is within the button's boundaries - return mouse_x >= actual_x - half_width - && mouse_x <= actual_x + half_width - && mouse_y >= actual_y - half_height - && mouse_y <= actual_y + half_height; -} + const Button & button, const Transform & transform) { + int actual_x = transform.position.x + button.offset.x; + int actual_y = transform.position.y + button.offset.y; + int half_width = button.dimensions.x / 2; + int half_height = button.dimensions.y / 2; + + // Check if the mouse is within the button's boundaries + return mouse_x >= actual_x - half_width && mouse_x <= actual_x + half_width + && mouse_y >= actual_y - half_height && mouse_y <= actual_y + half_height; +} void InputSystem::handle_button_press(Button & button) { //checks if the button is a toggle button diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 557ba47..eafeb91 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -31,15 +31,15 @@ public: private: //! Stores the last position of the mouse when the button was pressed. - ivec2 last_mouse_down_position{std::numeric_limits::max(), std::numeric_limits::max()}; + ivec2 last_mouse_down_position{std::numeric_limits::max(), + std::numeric_limits::max()}; //! Stores the last mouse button pressed. MouseButton last_mouse_button = MouseButton::NONE; - + //! The maximum allowable distance between mouse down and mouse up to register as a click. const int click_tolerance = 5; - /** * \brief Handles the mouse click event. * \param mouse_button The mouse button involved in the click. -- cgit v1.2.3