aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/api/Button.cpp4
-rw-r--r--src/crepe/api/Button.h4
-rw-r--r--src/crepe/api/CMakeLists.txt4
-rw-r--r--src/crepe/api/UIObject.cpp8
-rw-r--r--src/crepe/api/UIObject.h (renamed from src/crepe/api/UiObject.h)3
-rw-r--r--src/crepe/api/UiObject.cpp8
-rw-r--r--src/crepe/system/InputSystem.cpp6
7 files changed, 17 insertions, 20 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp
index b104329..313ec4c 100644
--- a/src/crepe/api/Button.cpp
+++ b/src/crepe/api/Button.cpp
@@ -2,8 +2,8 @@
namespace crepe {
-Button::Button(game_object_id_t id, vec2 dimensions, vec2 offset,
- std::function<void()> on_click, bool is_toggle)
+Button::Button(game_object_id_t id, const vec2& dimensions, const vec2& offset,
+ const 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 5c803ba..baee71f 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -2,7 +2,7 @@
#include <functional>
-#include "UiObject.h"
+#include "UIObject.h"
namespace crepe {
@@ -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, const vec2 & dimensions, const vec2 & offset, const std::function<void()>& on_click,
bool is_toggle = false);
/**
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index aeb451d..25a9439 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -24,7 +24,7 @@ target_sources(crepe PUBLIC
EventHandler.cpp
Script.cpp
Button.cpp
- UiObject.cpp
+ UIObject.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
@@ -61,5 +61,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
LoopTimer.h
Asset.h
Button.h
- UiObject.h
+ UIObject.h
)
diff --git a/src/crepe/api/UIObject.cpp b/src/crepe/api/UIObject.cpp
new file mode 100644
index 0000000..784328a
--- /dev/null
+++ b/src/crepe/api/UIObject.cpp
@@ -0,0 +1,8 @@
+#include "UIObject.h"
+
+using namespace crepe;
+
+UIObject::UIObject(game_object_id_t id, const vec2 & dimensions, const vec2 &offset)
+ : Component(id),
+ dimensions(dimensions),
+ offset(offset) {}
diff --git a/src/crepe/api/UiObject.h b/src/crepe/api/UIObject.h
index 0634f97..614794d 100644
--- a/src/crepe/api/UiObject.h
+++ b/src/crepe/api/UIObject.h
@@ -16,9 +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, const vec2 & dimensions, const vec2 & offset);
//! Width and height of the UIObject
vec2 dimensions;
+ //! Position offset relative to this GameObjects Transform
vec2 offset;
};
diff --git a/src/crepe/api/UiObject.cpp b/src/crepe/api/UiObject.cpp
deleted file mode 100644
index 2b287b3..0000000
--- a/src/crepe/api/UiObject.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "UiObject.h"
-
-using namespace crepe;
-
-UIObject::UIObject(game_object_id_t id, vec2 dimensions, vec2 offset)
- : Component(id),
- dimensions(dimensions),
- offset(offset) {}
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 8fe583f..afd71fe 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -153,7 +153,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)) {
@@ -176,16 +176,12 @@ bool InputSystem::is_mouse_inside_button(const int mouse_x, const int mouse_y,
}
void InputSystem::handle_button_press(Button & button) {
- //checks if the button is a toggle button
if (button.is_toggle) {
- //if the toggle button is not in a pressed state and it has a on_click call the on_click
if (!button.is_pressed && button.on_click) {
button.on_click();
}
- //toggle the pressed state
button.is_pressed = !button.is_pressed;
} else if (button.on_click) {
- // if the button is not a toggle button and has a on_click call the on_click
button.on_click();
}
}