CFont. More...
CFont.
Font engine class.
Example03_GUI.cpp, Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, SpacePong.cpp, and SpacePong.h.
Public Member Functions | |
| void | Clean () |
| Clean and reset the content of current font. | |
| unsigned char | Create (char *filebmp) |
| Create a font(with 96 characters) from an external image file(BMP/PNG). | |
| unsigned char | Create (SDL_Surface *surface) |
| Create a new font(with 96 characters) from a surface. | |
| int | GetAlpha () |
| Get alpha blending information. | |
| int | GetKerning () |
| Get the kerning value for this font. | |
| char * | GetName () |
| Get the font name. | |
| SDL_Surface * | GetSurface () |
| Get font surface. | |
| void | Info () |
| Print a lot of useful font information. Very useful for debugging purposes. | |
| unsigned char | Load (int idDPF, char *fontname) |
| Load a font from a DPF(using an idDPF). | |
| unsigned char | Load (char *fileDPF, char *fontname) |
| Load a font from a DPF(using a filename). | |
| void | PutString (SDL_Surface *Surface, int x, int y, char *str, SDL_Rect *clip=NULL) |
| Draw a string using this font. | |
| void | PutStringXCenter (SDL_Surface *Surface, int y, char *str, SDL_Rect *clip=NULL) |
| Render a X-centered string. | |
| void | PutStringYCenter (SDL_Surface *Surface, int x, char *str, SDL_Rect *clip=NULL) |
| Render a Y-centered string. | |
| int | Save (int idDPF, char *fontname) |
| Save this font to a DPF(using an idDPF). | |
| int | Save (char *fileDPF, char *fontname) |
| Save this font to a DPF(using a filename). | |
| void | SetAlpha (int shade) |
| Set the alpha per-surface. | |
| void | SetKerning (int value) |
| Set the kerning value for this font. | |
| void | SetName (char *name) |
| Set a new name for the font. | |
| int | StringWidth (char *str) |
| Get the size of the given string. | |
| unsigned char | Test (SDL_Surface *) |
| Test if a given surface can be converted to a font. | |
| unsigned char | Test (char *filebmp) |
| Test if a given BMP can be converted to a font. | |
| void CRM32Pro_CFont::Clean | ( | ) |
Clean and reset the content of current font.
Useful to reuse the tile object with another content without use 'delete' and 'new' operators.
| unsigned char CRM32Pro_CFont::Create | ( | char * | filename | ) |
Create a font(with 96 characters) from an external image file(BMP/PNG).
To create a bitmap with your desired characters set:
1.Create a text using your favourite design software with desired aspect of your font using this string:
! " # $ % & ' ( ) * + , - . / 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 { | } ~
If you use an image file without alpha per-pixel, you must assure that the background(colorkey) color is RGB(0,0,0).
2.Between each character must exist a separation of at least two pixels. Left and right margins of the whole bitmap must be at least of five pixels.
| filename | Image file name, with its full path, containing all characters of the font |
| unsigned char CRM32Pro_CFont::Create | ( | SDL_Surface * | surface | ) |
Create a new font(with 96 characters) from a surface.
It supports alpha per-pixel surfaces.
The surface must contain the characters set using the right format. See description of Create(char *) to further information.
| surface | surface with all characters of this font |
| int CRM32Pro_CFont::GetAlpha | ( | ) |
Get alpha blending information.
To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).
| int CRM32Pro_CFont::GetKerning | ( | ) |
Get the kerning value for this font.
| char * CRM32Pro_CFont::GetName | ( | ) |
Get the font name.
| SDL_Surface * CRM32Pro_CFont::GetSurface | ( | ) |
Get font surface.
| unsigned char CRM32Pro_CFont::Load | ( | int | idDPF, | |
| char * | namefnt | |||
| ) |
Load a font from a DPF(using an idDPF).
It automatically updates fonts v1.0(all ones until CRM32Pro v4.95) to fonts v2.0(since CRM32Pro v4.96).
Note that new fonts v2.0 are not compatible with old CRM32Pro versions.
| idDPF | ID of the opened DPF | |
| namefnt | name of this font |
| unsigned char CRM32Pro_CFont::Load | ( | char * | fileDPF, | |
| char * | namefnt | |||
| ) |
Load a font from a DPF(using a filename).
It automatically updates fonts v1.0(all ones until CRM32Pro v4.95) to fonts v2.0(since CRM32Pro v4.96).
Note that new fonts v2.0 are not compatible with old CRM32Pro versions.
| fileDPF | name and optional path of a DPF that contains the font | |
| namefnt | name of this font |
| void CRM32Pro_CFont::PutString | ( | SDL_Surface * | surface, | |
| int | x, | |||
| int | y, | |||
| char * | str, | |||
| SDL_Rect * | clip = NULL | |||
| ) |
Draw a string using this font.
| surface | surface to draw the render of this font | |
| x | position x of this font on surface | |
| y | position y of this font on surface | |
| str | string to be rendered | |
| clip | SDL_Rect with clip region, by default is NULL |
| void CRM32Pro_CFont::PutStringXCenter | ( | SDL_Surface * | surface, | |
| int | y, | |||
| char * | str, | |||
| SDL_Rect * | clip = NULL | |||
| ) |
Render a X-centered string.
| surface | surface to draw the render of this font | |
| y | position Y of this font on surface | |
| str | string to be rendered | |
| clip | SDL_Rect with clip region, by default is NULL |
| void CRM32Pro_CFont::PutStringYCenter | ( | SDL_Surface * | surface, | |
| int | x, | |||
| char * | str, | |||
| SDL_Rect * | clip = NULL | |||
| ) |
Render a Y-centered string.
| surface | surface to draw the render of this font | |
| x | position X of this font on surface | |
| str | string to be rendered | |
| clip | SDL_Rect with clip region, by default is NULL |
| int CRM32Pro_CFont::Save | ( | int | idDPF, | |
| char * | fontname | |||
| ) |
Save this font to a DPF(using an idDPF).
Note if you try to save a font which was converted to the screen format to 8bits, it will convert the surface to 32bits before to proceed to save it. So, a font is never saved with a color depht of 8bits.
| idDPF | ID of the opened DPF | |
| fontname | name of this font |
| int CRM32Pro_CFont::Save | ( | char * | fileDPF, | |
| char * | fontname | |||
| ) |
Save this font to a DPF(using a filename).
| fileDPF | name and optional path of a DPF to store this font | |
| fontname | name of this font |
| void CRM32Pro_CFont::SetAlpha | ( | int | shade | ) |
Set the alpha per-surface.
A surface with enabled alpha blending(per-pixel or per-surface) will be never created on video memory if alpha blending is not supported by the hardware. Right now, only glSDL supports it.
With per-pixel alpha, per-surface alpha is useless, so any attempt to activate it will be ignored.
Note that enabling and disabling the alpha blending on the execution time could slowdown your graphic performance.
To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).
| shade | integer from 0(transparent) to 254(almost full opaque) to enable the per-surface alpha or 255(full opaque) to disable it. |
| void CRM32Pro_CFont::SetKerning | ( | int | value | ) |
Set the kerning value for this font.
When each character is rendered, the kerning value will modify its X position. By default, this value is 0.
| value | signed integer with the kerning value in pixels. |
| void CRM32Pro_CFont::SetName | ( | char * | name | ) |
Set a new name for the font.
| name | pointer to the new name. Maximum of 31 characters. |
| int CRM32Pro_CFont::StringWidth | ( | char * | str | ) |
Get the size of the given string.
| str | desired string to be measured |
| unsigned char CRM32Pro_CFont::Test | ( | SDL_Surface * | surface | ) |
Test if a given surface can be converted to a font.
It supports surfaces with alpha per pixel enabled.
| surface | surface with font characters sample |
| unsigned char CRM32Pro_CFont::Test | ( | char * | filebmp | ) |
Test if a given BMP can be converted to a font.
| filebmp | BMP file with font characters sample |
1.6.1