Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
font.c File Reference

Macros

#define TEXT_DRAW   0
 Flag for drawTextWordWrapFlags() to draw the text normally.
 
#define TEXT_MEASURE   1
 Flag for drawTexTWordWrapFlags() to measure the text without drawing.
 
#define MARQUEE_SPEED   40000
 

Functions

void drawCharBounds (paletteColor_t color, int h, const font_ch_t *ch, int16_t xOff, int16_t yOff, int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax)
 Draw a single character from a font to a display.
 
void drawChar (paletteColor_t color, int h, const font_ch_t *ch, int16_t xOff, int16_t yOff)
 Draw a single character from a font to a display.
 
int16_t drawTextBounds (const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff, int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax)
 Draw text to a display with the given color and font.
 
int16_t drawText (const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff)
 Draw text to a display with the given color and font.
 
uint16_t textWidth (const font_t *font, const char *text)
 Return the pixel width of some text in a given font.
 
const char * drawTextWordWrap (const font_t *font, paletteColor_t color, const char *text, int16_t *xOff, int16_t *yOff, int16_t xMax, int16_t yMax)
 Draws text, breaking on word boundaries, until the given bounds are filled or all text is drawn.
 
const char * drawTextWordWrapFixed (const font_t *font, paletteColor_t color, const char *text, int16_t xStart, int16_t yStart, int16_t *xOff, int16_t *yOff, int16_t xMax, int16_t yMax)
 
uint16_t textWordWrapHeight (const font_t *font, const char *text, int16_t width, int16_t maxHeight)
 Return the height of a block of word wrapped text.
 
void makeOutlineFont (font_t *srcFont, font_t *dstFont, bool spiRam)
 Create the outline of a font as a separate font.
 
int16_t drawTextMarquee (const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff, int16_t xMax, int32_t *timer)
 Draw text to the display with a marquee effect.
 
bool drawTextEllipsize (const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff, int16_t maxW, bool center)
 Draw text to the display that fits within a given length, replacing any overflowing text with "...".
 
int16_t drawTextMulticolored (const font_t *font, const char *text, int16_t xOff, int16_t yOff, const paletteColor_t *colors, uint32_t colorCount, uint32_t segmentCount)
 Draws text divided into any number of colored segments.
 

Macro Definition Documentation

◆ TEXT_DRAW

#define TEXT_DRAW   0

Flag for drawTextWordWrapFlags() to draw the text normally.

◆ TEXT_MEASURE

#define TEXT_MEASURE   1

Flag for drawTexTWordWrapFlags() to measure the text without drawing.

◆ MARQUEE_SPEED

#define MARQUEE_SPEED   40000

Function Documentation

◆ drawCharBounds()

void drawCharBounds ( paletteColor_t color,
int h,
const font_ch_t * ch,
int16_t xOff,
int16_t yOff,
int16_t xMin,
int16_t yMin,
int16_t xMax,
int16_t yMax )

Draw a single character from a font to a display.

Parameters
colorThe color of the character to draw
hThe height of the character to draw
chThe character bitmap to draw (includes the width of the char)
xOffThe x offset to draw the char at
yOffThe y offset to draw the char at
xMinThe left edge of the text bounds
yMinThe top edge of the text bounds
xMaxThe right edge of the text bounds
yMaxThe bottom edge of the text bounds

◆ drawChar()

void drawChar ( paletteColor_t color,
int h,
const font_ch_t * ch,
int16_t xOff,
int16_t yOff )

Draw a single character from a font to a display.

Parameters
colorThe color of the character to draw
hThe height of the character to draw
chThe character bitmap to draw (includes the width of the char)
xOffThe x offset to draw the char at
yOffThe y offset to draw the char at

◆ drawTextBounds()

int16_t drawTextBounds ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t xOff,
int16_t yOff,
int16_t xMin,
int16_t yMin,
int16_t xMax,
int16_t yMax )

Draw text to a display with the given color and font.

Parameters
fontThe font to use for the text
colorThe color of the character to draw
textThe text to draw to the display
xOffThe x offset to draw the text at
yOffThe y offset to draw the text at
xMinThe left edge of the text bounds
yMinThe top edge of the text bounds
xMaxThe right edge of the text bounds
yMaxThe bottom edge of the text bounds
Returns
The x offset at the end of the drawn string

◆ drawText()

int16_t drawText ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t xOff,
int16_t yOff )

Draw text to a display with the given color and font.

Parameters
fontThe font to use for the text
colorThe color of the character to draw
textThe text to draw to the display
xOffThe x offset to draw the text at
yOffThe y offset to draw the text at
Returns
The x offset at the end of the drawn string

◆ textWidth()

uint16_t textWidth ( const font_t * font,
const char * text )

Return the pixel width of some text in a given font.

Parameters
fontThe font to use
textThe text to measure
Returns
The width of the text rendered in the font

◆ drawTextWordWrap()

const char * drawTextWordWrap ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t * xOff,
int16_t * yOff,
int16_t xMax,
int16_t yMax )

Draws text, breaking on word boundaries, until the given bounds are filled or all text is drawn.

Text will be drawn, starting at (xOff, yOff), wrapping to the next line at ' ' or '-' when the next word would exceed xMax, or immediately when a newline ('\n') is encountered. Carriage returns and tabs ('\r', '\t') are not supported. When the bottom of the next character would exceed yMax, no more text is drawn and a pointer to the next undrawn character within text is returned. If all text has been written, NULL is returned.

Parameters
fontThe font to use when drawing the text
colorThe color of the text to be drawn
textThe text to be pointed, as a null-terminated string
xOffThe X-coordinate to begin drawing the text at
yOffThe Y-coordinate to begin drawing the text at
xMaxThe maximum x-coordinate at which any text may be drawn
yMaxThe maximum y-coordinate at which text may be drawn
Returns
A pointer to the first unprinted character within text, or NULL if all text has been written

◆ drawTextWordWrapFixed()

const char * drawTextWordWrapFixed ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t xStart,
int16_t yStart,
int16_t * xOff,
int16_t * yOff,
int16_t xMax,
int16_t yMax )

◆ textWordWrapHeight()

uint16_t textWordWrapHeight ( const font_t * font,
const char * text,
int16_t width,
int16_t maxHeight )

Return the height of a block of word wrapped text.

Parameters
fontThe font to use when drawing the text
textThe text to be pointed, as a null-terminated string
widthThe maximum x-coordinate at which any text may be drawn
maxHeightThe maximum y-coordinate at which text may be drawn
Returns
The height of the word wrapped text block

◆ makeOutlineFont()

void makeOutlineFont ( font_t * srcFont,
font_t * dstFont,
bool spiRam )

Create the outline of a font as a separate font.

Parameters
srcFontThe source font to make an outline of
dstFontThe destination font that will be initialized as an outline of the source font
spiRamtrue to allocate memory in SPI RAM, false to allocate memory in normal RAM

◆ drawTextMarquee()

int16_t drawTextMarquee ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t xOff,
int16_t yOff,
int16_t xMax,
int32_t * timer )

Draw text to the display with a marquee effect.

Parameters
fontThe font to use for the text
colorThe color of the character to draw
textThe text to draw to the display
xOffThe x offset to draw the text at
yOffThe y offset to draw the text at
xMaxThe x offset of the right edge of the marquee text
[in,out]timerA pointer to a timer value used to time the marquee
Returns
The x offset at the end of the drawn string

◆ drawTextEllipsize()

bool drawTextEllipsize ( const font_t * font,
paletteColor_t color,
const char * text,
int16_t xOff,
int16_t yOff,
int16_t maxW,
bool center )

Draw text to the display that fits within a given length, replacing any overflowing text with "...".

Parameters
fontThe font to use for the text
colorThe color of the character to draw
textThe text to draw to the display
xOffThe x offset to draw the text at
yOffThe y offset to draw the text at
maxWThe maximum width of text to draw
centerIf true, when text is not ellipsize it will be centered within the box
Returns
true
false

◆ drawTextMulticolored()

int16_t drawTextMulticolored ( const font_t * font,
const char * text,
int16_t xOff,
int16_t yOff,
const paletteColor_t * colors,
uint32_t colorCount,
uint32_t segmentCount )

Draws text divided into any number of colored segments.

The entire length of text will be divided into colorCount segments

Parameters
fontThe font to use for the text
textThe text to draw to the display
xOffThe x offset to draw the text at
yOffThe y offset to draw the text at
colorsAn array of colors to use when drawing the text
colorCountThe number of elements in the colors array
segmentCountThe number of segments to divide the text into
Returns
int16_t The x-offset at the end of the text