#include <sdlfont.h>
Collaboration diagram for SdlFont:
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 () |
SdlSurfaceContainer * | getBmps () const |
| |
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 SdlFont * | get (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 | |
SdlSurfaceContainer * | bmps |
the surfaces of the letters | |
char * | chLetters |
the characters, as arranged in the surface container | |
Classes | |
struct | 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).
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
SdlFont::SdlFont | ( | int | n, | |
bool | light, | |||
SdlSurfaceContainer * | bmps, | |||
const char * | l | |||
) |
Constructor. Initializes the font with the params.
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 |
bool SdlFont::create | ( | int | n, | |
bool | light, | |||
SdlSurfaceContainer * | bmps, | |||
const char * | l, | |||
Uint32 | color = RGB(128, 128, 128) , |
|||
bool | upper = false | |||
) |
Initializes the font.
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 |
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.
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.
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.
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.
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.
n | the identifyer of the font | |
light | the light-property of the wanted font |
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.
string | the string to scan | |
c | the character to look for | |
count | the number of characters of string to check |
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.
string | the string to scan | |
c | the character to look for | |
count | the number of characters of string to check |
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.
s | the string to convert |
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.
s | the string to convert |