CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
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:
Using your favourite image design software for creating an image containing the following character set (96 in total):
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
The image can be created using any kind of font and attributes and must only comply with:
Save the image to a PNG or a BMP file, load it using the Image Manager (in case of usage of colorkey, dont forget to set it now) and create a font with FontMgr::create()
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.
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. | |
Font * | CRM64Pro::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. | |
Sint32 CRM64Pro::Font::info | ( | Sint32 | iMode = 0 | ) |
Request Font object information.
For displaying the information, it uses the default log.
iMode | unused for the time being. |
Sint32 CRM64Pro::Font::getName | ( | string & | sName | ) |
Get the name.
sName | a string containing the font name. |
Uint32 CRM64Pro::Font::getID | ( | ) |
Get the ID.
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().
idImage | Image id with the whole characters set. They are identified using alpha channel so the image needs to have colorkey/alpha channel enabled. |
iOwnership | 0 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. |
Sint32 CRM64Pro::Font::getImage | ( | ) |
Get the assigned Image of this font.
Sint32 CRM64Pro::Font::setCursor | ( | Uint8 | cCursor | ) |
Set cursor character.
cCursor | A character on the range of (33, 129]. |
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.
sText | string to get the cursor position. |
iPixelPos | pixel position to convert to cursor position. If it is greater than the text width, it will return the last position. |
Sint32 CRM64Pro::Font::setKerning | ( | Sint32 | iKer | ) |
Set the kerning value.
iKer | signed integer with the kerning value in pixels. |
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).
sText | string to get its width. |
iCurPos | up to this character position. By default, it is set to -1 for positioning the cursor at the end of the string. |
Sint32 CRM64Pro::Font::getHeight | ( | ) |
Get the height of this font (in pixels).
Sint32 CRM64Pro::Font::setPosition | ( | Sint32 | iX, |
Sint32 | iY | ||
) |
Set the font position.
iX | an integer with the font X position. Check ePositionHelpers enum for a list of supported position helpers. |
iY | an integer with the font Y position. Check ePositionHelpers enum for a list of supported position helpers. |
Sint32 CRM64Pro::Font::getPosition | ( | Sint32 * | iX, |
Sint32 * | iY | ||
) |
Get the font position.
iX | an integer pointer filled in with X font position. If nullptr is passed, the method ignores the retrieving of this value. |
iY | an integer pointer filled in with Y font position. If nullptr is passed, the method ignores the retrieving of this value. |
Sint32 CRM64Pro::Font::render | ( | const string & | sText, |
Sint32 | iCurShow = 0 , |
||
Sint32 | iCurPos = -1 , |
||
Sint32 | idRes = 0 |
||
) |
Render a text using this font.
sText | string with the text to be rendered. |
iCurShow | 0 to hide the cursor or any other value to show it. Be default it is hidden. |
iCurPos | position of the cursor on the given text. By default it is set to -1 which means at the end. |
idRes | a valid screen or image handle. By default it tries to use the default screen. |
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.
sText | string with the text to be rendered. |
iCurShow | 0 to hide the cursor or any other value to show it. Be default it is hidden. |
iCurPos | position of the cursor on the given text. By default it is set to -1 which means at the end. |
dAngle | an angle in degrees that indicates the rotation that will be applied. |
poCenter | SDL_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. |
rf | SDL_FlipMode value stating which flipping actions should be performed. |
idRes | a valid screen or image handle. By default it tries to use the default screen. |
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.
sFileCDC | string containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
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.
idCDC | CDC id. |
Sint32 CRM64Pro::FontMgr::info | ( | Sint32 | iMode = 0 | ) |
Request Font Manager information.
For displaying the information, it uses the default log.
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. |
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.
sName | The 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. |
iVersion | Font version. 10 means 1.0 which is the only version supported (as of now). v1.0 is set by default. |
Sint32 CRM64Pro::FontMgr::close | ( | Sint32 | idCur | ) |
Close and destroy a font.
idCur | 0 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). |
Sint32 CRM64Pro::FontMgr::getNum | ( | ) |
Get number of loaded objects.
Sint32 CRM64Pro::FontMgr::setName | ( | Sint32 | idFont, |
const string & | sName | ||
) |
Change the object name.
idFont | Font id. |
sName | The 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. |
Font * CRM64Pro::FontMgr::get | ( | Sint32 | idFont | ) |
Get a pointer to the font using its handler.
idFont | Font id. |
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.
idFont | parent 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. |
Sint32 CRM64Pro::FontMgr::load | ( | const string & | sFileCDC, |
const string & | sName | ||
) |
Load a font stored in a CDC file.
sFileCDC | string containing the [directory]+filename. Directory separators '\' and '/' are supported. |
sName | string with the font name (maximum size of 64 characters). If the font is already created, this method will call child() for creating a child. |
Sint32 CRM64Pro::FontMgr::load | ( | const Sint32 | idCDC, |
const string & | sName | ||
) |
Load a font stored in a CDC file.
idCDC | CDC id. |
sName | string with the font name (maximum size of 64 characters). If the font is already created, this method will call child() for creating a child. |
Sint32 CRM64Pro::FontMgr::remove | ( | const Sint32 | idCDC, |
const string & | sName | ||
) |
Remove a font stored in a CDC file.
idCDC | CDC id. |
sName | string with the font name (maximum size of 64 characters). |