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

#include <th_gfx_font.h>

Inheritance diagram for bitmap_font:
font

Public Member Functions

 bitmap_font ()
 
void set_sprite_sheet (sprite_sheet *pSpriteSheet, bitmap_font_character_set character_set)
 Set the character glyph sprite sheet.
 
void set_scale_factor (int factor)
 
sprite_sheetget_sprite_sheet ()
 
void set_separation (int iCharSep, int iLineSep)
 Set the separation between characters and between lines.
 
text_layout get_text_dimensions (const char *sMessage, size_t iMessageLength, int iMaxWidth=INT_MAX) const override
 Get the size of drawn text.
 
void draw_text (render_target *pCanvas, const char *sMessage, size_t iMessageLength, int iX, int iY) const override
 Draw a single line of text.
 
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 override
 Draw a single line of text, splitting it at word boundaries.
 
- Public Member Functions inherited from font
virtual ~font ()=default
 

Constructor & Destructor Documentation

◆ bitmap_font()

bitmap_font::bitmap_font ( )
default

Member Function Documentation

◆ draw_text()

void bitmap_font::draw_text ( render_target pCanvas,
const char sMessage,
size_t  iMessageLength,
int  iX,
int  iY 
) const
overridevirtual

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.

Implements font.

◆ draw_text_wrapped()

text_layout bitmap_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
overridevirtual

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.

Implements font.

◆ get_sprite_sheet()

sprite_sheet * bitmap_font::get_sprite_sheet ( )
inline

◆ get_text_dimensions()

text_layout bitmap_font::get_text_dimensions ( const char sMessage,
size_t  iMessageLength,
int  iMaxWidth = INT_MAX 
) const
overridevirtual

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.

Implements font.

◆ set_scale_factor()

void bitmap_font::set_scale_factor ( int  factor)

◆ set_separation()

void bitmap_font::set_separation ( int  iCharSep,
int  iLineSep 
)

Set the separation between characters and between lines.

Generally, the sprite sheet glyphs will already include separation, and thus no extra separation is required (set iCharSep and iLineSep to 0).

◆ set_sprite_sheet()

void bitmap_font::set_sprite_sheet ( sprite_sheet pSpriteSheet,
bitmap_font_character_set  character_set 
)

Set the character glyph sprite sheet.

The sprite sheet should have the space character (ASCII 0x20) at sprite index 1, and other ASCII characters following on in simple order (i.e. '!' (ASCII 0x21) at index 2, 'A' (ASCII 0x41) at index 34, etc.)

Parameters
pSpriteSheetThe sprite sheet to use for the font.
character_setThe character set to use when mapping unicode to sprite indexes.

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