aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 20:13:09 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-04 20:13:09 +0100
commit66fdcffaddb0ab31d12b6b1d7892a8edaa31af65 (patch)
tree6c6692e0489133ac5264d53f7dc5a1e3d5be9320 /src/crepe/system
parent6454975779acb39d7d546e11855a07a952e68e5b (diff)
make format
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/InputSystem.cpp25
-rw-r--r--src/crepe/system/InputSystem.h6
2 files changed, 14 insertions, 17 deletions
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> transform_vec
= mgr.get_components_by_id<Transform>(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<int>::max(), std::numeric_limits<int>::max()};
+ ivec2 last_mouse_down_position{std::numeric_limits<int>::max(),
+ std::numeric_limits<int>::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.