SdlFont Class Reference
[SDL based classes]

Used to write text with a specific font. More...

#include <sdlfont.h>

Collaboration diagram for SdlFont:

Collaboration graph
[legend]
List of all members.

Public Types

enum  VAlign { top, baseline, bottom }
enum  HAlign { left, center, right }

Public Member Functions

DECLSPEC SdlFont (int n, bool light, SdlSurfaceContainer *bmps, const char *l)
DECLSPEC bool create (int n, bool light, SdlSurfaceContainer *bmps, const char *l, Uint32 color=RGB(128, 128, 128), bool upper=false)
DECLSPEC void destroy ()
SdlSurfaceContainergetBmps () const
 
Returns:
the surfaces of the letters

DECLSPEC int getCurpos (const char *text, const SDL_Rect &dst, Sint32 xCur, Sint32 yCur, VAlign va=baseline, HAlign ha=center)
DECLSPEC int getCurpos (const char *text, Sint32 dstx, Sint32 dsty, Sint32 xCur, Sint32 yCur, VAlign va=baseline, HAlign ha=center)
DECLSPEC Uint32 write (SdlSurface *surf, const char *text, Sint32 dstx, Sint32 dsty, VAlign va=baseline, HAlign ha=center, const SDL_Rect *clip=0, int curpos=-1)
DECLSPEC Uint32 write (SdlSurface *surf, const char *text, const SDL_Rect &dst, VAlign va=baseline, HAlign ha=center, const SDL_Rect *clip=0, int curpos=-1)

Static Public Member Functions

static DECLSPEC SdlFontget (int n, bool light)
static DECLSPEC const char * strnchr (const char *string, int c, size_t count)
static DECLSPEC const char * strnrchr (const char *string, int c, size_t count)
static DECLSPEC VAlign strToVAlign (const char *s)
static DECLSPEC HAlign strToHAlign (const char *s)

Public Attributes

Uint32 color
 the font's color, as set in create()

Protected Attributes

bool bUpperCase
 whether to use uppercase letters only, or mixed
SdlSurfaceContainerbmps
 the surfaces of the letters
char * chLetters
 the characters, as arranged in the surface container

Classes

struct  FONT

Detailed Description

Used to write text with a specific font.

This class is used to write text on SdlSurface objects by using the font that was used to init it.
Currently only fixed letter fonts are supported (every character has the same width).

See also:
SdlFontSurfaces


Member Enumeration Documentation

enum SdlFont::VAlign

Vertical alignment of a text to draw
top the text is drawn at the top of a rect
baseline the text is drawn at the vertical center of a rect
bottom the text is drawn at the bottom of a rect

enum SdlFont::HAlign

Horizontal alignment of a text to draw
left the text's first letter is drawn at the left border of a rect
center the text is drawn horizontally centred in a rect
right the text's right end is drawn at the right border of a rect


Constructor & Destructor Documentation

SdlFont::SdlFont ( int  n,
bool  light,
SdlSurfaceContainer bmps,
const char *  l 
)

Constructor. Initializes the font with the params.

Parameters:
n the font's identifier (usually bigger, if font-size is bigger); it must not be above or equal to SdlFont::nFonts (=16)
light true, if the font is better used on dark background; false if it is better visible on light background
bmps the surfaces with the letters
l a string of the letters as they are arranged in bmps
See also:
create


Member Function Documentation

bool SdlFont::create ( int  n,
bool  light,
SdlSurfaceContainer bmps,
const char *  l,
Uint32  color = RGB(128, 128, 128),
bool  upper = false 
)

Initializes the font.

Parameters:
n the font's identifier (usually bigger, if font-size is bigger); it must not be above or equal to SdlFont::nFonts (=16)
light true, if the font is better used on dark background; false if it is better visible on light background
bmps the surfaces with the letters
l a string of the letters as they are arranged in bmps
color the color, the font's letter have
upper true, if only uppercase letters are availible; false, if both (upper- and lowercase) are availible
Returns:
true, if all went good; false, if an error occured

void SdlFont::destroy (  ) 

Uninitializes the font.

int SdlFont::getCurpos ( const char *  text,
const SDL_Rect &  dst,
Sint32  xCur,
Sint32  yCur,
VAlign  va = baseline,
HAlign  ha = center 
)

Calculates the position of a text-cursor, that is nearest to a coordinate.

Parameters:
text the text string, can contain newline-characters
dst the rect, in which the string is located
xCur the x coordinate
yCur the y coordinate
va the vertical alignment of the text in the rect
ha the horizontal alignment of the text in the rect

int SdlFont::getCurpos ( const char *  text,
Sint32  dstx,
Sint32  dsty,
Sint32  xCur,
Sint32  yCur,
VAlign  va = baseline,
HAlign  ha = center 
)

Calculates the position of a text-cursor, that is nearest to a coordinate.

Parameters:
text the text string, can contain newline-characters
dstx the x coordinate, that sets the string's x-location
dsty the y coordinate, that sets the string's y-location
xCur the x coordinate
yCur the y coordinate
va the vertical alignment of the text in the rect
ha the horizontal alignment of the text in the rect

Uint32 SdlFont::write ( SdlSurface surf,
const char *  text,
Sint32  dstx,
Sint32  dsty,
VAlign  va = baseline,
HAlign  ha = center,
const SDL_Rect *  clip = 0,
int  curpos = -1 
)

Draws the text onto a surface, using a reference position.

Parameters:
surf the destination surface where the text is drawn on
text the string to write
dstx the reference x-position, where to draw the text
dsty the reference y-position, where to draw the text
va the vertical alignment of the text
ha the horizontal alignment of the text
clip the clipping rect
curpos the text-cursor's position (zero, if before first character; strlen(text), if after the last character)

Uint32 SdlFont::write ( SdlSurface surf,
const char *  text,
const SDL_Rect &  dst,
VAlign  va = baseline,
HAlign  ha = center,
const SDL_Rect *  clip = 0,
int  curpos = -1 
)

Draws the text onto a surface, using a reference rect.

Parameters:
surf the destination surface where the text is drawn on
text the string to write
dst the reference rect, where to draw the text
va the vertical alignment of the text
ha the horizontal alignment of the text
clip the clipping rect
curpos the text-cursor's position (zero, if before first character; strlen(text), if after the last character)

SdlFont * SdlFont::get ( int  n,
bool  light 
) [static]

This method can be used to get a pointer to a font.

Parameters:
n the identifyer of the font
light the light-property of the wanted font
Returns:
a pointer to a font with the given id and given light-property or NULL, if the font does not exist

const char * SdlFont::strnchr ( const char *  string,
int  c,
size_t  count 
) [static]

Similar to strchr, but returns NULL, if the first occurance of c is behind count characters in string.

Parameters:
string the string to scan
c the character to look for
count the number of characters of string to check
Returns:
a pointer to the first occurance of c in string, or NULL, if it does not occur up to the count'th character

const char * SdlFont::strnrchr ( const char *  string,
int  c,
size_t  count 
) [static]

Similar to strrchr, but only seeks in the first count characters of string.

Parameters:
string the string to scan
c the character to look for
count the number of characters of string to check
Returns:
a pointer to the last occurance of c in the first count characters of string, or NULL, if it does not occur up to the count'th character

SdlFont::VAlign SdlFont::strToVAlign ( const char *  s  )  [static]

Converts a string to a kind of vertical alignment. Possible strings are: top; baseline (or center); bottom.

Parameters:
s the string to convert
Returns:
the corresponding value or top, if the expression is unknown

SdlFont::HAlign SdlFont::strToHAlign ( const char *  s  )  [static]

Converts a string to a kind of horizontal alignment. Possible strings are: left; center (or middle); right.

Parameters:
s the string to convert
Returns:
the corresponding value or left, if the expression is unknown


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:33 2007 for netrinjo by  doxygen 1.5.1