Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_text_region.hpp
1#pragma once
2
3#include "structure/graphics/painter/spk_font_painter.hpp"
4#include "structure/graphics/spk_color.hpp"
5#include "structure/graphics/spk_extend_2d.hpp"
6#include "structure/graphics/spk_font.hpp"
7#include "structure/widget/spk_widget.hpp"
8#include "type/spk_text_aligmnent.hpp"
9
10namespace spk
11{
24 {
25 private:
28 spk::Color _glyphColor{1.0f, 1.0f, 1.0f, 1.0f};
29 spk::Color _outlineColor{0.0f, 0.0f, 0.0f, 1.0f};
30 HorizontalAlignment _horizontalAlignment = HorizontalAlignment::Centered;
31 VerticalAlignment _verticalAlignment = VerticalAlignment::Centered;
32 std::wstring _text;
33 spk::Extend2D _geometry{};
34
35 spk::FontMesh _mesh;
36 spk::FontPainter _painter;
37 Font::Bitmap::EditionContract _bitmapEditionContract;
38
39 void _rebuildMesh();
40 void _subscribeToBitmapEdition();
41
42 public:
46 TextRegion();
47
52 void setFont(spk::Font *p_font);
57 void setFontSize(const spk::Font::Size &p_size);
62 void setGlyphColor(const spk::Color &p_color);
67 void setOutlineColor(const spk::Color &p_color);
73 void setColors(const spk::Color &p_glyphColor, const spk::Color &p_outlineColor);
79 void setAlignment(HorizontalAlignment p_horizontalAlignment, VerticalAlignment p_verticalAlignment);
84 void setText(const std::wstring &p_text);
85
90 void setLayer(const float &p_layer);
95 const float &layer() const;
96
101 spk::Font *font() const;
106 const spk::Font::Size &fontSize() const;
111 const spk::Color &glyphColor() const;
116 const spk::Color &outlineColor() const;
121 const std::wstring &text() const;
126 HorizontalAlignment horizontalAlignment() const;
131 VerticalAlignment verticalAlignment() const;
132
137 void setGeometry(const spk::Extend2D &p_geometry);
142 const spk::Extend2D &geometry() const;
143
148 const spk::Vector2UInt computeTextSize() const;
149
153 void render();
154 };
155}
spk::ContractProvider::Contract EditionContract
Contract type returned by edition subscriptions.
Definition spk_font.hpp:108
Loads font data and provides cached bitmap atlases per size.
Definition spk_font.hpp:33
Painter that renders FontMesh instances.
Definition spk_font_painter.hpp:248
void render()
Renders the text region.
Definition spk_text_region.cpp:187
void setAlignment(HorizontalAlignment p_horizontalAlignment, VerticalAlignment p_verticalAlignment)
Sets text alignment within the region.
Definition spk_text_region.cpp:111
const std::wstring & text() const
Returns the current text content.
Definition spk_text_region.cpp:144
const spk::Font::Size & fontSize() const
Returns the current font size.
Definition spk_text_region.cpp:129
const spk::Extend2D & geometry() const
Returns the current render geometry.
Definition spk_text_region.cpp:165
void setText(const std::wstring &p_text)
Sets the text content.
Definition spk_text_region.cpp:118
void setOutlineColor(const spk::Color &p_color)
Sets the glyph outline color.
Definition spk_text_region.cpp:98
const float & layer() const
Returns the current layer value.
Definition spk_text_region.cpp:182
void setGlyphColor(const spk::Color &p_color)
Sets the glyph fill color.
Definition spk_text_region.cpp:92
void setColors(const spk::Color &p_glyphColor, const spk::Color &p_outlineColor)
Sets glyph and outline colors together.
Definition spk_text_region.cpp:104
const spk::Vector2UInt computeTextSize() const
Computes the text size using current font settings.
Definition spk_text_region.cpp:170
void setLayer(const float &p_layer)
Sets the rendering layer.
Definition spk_text_region.cpp:177
const spk::Color & outlineColor() const
Returns the glyph outline color.
Definition spk_text_region.cpp:139
void setGeometry(const spk::Extend2D &p_geometry)
Sets the geometry used to render the text.
Definition spk_text_region.cpp:159
spk::Font * font() const
Returns the current font pointer.
Definition spk_text_region.cpp:124
const spk::Color & glyphColor() const
Returns the glyph fill color.
Definition spk_text_region.cpp:134
void setFontSize(const spk::Font::Size &p_size)
Sets the font size used for rendering.
Definition spk_text_region.cpp:85
VerticalAlignment verticalAlignment() const
Returns the vertical alignment setting.
Definition spk_text_region.cpp:154
HorizontalAlignment horizontalAlignment() const
Returns the horizontal alignment setting.
Definition spk_text_region.cpp:149
void setFont(spk::Font *p_font)
Sets the font used for rendering.
Definition spk_text_region.cpp:73
TextRegion()
Builds an empty text region.
Definition spk_text_region.cpp:7
RGBA color utility storing normalized floating components.
Definition spk_color.hpp:18
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24
Defines glyph and outline sizes for a font bitmap.
Definition spk_font.hpp:40
Mesh specialization for font glyphs.
Definition spk_font_painter.hpp:51
static spk::Font::Size defaultFontSize
Default font size used when widgets do not specify one.
Definition spk_widget.hpp:84
static spk::Font defaultFont
Default font used when widgets do not specify one.
Definition spk_widget.hpp:82