aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-03 12:35:00 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-03 12:35:00 +0100
commit0c9d708d4d44b2de0bb8c8f59e7e6fb098eca272 (patch)
tree07ac4a175ae58d6c47ae88d543863266c000dc1e /src/crepe
parent7551c98ee239963ad65123132419c3c0a9cfccb3 (diff)
changed test for changes
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/system/InputSystem.cpp14
-rw-r--r--src/crepe/system/InputSystem.h6
2 files changed, 12 insertions, 8 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 5b220eb..1cd3974 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -141,11 +141,15 @@ 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) {
- return mouse_x >= transform.position.x
- && mouse_x <= transform.position.x + button.width
- && mouse_y >= transform.position.y
- && mouse_y <= transform.position.y + button.height;
+bool InputSystem::is_mouse_inside_button(
+ const int& mouse_x, const int& mouse_y,
+ const Button & button, const Transform & transform) {
+ int half_width = button.width / 2;
+ int half_height = button.height / 2;
+ return mouse_x >= transform.position.x - half_width
+ && mouse_x <= transform.position.x + half_width
+ && mouse_y >= transform.position.y - half_height
+ && mouse_y <= transform.position.y + half_height;
}
void InputSystem::handle_button_press(Button & button) {
diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h
index e937d01..4244d91 100644
--- a/src/crepe/system/InputSystem.h
+++ b/src/crepe/system/InputSystem.h
@@ -64,13 +64,13 @@ private:
/**
* \brief Checks if the mouse position is inside the bounds of the button.
- * \param mouse_x The X coordinate of the mouse.
- * \param mouse_y The Y coordinate of the mouse.
+ * \param world_mouse_x The X coordinate of the mouse in world space.
+ * \param world_mouse_y The Y coordinate of the mouse in world space.
* \param button The button to check.
* \param transform The transform component of the button.
* \return True if the mouse is inside the button, false otherwise.
*/
- bool is_mouse_inside_button(const int& mouse_x, const int& mouse_y, const Button& button, const Transform& transform);
+ bool is_mouse_inside_button(const int& world_mouse_x, const int& world_mouse_y, const Button& button, const Transform& transform);
/**
* \brief Handles the button press event, calling the on_click callback if necessary.