diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Button.cpp | 6 | ||||
-rw-r--r-- | src/crepe/api/Button.h | 42 | ||||
-rw-r--r-- | src/crepe/api/Event.h | 4 |
3 files changed, 33 insertions, 19 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp index c0ff5a8..a27ff53 100644 --- a/src/crepe/api/Button.cpp +++ b/src/crepe/api/Button.cpp @@ -2,12 +2,10 @@ namespace crepe { -Button::Button(game_object_id_t id, int width, int height, bool is_toggle, - std::function<void()> on_click) +Button::Button(game_object_id_t id, int width, int height, std::function<void()> on_click, bool is_toggle + ) : UiObject(id, width, height), is_toggle(is_toggle), - is_pressed(false), - hover(false), on_click(on_click) {} } // namespace crepe diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index 2fa94ae..1410529 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -24,8 +24,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, int width, int height, bool is_toggle = false, - std::function<void()> on_click = nullptr); + Button(game_object_id_t id, int width, int height, std::function<void()> on_click, bool is_toggle = false); /** * \brief Indicates if the button is a toggle button (can be pressed and released). @@ -33,29 +32,46 @@ public: * A toggle button allows for a pressed/released state, whereas a regular button * typically only has an on-click state. */ - bool is_toggle; + bool is_toggle = false; /** - * \brief Indicates whether the button is currently pressed. + * \brief The callback function to be executed when the button is clicked. * - * This state is true when the button is actively pressed and false otherwise. + * This function is invoked whenever the button is clicked. It can be set to any + * function that matches the signature `void()`. */ - bool is_pressed; + std::function<void()> on_click; + + /** + * \brief Callback function to be executed when the mouse enters the button's boundaries. + * + * 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; /** - * \brief Indicates whether the mouse is currently hovering over the button. + * \brief Callback function to be executed when the mouse exits the button's boundaries. + * + * 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; + private: + friend class InputSystem; + /** + * \brief Indicates whether the button is currently pressed. * - * This is set to true when the mouse is over the button and false otherwise. + * This state is true when the button is actively pressed and false otherwise. */ - bool hover; + bool is_pressed = false; /** - * \brief The callback function to be executed when the button is clicked. + * \brief Indicates whether the mouse is currently hovering over the button. * - * This function is invoked whenever the button is clicked. It can be set to any - * function that matches the signature `void()`. Defaults to nullptr. + * This is set to true when the mouse is over the button and false otherwise. */ - std::function<void()> on_click; + bool hover = false; public: /** diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h index a7d5511..91a30b5 100644 --- a/src/crepe/api/Event.h +++ b/src/crepe/api/Event.h @@ -89,10 +89,10 @@ public: //! Y-coordinate of the mouse position at the time of the event. int mouse_y = 0; - // Relative movement in x + // Movement since last event in x int rel_x = 0; - // Relative movement in y + // Movement since last event in y int rel_y = 0; }; |