diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-28 09:01:37 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-28 09:01:37 +0100 |
commit | 570acb7e9258edcd6a06fff4dd2ce0ff12a3e873 (patch) | |
tree | 0b9d8406f6d6a8e2dcd187bee7277bc81a270acc /src/crepe/api/Button.h | |
parent | 8635d1ace31232c295c6cb85ea215887c6fb1319 (diff) |
added on_enter and on_hover
Diffstat (limited to 'src/crepe/api/Button.h')
-rw-r--r-- | src/crepe/api/Button.h | 42 |
1 files changed, 29 insertions, 13 deletions
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: /** |