CRM64Pro GDK v0.14.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
CRM64Pro::Font

Font Object class. More...

Detailed Description

Font Object class.

Public Member Functions

bool info (Sint32 iMode=0) override
 Request Font object information.
const string & getName () const override
 Get the name.
Uint32 getID () const override
 Get the ID.
Sint32 assignImage (Sint32 idImage, Sint32 iOwnership=0)
 Assign an Image to this font.
Sint32 getImage () const
 Get the assigned Image of this font.
bool setCursor (Uint8 cCursor)
 Set cursor character.
Uint8 getCursor ()
 Get cursor character.
Sint32 getCursorPositionByPixel (const string &sText, Sint32 iPixelPos)
 Get the cursor position given a number of pixels.
bool setKerning (Sint32 iKer)
 Set the kerning value.
Sint32 getKerning () const
 Get the kerning value.
Sint32 getWidth (const string &sText, Sint32 iCurPos=-1)
 Get the width of the given string (in pixels).
Sint32 getHeight () const
 Get the height of this font (in pixels).
bool setPosition (const Position &posX, const Position &posY)
 Set the font position.
const PositiongetPositionX () const
 Get the font X position.
const PositiongetPositionY () const
 Get the font Y position.
Sint32 render (const string &sText, Sint32 iCurShow=0, Sint32 iCurPos=-1, Sint32 idRes=0)
 Render a text using this font.
Sint32 renderEx (const string &sText, Sint32 iCurShow=0, Sint32 iCurPos=-1, float fScale=1.0, const double dAngle=0.0, const SDL_FPoint *poCenter=nullptr, const SDL_FlipMode rf=SDL_FLIP_NONE, Sint32 idRes=0)
 Render a text using this font.
Sint32 save (const string &sCDCFile, const string &sResourceName="")
 Save the font to a CDC file.
Sint32 save (const Sint32 idCDC, const string &sResourceName="")
 Save the font to a CDC file.

Member Function Documentation

◆ info()

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

Request Font object information.

Writes information to the default log.

Parameters
iModeUnused for the time being.
Returns
true on success, or false on failure.

◆ getName()

const string & CRM64Pro::Font::getName ( ) const
override

Get the name.

Returns
The object name.

◆ getID()

Uint32 CRM64Pro::Font::getID ( ) const
override

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 another 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 ( ) const

Get the assigned Image of this font.

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

◆ setCursor()

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

Set cursor character.

Parameters
cCursorA character on the range of (33, 129].
Returns
true on success or false 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.
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.
Note
If the pixel position is outside the text width, it will return -1.

◆ setKerning()

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

Set the kerning value.

Parameters
iKerSigned integer with the kerning value in pixels.
Returns
true on success or false on failure.

◆ getKerning()

Sint32 CRM64Pro::Font::getKerning ( ) const

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 ( ) const

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()

bool CRM64Pro::Font::setPosition ( const Position & posX,
const Position & posY )

Set the font position.

Parameters
posXPosition struct with X position. Can be absolute (float) or use position helpers from ::ePositionHelpers enum.
posYPosition struct with Y position. Can be absolute (float) or use position helpers from ::ePositionHelpers enum.
Returns
true on success or false on failure.
Note
Supports implicit conversion from float: setPosition(100.0f, 200.0f) or explicit helpers: setPosition(Position(PH_CENTER, -10.0f), Position(PH_TOP))

◆ getPositionX()

const Position & CRM64Pro::Font::getPositionX ( ) const

Get the font X position.

Returns
The Position struct containing X position (absolute or with helper).

◆ getPositionY()

const Position & CRM64Pro::Font::getPositionY ( ) const

Get the font Y position.

Returns
The Position struct containing Y position (absolute or with helper).

◆ 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. By 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,
float fScale = 1.0,
const double dAngle = 0.0,
const SDL_FPoint * 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. By default it is hidden.
fScaleA float number indicating the scaling factor to be applied to each character.
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_FPoint 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 & sCDCFile,
const string & sResourceName = "" )

Save the font to a CDC file.

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

Parameters
sCDCFileString containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported.
sResourceNameOptional resource name to use in the CDC. If empty (default), uses the Font object's internal name.
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, the parent font will be saved.

◆ save() [2/2]

Sint32 CRM64Pro::Font::save ( const Sint32 idCDC,
const string & sResourceName = "" )

Save the font to a CDC file.

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

Parameters
idCDCCDC id.
sResourceNameOptional resource name to use in the CDC. If empty (default), uses the Font object's internal name.
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.