From d10f220ff6c5d62bb51793a0ef4ee37090161d89 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 4 Dec 2024 21:50:00 +0100 Subject: feedback changes --- src/crepe/api/Button.cpp | 4 ++-- src/crepe/api/Button.h | 4 ++-- src/crepe/api/CMakeLists.txt | 4 ++-- src/crepe/api/UIObject.cpp | 8 ++++++++ src/crepe/api/UIObject.h | 26 ++++++++++++++++++++++++++ src/crepe/api/UiObject.cpp | 8 -------- src/crepe/api/UiObject.h | 25 ------------------------- src/crepe/system/InputSystem.cpp | 6 +----- 8 files changed, 41 insertions(+), 44 deletions(-) create mode 100644 src/crepe/api/UIObject.cpp create mode 100644 src/crepe/api/UIObject.h delete mode 100644 src/crepe/api/UiObject.cpp delete mode 100644 src/crepe/api/UiObject.h (limited to 'src') 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 on_click, bool is_toggle) +Button::Button(game_object_id_t id, const vec2& dimensions, const vec2& offset, + const std::function& 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 -#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 on_click, + Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, const std::function& 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 new file mode 100644 index 0000000..614794d --- /dev/null +++ b/src/crepe/api/UIObject.h @@ -0,0 +1,26 @@ +#pragma once + +#include "../Component.h" + +namespace crepe { + +/** + * @class UiObject + * \brief Represents a UI object in the game, derived from the Component class. + */ +class UIObject : public Component { +public: + /** + * \brief Constructs a UiObject with the specified game object ID. + * \param id The unique ID of the game object associated with this UI object. + * \param dimensions width and height of the UIObject + * \param offset Offset relative to the GameObject Transform + */ + 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; +}; + +} // namespace crepe 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/api/UiObject.h b/src/crepe/api/UiObject.h deleted file mode 100644 index 0634f97..0000000 --- a/src/crepe/api/UiObject.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "../Component.h" - -namespace crepe { - -/** - * @class UiObject - * \brief Represents a UI object in the game, derived from the Component class. - */ -class UIObject : public Component { -public: - /** - * \brief Constructs a UiObject with the specified game object ID. - * \param id The unique ID of the game object associated with this UI object. - * \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); - //! 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 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_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)) { @@ -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(); } } -- cgit v1.2.3