citro2d
Data Structures | Enumerations | Functions
Text drawing functions

Data Structures

struct  C2D_Text
 Text object. More...
 

Enumerations

enum  {
  C2D_AtBaseline = BIT(0),
  C2D_WithColor = BIT(1),
  C2D_AlignLeft = 0 << 2,
  C2D_AlignRight = 1 << 2,
  C2D_AlignCenter = 2 << 2,
  C2D_AlignJustified = 3 << 2,
  C2D_AlignMask = 3 << 2,
  C2D_WordWrap = BIT(4)
}
 

Functions

C2D_TextBuf C2D_TextBufNew (size_t maxGlyphs)
 Creates a new text buffer. More...
 
C2D_TextBuf C2D_TextBufResize (C2D_TextBuf buf, size_t maxGlyphs)
 Resizes a text buffer. More...
 
void C2D_TextBufDelete (C2D_TextBuf buf)
 Deletes a text buffer. More...
 
void C2D_TextBufClear (C2D_TextBuf buf)
 Clears all stored text in a buffer. More...
 
size_t C2D_TextBufGetNumGlyphs (C2D_TextBuf buf)
 Retrieves the number of glyphs stored in a text buffer. More...
 
const char * C2D_TextParseLine (C2D_Text *text, C2D_TextBuf buf, const char *str, u32 lineNo)
 Parses and adds a single line of text to a text buffer. More...
 
const char * C2D_TextFontParseLine (C2D_Text *text, C2D_Font font, C2D_TextBuf buf, const char *str, u32 lineNo)
 Parses and adds a single line of text to a text buffer. More...
 
const char * C2D_TextParse (C2D_Text *text, C2D_TextBuf buf, const char *str)
 Parses and adds arbitrary text (including newlines) to a text buffer. More...
 
const char * C2D_TextFontParse (C2D_Text *text, C2D_Font font, C2D_TextBuf buf, const char *str)
 Parses and adds arbitrary text (including newlines) to a text buffer. More...
 
void C2D_TextOptimize (const C2D_Text *text)
 Optimizes a text object in order to be drawn more efficiently. More...
 
void C2D_TextGetDimensions (const C2D_Text *text, float scaleX, float scaleY, float *outWidth, float *outHeight)
 Retrieves the total dimensions of a text object. More...
 
void C2D_DrawText (const C2D_Text *text, u32 flags, float x, float y, float z, float scaleX, float scaleY,...)
 Draws text using the GPU. More...
 

Detailed Description

Enumeration Type Documentation

anonymous enum
Enumerator
C2D_AtBaseline 

Matches the Y coordinate with the baseline of the font.

C2D_WithColor 

Draws text with color. Requires a u32 color value.

C2D_AlignLeft 

Draws text aligned to the left. This is the default.

C2D_AlignRight 

Draws text aligned to the right.

C2D_AlignCenter 

Draws text centered.

C2D_AlignJustified 

Draws text justified. When C2D_WordWrap is not specified, right edge is x + scaleX*text->width. Otherwise, right edge is x + the width specified for those values.

C2D_AlignMask 

Bitmask for alignment values.

C2D_WordWrap 

Draws text with wrapping of full words before specified width. Requires a float value, passed after color if C2D_WithColor is specified.

Function Documentation

void C2D_DrawText ( const C2D_Text text,
u32  flags,
float  x,
float  y,
float  z,
float  scaleX,
float  scaleY,
  ... 
)

Draws text using the GPU.

Parameters
[in]textPointer to text object.
[in]flagsText drawing flags.
[in]xHorizontal position to draw the text on.
[in]yVertical position to draw the text on. If C2D_AtBaseline is not specified (default), this is the top left corner of the block of text; otherwise this is the position of the baseline of the first line of text.
[in]zDepth value of the text. If unsure, pass 0.0f.
[in]scaleXHorizontal size of the font. 1.0f corresponds to the native size of the font.
[in]scaleYVertical size of the font. 1.0f corresponds to the native size of the font.
Remarks
The default 3DS system font has a glyph height of 30px, and the baseline is at 25px.
void C2D_TextBufClear ( C2D_TextBuf  buf)

Clears all stored text in a buffer.

Parameters
[in]bufText buffer handle.
void C2D_TextBufDelete ( C2D_TextBuf  buf)

Deletes a text buffer.

Parameters
[in]bufText buffer handle.
Remarks
This also invalidates all text objects previously created with this buffer.
size_t C2D_TextBufGetNumGlyphs ( C2D_TextBuf  buf)

Retrieves the number of glyphs stored in a text buffer.

Parameters
[in]bufText buffer handle.
Returns
The number of glyphs.
C2D_TextBuf C2D_TextBufNew ( size_t  maxGlyphs)

Creates a new text buffer.

Parameters
[in]maxGlyphsMaximum number of glyphs that can be stored in the buffer.
Returns
Text buffer handle (or NULL on failure).
C2D_TextBuf C2D_TextBufResize ( C2D_TextBuf  buf,
size_t  maxGlyphs 
)

Resizes a text buffer.

Parameters
[in]bufText buffer to resize.
[in]maxGlyphsMaximum number of glyphs that can be stored in the buffer.
Returns
New text buffer handle (or NULL on failure).
Remarks
If successful, old text buffer handle becomes invalid.
const char* C2D_TextFontParse ( C2D_Text text,
C2D_Font  font,
C2D_TextBuf  buf,
const char *  str 
)

Parses and adds arbitrary text (including newlines) to a text buffer.

Parameters
[out]textPointer to text object to store information in.
[in]fontFont to get glyphs from, or null for system font
[in]bufText buffer handle.
[in]strString to parse.
Remarks
Whitespace doesn't add any glyphs to the text buffer and is thus "free".
Returns
On success, a pointer to the character on which string processing stopped, which can be the null character ('\0'; indicating the end of the string was reached), or any other character (indicating the text buffer is full and no more glyphs can be added). On failure, NULL.
const char* C2D_TextFontParseLine ( C2D_Text text,
C2D_Font  font,
C2D_TextBuf  buf,
const char *  str,
u32  lineNo 
)

Parses and adds a single line of text to a text buffer.

Parameters
[out]textPointer to text object to store information in.
[in]fontFont to get glyphs from, or null for system font
[in]bufText buffer handle.
[in]strString to parse.
[in]lineNoLine number assigned to the text (used to calculate vertical position).
Remarks
Whitespace doesn't add any glyphs to the text buffer and is thus "free".
Returns
On success, a pointer to the character on which string processing stopped, which can be a newline ('
'; indicating that's where the line ended), the null character ('\0'; indicating the end of the string was reached), or any other character (indicating the text buffer is full and no more glyphs can be added). On failure, NULL.
void C2D_TextGetDimensions ( const C2D_Text text,
float  scaleX,
float  scaleY,
float *  outWidth,
float *  outHeight 
)

Retrieves the total dimensions of a text object.

Parameters
[in]textPointer to text object.
[in]scaleXHorizontal size of the font. 1.0f corresponds to the native size of the font.
[in]scaleYVertical size of the font. 1.0f corresponds to the native size of the font.
[out]outWidth(optional) Variable in which to store the width of the text.
[out]outHeight(optional) Variable in which to store the height of the text.
void C2D_TextOptimize ( const C2D_Text text)

Optimizes a text object in order to be drawn more efficiently.

Parameters
[in]textPointer to text object.
const char* C2D_TextParse ( C2D_Text text,
C2D_TextBuf  buf,
const char *  str 
)

Parses and adds arbitrary text (including newlines) to a text buffer.

Parameters
[out]textPointer to text object to store information in.
[in]bufText buffer handle.
[in]strString to parse.
Remarks
Whitespace doesn't add any glyphs to the text buffer and is thus "free".
Returns
On success, a pointer to the character on which string processing stopped, which can be the null character ('\0'; indicating the end of the string was reached), or any other character (indicating the text buffer is full and no more glyphs can be added). On failure, NULL.
const char* C2D_TextParseLine ( C2D_Text text,
C2D_TextBuf  buf,
const char *  str,
u32  lineNo 
)

Parses and adds a single line of text to a text buffer.

Parameters
[out]textPointer to text object to store information in.
[in]bufText buffer handle.
[in]strString to parse.
[in]lineNoLine number assigned to the text (used to calculate vertical position).
Remarks
Whitespace doesn't add any glyphs to the text buffer and is thus "free".
Returns
On success, a pointer to the character on which string processing stopped, which can be a newline ('
'; indicating that's where the line ended), the null character ('\0'; indicating the end of the string was reached), or any other character (indicating the text buffer is full and no more glyphs can be added). On failure, NULL.