MTek-GDL 0.100.4-muffintrap
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
mgdl-font.h File Reference

Class for loading fonts and drawing text with them. More...

#include "mgdl-types.h"
#include "mgdl-color.h"
#include "mgdl-texture.h"

Go to the source code of this file.

Data Structures

struct  Font
 Represents a font that can be used to draw text. More...
 

Typedefs

typedef struct Font Font
 

Functions

FontFont_Create (void)
 
void Font_SetSpacingOnce (Font *font, float x, float y)
 Sets the spacing of the font for the next Print call.
 
void Font_SetLineLimitOnce (short limit)
 Sets the max amount of letters printed for the next Print* call.
 
FontFont_Load (Texture *fontTexture, short charw, short charh, char firstCharacter)
 Loads a font from an image.
 
FontFont_LoadPadded (Texture *fontTexture, short charw, short charh, char firstCharacter, short charactersPerRow)
 Loads a font from an image.
 
FontFont_LoadSelective (Texture *fontTexture, short charw, short charh, short charactersPerRow, const char *characters)
 Loads a font from an image.
 
void Font_Printf (Font *font, Color4f *color, float x, float y, float textHeight, const char *format,...)
 Draws text either in 2D or 3D.
 
void Font_Print (Font *font, Color4f *color, float x, float y, float textHeight, const char *text)
 Draws text either in 2D or 3D.
 
void Font_PrintfAligned (Font *font, Color4f *color, float x, float y, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, const char *format,...)
 Draws text either in 2D or 3D.
 
void Font_PrintAligned (Font *font, Color4f *color, float x, float y, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, const char *text)
 Draws text either in 2D or 3D.
 
void Font_PrintfOrigo (Font *font, Color4f *color, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, const char *format,...)
 Draws text either in 2D or 3D.
 
void Font_PrintOrigo (Font *font, Color4f *color, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, const char *text)
 Draws text either in 2D or 3D.
 
void Font_Icon (Font *font, Color4f *color, float x, float y, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, IconSymbol glyph)
 Draws an icon, only compatible with the debug font.
 
void Font_IconRotated (Font *font, Color4f *color, float x, float y, float textHeight, AlignmentModes alignmentX, AlignmentModes alignmentY, u8 rotation, IconSymbol glyph)
 Draws an icon rotated.
 
RectF Font_GetUVRect (Font *font, char letter)
 Get the texture coordinate corners of a letter.
 
RectF Font_GetUVRectIcon (Font *font, IconSymbol glyph)
 Get the texture coordinate corners of an IconSymbol.
 
void _Font_Bind (Font *font, short charw, short charh, char firstCharacter)
 
void _Font_BindPadded (Font *font, short charw, short charh, char firstCharacter, short charactersPerRow)
 
void _Font_BindSelective (Font *font, short charw, short charh, const char *characters, short charactersPerRow)
 
void _Font_CreateTextureCoordList (Font *font, short rows, short charactersPerRow, short texW, short texH)
 
void _Font_CreateTextureCoordListSelective (Font *font, short rows, short charactersPerRow, short texW, short texH, const char *characters)
 
void _Font_CreateCoordinatesForGlyph (Font *font, u32 textureIndex, short cx, short cy, short texW, short texH)
 
vec2 _Font_GetTextureCoordinate (Font *font, char character)
 
vec2 _Font_GetTextureCoordinateGlyph (Font *font, IconSymbol glyph)
 

Detailed Description

Class for loading fonts and drawing text with them.

Font system module header.

Function Documentation

◆ Font_GetUVRect()

RectF Font_GetUVRect ( Font font,
char  letter 
)

Get the texture coordinate corners of a letter.

Parameters
fontFont to read coordinates from
letterThe letter
Returns
The rectangle for uv coordinates.

◆ Font_GetUVRectIcon()

RectF Font_GetUVRectIcon ( Font font,
IconSymbol  glyph 
)

Get the texture coordinate corners of an IconSymbol.

Note
Only combatible with the Default Font. Other fonts may support the icons too but they are not
Parameters
fontFont to read coordinates from
glyphThe icon
Returns
The rectangle for uv coordinates.

◆ Font_Icon()

void Font_Icon ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
IconSymbol  glyph 
)

Draws an icon, only compatible with the debug font.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D. Starts drawing from origo.

Parameters
colorColor of the text. Font color is multiplied by this.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
glybhThe symbol/icon/glyph to be drawn.

◆ Font_IconRotated()

void Font_IconRotated ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
u8  rotation,
IconSymbol  glyph 
)

Draws an icon rotated.

Note
Only combatible with the Default Font. Other fonts may support the icons too but they are not a standard

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D. Starts drawing from origo.

Parameters
colorColor of the text. Font color is multiplied by this.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
rotationHow many clockwise 90 degree turns to do
glybhThe symbol/icon/glyph to be drawn.

◆ Font_Load()

Font * Font_Load ( Texture fontTexture,
short  charw,
short  charh,
char  firstCharacter 
)

Loads a font from an image.

The image must be PNG image. Grayscale or color. The amount of characters on every line is expected to be image width / character width. The characters should fill the image evenly.

Parameters
fontTextureTexture object.
charwWidth of a character in pixels.
charwHeight of a character in pixels.
firstCharacterThe first character in the image.
Returns
Loaded font or nullptr if failed to load.

◆ Font_LoadPadded()

Font * Font_LoadPadded ( Texture fontTexture,
short  charw,
short  charh,
char  firstCharacter,
short  charactersPerRow 
)

Loads a font from an image.

The image must be PNG image. Grayscale or color. The characters should start from the top left corner, but don't need to fill the image horizontally.

Parameters
filenameName of the image file.
charwWidth of a character in pixels.
charwHeight of a character in pixels.
firstCharacterThe first character in the image.
charactersPerRowHow many characters are on a row.
Returns
True if the loading succeeded.

◆ Font_LoadSelective()

Font * Font_LoadSelective ( Texture fontTexture,
short  charw,
short  charh,
short  charactersPerRow,
const char *  characters 
)

Loads a font from an image.

The image must be PNG image. Grayscale or color. The characters should start from the top left corner, but don't need to fill the image horizontally.

Parameters
filenameName of the image file.
charwWidth of a character in pixels.
charwHeight of a character in pixels.
firstCharacterThe first character in the image.
charactersPerRowHow many characters are on a row.
charactersThe characters to be loaded. Other characters are skipped.
Returns
True if the loading succeeded.

◆ Font_Print()

void Font_Print ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
const char *  text 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D.

Parameters
colorColor of the text. Font color is multiplied by this.
xUpper left corner x of first letter.
yUpper left corner y of first letter.
textHeightHeight of the text.
textText to be drawn.

◆ Font_PrintAligned()

void Font_PrintAligned ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
const char *  text 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D.

Parameters
colorColor of the text. Font color is multiplied by this.
xUpper left corner x of first letter.
yUpper left corner y of first letter.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
textText to be drawn.

◆ Font_Printf()

void Font_Printf ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
const char *  format,
  ... 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D.

Parameters
colorColor of the text. Font color is multiplied by this.
xUpper left corner x of first letter.
yUpper left corner y of first letter.
textHeightHeight of the text.
formatText, has to containg formatting markers.
__VA_ARGS__Values to the formatting markers.

◆ Font_PrintfAligned()

void Font_PrintfAligned ( Font font,
Color4f color,
float  x,
float  y,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
const char *  format,
  ... 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D.

Parameters
colorColor of the text. Font color is multiplied by this.
xUpper left corner x of first letter.
yUpper left corner y of first letter.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
formatText, has to containg formatting markers.
__VA_ARGS__Values to the formatting markers.

◆ Font_PrintfOrigo()

void Font_PrintfOrigo ( Font font,
Color4f color,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
const char *  format,
  ... 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D. Starts drawing from origo.

Parameters
colorColor of the text. Font color is multiplied by this.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
formatText, has to containg formatting markers.
__VA_ARGS__Values to the formatting markers.

◆ Font_PrintOrigo()

void Font_PrintOrigo ( Font font,
Color4f color,
float  textHeight,
AlignmentModes  alignmentX,
AlignmentModes  alignmentY,
const char *  text 
)

Draws text either in 2D or 3D.

X, Y and text height are in units when drawing in 3D and in pixels when drawing in 2D. Starts drawing from origo.

Parameters
colorColor of the text. Font color is multiplied by this.
textHeightHeight of the text.
alignmentXAlignment of text on the horizontal axis.
alignmentYAlignment of text on the vertical axis.
textText to be drawn.

◆ Font_SetLineLimitOnce()

void Font_SetLineLimitOnce ( short  limit)

Sets the max amount of letters printed for the next Print* call.

Parameters
limitMaximum amount of letters drawn;

◆ Font_SetSpacingOnce()

void Font_SetSpacingOnce ( Font font,
float  x,
float  y 
)

Sets the spacing of the font for the next Print call.

Parameters
xSpacing between letters horizontally.
ySpacing between rows vertically.