SDLGameEngine

SgeFont

Bitmap font handling and effects. More...

Data Structures

struct  SGEBITMAPFONT
 a bitmap font structure More...
struct  SGEFONT
 a font structure More...
struct  SGEFONTFXFADEINFO
 internal, holds information about a current fade state More...
struct  SGEFONTFXCOUNTDOWNINFO
 internal, holds information about a current count down More...
struct  SGEFONTFX
 holds information about a font effect More...
struct  SGEFONTFXFADEINOUTINFO
 internal, holds information about a in and out fading effect More...

Defines

#define SGEFONT_BITMAP   1
 font is a sge bitmap font

Enumerations

enum  SGEFONTFX_TYPES {
  SGEFONTFX_FADE_IN, SGEFONTFX_FADE_OUT, SGEFONTFX_FADE_INOUT, SGEFONTFX_MOVE_IN,
  SGEFONTFX_MOVE_OUT, SGEFONTFX_MOVE_INOUT, SGEFONTFX_COUNTDOWN
}
 

different font effects

More...
enum  SGEFONTFX_MOVEMENT { SGEFONTFX_MOVE_LINEAR, SGEFONTFX_MOVE_SLOWDOWN, SGEFONTFX_MOVE_ACCELERATE, SGEFONTFX_MOVE_BOUNCE }
 

different move effects

More...

Functions

SGEFONTsgeFontNew (int type)
 create a new empty font
SGEFONTsgeFontNewFile (SGEFILE *f, int type, const char *filename)
 create a new font from a file
void sgeFontDestroy (SGEFONT *f)
 destroy a font and free its resources
int sgeFontGetLineHeight (SGEFONT *f)
 get the height of a line with the font
int sgeFontPrint (SGEFONT *f, SDL_Surface *dest, int x, int y, const char *text)
 print a text with the font
int sgeFontGetWidth (SGEFONT *f, const char *text)
 get the width of a text
void sgeFontIgnoreAlpha (SGEFONT *f)
 ignore the alpha channel of a font
void sgeFontUseAlpha (SGEFONT *f)
 use the alpha channel of a font (default)
SGEFONTFXsgeFontFXNew (SGEFONT *f, Uint32 fxtype, Uint8 movement, Uint32 runtime, Uint32 charOffset, int startx, int starty, int endx, int endy, const char *text)
 create a new font effect
void sgeFontFXDraw (SGEFONTFX *fx)
 draw the effect
void sgeFontFXDestroy (SGEFONTFX *fx)
 destroy the effect and free its resources
void sgeFontFXCountdownSetValues (SGEFONTFX *fx, Sint32 start, Sint32 end)
 set the value range for a count down (or up) effect
void sgeFontFXPreDelay (SGEFONTFX *fx, Uint32 delay)
 set the miliseconds to wait before starting the effect
void sgeFontFXHideOnPreDelay (SGEFONTFX *fx, Uint8 yesno)
 hide the effect until pre delay is over
void sgeFontFXPostDelay (SGEFONTFX *fx, Uint32 delay)
 wait after a effect is finished until it actually is treated as finished
void sgeFontFXSetFinished (SGEFONTFX *fx)
 force an early finish of a effect
int sgeFontFXFinished (SGEFONTFX *fx)
 check if a effect is finished
void sgeFontFXSetTarget (SGEFONTFX *fx, SDL_Surface *surface)
 change render target (default screen) of the effect

Variables

Uint8 SGEFONT::alpha
 The alpha of the font, 0 to 255, 255 is fully opaque.

Detailed Description

Bitmap font handling and effects.

Print with bitmap fonts, including animated text effects.

Bitmap fonts are wide PNG images having all characters in one row, split by a single pixel line of pink color (0xff00ff).

If the font is called myfont.png, there has to be a file called myfont.png.map which lists the characters from the image, so if your image shows the characters SGE, then your map file should read 'SGE'

Just have a look at the standard fonts to see how they are done.


Define Documentation

#define SGEFONT_BITMAP   1

font is a sge bitmap font

SGEFONT_BITMAP

Definition at line 46 of file sgefont.h.


Enumeration Type Documentation

different move effects

Enumerator:
SGEFONTFX_MOVE_LINEAR 

move at a constant speed

SGEFONTFX_MOVE_SLOWDOWN 

move fast, then slow down until rest

SGEFONTFX_MOVE_ACCELERATE 

accelerate movement

SGEFONTFX_MOVE_BOUNCE 

bounce the font in

Definition at line 97 of file sgefont.h.

different font effects

Enumerator:
SGEFONTFX_FADE_IN 

fade the font in

SGEFONTFX_FADE_OUT 

fade the font out

SGEFONTFX_FADE_INOUT 

fade the font in, then out

SGEFONTFX_MOVE_IN 

move the font in

SGEFONTFX_MOVE_OUT 

move the font out

SGEFONTFX_MOVE_INOUT 

move the font in, then out

SGEFONTFX_COUNTDOWN 

show a count down

Definition at line 76 of file sgefont.h.


Function Documentation

void sgeFontDestroy ( SGEFONT f)

destroy a font and free its resources

Parameters:
fa pointer to a SGEFONT

Definition at line 91 of file sgefont.c.

void sgeFontFXCountdownSetValues ( SGEFONTFX fx,
Sint32  start,
Sint32  end 
)

set the value range for a count down (or up) effect

Parameters:
fxa pointer to a SGEFONTFX
startthe start value
endthe end value

The end value can be higher then start value for a 'count up' effect

Definition at line 607 of file sgefont.c.

void sgeFontFXDestroy ( SGEFONTFX fx)

destroy the effect and free its resources

Parameters:
fxa pointer to a SGEFONTFX

Definition at line 479 of file sgefont.c.

void sgeFontFXDraw ( SGEFONTFX fx)

draw the effect

Parameters:
fxa pointer to a SGEFONTFX

Definition at line 475 of file sgefont.c.

int sgeFontFXFinished ( SGEFONTFX fx)

check if a effect is finished

Parameters:
fxa pointer to a SGEFONTFX
Returns:
YES/NO if the effect is finished

Includes pre and post delay into its calculation.

See also:
sgeFontFXPreDelay
sgeFontFXPostDelay

Definition at line 626 of file sgefont.c.

void sgeFontFXHideOnPreDelay ( SGEFONTFX fx,
Uint8  yesno 
)

hide the effect until pre delay is over

Parameters:
fxa pointer to a SGEFONTFX
YES/NOif you want to hide, default is not to hide
See also:
sgeFontFXPreDelay

Definition at line 633 of file sgefont.c.

SGEFONTFX* sgeFontFXNew ( SGEFONT f,
Uint32  fxtype,
Uint8  movement,
Uint32  runtime,
Uint32  charOffset,
int  startx,
int  starty,
int  endx,
int  endy,
const char *  text 
)

create a new font effect

Parameters:
fa pointer to a SGEFONT
fxtypethe effect type SGEFONTFX_TYPES
movementthe movement type SGEFONTFX_MOVEMENT
runtimehow long should the effect take, in miliseconds
charOffsetthe offset of the characters in miliseconds, read detail description
startxthe x position to start the effect from
startythe y position to start the effect from
endxthe x position to end the effect at
endythe y position to end the effect at
textthe text to make the effect with
Returns:
a pointer to a new SGEFONTFX

The charOffset defines how much 'behind' the single characters of the text are treated.

Setting charOffset to 0 means there is no per character treatment and the full text will only be one big image.

Setting charOffset to>0 means that each character is treated as a single image with a delay of charOffset miliseconds.

example:

Fade the text in from -100, 0 (outside the screen up left) to the bottom of the screen (1, 220), move every single character with a offset of 99 in a down slowing movement. The whole effect should take 1000 miliseconds. As we use a offset of 99, it actually takes longer then 1000 miliseconds depending on text length. It takes 1000 miliseconds for the first character and then continues until all characters are on its destination.

 SGEFONTFX *fx=sgeFontFXNew(data->font, SGEFONTFX_FADE_IN, SGEFONTFX_MOVE_SLOWDOWN, 1000, 99, -100, 0, 1, 220, "Look at me, i am fancy");

Definition at line 355 of file sgefont.c.

void sgeFontFXPostDelay ( SGEFONTFX fx,
Uint32  delay 
)

wait after a effect is finished until it actually is treated as finished

Parameters:
fxa pointer to a SGEFONTFX
delaythe delay in miliseconds
See also:
sgeFontFXFinished

Definition at line 617 of file sgefont.c.

void sgeFontFXPreDelay ( SGEFONTFX fx,
Uint32  delay 
)

set the miliseconds to wait before starting the effect

Parameters:
fxa pointer to a SGEFONTFX
delaythe delay in miliseconds
See also:
sgeFontFXHideOnPreDelay

Definition at line 613 of file sgefont.c.

void sgeFontFXSetFinished ( SGEFONTFX fx)

force an early finish of a effect

Parameters:
fxa pointer to a SGEFONTFX

Definition at line 621 of file sgefont.c.

void sgeFontFXSetTarget ( SGEFONTFX fx,
SDL_Surface *  surface 
)

change render target (default screen) of the effect

Parameters:
fxa pointer to a SGEFONTFX
surfacea pointer to a SDL_Surface on which to render the effect

Definition at line 637 of file sgefont.c.

int sgeFontGetLineHeight ( SGEFONT f)

get the height of a line with the font

Parameters:
fa pointer to a SGEFONT
Returns:
the height of a single line in pixels

Definition at line 109 of file sgefont.c.

int sgeFontGetWidth ( SGEFONT f,
const char *  text 
)

get the width of a text

Parameters:
fa pointer to a SGEFONT
textthe text to check the with of
Returns:
the width of the text if it would have printed

Definition at line 167 of file sgefont.c.

void sgeFontIgnoreAlpha ( SGEFONT f)

ignore the alpha channel of a font

Parameters:
fa pointer to a SGEFONT
See also:
sgeFontUseAlpha

faster but prints a background color

Definition at line 175 of file sgefont.c.

SGEFONT* sgeFontNew ( int  type)

create a new empty font

Parameters:
typethe type of the font
Returns:
a pointer to a new SGEFONT
See also:
SGEFONT_BITMAP

Definition at line 16 of file sgefont.c.

SGEFONT* sgeFontNewFile ( SGEFILE f,
int  type,
const char *  filename 
)

create a new font from a file

Parameters:
fa pointer to a opened sge file archive SGEFILE
typetype of the font
filenamethe name of the png file holding the font bitmap
Returns:
a pointer to a new SGEFONT
See also:
SGEFONT_BITMAP

Definition at line 67 of file sgefont.c.

int sgeFontPrint ( SGEFONT f,
SDL_Surface *  dest,
int  x,
int  y,
const char *  text 
)

print a text with the font

Parameters:
fa pointer to a SGEFONT
desta SDL_Surface to print on (e.g. screen)
xthe x position to print the font
ythe y position to print the font
textthe text to print

Definition at line 159 of file sgefont.c.

void sgeFontUseAlpha ( SGEFONT f)

use the alpha channel of a font (default)

Parameters:
fa pointer to a SGEFONT
See also:
sgeFontIgnoreAlpha

Definition at line 181 of file sgefont.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines