| CRM64Pro GDK v0.15.0 A free cross-platform game development kit built on top of SDL 3.0

Loading...
Searching...
No Matches
CRM64Pro::Font
Graphics modules » 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 Position & | getPositionX () const
| Get the font X position.
const Position & | getPositionY () 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 fScaleX=1.0f, float fScaleY=1.0f, 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

  iMode | Unused 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

  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 another item. By default it is set to 0.

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

Note
  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

  cCursor | A 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

  sText | String to get the cursor position.
  iPixelPos | Pixel 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

  iKer | Signed 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

  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.

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

  posX | Position struct with X position. Can be absolute (float) or use position helpers from ::ePositionHelpers enum.
  posY | Position 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

  sText | String with the text to be rendered.
  iCurShow | 0 to hide the cursor or any other value to show it. By 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.

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 | fScaleX = 1.0f,
|  | float | fScaleY = 1.0f,
|  | 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

  sText | String with the text to be rendered.
  iCurShow | 0 to hide the cursor or any other value to show it. By 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.
  fScaleX | X scaling factor.
  fScaleY | Y scaling factor.
  dAngle | An angle in degrees that indicates the rotation that will be applied.
  poCenter | SDL_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.
  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.

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

  sCDCFile | String containing the [directory]+filename+[extension]. Directory separators '\' and '/' are supported.
  sResourceName | Optional 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

  idCDC | CDC id.
  sResourceName | Optional 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.