23 #include "hx3d/gui/text.hpp" 25 #include "hx3d/core/core.hpp" 26 #include "hx3d/graphics/font.hpp" 28 #include "hx3d/utils/log.hpp" 29 #include "hx3d/utils/assets.hpp" 35 Text(
Core::Assets()->get<Font>(
"default")) {}
38 Text(nullptr, font) {}
97 for (
unsigned int i = 0; i <
_content.size(); ++i) {
98 texture_glyph_t *glyph = texture_font_get_glyph(fontData.font, &
_content[i]);
99 if (glyph !=
nullptr) {
102 kerning = texture_glyph_get_kerning(glyph, &
_content[i-1]);
106 float x0 = pen.x + glyph->offset_x;
107 float y0 = pen.y + glyph->offset_y;
108 float x1 = x0 + glyph->width;
109 float y1 = y0 - glyph->height;
110 float s0 = glyph->s0;
111 float t0 = glyph->t0;
112 float s1 = glyph->s1;
113 float t1 = glyph->t1;
115 _geometry->setAttribute(
"Position", std::vector<float> {
122 _geometry->setAttribute(
"Texture", std::vector<float> {
133 pen.x += glyph->advance_x;
139 if (
_font ==
nullptr)
146 for (
unsigned int i = 0; i <
_content.size(); ++i) {
147 texture_glyph_t *glyph = texture_font_get_glyph(fontData.font, &
_content[i]);
148 if (glyph !=
nullptr) {
151 kerning = texture_glyph_get_kerning(glyph, &
_content[i-1]);
155 pen.x += glyph->advance_x;
170 for (
unsigned int i = 0; i <
_content.size(); ++i) {
171 texture_glyph_t *glyph = texture_font_get_glyph(fontData.font, &
_content[i]);
172 if (glyph !=
nullptr) {
175 kerning = texture_glyph_get_kerning(glyph, &
_content[i-1]);
178 pen +=
function.sample();
181 float x0 = pen.x + glyph->offset_x;
182 float y0 = pen.y + glyph->offset_y;
183 float x1 = x0 + glyph->width;
184 float y1 = y0 - glyph->height;
185 float s0 = glyph->s0;
186 float t0 = glyph->t0;
187 float s1 = glyph->s1;
188 float t1 = glyph->t1;
190 _geometry->setAttribute(
"Position", std::vector<float> {
197 _geometry->setAttribute(
"Texture", std::vector<float> {
208 pen.x += glyph->advance_x;
bool isCenterAligned()
Is the text center aligned ?
void init()
Initialize the text.
void setTint(Color tint)
Set the mesh tint.
void setCharacterSize(int size)
Set the character size.
void setCenterAlignment(bool value)
Set the center alignment.
bool _centerAligned
Is the text center aligned ?
Text()
Create a text without font. See setFont.
void setFont(Ptr< Font > font)
Set the font.
float _length
Text length.
float calculateLength()
Calculate the text length.
int _characterSize
Character size.
std::string _content
Text content.
Ptr< Font > _font
Text font.
void setContent(std::string content)
Set the text content.
Ptr< geom::BaseGeometry > _geometry
Current geometry.
Centralized framework management.
int getCharacterSize()
Get the character size.
Math function definition.
float getLength()
Get the text length.
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Ptr< Font > getFont()
Get the text font.
void functionDraw(Ptr< Shader > shader, math::Function function)
Draw the text following a function.