aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Button.cpp4
-rw-r--r--src/crepe/api/Button.h27
-rw-r--r--src/crepe/api/Event.h14
-rw-r--r--src/crepe/api/UiObject.cpp5
-rw-r--r--src/crepe/api/UiObject.h21
5 files changed, 29 insertions, 42 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp
index d325014..f179f60 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, int width, int height, std::function<void()> on_click,
+Button::Button(game_object_id_t id, vec2 dimensions,vec2 offset, std::function<void()> on_click,
bool is_toggle)
- : UiObject(id, width, height),
+ : 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 06d64d6..043cc78 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -7,25 +7,21 @@
namespace crepe {
/**
- * \class Button
* \brief Represents a clickable UI button, derived from the UiObject class.
*
- * This class provides functionality for a button in the UI, including toggle state,
- * click handling, and mouse hover detection. A callback function can be provided to
- * handle button clicks.
*/
-class Button : public UiObject {
+class Button : public UIObject {
public:
/**
* \brief Constructs a Button with the specified game object ID and dimensions.
*
* \param id The unique ID of the game object associated with this button.
- * \param width The width of the button.
- * \param height The height of the button.
+ * \param Dimensions The width and height of the UIObject
+ * \param offset The offset relative this GameObjects Transform
* \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, int width, int height, std::function<void()> on_click,
+ Button(game_object_id_t id, vec2 dimensions,vec2 offset, std::function<void()> on_click,
bool is_toggle = false);
/**
@@ -50,7 +46,7 @@ public:
* This function is triggered when the mouse cursor moves over the button, allowing
* custom actions like visual effects, highlighting, or sound effects.
*/
- std::function<void()> on_enter = nullptr;
+ std::function<void()> on_mouse_enter = nullptr;
/**
* \brief Callback function to be executed when the mouse exits the button's boundaries.
@@ -58,14 +54,15 @@ public:
* This function is triggered when the mouse cursor moves out of the button's area,
* allowing custom actions like resetting visual effects or playing exit-related effects.
*/
- std::function<void()> on_exit = nullptr;
+ std::function<void()> on_mouse_exit = nullptr;
private:
+ //! friend relation for is_pressed and hover variables
friend class InputSystem;
/**
- * \brief Indicates whether the button is currently pressed.
+ * \brief Indicates whether the toggle button is pressed
*
- * This state is true when the button is actively pressed and false otherwise.
+ * This state indicates if the toggle button is pressed or not
*/
bool is_pressed = false;
@@ -77,12 +74,6 @@ private:
bool hover = false;
public:
- /**
- * \brief Retrieves the maximum number of instances allowed for this button type.
- *
- * \return Always returns 1, as only a single instance of this type is allowed.
- */
- virtual int get_instances_max() const override { return 1; }
};
} // namespace crepe
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index 91a30b5..8083d7c 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -90,10 +90,12 @@ public:
int mouse_y = 0;
// Movement since last event in x
- int rel_x = 0;
+ int delta_x = 0;
// Movement since last event in y
- int rel_y = 0;
+ int delta_y = 0;
+
+
};
/**
@@ -102,13 +104,15 @@ public:
class MouseScrollEvent : public Event {
public:
//! X-coordinate of the mouse position at the time of the event.
- int scroll_x = 0;
+ int mouse_x = 0;
//! Y-coordinate of the mouse position at the time of the event.
- int scroll_y = 0;
+ int mouse_y = 0;
//! scroll direction (-1 = down, 1 = up)
- int direction = 0;
+ int scroll_direction = 0;
+ //! scroll amount in y axis (from and away from the person).
+ float scroll_delta = 0;
};
/**
* \brief Event triggered during a collision between objects.
diff --git a/src/crepe/api/UiObject.cpp b/src/crepe/api/UiObject.cpp
index 7859a90..0262d31 100644
--- a/src/crepe/api/UiObject.cpp
+++ b/src/crepe/api/UiObject.cpp
@@ -2,7 +2,6 @@
using namespace crepe;
-UiObject::UiObject(game_object_id_t id, int width, int height)
+UIObject::UIObject(game_object_id_t id, vec2 dimensions,vec2 offset)
: Component(id),
- width(width),
- height(height){};
+ dimensions(dimensions),offset(offset){}
diff --git a/src/crepe/api/UiObject.h b/src/crepe/api/UiObject.h
index c056877..1130f99 100644
--- a/src/crepe/api/UiObject.h
+++ b/src/crepe/api/UiObject.h
@@ -8,26 +8,19 @@ namespace crepe {
* @class UiObject
* \brief Represents a UI object in the game, derived from the Component class.
*/
-class UiObject : public Component {
+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, int width, int height);
+ UIObject(game_object_id_t id, vec2 dimensions,vec2 offset);
+ //! Width and height of the UIObject
+ vec2 dimensions;
+ vec2 offset;
- //! The width of the UI object.
- int width = 0;
-
- //! The height of the UI object.
- int height = 0;
-
-public:
- /**
- * \brief Retrieves the maximum number of instances allowed for this UI object type.
- * /return Always returns 1, as only a single instance is allowed.
- */
- virtual int get_instances_max() const override { return 1; }
};
} // namespace crepe