|
Player12
An open source football management simulator
|
Manages a collection of UI buttons. More...
#include <button_manager.h>
Public Member Functions | |
| ButtonManager (SDL_Renderer *renderer_ptr, TTF_Font *font_ptr) | |
| Constructs a new ButtonManager. | |
| ~ButtonManager () | |
| Destroys the ButtonManager. | |
| ButtonManager (const ButtonManager &)=delete | |
| ButtonManager & | operator= (const ButtonManager &)=delete |
| int | getButtonCount () const |
| Gets the total number of buttons managed. | |
| int | addButton (const SDL_FRect &rect, std::string_view label, std::function< void()> callback) |
| Adds a new button. | |
| int | addButton (const SDL_FRect &rect, std::string_view label, const ButtonStyle &style, std::function< void()> callback) |
| Adds a new button with a specific style. | |
| int | addButton (float x, float y, float w, float h, std::string_view label, std::function< void()> callback) |
| Adds a new button using individual coordinates. | |
| int | addButton (float x, float y, float w, float h, std::string_view label, const ButtonStyle &style, std::function< void()> callback) |
| Adds a new button with a specific style using individual coordinates. | |
| void | removeButton (int buttonId) |
| Removes a button by ID. | |
| void | clearButtons () |
| Clears all managed buttons. | |
| void | setButtonStyle (int buttonId, const ButtonStyle &style) |
| Sets the style of a specific button. | |
| void | setButtonVisible (int buttonId, bool visible) |
| Sets the visibility of a specific button. | |
| void | setButtonEnabled (int buttonId, bool enabled) |
| Sets the enabled state of a specific button. | |
| void | setButtonText (int buttonId, std::string_view text) |
| Sets the text label of a specific button. | |
| void | setButtonSelected (int buttonId, bool selected) |
| Sets whether a specific button is selected. | |
| void | handleMouseMove (float x, float y) |
| Handles mouse movement events for buttons. | |
| bool | handleMouseClick (float x, float y) const |
| Handles mouse click events for buttons. | |
| void | render () |
| Renders all visible buttons. | |
| void | setFont (TTF_Font *newFont) |
| Sets the font used for all buttons. | |
| TTF_Font * | getFont () const |
| Gets the font currently used for buttons. | |
| void | setDefaultStyle (const ButtonStyle &style) |
| Sets the default style applied to new buttons. | |
| const std::vector< Button > & | getButtons () const |
| Gets a copy of the list of buttons. | |
| void | recreateTextures () |
| Recreates textures for all buttons (e.g. on text change). | |
| void | updateButtonPosition (size_t buttonIndex, SDL_FRect newRect) |
| Updates a button's position by its index. | |
| void | updateButtonPositionById (int buttonId, SDL_FRect newRect) |
| Updates a button's position by its ID. | |
Private Member Functions | |
| void | renderButton (const Button &button) |
| bool | isPointInButton (float x, float y, const Button &button) const |
| void | createButtonTexture (Button &btn) |
Private Attributes | |
| SDL_Renderer * | renderer |
| TTF_Font * | font |
| std::vector< Button > | buttons |
| ButtonStyle | defaultStyle |
| int | nextButtonId = 0 |
Manages a collection of UI buttons.
| ButtonManager::ButtonManager | ( | SDL_Renderer * | renderer_ptr, |
| TTF_Font * | font_ptr | ||
| ) |
Constructs a new ButtonManager.
| renderer_ptr | The SDL renderer used for drawing buttons. |
| font_ptr | The font used for button text. |
| ButtonManager::~ButtonManager | ( | ) |
Destroys the ButtonManager.
|
delete |
| int ButtonManager::addButton | ( | const SDL_FRect & | rect, |
| std::string_view | label, | ||
| const ButtonStyle & | style, | ||
| std::function< void()> | callback | ||
| ) |
Adds a new button with a specific style.
| rect | The rectangle defining the button's position and size. |
| label | The text displayed on the button. |
| style | The style to apply to the button. |
| callback | The function to call when the button is clicked. |
| int ButtonManager::addButton | ( | const SDL_FRect & | rect, |
| std::string_view | label, | ||
| std::function< void()> | callback | ||
| ) |
Adds a new button.
| rect | The rectangle defining the button's position and size. |
| label | The text displayed on the button. |
| callback | The function to call when the button is clicked. |
| int ButtonManager::addButton | ( | float | x, |
| float | y, | ||
| float | w, | ||
| float | h, | ||
| std::string_view | label, | ||
| const ButtonStyle & | style, | ||
| std::function< void()> | callback | ||
| ) |
Adds a new button with a specific style using individual coordinates.
| x | The x-coordinate. |
| y | The y-coordinate. |
| w | The width. |
| h | The height. |
| label | The text displayed on the button. |
| style | The style to apply to the button. |
| callback | The function to call when the button is clicked. |
| int ButtonManager::addButton | ( | float | x, |
| float | y, | ||
| float | w, | ||
| float | h, | ||
| std::string_view | label, | ||
| std::function< void()> | callback | ||
| ) |
Adds a new button using individual coordinates.
| x | The x-coordinate. |
| y | The y-coordinate. |
| w | The width. |
| h | The height. |
| label | The text displayed on the button. |
| callback | The function to call when the button is clicked. |
| void ButtonManager::clearButtons | ( | ) |
Clears all managed buttons.
|
private |
|
inline |
Gets the total number of buttons managed.
|
inline |
Gets a copy of the list of buttons.
|
inline |
Gets the font currently used for buttons.
| bool ButtonManager::handleMouseClick | ( | float | x, |
| float | y | ||
| ) | const |
Handles mouse click events for buttons.
| x | The mouse x-coordinate. |
| y | The mouse y-coordinate. |
| void ButtonManager::handleMouseMove | ( | float | x, |
| float | y | ||
| ) |
Handles mouse movement events for buttons.
| x | The mouse x-coordinate. |
| y | The mouse y-coordinate. |
|
private |
|
delete |
| void ButtonManager::recreateTextures | ( | ) |
Recreates textures for all buttons (e.g. on text change).
| void ButtonManager::removeButton | ( | int | buttonId | ) |
Removes a button by ID.
| buttonId | The ID of the button to remove. |
| void ButtonManager::render | ( | ) |
Renders all visible buttons.
|
private |
| void ButtonManager::setButtonEnabled | ( | int | buttonId, |
| bool | enabled | ||
| ) |
Sets the enabled state of a specific button.
| buttonId | The ID of the button. |
| enabled | True to enable it, false to disable it. |
| void ButtonManager::setButtonSelected | ( | int | buttonId, |
| bool | selected | ||
| ) |
Sets whether a specific button is selected.
| buttonId | The ID of the button. |
| selected | True if selected, false otherwise. |
| void ButtonManager::setButtonStyle | ( | int | buttonId, |
| const ButtonStyle & | style | ||
| ) |
Sets the style of a specific button.
| buttonId | The ID of the button. |
| style | The new style to apply. |
| void ButtonManager::setButtonText | ( | int | buttonId, |
| std::string_view | text | ||
| ) |
Sets the text label of a specific button.
| buttonId | The ID of the button. |
| text | The new text for the button. |
| void ButtonManager::setButtonVisible | ( | int | buttonId, |
| bool | visible | ||
| ) |
Sets the visibility of a specific button.
| buttonId | The ID of the button. |
| visible | True to make it visible, false to hide it. |
|
inline |
Sets the default style applied to new buttons.
| style | The default style. |
|
inline |
Sets the font used for all buttons.
| newFont | The new font to use. |
| void ButtonManager::updateButtonPosition | ( | size_t | buttonIndex, |
| SDL_FRect | newRect | ||
| ) |
Updates a button's position by its index.
| buttonIndex | The index of the button in the internal list. |
| newRect | The new rectangle. |
| void ButtonManager::updateButtonPositionById | ( | int | buttonId, |
| SDL_FRect | newRect | ||
| ) |
Updates a button's position by its ID.
| buttonId | The ID of the button. |
| newRect | The new rectangle. |
|
private |
|
private |
|
private |
|
private |
|
private |