Wrapper class for citro2d text rendering with support for custom and system fonts. More...
#include <text.hpp>
Public Member Functions | |
| Text (const std::string &content, Font *font) | |
| Constructs a Text object with a custom font. | |
| Text (const std::string &content) | |
| Constructs a Text object with the system font. | |
| ~Text () | |
| Destructor that frees the text buffer. | |
| void | Draw (float x, float y, float z=0.0f, float scaleX=1.0f, float scaleY=1.0f) |
| Draws text with basic parameters and left alignment. | |
| void | DrawWithColor (float x, float y, float z, float scaleX, float scaleY, u32 color) |
| Draws text with a specified color and left alignment. | |
| void | DrawAligned (u32 flags, float x, float y, float z, float scaleX, float scaleY) |
| Draws text with custom alignment flags. | |
| void | DrawWithColorAligned (u32 flags, float x, float y, float z, float scaleX, float scaleY, u32 color) |
| Draws text with color and custom alignment. | |
| void | GetDimensions (float scaleX, float scaleY, float *outWidth, float *outHeight) const |
| Gets the dimensions of the rendered text. | |
| void | SetContent (const std::string &newContent) |
| Updates the text content and re-parses it. | |
| Text (const Text &)=delete | |
| Copy constructor (deleted). | |
| Text & | operator= (const Text &)=delete |
| Copy assignment operator (deleted). | |
Wrapper class for citro2d text rendering with support for custom and system fonts.
This class manages text buffers and provides convenient methods for drawing text with various options including colors, alignment, and scaling. It supports both custom fonts and the 3DS system font.
| xs::text::Text::Text | ( | const std::string & | content, |
| Font * | font ) |
Constructs a Text object with a custom font.
| content | The text string to render. |
| font | Pointer to a Font object to use for rendering. |
Creates a text buffer with 4096 glyph capacity and parses the provided content using the specified font. The text is automatically optimized for efficient rendering.
|
explicit |
Constructs a Text object with the system font.
| content | The text string to render. |
Creates a text buffer with 4096 glyph capacity and parses the provided content using the 3DS system font. The text is automatically optimized for efficient rendering.
| xs::text::Text::~Text | ( | ) |
Destructor that frees the text buffer.
Automatically releases the text buffer resources using C2D_TextBufDelete.
|
delete |
Copy constructor (deleted).
Text objects cannot be copied to prevent issues with shared text buffers.
| void xs::text::Text::Draw | ( | float | x, |
| float | y, | ||
| float | z = 0.0f, | ||
| float | scaleX = 1.0f, | ||
| float | scaleY = 1.0f ) |
Draws text with basic parameters and left alignment.
| x | Horizontal position to draw the text. |
| y | Vertical position (top-left corner of text block). |
| z | Depth value for z-ordering (default: 0.0f). |
| scaleX | Horizontal scale factor (default: 1.0f, native font size). |
| scaleY | Vertical scale factor (default: 1.0f, native font size). |
Renders the text at the specified position with left alignment. Use scale values > 1.0f to enlarge text, < 1.0f to shrink it.
| void xs::text::Text::DrawAligned | ( | u32 | flags, |
| float | x, | ||
| float | y, | ||
| float | z, | ||
| float | scaleX, | ||
| float | scaleY ) |
Draws text with custom alignment flags.
| flags | Alignment and rendering flags (e.g., C2D_AlignLeft, C2D_AlignRight, C2D_AlignCenter, C2D_AlignJustified, C2D_AtBaseline, C2D_WordWrap). |
| x | Horizontal position to draw the text. |
| y | Vertical position. Interpretation depends on alignment flags. |
| z | Depth value for z-ordering. |
| scaleX | Horizontal scale factor. |
| scaleY | Vertical scale factor. |
Provides full control over text alignment and rendering options:
Flags can be combined using the bitwise OR operator (|).
| void xs::text::Text::DrawWithColor | ( | float | x, |
| float | y, | ||
| float | z, | ||
| float | scaleX, | ||
| float | scaleY, | ||
| u32 | color ) |
Draws text with a specified color and left alignment.
| x | Horizontal position to draw the text. |
| y | Vertical position (top-left corner of text block). |
| z | Depth value for z-ordering. |
| scaleX | Horizontal scale factor. |
| scaleY | Vertical scale factor. |
| color | Color value in u32 RGBA8 format (0xRRGGBBAA). |
Renders the text with the specified color. The color format uses 8 bits per channel (red, green, blue, alpha).
| void xs::text::Text::DrawWithColorAligned | ( | u32 | flags, |
| float | x, | ||
| float | y, | ||
| float | z, | ||
| float | scaleX, | ||
| float | scaleY, | ||
| u32 | color ) |
Draws text with color and custom alignment.
| flags | Alignment and rendering flags (e.g., C2D_AlignLeft, C2D_AlignRight, C2D_AlignCenter, C2D_AlignJustified, C2D_AtBaseline, C2D_WordWrap). |
| x | Horizontal position to draw the text. |
| y | Vertical position. Interpretation depends on alignment flags. |
| z | Depth value for z-ordering. |
| scaleX | Horizontal scale factor. |
| scaleY | Vertical scale factor. |
| color | Color value in u32 RGBA8 format (0xRRGGBBAA). |
Combines color rendering with custom alignment options. See DrawAligned() for details on alignment flags and DrawWithColor() for color format.
| void xs::text::Text::GetDimensions | ( | float | scaleX, |
| float | scaleY, | ||
| float * | outWidth, | ||
| float * | outHeight ) const |
Gets the dimensions of the rendered text.
| scaleX | Horizontal scale factor to calculate dimensions for. |
| scaleY | Vertical scale factor to calculate dimensions for. |
| outWidth | Pointer to store the calculated width (can be nullptr to skip). |
| outHeight | Pointer to store the calculated height (can be nullptr to skip). |
Calculates the bounding box dimensions of the text when rendered with the specified scale factors. This is useful for layout calculations, centering text, or creating text boxes.
Copy assignment operator (deleted).
Text objects cannot be copy-assigned to prevent issues with shared text buffers.
| void xs::text::Text::SetContent | ( | const std::string & | newContent | ) |
Updates the text content and re-parses it.
| newContent | The new text string to render. |
Clears the existing text buffer, parses the new content, and optimizes it for rendering. This allows dynamic text updates without creating a new Text object.