From 570acb7e9258edcd6a06fff4dd2ce0ff12a3e873 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 28 Nov 2024 09:01:37 +0100 Subject: added on_enter and on_hover --- src/crepe/api/Button.h | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'src/crepe/api/Button.h') 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 on_click = nullptr); + Button(game_object_id_t id, int width, int height, std::function 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 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 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 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 on_click; + bool hover = false; public: /** -- cgit v1.2.3