mx::mxRegularFont Class Reference

List of all members.

Public Member Functions

 mxRegularFont ()
 mxRegularFont (const mxRegularFont &font)
mxRegularFontoperator= (const mxRegularFont &font)
void setFont (const mxRegularFont &font)
bool loadFont (std::string font_name)
void freeFont ()
SDL_FontgetFont ()
SDL_Fontoperator* ()
void printText (mxSurface &surface, unsigned int x, unsigned int y, unsigned int color, std::string text)
void printText (mxSurface &surface, Point p, Color color, std::string text)
void printSizedText (mxSurface &surface, unsigned int x, unsigned int y, unsigned int size_w, unsigned int size_h, unsigned int color, std::string text)
int printTextWidth_64 (int *depth, mxSurface &surface, int x, int y, int size_width, unsigned int color, const char *src)
int printTextDepth (mxSurface &surface, unsigned int x, unsigned int y, unsigned int color, std::string text)

Protected Attributes

struct SDL_Fontfont


Detailed Description

encapsulating handling mxFonts.

Definition at line 30 of file mx_font.h.


Constructor & Destructor Documentation

mx::mxRegularFont::mxRegularFont (  ) 

default constructor

Definition at line 21 of file mx_font.cpp.

References font.

00022                 {
00023                         font = 0;
00024                 }

mx::mxRegularFont::mxRegularFont ( const mxRegularFont font  ) 

copy constructor

Parameters:
font parameter to copy from

Definition at line 28 of file mx_font.cpp.

References setFont().

00029                 {
00030                         setFont(fontX);
00031 
00032                 }


Member Function Documentation

void mx::mxRegularFont::freeFont (  ) 

freeFont release this font from memory

Definition at line 56 of file mx_font.cpp.

References font.

Referenced by setFont().

00057                 {
00058                         if(font != 0)
00059                                 SDL_FreeFont(font);
00060 
00061                 }

SDL_Font* mx::mxRegularFont::getFont (  )  [inline]

getFont

Returns:
return the font encapsulated by this object in its true form as a SDL_Font structure

Definition at line 64 of file mx_font.h.

00064 { return font; }

bool mx::mxRegularFont::loadFont ( std::string  font_name  ) 

load font from string on disk

Parameters:
font_name the name of the mxFont in std::string form.
Returns:
boolean value for true if successful load, false on failure.

Definition at line 47 of file mx_font.cpp.

References font.

00048                 {
00049                         font = SDL_InitFont(font_name.c_str());
00050                         if(font == 0)
00051                                 throw mx::mxException<std::string>(" could not load font: " + font_name + "\n");
00052                         return true;
00053                 }

SDL_Font* mx::mxRegularFont::operator* (  )  [inline]

operator()*

Returns:
return the font encapsulated by this object in its true form as a SDL_Font structure

Definition at line 68 of file mx_font.h.

00068 { return font; }

mxRegularFont & mx::mxRegularFont::operator= ( const mxRegularFont font  ) 

overloaded operator = for assigning another font

Parameters:
font font to assign from
Returns:
to allow operator chaining a mxRegularFont

Definition at line 34 of file mx_font.cpp.

References setFont().

00035                 {
00036                         setFont(fontX);
00037                         return *this;
00038                 }

void mx::mxRegularFont::printSizedText ( mxSurface surface,
unsigned int  x,
unsigned int  y,
unsigned int  size_w,
unsigned int  size_h,
unsigned int  color,
std::string  text 
)

printSizedText - print text stretched to a specific size

Parameters:
surface to print to
x x coordinate
y y coordinate
size_w width in pixels
size_h height in pixels
color 32bit RGBA value
text string value

Definition at line 70 of file mx_font.cpp.

References font, and mx::mxSurface::getSurface().

00071                 {
00072                         if(font == 0) return;
00073                         SDL_PrintTextScaled(surface.getSurface(), font, x,y,w,h,color,text.c_str());
00074                 }

void mx::mxRegularFont::printText ( mxSurface surface,
Point  p,
Color  color,
std::string  text 
) [inline]

printText overloaded method

Parameters:
surface to print string to
p Point object 2d coordinate
color Color object
text text to print to surface

Definition at line 84 of file mx_font.h.

References mx::Color::mapRGB(), printText(), mx::Point::x, and mx::Point::y.

00084                                                                                          {
00085                         printText(surface, p.x, p.y, Color::mapRGB(surface, color), text);
00086                 }

void mx::mxRegularFont::printText ( mxSurface surface,
unsigned int  x,
unsigned int  y,
unsigned int  color,
std::string  text 
)

printText

Parameters:
surface surface to print to
x x coordinate in pixels
y y coordinate in pixels
color color value in 32bit RGBA
text string to print to surface

Definition at line 64 of file mx_font.cpp.

References font, and mx::mxSurface::getSurface().

Referenced by printText().

00065                 {
00066                         if(font == 0) return;
00067                         SDL_PrintText(surface.getSurface(), font, x, y, color, text.c_str());
00068                 }

int mx::mxRegularFont::printTextDepth ( mxSurface surface,
unsigned int  x,
unsigned int  y,
unsigned int  color,
std::string  text 
)

printTextDepth - print text with coordinate offset returned by the function

Parameters:
surface surface to draw to
x x coordinate
y y coordinate
color 32bit RGBA value
text string to draw to surface

Definition at line 81 of file mx_font.cpp.

References font, and mx::mxSurface::getSurface().

00081                                                                                                                                         {
00082                         int  depth = 0;
00083                         SDL_PrintTextDepth(&depth,surface.getSurface(), font,  x, y, color, text.c_str());
00084                         return depth;
00085                 }

int mx::mxRegularFont::printTextWidth_64 ( int *  depth,
mxSurface surface,
int  x,
int  y,
int  size_width,
unsigned int  color,
const char *  src 
)

printTextWidth_64 - print text with coordinate offset returned in depth variable, used for getting the offset of console height in masterx project

Parameters:
depth pointer to integer to contain coordinate
surface surface to draw to
x x coordinate in pixels
y y coordinate in pixels
size_width width in pixels
color 32bit RGBA value
src text to print to screen

Definition at line 76 of file mx_font.cpp.

References font, and mx::mxSurface::getSurface().

00076                                                                                                                                                  {
00077                         SDL_PrintTextWidth(depth, surface.getSurface(), font, x, y, width, color, src);
00078                         return *depth;
00079                 }

void mx::mxRegularFont::setFont ( const mxRegularFont font  ) 

setFont set another font to this font, same as overloaded operator = but as a method

Parameters:
font takes a font to assign to this object

Definition at line 40 of file mx_font.cpp.

References font, and freeFont().

Referenced by mxRegularFont(), and operator=().

00041                 {
00042                         freeFont();
00043                         font = fontX.font;
00044                 }


Member Data Documentation

struct SDL_Font* mx::mxRegularFont::font [read, protected]

the SDL_Font structure to hold are font

Definition at line 122 of file mx_font.h.

Referenced by freeFont(), loadFont(), mxRegularFont(), printSizedText(), printText(), printTextDepth(), printTextWidth_64(), and setFont().


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

Generated on Wed Jun 10 14:52:02 2009 for libmx by  doxygen 1.5.8