Nuclide
Software Development Kit for id Tech

Typeface format loader/handler for rendering bitmap/vector based text and icons. More...

Classes

struct  font_s
 Representation of a font. More...
 

Enumerations

enum  drawflag_t { DRAWFLAG_NORMAL = 0 , DRAWFLAG_ADDITIVE , DRAWFLAG_MODULATE , DRAWFLAG_2XMODULATE }
 Flags for 2D drawing operations. More...
 

Functions

void Font_Load (string strFile, font_s &fntNew)
 Load a desired .font definition into memory. More...
 
void Font_DrawText (vector vecOrigin, string strText, font_s fnt)
 Draw text on the screen at the desired position with a desired font. More...
 
void Font_DrawText_A (vector vecOrigin, string strText, float a, font_s fnt)
 Draw alpha-blended text on the screen at the desired position with a desired font. More...
 
void Font_DrawText_RGB (vector vecOrigin, string strText, vector col, font_s fnt)
 Draw tinted text on the screen at the desired position with a desired font. More...
 
void Font_DrawText_RGBA (vector vecOrigin, string strText, vector col, float a, font_s fnt)
 Draw tinted and alpha blended text on the screen at the desired position with a desired font. More...
 
void Font_DrawRText (vector vecOrigin, string strText, font_s fnt)
 Right-aligned variant of Font_DrawText. More...
 
void Font_DrawRText_A (vector vecOrigin, string strText, float a, font_s fnt)
 Right-aligned variant of Font_DrawText_A. More...
 
void Font_DrawRText_RGB (vector vecOrigin, string strText, vector col, font_s fnt)
 Right-aligned variant of Font_DrawText_RGB. More...
 
void Font_DrawRText_RGBA (vector vecOrigin, string strText, vector col, float a, font_s fnt)
 Right-aligned variant of Font_DrawText_RGBA. More...
 
void Font_DrawField (vector vecOrigin, vector vecSize, string strText, font_s fnt, alignflags_t iAlignFlags)
 Draws a textfield with line wrapping. More...
 
void Font_DrawFieldAtHeight (vector vecOrigin, vector vecSize, int iTextHeight, string strText, font_s fnt, alignflags_t iAlignFlags)
 Draws a textfield with line wrapping at a custom text height. More...
 
string Font_RGBtoHex (vector vecColor)
 Converts a normalized RGB color vector to a hex color string. More...
 
int Font_GetHeight (font_s fnt)
 Returns the height of a specified font in pixels. More...
 
float Font_StringWidth (string strText, bool hasColor, font_s fnt)
 Returns the width of a series of characters in pixels. More...
 
float Font_GetID (font_s fnt)
 Get the internal font id. More...
 

Variables

typedef enumflags
 Defines the valid alignment flags for text fields. More...
 

Detailed Description

Typeface format loader/handler for rendering bitmap/vector based text and icons.

Enumeration Type Documentation

◆ drawflag_t

enum drawflag_t

Flags for 2D drawing operations.

Enumerator
DRAWFLAG_NORMAL 

The default.

DRAWFLAG_ADDITIVE 

Render with an additive blend mode.

DRAWFLAG_MODULATE 

Not implemented in FTEQW.

DRAWFLAG_2XMODULATE 

Not implemented in FTEQW.

Function Documentation

◆ Font_DrawField()

void Font_DrawField ( vector  vecOrigin,
vector  vecSize,
string  strText,
font_s  fnt,
alignflags_t  iAlignFlags 
)

Draws a textfield with line wrapping.

Parameters
vecOriginis the absolute starting position.
vecSizeis the total area in pixels that the field takes up on the screen.
strTextis the text to be drawn onto the screen.
fntis the font to be used for rendering the text.
iAlignFlagssets how the text may be aligned.

◆ Font_DrawFieldAtHeight()

void Font_DrawFieldAtHeight ( vector  vecOrigin,
vector  vecSize,
int  iTextHeight,
string  strText,
font_s  fnt,
alignflags_t  iAlignFlags 
)

Draws a textfield with line wrapping at a custom text height.

Parameters
vecOriginis the absolute starting position.
vecSizeis the total area in pixels that the field takes up on the screen.
iTextHeightis the desired text height in pixels.
strTextis the text to be drawn onto the screen.
fntis the font to be used for rendering the text.
iAlignFlagssets how the text may be aligned.

◆ Font_DrawRText()

void Font_DrawRText ( vector  vecOrigin,
string  strText,
font_s  fnt 
)

Right-aligned variant of Font_DrawText.

See also
Font_DrawText

◆ Font_DrawRText_A()

void Font_DrawRText_A ( vector  vecOrigin,
string  strText,
float  a,
font_s  fnt 
)

Right-aligned variant of Font_DrawText_A.

See also
Font_DrawText_A

◆ Font_DrawRText_RGB()

void Font_DrawRText_RGB ( vector  vecOrigin,
string  strText,
vector  col,
font_s  fnt 
)

Right-aligned variant of Font_DrawText_RGB.

See also
Font_DrawText_RGB

◆ Font_DrawRText_RGBA()

void Font_DrawRText_RGBA ( vector  vecOrigin,
string  strText,
vector  col,
float  a,
font_s  fnt 
)

Right-aligned variant of Font_DrawText_RGBA.

See also
Font_DrawText_RGBA

◆ Font_DrawText()

void Font_DrawText ( vector  vecOrigin,
string  strText,
font_s  fnt 
)

Draw text on the screen at the desired position with a desired font.

Parameters
vecOriginis the absolute starting position.
strTextis the text to be drawn.
fntis the font to be used.

◆ Font_DrawText_A()

void Font_DrawText_A ( vector  vecOrigin,
string  strText,
float  a,
font_s  fnt 
)

Draw alpha-blended text on the screen at the desired position with a desired font.

Parameters
vecOriginis the absolute starting position.
strTextis the text to be drawn.
ais the alpha value to blend with.
fntis the font to be used.

◆ Font_DrawText_RGB()

void Font_DrawText_RGB ( vector  vecOrigin,
string  strText,
vector  col,
font_s  fnt 
)

Draw tinted text on the screen at the desired position with a desired font.

Parameters
vecOriginis the absolute starting position.
strTextis the text to be drawn.
colis the normalized color value to tint the text with.
fntis the font to be used.

◆ Font_DrawText_RGBA()

void Font_DrawText_RGBA ( vector  vecOrigin,
string  strText,
vector  col,
float  a,
font_s  fnt 
)

Draw tinted and alpha blended text on the screen at the desired position with a desired font.

Parameters
vecOriginis the absolute starting position.
strTextis the text to be drawn.
colis the normalized color value to tint the text with.
ais the alpha value to blend with.
fntis the font to be used.

◆ Font_GetHeight()

int Font_GetHeight ( font_s  fnt)

Returns the height of a specified font in pixels.

Parameters
fntis the font to be queried.
Returns
is the height of a font in pixels.
See also
Font_StringWidth

◆ Font_GetID()

float Font_GetID ( font_s  fnt)

Get the internal font id.

The internal font id is only useful for when you want to assign 'drawfont' yourself, or have some other use for it. Those id's are meant to be unique, but may change between vid_reload or other cases where video memory is de-allocated. Overall you should never need to use this, unless you know what you're doing or are porting old code.

Parameters
fntis the font to be queried.
Returns
the internal 'drawfont' id of the specified font.

◆ Font_Load()

void Font_Load ( string  strFile,
font_s fntNew 
)

Load a desired .font definition into memory.

Parameters
strFileis the path to the file in question.
fntNewis the location of where the font will be stored.

◆ Font_RGBtoHex()

string Font_RGBtoHex ( vector  vecColor)

Converts a normalized RGB color vector to a hex color string.

Parameters
vecColoris the normalized input color. E.g. [1.0f, 0.0f, 0.0f]
Returns
is a hex color string. e.g. "^xF00"

◆ Font_StringWidth()

float Font_StringWidth ( string  strText,
bool  hasColor,
font_s  fnt 
)

Returns the width of a series of characters in pixels.

If you have a string with funstring color codes (e.g. ^1 or ^xF00) and want to make sure those are not interpreted as visible characters, set the parameter hasColor to true. Rendering may be more expensive this way, but you should generally cache the result instead of querying it every frame anyway.

The return value is of type float, to be a drop-in replacement for the engine builtin stringwidth().

Parameters
strTextis the text to get the length of.
hasColorhints if funstring color codes are present in the string.
fntis the font used with the text in question.

Variable Documentation

◆ enumflags

typedef enumflags
Initial value:
{
AF_LEFT,
AF_TOP,
AF_RIGHT,
AF_BOTTOM
} alignflags_t

Defines the valid alignment flags for text fields.

See also
Font_DrawField