aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Button.cpp6
-rw-r--r--src/crepe/api/Button.h2
-rw-r--r--src/crepe/api/Event.h2
-rw-r--r--src/crepe/api/UiObject.cpp5
-rw-r--r--src/crepe/api/UiObject.h3
-rw-r--r--src/crepe/system/InputSystem.cpp25
-rw-r--r--src/crepe/system/InputSystem.h6
7 files changed, 22 insertions, 27 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp
index f179f60..b104329 100644
--- a/src/crepe/api/Button.cpp
+++ b/src/crepe/api/Button.cpp
@@ -2,9 +2,9 @@
namespace crepe {
-Button::Button(game_object_id_t id, vec2 dimensions,vec2 offset, std::function<void()> on_click,
- bool is_toggle)
- : UIObject(id, dimensions,offset),
+Button::Button(game_object_id_t id, vec2 dimensions, vec2 offset,
+ std::function<void()> on_click, bool is_toggle)
+ : UIObject(id, dimensions, offset),
is_toggle(is_toggle),
on_click(on_click) {}
diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h
index 043cc78..5c803ba 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -21,7 +21,7 @@ public:
* \param is_toggle Optional flag to indicate if the button is a toggle button. Defaults to false.
* \param on_click callback function that will be invoked when the button is clicked.
*/
- Button(game_object_id_t id, vec2 dimensions,vec2 offset, std::function<void()> on_click,
+ Button(game_object_id_t id, vec2 dimensions, vec2 offset, std::function<void()> on_click,
bool is_toggle = false);
/**
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index 8083d7c..6298118 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -94,8 +94,6 @@ public:
// Movement since last event in y
int delta_y = 0;
-
-
};
/**
diff --git a/src/crepe/api/UiObject.cpp b/src/crepe/api/UiObject.cpp
index 0262d31..2b287b3 100644
--- a/src/crepe/api/UiObject.cpp
+++ b/src/crepe/api/UiObject.cpp
@@ -2,6 +2,7 @@
using namespace crepe;
-UIObject::UIObject(game_object_id_t id, vec2 dimensions,vec2 offset)
+UIObject::UIObject(game_object_id_t id, vec2 dimensions, vec2 offset)
: Component(id),
- dimensions(dimensions),offset(offset){}
+ dimensions(dimensions),
+ offset(offset) {}
diff --git a/src/crepe/api/UiObject.h b/src/crepe/api/UiObject.h
index 1130f99..0634f97 100644
--- a/src/crepe/api/UiObject.h
+++ b/src/crepe/api/UiObject.h
@@ -16,11 +16,10 @@ public:
* \param dimensions width and height of the UIObject
* \param offset Offset relative to the GameObject Transform
*/
- UIObject(game_object_id_t id, vec2 dimensions,vec2 offset);
+ UIObject(game_object_id_t id, vec2 dimensions, vec2 offset);
//! Width and height of the UIObject
vec2 dimensions;
vec2 offset;
-
};
} // namespace crepe
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.