A clickable UI button component. More...
#include <Button.h>
Public Member Functions | |
Button ()=default | |
Default constructor. Initializes the button with default values. | |
Button (const Button &)=delete | |
Button & | operator= (const Button &)=delete |
Button (std::string key) | |
Constructor that initializes the button with a texture key. | |
void | SetOrigin (float x, float y) |
Sets the origin of the button. | |
void | SetPosition (float x, float y) |
Sets the position of the button. | |
void | SetAngleRadians (float rad) |
Sets the angle of the button in radians. | |
void | SetAngleDegrees (float deg) |
Sets the angle of the button in degrees. | |
void | SetScaleFactor (float x, float y) |
Sets the scale of the button. | |
void | SetScalePixel (float x, float y) |
Sets the scale of the button in pixels. | |
float | GetWidth () const |
Gets the width of the button. | |
float | GetHeight () const |
Gets the height of the button. | |
float | GetAngle () const |
Gets the angle of the button in radians. | |
float | GetScaleX () const |
Gets the x-scale factor of the button. | |
float | GetScaleY () const |
Gets the y-scale factor of the button. | |
float | GetPosX () const |
Gets the x-coordinate of the button's position. | |
float | GetPosY () const |
Gets the y-coordinate of the button's position. | |
void | SetOnPressCommand (UICommand *cmd) |
Sets the command to be executed when the button is pressed. | |
void | SetOnHoverCommand (UICommand *cmd) |
Sets the command to be executed when the button is hovered. | |
void | SetOnHoldCommand (UICommand *cmd) |
Sets the command to be executed when the button is held. | |
void | SetOnReleaseCommand (UICommand *cmd) |
Sets the command to be executed when the button is released. | |
void | SetDefaultSprite (const std::string &key) |
Sets the default sprite for the button. | |
void | SetOnPressSprite (const std::string &key) |
Sets the sprite for the button when pressed. | |
void | SetOnHeldSprite (const std::string &key) |
Sets the sprite for the button when held. | |
void | SetOnHoverSprite (const std::string &key) |
Sets the sprite for the button when hovered. | |
void | SetText (const std::string &text, std::string fontKey) |
Sets the text label for the button. | |
std::string | GetText () const |
Gets the text label of the button. | |
void | SetTextScale (float x, float y) |
Sets the text scale for the button. | |
void | SetTextScalePixel (float x, float y) |
Sets the text scale in pixels for the button. | |
![]() | |
virtual | ~UIComponent ()=default |
Virtual destructor. | |
int | GetLayer () const |
Gets the rendering layer of the component. | |
virtual void | SetLayer (int layer) |
Sets the rendering layer of the component. | |
UIComponentType | GetType () const |
Gets the type of the UI component. | |
bool | IsEnabled () const |
Returns whether the component is enabled or not. | |
void | SetEnabled (bool enabled) |
Sets the enabled state of the component. | |
void | SetOwningCanvas (Canvas *canvas) |
Gets the owning canvas of the component. | |
Private Member Functions | |
void | OnPress () override |
Called when the button is pressed. | |
void | OnHover () |
Called when the button is hovered. | |
void | OnHold () |
Called when the button is held. | |
void | OnRelease () |
Called when the button is released. | |
void | Render () override |
Updates the world matrix of the button. | |
bool | IsMouseOver (float xPos, float yPos) override |
Checks if the mouse is over the button. | |
void | UpdateWorld () |
Updates the world matrix of the button. | |
Private Attributes | |
GraphicsObject_Sprite * | pSprite |
The current sprite for the button. | |
GraphicsObject_Sprite * | pDefaultSprite |
The default sprite. | |
GraphicsObject_Sprite * | pOnPressSprite |
Sprite when pressed. | |
GraphicsObject_Sprite * | pOnHeldSprite |
Sprite when held. | |
GraphicsObject_Sprite * | pOnHoverSprite |
Sprite when hovered. | |
Matrix | trans |
Translation matrix. | |
Matrix | rot |
Rotation matrix. | |
Matrix | scale |
Scale matrix. | |
float | posX |
X position of the button. | |
float | posY |
Y position of the button. | |
float | angle |
Angle in radians. | |
float | scaleX |
X scale factor. | |
float | scaleY |
Y scale factor. | |
UICommand * | pOnPressCommand |
Command for press event. | |
UICommand * | pOnHoverCommand |
Command for hover event. | |
UICommand * | pOnHoldCommand |
Command for hold event. | |
UICommand * | pOnReleaseCommand |
Command for release event. | |
SpriteString * | pTextLabel |
Text label for the button. | |
bool | textScaleSet |
Whether text scale is set manually. | |
float | textScaleX |
X scale for text. | |
float | textScaleY |
Y scale for text. | |
std::string | font |
Font key for the text. | |
Friends | |
class | UIAttorney |
Additional Inherited Members | |
![]() | |
bool | Enabled = true |
Indicates if the component is enabled or not. | |
int | Layer = 0 |
Rendering layer in. | |
UIComponentType | Type = UIComponentType::None |
Type of the UI component. | |
Canvas * | pOwningCanvas = nullptr |
Pointer to the owning canvas, if any. | |
A clickable UI button component.
The Button class represents a UI button that can display text, respond to mouse events, and execute commands when pressed, hovered, held, or released. It supports custom sprites for different button states and can be added to a Canvas or other UI containers.
Example usage:
Button::Button | ( | std::string | key | ) |
Constructor that initializes the button with a texture key.
key | The texture key for the button's default sprite. |
float Button::GetAngle | ( | ) | const |
Gets the angle of the button in radians.
float Button::GetHeight | ( | ) | const |
Gets the height of the button.
float Button::GetPosX | ( | ) | const |
Gets the x-coordinate of the button's position.
float Button::GetPosY | ( | ) | const |
Gets the y-coordinate of the button's position.
float Button::GetScaleX | ( | ) | const |
Gets the x-scale factor of the button.
float Button::GetScaleY | ( | ) | const |
Gets the y-scale factor of the button.
std::string Button::GetText | ( | ) | const |
Gets the text label of the button.
float Button::GetWidth | ( | ) | const |
Gets the width of the button.
|
overrideprivatevirtual |
Checks if the mouse is over the button.
xPos | The x-coordinate of the mouse position. |
yPos | The y-coordinate of the mouse position. |
Implements UIComponent.
|
overrideprivatevirtual |
Called when the button is pressed.
Implements UIComponent.
|
overrideprivatevirtual |
Updates the world matrix of the button.
Implements UIComponent.
void Button::SetAngleDegrees | ( | float | deg | ) |
Sets the angle of the button in degrees.
deg | The angle in degrees. |
void Button::SetAngleRadians | ( | float | rad | ) |
Sets the angle of the button in radians.
rad | The angle in radians. |
void Button::SetDefaultSprite | ( | const std::string & | key | ) |
Sets the default sprite for the button.
key | The texture key for the default sprite. |
void Button::SetOnHeldSprite | ( | const std::string & | key | ) |
Sets the sprite for the button when held.
key | The texture key for the held sprite. |
void Button::SetOnHoldCommand | ( | UICommand * | cmd | ) |
Sets the command to be executed when the button is held.
cmd | The command to be executed. |
void Button::SetOnHoverCommand | ( | UICommand * | cmd | ) |
Sets the command to be executed when the button is hovered.
cmd | The command to be executed. |
void Button::SetOnHoverSprite | ( | const std::string & | key | ) |
Sets the sprite for the button when hovered.
key | The texture key for the hovered sprite. |
void Button::SetOnPressCommand | ( | UICommand * | cmd | ) |
Sets the command to be executed when the button is pressed.
cmd | The command to be executed. |
void Button::SetOnPressSprite | ( | const std::string & | key | ) |
Sets the sprite for the button when pressed.
key | The texture key for the pressed sprite. |
void Button::SetOnReleaseCommand | ( | UICommand * | cmd | ) |
Sets the command to be executed when the button is released.
cmd | The command to be executed. |
void Button::SetOrigin | ( | float | x, |
float | y ) |
Sets the origin of the button.
x | The x-coordinate of the origin (0.0 to 1.0). |
y | The y-coordinate of the origin (0.0 to 1.0). |
void Button::SetPosition | ( | float | x, |
float | y ) |
Sets the position of the button.
x | The x-coordinate of the button's position. |
y | The y-coordinate of the button's position. |
void Button::SetScaleFactor | ( | float | x, |
float | y ) |
Sets the scale of the button.
x | The x-scale factor. |
y | The y-scale factor. |
void Button::SetScalePixel | ( | float | x, |
float | y ) |
Sets the scale of the button in pixels.
x | The width in pixels. |
y | The height in pixels. |
void Button::SetText | ( | const std::string & | text, |
std::string | fontKey ) |
Sets the text label for the button.
text | The text to display on the button. |
fontKey | The texture key for the font to use. |
void Button::SetTextScale | ( | float | x, |
float | y ) |
Sets the text scale for the button.
x | The x-scale factor for the text. |
y | The y-scale factor for the text. |
void Button::SetTextScalePixel | ( | float | x, |
float | y ) |
Sets the text scale in pixels for the button.
x | The width in pixels for the text. |
y | The height in pixels for the text. |