Dualie
Loading...
Searching...
No Matches
Text.hpp
1//
2// Created by caleb on 7/20/24.
3//
4
5#ifndef DUALIE_TEXT_HPP
6#define DUALIE_TEXT_HPP
7#include <citro2d.h>
8#include <Dualie/Graphics/Transformable.hpp>
9#include <Dualie/Graphics/Drawable.hpp>
10#include <Dualie/Graphics/TextBuffer.hpp>
11#include <Dualie/Graphics/Color.hpp>
12
13
14namespace dl
15{
16
17 enum TextAlignment
18 {
19 AtBaseline = BIT(0),
20 AlignLeft = 0 << 2,
21 AlignRight = 1 << 2,
22 AlignCenter = 2 << 2,
23 AlignJustified = 3 << 2,
24 AlignMask = 3 << 2,
25 };
26
30 class Text : public dl::Transformable, public dl::Drawable
31 {
32 C2D_TextBuf p_buf;
33 C2D_Text m_textBuf;
34 C2D_Font m_defaultFont;
35 C2D_Font m_customFont;
36 TextAlignment m_alignment;
37
38 std::string m_textString;
39
40 dl::Vector2f m_origin;
41
42 dl::Vector2f m_scale;
43 dl::Color m_color;
44
45 public:
46 explicit Text(const dl::TextBuffer& textBuffer);
47 ~Text();
48
52 void updateDynamicText();
53
58 void setString(std::string str);
59
64 void setScale(const dl::Vector2f& scale);
65
70 void setAlignment(TextAlignment alignment);
71
78 void setOrigin(const dl::Vector2f& origin);
79
87 void setOrigin(float x, float y);
88
93 void setColor(const dl::Color& color);
94
99 const std::string &getString();
100
101
105 const dl::Vector2f& getOrigin();
106
111 const dl::Vector2f& getScale();
112
113 void draw(const dl::Vector2f &viewOffset) override;
114
115
116 };
117
118}
119
120#endif //DUALIE_TEXT_HPP
A class used to describe a RGBA color.
Definition Color.hpp:19
The base class for any object that can be drawn to the screen.
Definition Drawable.hpp:15
Used to contain text objects. This class is required for the Text object to operate.
Definition TextBuffer.hpp:17
A class used to handle the transformation and drawing of visible text.
Definition Text.hpp:31
void setString(std::string str)
Sets the text's string.
Definition Text.cpp:28
void setColor(const dl::Color &color)
Sets the color of the text.
Definition Text.cpp:77
void setOrigin(const dl::Vector2f &origin)
Sets the origin of the shape. The default origin is (0,0) and is the top left pixel of the shape boun...
Definition Text.cpp:40
void setScale(const dl::Vector2f &scale)
Sets the scale of the text.
Definition Text.cpp:51
void draw(const dl::Vector2f &viewOffset) override
Draws the drawable to the screen.
Definition Text.cpp:21
void setAlignment(TextAlignment alignment)
Sets the alignment of the text.
Definition Text.cpp:72
const std::string & getString()
Definition Text.cpp:35
const dl::Vector2f & getScale()
Definition Text.cpp:62
void updateDynamicText()
reparses and reoptimizes the text. This should be used if you call TextBuffer::flushBuffer beforehand...
Definition Text.cpp:67
const dl::Vector2f & getOrigin()
Definition Text.cpp:57
A base class for anything that has a position on the screen.
Definition Transformable.hpp:16