SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
Textbox.h
1#ifndef TEXTBOX_H
2#define TEXTBOX_H
3
4#include "UIComponent.h"
5#include "../Inputable/Inputable.h"
6#include "../Sprites/SpriteString.h"
7#include <string>
8
28class Textbox : public UIComponent, public Inputable
29{
30public:
34 Textbox() = default;
35 Textbox(const Textbox&) = delete;
36 Textbox& operator=(const Textbox&) = delete;
37 ~Textbox();
38
46 Textbox(const std::string& textureKey, const std::string& fontKey, float width, float height);
47
52 void SetPosition(float x, float y);
53
59 void SetScale(float x, float y);
60
65 void SetLayer(int layer) override;
66
71 const std::string& GetText() const;
72
76 void LoseFocus();
77
81 char GetCharFromKey(AZUL_KEY key, bool shiftHeld);
82
86 void ClearText();
87
92 void SetCharacterLimit(int limit);
93
99 void SetTextSize(float x, float y);
100
106 void SetTextSizePixel(float x, float y);
107
108private:
111 std::string text;
112 std::string fontKey;
113
114 float posX;
115 float posY;
116 float width;
117 float height;
118 float scaleX;
119 float scaleY;
120
123 bool capsLock;
124
126
131 void KeyPress(AZUL_KEY key) override;
132
137 void KeyHeld(AZUL_KEY key) override;
138
143 void KeyRelease(AZUL_KEY key) override;
144
148 void Render() override;
149
156 bool IsMouseOver(float x, float y) override;
157
161 void OnPress() override;
162
163
167 void UpdateTextLabel();
168
172 void KeyboardReg();
173
177 void KeyboardDereg();
178};
179
180#endif // TEXTBOX_H
Represents a sprite in the SUNENGINE.
Definition Sprites/SUNENGINESprite.h:16
Represents a string of sprites in the SUNENGINE.
Definition SpriteString.h:18
bool capsLock
True if caps lock is active.
Definition Textbox.h:123
float posY
Y position of the textbox center.
Definition Textbox.h:115
float scaleX
X scale factor.
Definition Textbox.h:118
void SetLayer(int layer) override
Sets the rendering layer of the textbox.
Definition Textbox.cpp:54
void KeyHeld(AZUL_KEY key) override
Handles key held events for text input and editing.
Definition Textbox.cpp:216
bool isFocused
True if the textbox is focused for input.
Definition Textbox.h:121
void OnPress() override
Handles mouse press events (focuses the textbox).
Definition Textbox.cpp:92
char GetCharFromKey(AZUL_KEY key, bool shiftHeld)
Sets the focus to the textbox (starts receiving keyboard input).
Definition Textbox.cpp:101
void UpdateTextLabel()
Updates the world matrix of the textbox.
Definition Textbox.cpp:232
void SetScale(float x, float y)
Sets the scale of the textbox.
Definition Textbox.cpp:46
void Render() override
Renders the textbox background and text label.
Definition Textbox.cpp:73
float height
Height of the textbox.
Definition Textbox.h:117
void SetTextSize(float x, float y)
Sets the size of the text in the textbox.
Definition Textbox.cpp:154
int characterLimit
Maximum number of characters allowed in the textbox.
Definition Textbox.h:125
void SetPosition(float x, float y)
Sets the text label of the textbox.
Definition Textbox.cpp:38
void KeyboardDereg()
Handles deregistration when the textbox is unfocused.
Definition Textbox.cpp:482
void KeyRelease(AZUL_KEY key) override
Handles key release events.
Definition Textbox.cpp:224
void ClearText()
Clears the current text in the textbox.
Definition Textbox.cpp:137
SUNENGINESprite * pBackgroundSprite
Background sprite for the textbox.
Definition Textbox.h:109
std::string text
Current text in the textbox.
Definition Textbox.h:111
bool IsMouseOver(float x, float y) override
Checks if the mouse is over the textbox.
Definition Textbox.cpp:82
bool shiftHeld
True if shift is currently held.
Definition Textbox.h:122
SpriteString * pTextLabel
Text label for displaying input.
Definition Textbox.h:110
const std::string & GetText() const
Gets the current text in the textbox.
Definition Textbox.cpp:59
void SetCharacterLimit(int limit)
Sets the maximum number of characters allowed in the textbox.
Definition Textbox.cpp:143
void LoseFocus()
Removes focus from the textbox (stops receiving keyboard input).
Definition Textbox.cpp:64
void SetTextSizePixel(float x, float y)
Sets the size of the text in the textbox by pixel dimensions.
Definition Textbox.cpp:167
std::string fontKey
Font key for the text label.
Definition Textbox.h:112
void KeyboardReg()
Handles registration when the textbox is focused.
Definition Textbox.cpp:425
void KeyPress(AZUL_KEY key) override
Handles key press events for text input and editing.
Definition Textbox.cpp:180
float width
Width of the textbox.
Definition Textbox.h:116
float scaleY
Y scale factor.
Definition Textbox.h:119
Textbox()=default
Default constructor (for serialization).
float posX
X position of the textbox center.
Definition Textbox.h:114
Abstract base class for all UI components.
Definition UIComponent.h:32