libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiTextRenderer Class Reference

FreeType2-based glyph shaping/caching. More...

#include <GuiTextRenderer.h>

Public Member Functions

 GuiTextRenderer (const uint8_t *fontBuffer, FT_Long bufferSize, GlyphRenderer *glyphRenderer, float uiScale=1.0f)
 
void setPixelSize (int16_t pixelSize)
 Selects the pixel size subsequent drawText()/getWidth()/getHeight() calls use.
 
uint16_t drawText (int16_t x, int16_t y, const wchar_t *text, PixelColor color=black, uint32_t renderFlags=0)
 Draws text at (x, y) using the current pixel size.
 
uint16_t drawText (int16_t x, int16_t y, const char *text, PixelColor color=black, uint32_t renderFlags=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint16_t getWidth (const wchar_t *text)
 
uint16_t getWidth (const char *text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint16_t getHeight (const wchar_t *text)
 
uint16_t getHeight (const char *text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void getOffset (const wchar_t *text, FontOffset *offset)
 

Static Public Member Functions

static wchar_t * charToWideChar (const char *p)
 

Detailed Description

FreeType2-based glyph shaping/caching.

Shapes and caches glyphs per pixel size, then delegates only the final rasterized-quad draw to a GlyphRenderer - GuiText calls through this rather than touching FreeType or a platform texture directly.

Examples
demo.cpp.

Definition at line 77 of file GuiTextRenderer.h.

Constructor & Destructor Documentation

◆ GuiTextRenderer()

GuiTextRenderer::GuiTextRenderer ( const uint8_t * fontBuffer,
FT_Long bufferSize,
GlyphRenderer * glyphRenderer,
float uiScale = 1.0f )
Parameters
fontBufferTTF/OTF font data - must remain valid for the lifetime of this GuiTextRenderer, FreeType keeps a pointer into it
bufferSizeLength of fontBuffer in bytes
glyphRendererPlatform renderer rasterized glyph quads are drawn through
uiScalePhysical-pixels-per-design-pixel to rasterize glyphs at (pass VideoDriver::getUIScale()). Sizes, metrics and layout stay in design pixels; only the glyph textures get sharper. 1.0 rasterizes at the design size.

Definition at line 68 of file GuiTextRenderer.cpp.

◆ ~GuiTextRenderer()

GuiTextRenderer::~GuiTextRenderer ( )

Definition at line 76 of file GuiTextRenderer.cpp.

Member Function Documentation

◆ charToWideChar()

wchar_t * GuiTextRenderer::charToWideChar ( const char * p)
static
Returns
a newly-allocated wide-char copy of a UTF-8 string p - caller owns the result (delete[])

Definition at line 292 of file GuiTextRenderer.cpp.

◆ drawText() [1/2]

uint16_t GuiTextRenderer::drawText ( int16_t x,
int16_t y,
const char * text,
PixelColor color = black,
uint32_t renderFlags = 0 )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 338 of file GuiTextRenderer.cpp.

◆ drawText() [2/2]

uint16_t GuiTextRenderer::drawText ( int16_t x,
int16_t y,
const wchar_t * text,
PixelColor color = black,
uint32_t renderFlags = 0 )

Draws text at (x, y) using the current pixel size.

Parameters
xLeft edge, in pixels
yTop edge, in pixels
textText to draw
colorText color
renderFlagsBitmask of GUI_TEXT_JUSTIFY_*‍/GUI_TEXT_ALIGN_*‍/GUI_TEXT_STYLE_* flags
Returns
the drawn text's width in pixels

Definition at line 231 of file GuiTextRenderer.cpp.

◆ getHeight() [1/2]

uint16_t GuiTextRenderer::getHeight ( const char * text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 352 of file GuiTextRenderer.cpp.

◆ getHeight() [2/2]

uint16_t GuiTextRenderer::getHeight ( const wchar_t * text)
Returns
text height in pixels at the current pixel size

Definition at line 223 of file GuiTextRenderer.cpp.

◆ getOffset()

void GuiTextRenderer::getOffset ( const wchar_t * text,
FontOffset * offset )
Parameters
textText to measure
offsetFilled with the ascender/descender/max/min metrics for text at the current pixel size

Definition at line 183 of file GuiTextRenderer.cpp.

◆ getWidth() [1/2]

uint16_t GuiTextRenderer::getWidth ( const char * text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 345 of file GuiTextRenderer.cpp.

◆ getWidth() [2/2]

uint16_t GuiTextRenderer::getWidth ( const wchar_t * text)
Returns
text width in pixels at the current pixel size

Definition at line 204 of file GuiTextRenderer.cpp.

◆ setPixelSize()

void GuiTextRenderer::setPixelSize ( int16_t pixelSize)

Selects the pixel size subsequent drawText()/getWidth()/getHeight() calls use.

Shaped glyphs are cached per size, so switching sizes repeatedly doesn't re-shape glyphs already seen at that size.

Definition at line 94 of file GuiTextRenderer.cpp.


The documentation for this class was generated from the following files: