3#include "structure/graphics/painter/spk_mesh_painter.hpp"
4#include "structure/graphics/spk_color.hpp"
5#include "structure/graphics/spk_font.hpp"
7#include "structure/geometry/spk_mesh.hpp"
8#include "structure/opengl/spk_vertex_buffer_object.hpp"
10#include "type/spk_text_aligmnent.hpp"
66 Font *_font =
nullptr;
70 spk::Vector2Int _cursor{0, 0};
71 wchar_t _previousGlyph = 0;
76 spk::Vector2Int min{std::numeric_limits<int>::max(), std::numeric_limits<int>::max()};
77 spk::Vector2Int max{std::numeric_limits<int>::min(), std::numeric_limits<int>::min()};
80 void include(
const spk::Vector2Int &p_point)
89 min.
x = std::min(min.
x, p_point.
x);
90 min.
y = std::min(min.
y, p_point.
y);
91 max.
x = std::max(max.
x, p_point.
x);
92 max.
y = std::max(max.
y, p_point.
y);
95 spk::Vector2Int size()
const
103 using Placement = std::pair<const Font::Bitmap::Glyph *, spk::Vector2Int>;
104 std::vector<Placement> _placements;
105 std::vector<size_t> _lineBreaks{0};
107 void _validateSingleLine(
const std::wstring &p_text)
const;
109 int _ensureLineHeight();
113 spk::Vector2Int _computeOffset(
const Bounds &p_bounds,
const spk::Vector2Int &p_anchor, spk::HorizontalAlignment p_horizontalAlignment, spk::VerticalAlignment p_verticalAlignment)
const;
117 std::vector<Placement> placements;
121 LayoutResult _layout(
const std::wstring &p_text,
Font::Bitmap &p_bitmap,
int p_lineHeight,
bool p_buildPlacements)
const;
179 FontMesh construct(
const spk::Vector2Int &p_anchor, spk::HorizontalAlignment p_horizontalAlignment = spk::HorizontalAlignment::Centered, spk::VerticalAlignment p_verticalAlignment = spk::VerticalAlignment::Centered);
183 Font *_font =
nullptr;
231 layout.addAttribute({0, Attribute::Type::Vector2Int});
232 layout.addAttribute({1, Attribute::Type::Vector2});
251 OpenGL::UBO &_modelData;
253 OpenGL::UBO &_styleUBO;
267 void setLayer(
const float &p_layer);
272 const float &
layer()
const;
Font atlas texture and glyph metadata for a specific size.
Definition spk_font.hpp:78
Loads font data and provides cached bitmap atlases per size.
Definition spk_font.hpp:33
spk::Vector2UInt computeTextSize(const std::wstring &p_text) const
Computes the pixel size for a text string.
Definition spk_font_painter.cpp:218
FontMesh construct(const spk::Vector2Int &p_anchor, spk::HorizontalAlignment p_horizontalAlignment=spk::HorizontalAlignment::Centered, spk::VerticalAlignment p_verticalAlignment=spk::VerticalAlignment::Centered)
Builds a FontMesh with alignment around an anchor.
Definition spk_font_painter.cpp:236
Builder()=default
Builds an empty builder.
Builder & setTabSize(size_t p_tabSize)
Sets the tab size used for layout.
Definition spk_font_painter.cpp:145
Builder & addNewline()
Inserts a line break in the layout buffer.
Definition spk_font_painter.cpp:212
Builder & addText(const std::wstring &p_text)
Appends text to the layout buffer.
Definition spk_font_painter.cpp:162
Builder & clear()
Clears any accumulated text and layout state.
Definition spk_font_painter.cpp:151
void setLayer(const float &p_layer)
Sets the layer value used during rendering.
Definition spk_font_painter.cpp:359
void setColors(const spk::Color &p_glyphColor, const spk::Color &p_outlineColor)
Sets glyph and outline colors together.
Definition spk_font_painter.cpp:407
const float & layer() const
Returns the current layer value.
Definition spk_font_painter.cpp:370
const spk::Color & outlineColor() const
Returns the current outline color.
Definition spk_font_painter.cpp:420
const spk::Color & glyphColor() const
Returns the current glyph color.
Definition spk_font_painter.cpp:415
void setMesh(const FontMesh *p_mesh) override
Sets the font mesh to render.
Definition spk_font_painter.cpp:375
void setGlyphColor(const spk::Color &p_color)
Sets the glyph fill color.
Definition spk_font_painter.cpp:395
FontPainter()
Builds a font painter with its rendering pipeline.
Definition spk_font_painter.cpp:348
void setOutlineColor(const spk::Color &p_color)
Sets the glyph outline color.
Definition spk_font_painter.cpp:401
Stores polygon data and exposes GPU-ready vertex/index buffers.
Definition spk_mesh.hpp:29
const std::shared_ptr< spk::OpenGL::BufferSetObject > & bufferSet() const
Definition spk_mesh.hpp:338
Loads shader artifacts and orchestrates draw calls with strongly typed constants and attributes.
Definition spk_pipeline.hpp:38
Base painter that renders a mesh through a Lumina pipeline.
Definition spk_mesh_painter.hpp:24
VertexBufferObject & vbo()
Access mutable VBO.
Definition spk_buffer_set_object.cpp:76
Layout & layout()
Access layout descriptor.
Definition spk_vertex_buffer_object.cpp:253
RGBA color utility storing normalized floating components.
Definition spk_color.hpp:18
Glyph quad data and layout metrics.
Definition spk_font.hpp:119
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
void _configureBufferSet() const override
Configures the vertex buffer layout for font vertices.
Definition spk_font_painter.hpp:227
FontMesh()=default
Builds an empty font mesh.
const Font::Size & fontSize() const
Returns the configured font size.
Definition spk_font_painter.cpp:318
Font::Bitmap & bitmap()
Returns the bitmap associated with the font.
Definition spk_font_painter.cpp:308
const Font * font() const
Returns the font used by this mesh.
Definition spk_font_painter.cpp:303
Vertex containing a position and UV coordinates for font rendering.
Definition spk_font_painter.hpp:30
spk::Vector2 uv
Texture coordinates.
Definition spk_font_painter.hpp:38
spk::Vector2Int pos
Vertex position in integer coordinates.
Definition spk_font_painter.hpp:34
TType x
X component.
Definition spk_vector2.hpp:44
TType y
Y component.
Definition spk_vector2.hpp:48
Describes a vertex attribute entry in the layout.
Definition spk_vertex_buffer_object.hpp:38