SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Button.h
1#ifndef Button_H
2#define Button_H
3
4#include "AzulCore.h"
5#include "UIComponent.h"
6
7class UICommand;
8class SpriteFont;
9class SpriteString;
10
29class Button : public UIComponent
30{
31public:
36 Button() = default;
37 Button(const Button&) = delete;
38 Button& operator=(const Button&) = delete;
39 ~Button();
40
45 Button(std::string key);
46
52 void SetOrigin(float x, float y);
53
59 void SetPosition(float x, float y);
60
65 void SetAngleRadians(float rad);
66
71 void SetAngleDegrees(float deg);
72
78 void SetScaleFactor(float x, float y);
79
85 void SetScalePixel(float x, float y);
86
91 float GetWidth() const;
92
97 float GetHeight() const;
98
103 float GetAngle() const;
104
109 float GetScaleX() const;
110
115 float GetScaleY() const;
116
121 float GetPosX() const;
122
127 float GetPosY() const;
128
133 void SetOnPressCommand(UICommand* cmd);
134
139 void SetOnHoverCommand(UICommand* cmd);
140
145 void SetOnHoldCommand(UICommand* cmd);
146
152
157 void SetDefaultSprite(const std::string& key);
158
163 void SetOnPressSprite(const std::string& key);
164
169 void SetOnHeldSprite(const std::string& key);
170
175 void SetOnHoverSprite(const std::string& key);
176
182 void SetText(const std::string& text, std::string fontKey);
183
188 std::string GetText() const;
189
195 void SetTextScale(float x, float y);
196
202 void SetTextScalePixel(float x, float y);
203
204private:
205 friend class UIAttorney;
206
207 GraphicsObject_Sprite* pSprite;
208 GraphicsObject_Sprite* pDefaultSprite;
209 GraphicsObject_Sprite* pOnPressSprite;
210 GraphicsObject_Sprite* pOnHeldSprite;
211 GraphicsObject_Sprite* pOnHoverSprite;
212
213 Matrix trans;
214 Matrix rot;
215 Matrix scale;
216
217 float posX;
218 float posY;
219 float angle;
220 float scaleX;
221 float scaleY;
222
227
229
233 std::string font;
234
238 void OnPress() override;
239
243 void OnHover();
244
248 void OnHold();
249
253 void OnRelease();
254
258 void Render() override;
259
266 bool IsMouseOver(float xPos, float yPos) override;
267
271 void UpdateWorld();
272};
273
274#endif
void OnRelease()
Called when the button is released.
Definition Button.cpp:208
float GetWidth() const
Gets the width of the button.
Definition Button.cpp:84
void OnHold()
Called when the button is held.
Definition Button.cpp:192
void SetPosition(float x, float y)
Sets the position of the button.
Definition Button.cpp:56
Button()=default
Default constructor. Initializes the button with default values.
void SetOnPressCommand(UICommand *cmd)
Sets the command to be executed when the button is pressed.
Definition Button.cpp:218
float textScaleX
X scale for text.
Definition Button.h:231
void UpdateWorld()
Updates the world matrix of the button.
Definition Button.cpp:385
UICommand * pOnReleaseCommand
Command for release event.
Definition Button.h:226
void OnPress() override
Called when the button is pressed.
Definition Button.cpp:158
void SetOnHoldCommand(UICommand *cmd)
Sets the command to be executed when the button is held.
Definition Button.cpp:236
float textScaleY
Y scale for text.
Definition Button.h:232
std::string GetText() const
Gets the text label of the button.
Definition Button.cpp:285
void Render() override
Updates the world matrix of the button.
Definition Button.cpp:119
float GetPosY() const
Gets the y-coordinate of the button's position.
Definition Button.cpp:114
void SetOrigin(float x, float y)
Sets the origin of the button.
Definition Button.cpp:50
Matrix rot
Rotation matrix.
Definition Button.h:214
void SetScalePixel(float x, float y)
Sets the scale of the button in pixels.
Definition Button.cpp:78
void OnHover()
Called when the button is hovered.
Definition Button.cpp:175
void SetOnHeldSprite(const std::string &key)
Sets the sprite for the button when held.
Definition Button.cpp:364
UICommand * pOnHoverCommand
Command for hover event.
Definition Button.h:224
float scaleX
X scale factor.
Definition Button.h:220
void SetAngleRadians(float rad)
Sets the angle of the button in radians.
Definition Button.cpp:62
GraphicsObject_Sprite * pSprite
The current sprite for the button.
Definition Button.h:207
void SetDefaultSprite(const std::string &key)
Sets the default sprite for the button.
Definition Button.cpp:344
float posX
X position of the button.
Definition Button.h:217
void SetOnHoverCommand(UICommand *cmd)
Sets the command to be executed when the button is hovered.
Definition Button.cpp:227
float GetScaleX() const
Gets the x-scale factor of the button.
Definition Button.cpp:99
float GetPosX() const
Gets the x-coordinate of the button's position.
Definition Button.cpp:109
void SetTextScale(float x, float y)
Sets the text scale for the button.
Definition Button.cpp:294
Matrix trans
Translation matrix.
Definition Button.h:213
GraphicsObject_Sprite * pOnHoverSprite
Sprite when hovered.
Definition Button.h:211
UICommand * pOnPressCommand
Command for press event.
Definition Button.h:223
GraphicsObject_Sprite * pOnPressSprite
Sprite when pressed.
Definition Button.h:209
void SetOnReleaseCommand(UICommand *cmd)
Sets the command to be executed when the button is released.
Definition Button.cpp:245
void SetText(const std::string &text, std::string fontKey)
Sets the text label for the button.
Definition Button.cpp:254
void SetTextScalePixel(float x, float y)
Sets the text scale in pixels for the button.
Definition Button.cpp:319
std::string font
Font key for the text.
Definition Button.h:233
bool IsMouseOver(float xPos, float yPos) override
Checks if the mouse is over the button.
Definition Button.cpp:130
float posY
Y position of the button.
Definition Button.h:218
float scaleY
Y scale factor.
Definition Button.h:221
GraphicsObject_Sprite * pDefaultSprite
The default sprite.
Definition Button.h:208
float angle
Angle in radians.
Definition Button.h:219
bool textScaleSet
Whether text scale is set manually.
Definition Button.h:230
float GetHeight() const
Gets the height of the button.
Definition Button.cpp:89
float GetAngle() const
Gets the angle of the button in radians.
Definition Button.cpp:94
SpriteString * pTextLabel
Text label for the button.
Definition Button.h:228
float GetScaleY() const
Gets the y-scale factor of the button.
Definition Button.cpp:104
void SetScaleFactor(float x, float y)
Sets the scale of the button.
Definition Button.cpp:72
Matrix scale
Scale matrix.
Definition Button.h:215
void SetOnHoverSprite(const std::string &key)
Sets the sprite for the button when hovered.
Definition Button.cpp:374
UICommand * pOnHoldCommand
Command for hold event.
Definition Button.h:225
GraphicsObject_Sprite * pOnHeldSprite
Sprite when held.
Definition Button.h:210
void SetOnPressSprite(const std::string &key)
Sets the sprite for the button when pressed.
Definition Button.cpp:354
void SetAngleDegrees(float deg)
Sets the angle of the button in degrees.
Definition Button.cpp:67
Represents a font in the SUNENGINE.
Definition SpriteFont.h:19
Represents a string of sprites in the SUNENGINE.
Definition SpriteString.h:18
Abstract base class for UI-related command objects.
Definition UICommand.h:32
Abstract base class for all UI components.
Definition UIComponent.h:32