CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
Public Member Functions | List of all members
font Class Referenceabstract

#include <th_gfx_font.h>

Inheritance diagram for font:
bitmap_font freetype_font

Public Member Functions

virtual ~font ()=default
 
virtual text_layout get_text_dimensions (const char *sMessage, size_t iMessageLength, int iMaxWidth=INT_MAX) const =0
 Get the size of drawn text.
 
virtual void draw_text (render_target *pCanvas, const char *sMessage, size_t iMessageLength, int iX, int iY) const =0
 Draw a single line of text.
 
virtual text_layout draw_text_wrapped (render_target *pCanvas, const char *sMessage, size_t iMessageLength, int iX, int iY, int iWidth, int iMaxRows=INT_MAX, int iSkipRows=0, text_alignment eAlign=text_alignment::left) const =0
 Draw a single line of text, splitting it at word boundaries.
 

Constructor & Destructor Documentation

◆ ~font()

virtual font::~font ( )
virtualdefault

Member Function Documentation

◆ draw_text()

virtual void font::draw_text ( render_target pCanvas,
const char sMessage,
size_t  iMessageLength,
int  iX,
int  iY 
) const
pure virtual

Draw a single line of text.

Parameters
pCanvasThe render target to draw onto.
sMessageA UTF-8 encoded string containing a single line of text to draw.
iMessageLengthThe length, in bytes (not characters), of the string at sMessage.
iXThe X coordinate of the top-left corner of the bounding rectangle for the drawn text.
iYThe Y coordinate of the top-left corner of the bounding rectangle for the drawn text.

Implemented in bitmap_font, and freetype_font.

◆ draw_text_wrapped()

virtual text_layout font::draw_text_wrapped ( render_target pCanvas,
const char sMessage,
size_t  iMessageLength,
int  iX,
int  iY,
int  iWidth,
int  iMaxRows = INT_MAX,
int  iSkipRows = 0,
text_alignment  eAlign = text_alignment::left 
) const
pure virtual

Draw a single line of text, splitting it at word boundaries.

This function still only draws a single line of text (i.e. any line breaks like \r and \n in sMessage are ignored), but inserts line breaks between words so that no single line is wider than iWidth pixels. If iMaxRows is specified it will simply cut after that many rows.

Parameters
pCanvasThe canvas on which to draw. Can be nullptr, in which case nothing is drawn, but other calculations are still made.
sMessageThe line of text to draw, encoded in CP437.
iMessageLengthThe length (in bytes) of sMessage.
iXThe X position to start drawing on the canvas.
iYThe Y position to start drawing on the canvas.
iWidthThe maximum width of each line of text.
iMaxRowsThe maximum number of rows to draw. Default is INT_MAX.
iSkipRowsStart rendering text after skipping this many rows.
eAlignHow to align each line of text if the width of the line of text is smaller than iWidth.

Implemented in bitmap_font, and freetype_font.

◆ get_text_dimensions()

virtual text_layout font::get_text_dimensions ( const char sMessage,
size_t  iMessageLength,
int  iMaxWidth = INT_MAX 
) const
pure virtual

Get the size of drawn text.

If iMaxWidth is specified the text will wrap, so that the height can span multiple rows. Otherwise gets the size of a single line of text.

Parameters
sMessageA UTF-8 encoded string containing a single line of text to measure the width and height of.
iMessageLengthThe length, in bytes (not characters), of the string at sMessage.
iMaxWidthThe maximum length, in pixels, that the text may occupy. Default is INT_MAX.

Implemented in bitmap_font, and freetype_font.


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