@@ -15,104 +15,84 @@ class Text {
1515 public:
1616 /* *
1717 * Initializes a new Text object.
18+ *
1819 * @param text Text to initialize.
19- * @return void.
20+ * @param fontSize The size of the text.
21+ * @param color The color of the font.
22+ * @param font Font to initialize.
23+ * @param spacing The spacing of the text.
2024 */
21- Text (const std::string& text = " " )
22- {
23- SetText (text);
25+ Text (const std::string& text = " " , float fontSize = 10 , const ::Color& color = WHITE, const ::Font& font = ::GetFontDefault(), float spacing = 0 ) : text(text), fontSize(fontSize), color(color), font(font), spacing(spacing) {
26+ // Nothing.
2427 }
25-
28+
2629 /* *
27- * Initializes a new Text object.
30+ * Initializes a new Text object with a custom font.
31+ *
32+ * @param font Font to initialize.
2833 * @param text Text to initialize.
29- * @param posX X position of the text.
30- * @param posY Y position of the text.
31- * @return void .
34+ * @param fontSize The size of the text.
35+ * @param spacing The spacing of the text.
36+ * @param color The color of the font .
3237 */
33- Text (const std::string& text, const float posX, const float posY)
34- {
35- _text = text;
36- _position.x = posX;
37- _position.y = posY;
38+ Text (const ::Font& font, const std::string& text = " " , float fontSize = 10 , float spacing = 0 , const ::Color& color = WHITE) : font(font), text(text), fontSize(fontSize), spacing(spacing), color(color) {
39+ // Nothing.
3840 }
3941
42+ GETTERSETTER (std::string, Text, text)
43+ GETTERSETTER (float , FontSize, fontSize)
44+ GETTERSETTER (::Font, Font, font)
45+ GETTERSETTER (::Color, Color, color)
46+ GETTERSETTER (float , Spacing, spacing)
47+
4048 /* *
41- * Initializes a new Text object.
42- * @param text Text to initialize.
43- * @param posX X position of the text.
44- * @param posY Y position of the text.
45- * @return void.
49+ * Draw text with values in class.
4650 */
47- Text (const std::string& text, const ::Vector2& position)
48- {
49- _text = text;
50- _position = position;
51+ inline void Draw (const ::Vector2& position) {
52+ ::DrawTextEx (font, text.c_str(), position, fontSize, spacing, color);
5153 }
5254
5355 /* *
54- * Initializes a new Text object.
55- * @param font Font to initialize.
56- * @param text Text to initialize.
57- * @param posX X position of the text.
58- * @param posY Y position of the text.
59- * @return void.
56+ * Draw text with values in class.
6057 */
61- Text (const ::Font& font, const std::string& text, const ::Vector2& position, const float fontSize, const float spacing, const ::Color& color)
62- {
63- _font = font;
64- _text = text;
65- _position = position;
66- _fontSize = fontSize;
67- _spacing = spacing;
68- _color = color;
58+ inline void Draw (int posX, int posY) {
59+ ::DrawTextEx (font, text.c_str(), {static_cast <float >(posX), static_cast <float >(posY)}, fontSize, spacing, color);
6960 }
70-
7161
72- ~Text () {
62+ /* *
63+ * Draw text using Font and pro parameters (rotation).
64+ *
65+ * @see DrawTextPro()
66+ */
67+ inline void Draw (const ::Vector2& position, float rotation, const Vector2& origin = {0 , 0 }) {
68+ ::DrawTextPro (font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
7369 }
7470
7571 /* *
76- * @brief Draw text with values in class.
77- *
72+ * Measure string width for default font
7873 */
79- void Draw () {
80- ::DrawTextEx (_font, _text .c_str(), _position, _fontSize, _spacing, _color );
74+ inline int Measure () {
75+ return :: MeasureText (text .c_str (), static_cast < int >(fontSize) );
8176 }
8277
8378 /* *
84- * @brief Draw text with values in class.
85- *
79+ * Measure string size for Font
8680 */
87- void Draw ( const :: Vector2& position ) {
88- ::DrawTextEx (_font, _text .c_str(), position, _fontSize, _spacing, _color );
81+ inline Vector2 MeasureEx ( ) {
82+ return :: MeasureTextEx (font, text .c_str (), fontSize, spacing );
8983 }
90-
91- std::string GetText () const { return _text; }
92- void SetText (const std::string& text) { _text = text; }
93-
94- float GetFontSize () const { return _fontSize; }
95- void SetFontSize (float fontSize) { _fontSize = fontSize; }
96-
97- // Font GetFont() const { return _font; }
98- void SetFont (const ::Font& font) { _font = font; }
99-
100- Color GetColor () const { return _color; }
101- void SetColor (const ::Color& color) { _color = color; }
102-
103- float GetPosX () const { return _position.GetX (); }
104- void SetPosX (float posX) { _position.SetX (posX); }
105-
106- float GetPosY () const { return _position.GetY (); }
107- void SetPosY (float posY) { _position.SetY (posY); }
10884
109- Vector2 GetPosition () const { return _position; }
110- void SetPosition (const ::Vector2& position) { _position = position; }
85+ Text& operator =(const Text& other) {
86+ if (this == &other) {
87+ return *this ;
88+ }
11189
112- float GetSpacing () const { return _spacing; }
113- void SetSpacing (float spacing) { _spacing = spacing; }
90+ text = other.text ;
91+ fontSize = other.fontSize ;
92+ color = other.color ;
93+ font = other.font ;
94+ spacing = other.spacing ;
11495
115- Text& operator =(const Text& text) {
11696 return *this ;
11797 }
11898
@@ -152,13 +132,11 @@ class Text {
152132 ::DrawTextPro (font, text.c_str(), position, origin, rotation, fontSize, spacing, color);
153133 }
154134
155- private:
156- std::string _text = " " ;
157- float _fontSize = 10 ;
158- Font _font = ::GetFontDefault();
159- Color _color = WHITE;
160- Vector2 _position = {0.0 , 0.0 };
161- float _spacing = 0 ;
135+ std::string text;
136+ float fontSize;
137+ ::Color color;
138+ ::Font font;
139+ float spacing;
162140};
163141} // namespace raylib
164142
0 commit comments