CRM32Pro SDK  v5.22
List of all members | Public Member Functions
CRM32Pro_CFont Class Reference

CFont. More...

Detailed Description

CFont.

Font engine class.

Examples:
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. More...
 
unsigned char Create (SDL_Surface *surface)
 Create a new font(with 96 characters) from a surface. More...
 
unsigned char Create (char *filebmp)
 Create a font(with 96 characters) from an external image file(BMP/PNG) More...
 
int GetAlpha ()
 Get alpha blending information. More...
 
char GetCursorChar ()
 Get current cursor character. More...
 
int GetKerning ()
 Get the kerning value for this font. More...
 
char * GetName ()
 Get the font name. More...
 
SDL_Surface * GetSurface ()
 Get font surface. More...
 
void Info ()
 Print a lot of useful font information. Very useful for debugging purposes.
 
unsigned char Load (char *fileDPF, char *fontname)
 Load a font from a DPF(using a filename) More...
 
unsigned char Load (int idDPF, char *fontname)
 Load a font from a DPF(using an idDPF) More...
 
void PutString (SDL_Surface *Surface, int x, int y, char *str, SDL_Rect *clip=NULL)
 Draw a string using this font. More...
 
void PutStringWithCursor (SDL_Surface *Surface, int x, int y, char *str, int cursPos, SDL_Rect *clip=NULL, unsigned char showCurs=1)
 ! Draw a string using this font and adding the cursor char More...
 
void PutStringXCenter (SDL_Surface *Surface, int y, char *str, SDL_Rect *clip=NULL)
 Render a X-centered string. More...
 
void PutStringYCenter (SDL_Surface *Surface, int x, char *str, SDL_Rect *clip=NULL)
 Render a Y-centered string. More...
 
int Save (char *fileDPF, char *fontname)
 Save this font to a DPF(using a filename) More...
 
int Save (int idDPF, char *fontname)
 Save this font to a DPF(using an idDPF) More...
 
void SetAlpha (int shade)
 Set the alpha per-surface. More...
 
void SetCursorChar (char csor)
 Set current cursor character. More...
 
void SetKerning (int value)
 Set the kerning value for this font. More...
 
void SetName (char *name)
 Set a new name for the font. More...
 
int StringHeight ()
 Get the size(height) of this font (in pixels) More...
 
int StringWidth (char *str)
 Get the size(width) of the given string. More...
 
unsigned char Test (char *filebmp)
 Test if a given BMP can be converted to a font. More...
 
unsigned char Test (SDL_Surface *)
 Test if a given surface can be converted to a font. More...
 

Member Function Documentation

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

Parameters
surfacesurface with all characters of this font
Returns
96 Ok
any other number Failed. It also indicates the successfull imported characters
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.

Parameters
filenameImage file name, with its full path, containing all characters of the font
Returns
96 Ok
any other number Failed. It also indicates the successfull imported characters
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).

Returns
-1 Failed
From 0(transparent) to 254(almost full opaque) and alpha per-surface enabled
255 Alpha per-surface disabled
256 Alpha per-pixel enabled
char CRM32Pro_CFont::GetCursorChar ( )

Get current cursor character.

This cursor is used by PutStringWithCursor() method.

Returns
The cursor char.
int CRM32Pro_CFont::GetKerning ( )

Get the kerning value for this font.

Returns
signed integer with the kerning value in pixels.
char * CRM32Pro_CFont::GetName ( )

Get the font name.

Returns
a pointer to font name
SDL_Surface * CRM32Pro_CFont::GetSurface ( )

Get font surface.

Returns
pointer to SDL_Surface 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.

Parameters
fileDPFname and optional path of a DPF that contains the font
namefntname of this font
Returns
0 Failed
1 Ok
Examples:
Example03_GUI.cpp, Example08_SpriteCollision.cpp, Example09_LogicRenderRates.cpp, and SpacePong.cpp.
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.

Parameters
idDPFID of the opened DPF
namefntname of this font
Returns
0 Failed
1 Ok
void CRM32Pro_CFont::PutString ( SDL_Surface *  surface,
int  x,
int  y,
char *  str,
SDL_Rect *  clip = NULL 
)

Draw a string using this font.

Parameters
surfacesurface to draw the render of this font
xposition x of this font on surface
yposition y of this font on surface
strstring to be rendered
clipSDL_Rect with clip region, by default is NULL
Examples:
Example03_GUI.cpp, Example08_SpriteCollision.cpp, and Example09_LogicRenderRates.cpp.
void CRM32Pro_CFont::PutStringWithCursor ( SDL_Surface *  surface,
int  xs,
int  y,
char *  str,
int  cursPos,
SDL_Rect *  clip = NULL,
unsigned char  showCurs = 1 
)

! Draw a string using this font and adding the cursor char

Parameters
surfacesurface to draw the render of this font
xsposition x of this font on surface
yposition y of this font on surface
strstring to be rendered
cursPosPosition of the cursor inside the str
clipSDL_Rect with clip region, by default is NULL
showCurs0 to hide it or 1 to show it
void CRM32Pro_CFont::PutStringXCenter ( SDL_Surface *  surface,
int  y,
char *  str,
SDL_Rect *  clip = NULL 
)

Render a X-centered string.

Parameters
surfacesurface to draw the render of this font
yposition Y of this font on surface
strstring to be rendered
clipSDL_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.

Parameters
surfacesurface to draw the render of this font
xposition X of this font on surface
strstring to be rendered
clipSDL_Rect with clip region, by default is NULL
int CRM32Pro_CFont::Save ( char *  fileDPF,
char *  fontname 
)

Save this font to a DPF(using a filename)

Parameters
fileDPFname and optional path of a DPF to store this font
fontnamename of this font
Returns
-1 Font already exists.
0 Failed.
any other positive value, Ok and packed size of the added font
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.

Parameters
idDPFID of the opened DPF
fontnamename of this font
Returns
-1 Font already exists.
0 Failed.
any other positive value, Ok and packed size of the added 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).

Parameters
shadeinteger from 0(transparent) to 254(almost full opaque) to enable the per-surface alpha or 255(full opaque) to disable it.
void CRM32Pro_CFont::SetCursorChar ( char  csor)

Set current cursor character.

This cursor is used by PutStringWithCursor() method.

Parameters
csorThe cursor char.
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.

Parameters
valuesigned integer with the kerning value in pixels.
void CRM32Pro_CFont::SetName ( char *  name)

Set a new name for the font.

Parameters
namepointer to the new name. Maximum of 31 characters.
int CRM32Pro_CFont::StringHeight ( )

Get the size(height) of this font (in pixels)

Returns
size(height) in pixels of this font
int CRM32Pro_CFont::StringWidth ( char *  str)

Get the size(width) of the given string.

Parameters
strdesired string to be measured
Returns
size(width) in pixels of the given string
unsigned char CRM32Pro_CFont::Test ( char *  filebmp)

Test if a given BMP can be converted to a font.

Parameters
filebmpBMP file with font characters sample
Returns
0 The given surface is a valid font.
255 It was not possible to import any character.
Any other number indicates the number of successful imported characters of a total of 96.
In this case, a "FontWithErrors.bmp" will be generated which has an upper purple line that have to separate each character.Common errors are some characters joined or splitted.
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.

Parameters
surfacesurface with font characters sample
Returns
0 The given surface is a valid font.
255 It was not possible to import any character.
Any other number indicates the number of successful imported characters of a total of 96.
In this case, a "FontWithErrors.bmp" will be generated which has an upper purple line that have to separate each character.Common errors are some characters joined or splitted.

The documentation for this class was generated from the following files: