CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
Classes | Functions

Detailed Description

v2.00 (20 June 2023)
The Font module includes the Font Manager and Font for handling all the operations with fonts.

Instead of using a more sophisticated TTF font rendering system and as the GDK is focused on game development, we use a simply and blazing fast approach although still, quite powerful and free for using any kind of font.

The font creation process is described below:


The font has a method for getting the Image id in order to get access to the Image object, for example, you can export the font image to an external file or modify the alpha modulation.


The storage layer(FontMgr::load() and Font::save() methods) are using the CDC v1.x specification.


This is an advance "cloning" manager: when loading from a CDC file a font which is already loaded/created (using the name as the key), it will create a new child font.
Only a single instance of the Font Manager exists which is created once Main is instantiated.
You can get a reference to this manager using Main::IFontMgr() method.

Note
The Font Manager is automatically released when Main::Terminate() is called.
At this time, any resource still loaded, will be released avoding resource leaks.

Classes

class  CRM64Pro::Font
 Font Object class. More...
 
class  CRM64Pro::FontMgr
 Font Manager class. More...
 

Functions

Sint32 CRM64Pro::Font::info (Sint32 iMode=0)
 Request Font object information.
 
Sint32 CRM64Pro::Font::getName (string &sName)
 Get the name.
 
Uint32 CRM64Pro::Font::getID ()
 Get the ID.
 
Sint32 CRM64Pro::Font::assignImage (Sint32 idImage, Sint32 iOwnership=0)
 Assign an Image to this font.
 
Sint32 CRM64Pro::Font::getImage ()
 Get the assigned Image of this font.
 
Sint32 CRM64Pro::Font::setCursor (Uint8 cCursor)
 Set cursor character.
 
Uint8 CRM64Pro::Font::getCursor ()
 Get cursor character.
 
Sint32 CRM64Pro::Font::getCursorPositionByPixel (const string &sText, Sint32 iPixelPos)
 Get the cursor position given a number of pixels.
 
Sint32 CRM64Pro::Font::setKerning (Sint32 iKer)
 Set the kerning value.
 
Sint32 CRM64Pro::Font::getKerning ()
 Get the kerning value.
 
Sint32 CRM64Pro::Font::getWidth (const string &sText, Sint32 iCurPos=-1)
 Get the width of the given string (in pixels).
 
Sint32 CRM64Pro::Font::getHeight ()
 Get the height of this font (in pixels).
 
Sint32 CRM64Pro::Font::setPosition (Sint32 iX, Sint32 iY)
 Set the font position.
 
Sint32 CRM64Pro::Font::getPosition (Sint32 *iX, Sint32 *iY)
 Get the font position.
 
Sint32 CRM64Pro::Font::render (const string &sText, Sint32 iCurShow=0, Sint32 iCurPos=-1, Sint32 idRes=0)
 Render a text using this font.
 
Sint32 CRM64Pro::Font::renderEx (const string &sText, Sint32 iCurShow=0, Sint32 iCurPos=-1, const double dAngle=0.0, const SDL_Point *poCenter=nullptr, const SDL_FlipMode rf=SDL_FLIP_NONE, Sint32 idRes=0)
 Render a text using this font.
 
Sint32 CRM64Pro::Font::save (const string &sFileCDC)
 Save the font to a CDC file.
 
Sint32 CRM64Pro::Font::save (Sint32 idCDC)
 Save the font to a CDC file.
 
Sint32 CRM64Pro::FontMgr::info (Sint32 iMode=0)
 Request Font Manager information.
 
Sint32 CRM64Pro::FontMgr::create (const string &sName, Uint32 iVersion=10)
 Create a new font.
 
Sint32 CRM64Pro::FontMgr::close (Sint32 idFont)
 Close and destroy a font.
 
Sint32 CRM64Pro::FontMgr::getNum ()
 Get number of loaded objects.
 
Sint32 CRM64Pro::FontMgr::setName (Sint32 idFont, const string &sName)
 Change the object name.
 
FontCRM64Pro::FontMgr::get (Sint32 idFont)
 Get a pointer to the font using its handler.
 
Sint32 CRM64Pro::FontMgr::child (Sint32 idFont)
 Create a child font dependant on the provided one(the parent).
 
Sint32 CRM64Pro::FontMgr::load (const string &sFileCDC, const string &sName)
 Load a font stored in a CDC file.
 
Sint32 CRM64Pro::FontMgr::load (const Sint32 idCDC, const string &sName)
 Load a font stored in a CDC file.
 
Sint32 CRM64Pro::FontMgr::remove (const Sint32 idCDC, const string &sName)
 Remove a font stored in a CDC file.
 

Function Documentation

◆ info() [1/2]

Sint32 CRM64Pro::Font::info ( Sint32  iMode = 0)

Request Font object information.

For displaying the information, it uses the default log.

Parameters
iModeunused for the time being.
Returns
0 on success or a negative error code on failure.

◆ getName()

Sint32 CRM64Pro::Font::getName ( string &  sName)

Get the name.

Parameters
sNamea string containing the font name.
Returns
0 on success or a negative error code on failure.

◆ getID()

Uint32 CRM64Pro::Font::getID ( )

Get the ID.

Returns
the object ID.

◆ assignImage()

Sint32 CRM64Pro::Font::assignImage ( Sint32  idImage,
Sint32  iOwnership = 0 
)

Assign an Image to this font.

It is mainly used for associating an Image to the font when it is created via FontMgr::create().

Parameters
idImageImage id with the whole characters set.
They are identified using alpha channel so the image needs to have colorkey/alpha channel enabled.
iOwnership0 for creating our own copy of the image or any other value for taking the ownership of the image, in this case, the image can not be already owned by other item.
By default it is set to 0.
Returns
0 on success or a negative error code on failure.
Note
The image name associated to this font will be internally modified: starts with the reserved character '#' + an internal code + the font name.
When re-assigning a new image, the old one will be closed.

◆ getImage()

Sint32 CRM64Pro::Font::getImage ( )

Get the assigned Image of this font.

Returns
greater than 0 on success or a negative error code on failure.

◆ setCursor()

Sint32 CRM64Pro::Font::setCursor ( Uint8  cCursor)

Set cursor character.

Parameters
cCursorA character on the range of (33, 129].
Returns
0 on success or a negative error code on failure.

◆ getCursor()

Uint8 CRM64Pro::Font::getCursor ( )

Get cursor character.

Returns
greater than 33 and less than 130 on success or a negative error code on failure.

◆ getCursorPositionByPixel()

Sint32 CRM64Pro::Font::getCursorPositionByPixel ( const string &  sText,
Sint32  iPixelPos 
)

Get the cursor position given a number of pixels.

Parameters
sTextstring to get the cursor position.
iPixelPospixel position to convert to cursor position.
If it is greater than the text width, it will return the last position.
Returns
0 or greater on success (cursor position on the range of [0, text size in characters - 1]) or a negative error code on failure.

◆ setKerning()

Sint32 CRM64Pro::Font::setKerning ( Sint32  iKer)

Set the kerning value.

Parameters
iKersigned integer with the kerning value in pixels.
Returns
0 on success or a negative error code on failure.

◆ getKerning()

Sint32 CRM64Pro::Font::getKerning ( )

Get the kerning value.

Returns
signed integer with the kerning value in pixels.

◆ getWidth()

Sint32 CRM64Pro::Font::getWidth ( const string &  sText,
Sint32  iCurPos = -1 
)

Get the width of the given string (in pixels).

Parameters
sTextstring to get its width.
iCurPosup to this character position.
By default, it is set to -1 for positioning the cursor at the end of the string.
Returns
greater than 0(string width on pixels) on success or a negative error code on failure.

◆ getHeight()

Sint32 CRM64Pro::Font::getHeight ( )

Get the height of this font (in pixels).

Returns
greater than 0(string height on pixels) on success or a negative error code on failure.

◆ setPosition()

Sint32 CRM64Pro::Font::setPosition ( Sint32  iX,
Sint32  iY 
)

Set the font position.

Parameters
iXan integer with the font X position.
Check ePositionHelpers enum for a list of supported position helpers.
iYan integer with the font Y position.
Check ePositionHelpers enum for a list of supported position helpers.
Returns
0 on success or a negative error code on failure.

◆ getPosition()

Sint32 CRM64Pro::Font::getPosition ( Sint32 *  iX,
Sint32 *  iY 
)

Get the font position.

Parameters
iXan integer pointer filled in with X font position. If nullptr is passed, the method ignores the retrieving of this value.
iYan integer pointer filled in with Y font position. If nullptr is passed, the method ignores the retrieving of this value.
Returns
0 on success or a negative error code on failure.

◆ render()

Sint32 CRM64Pro::Font::render ( const string &  sText,
Sint32  iCurShow = 0,
Sint32  iCurPos = -1,
Sint32  idRes = 0 
)

Render a text using this font.

Parameters
sTextstring with the text to be rendered.
iCurShow0 to hide the cursor or any other value to show it.
Be default it is hidden.
iCurPosposition of the cursor on the given text.
By default it is set to -1 which means at the end.
idResa valid screen or image handle.
By default it tries to use the default screen.
Returns
0 on success or a negative error code on failure.

◆ renderEx()

Sint32 CRM64Pro::Font::renderEx ( const string &  sText,
Sint32  iCurShow = 0,
Sint32  iCurPos = -1,
const double  dAngle = 0.0,
const SDL_Point *  poCenter = nullptr,
const SDL_FlipMode  rf = SDL_FLIP_NONE,
Sint32  idRes = 0 
)

Render a text using this font.

Parameters
sTextstring with the text to be rendered.
iCurShow0 to hide the cursor or any other value to show it.
Be default it is hidden.
iCurPosposition of the cursor on the given text.
By default it is set to -1 which means at the end.
dAnglean angle in degrees that indicates the rotation that will be applied.
poCenterSDL_Point pointer indicating the point around which each character will be rotated.
By default, it is set to nullptr and the rotation will be done around rDst.w/2 and rDst.h/2.
rfSDL_FlipMode value stating which flipping actions should be performed.
idResa valid screen or image handle.
By default it tries to use the default screen.
Returns
0 on success or a negative error code on failure.

◆ save() [1/2]

Sint32 CRM64Pro::Font::save ( const string &  sFileCDC)

Save the font to a CDC file.

The associated image will also be saved in to the same CDC file.

Parameters
sFileCDCstring containing the [directory]+filename+[extension].
Directory separators '\' and '/' are supported.
Returns
0 or greater on success or a negative error code on failure.
Note
If the font already exists, it will be overwritten.
Can not save child fonts.

◆ save() [2/2]

Sint32 CRM64Pro::Font::save ( Sint32  idCDC)

Save the font to a CDC file.

The associated image will also be saved in to the same CDC file.

Parameters
idCDCCDC id.
Returns
0 or greater on success or a negative error code on failure.
Note
If the font already exists, it will be overwritten.
If the font is a child, it will call the save method of its parent.

◆ info() [2/2]

Sint32 CRM64Pro::FontMgr::info ( Sint32  iMode = 0)

Request Font Manager information.

For displaying the information, it uses the default log.

Parameters
iMode-1 for displaying only Manager information.
0 for displaying Manager and all Objects information. This is the default value.
idFont for displaying Manager and given Font id information.
Returns
0 on success or a negative error code on failure.

◆ create()

Sint32 CRM64Pro::FontMgr::create ( const string &  sName,
Uint32  iVersion = 10 
)

Create a new font.

This method will create an empty font (no image assigned), use Font::assignImage() method for assigning the image.

Parameters
sNameThe name to give to the font e.g. 'myFont'.
The object name must be unique and with a maximum size of 64 characters or will be truncated.
iVersionFont version. 10 means 1.0 which is the only version supported (as of now).
v1.0 is set by default.
Returns
greater than 0 on success(the Font id) or a negative error code on failure.
Note
If the provided name already exists, it does nothing and return an error code.

◆ close()

Sint32 CRM64Pro::FontMgr::close ( Sint32  idCur)

Close and destroy a font.

Parameters
idCur0 for closing all fonts or the Font id.
Stand-alone and child fonts can be closed but parent ones, can not as they have at least one dependency(a child).
Returns
0 on success or a negative error code on failure.
Note
If you forget to close a Font, it will be automatically closed once the GDK is terminated.

◆ getNum()

Sint32 CRM64Pro::FontMgr::getNum ( )

Get number of loaded objects.

Returns
the number of fonts.

◆ setName()

Sint32 CRM64Pro::FontMgr::setName ( Sint32  idFont,
const string &  sName 
)

Change the object name.

Parameters
idFontFont id.
sNameThe name to give to the font e.g. 'myFont'.
The object name must be unique and with a maximum size of 64 characters or will be truncated.
Returns
0 on success or a negative error code on failure.
Note
The image name associated to this font will be internally modified: starts with the reserved character '#' + an internal code + the font name.

◆ get()

Font * CRM64Pro::FontMgr::get ( Sint32  idFont)

Get a pointer to the font using its handler.

Parameters
idFontFont id.
Returns
nullptr the font was not found.
A pointer to the font object.

◆ child()

Sint32 CRM64Pro::FontMgr::child ( Sint32  idFont)

Create a child font dependant on the provided one(the parent).

A child font uses the attributes of the parent and creates also a parent child image for having different attributes.

Parameters
idFontparent Font id.
If the provided font is a child, internally it will redirect this request to the parent in order to create the new child.
Returns
greater than 0 on success(the Font id) or a negative error code on failure.
Note
The child use the parent's name.

◆ load() [1/2]

Sint32 CRM64Pro::FontMgr::load ( const string &  sFileCDC,
const string &  sName 
)

Load a font stored in a CDC file.

Parameters
sFileCDCstring containing the [directory]+filename.
Directory separators '\' and '/' are supported.
sNamestring with the font name (maximum size of 64 characters).
If the font is already created, this method will call child() for creating a child.
Returns
0 or greater on success(the Font id) or a negative error code on failure.

◆ load() [2/2]

Sint32 CRM64Pro::FontMgr::load ( const Sint32  idCDC,
const string &  sName 
)

Load a font stored in a CDC file.

Parameters
idCDCCDC id.
sNamestring with the font name (maximum size of 64 characters).
If the font is already created, this method will call child() for creating a child.
Returns
greater than 0 on success(the Font id) or a negative error code on failure.

◆ remove()

Sint32 CRM64Pro::FontMgr::remove ( const Sint32  idCDC,
const string &  sName 
)

Remove a font stored in a CDC file.

Parameters
idCDCCDC id.
sNamestring with the font name (maximum size of 64 characters).
Returns
greater than 0 on success or a negative error code on failure.
Note
The font must be closed before trying to remove it from the CDC.