00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "mx_font.h"
00016
00017
00018 namespace mx
00019 {
00020
00021 mxRegularFont::mxRegularFont()
00022 {
00023 font = 0;
00024 }
00025
00026
00027
00028 mxRegularFont::mxRegularFont(const mxRegularFont &fontX)
00029 {
00030 setFont(fontX);
00031
00032 }
00033
00034 mxRegularFont &mxRegularFont::operator=(const mxRegularFont &fontX)
00035 {
00036 setFont(fontX);
00037 return *this;
00038 }
00039
00040 void mxRegularFont::setFont(const mxRegularFont &fontX)
00041 {
00042 freeFont();
00043 font = fontX.font;
00044 }
00045
00046
00047 bool mxRegularFont::loadFont(std::string font_name)
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 }
00054
00055
00056 void mxRegularFont::freeFont()
00057 {
00058 if(font != 0)
00059 SDL_FreeFont(font);
00060
00061 }
00062
00063
00064 void mxRegularFont::printText(mxSurface &surface, unsigned int x, unsigned int y, unsigned int color, std::string text)
00065 {
00066 if(font == 0) return;
00067 SDL_PrintText(surface.getSurface(), font, x, y, color, text.c_str());
00068 }
00069
00070 void mxRegularFont::printSizedText(mxSurface &surface,unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned int color, std::string text)
00071 {
00072 if(font == 0) return;
00073 SDL_PrintTextScaled(surface.getSurface(), font, x,y,w,h,color,text.c_str());
00074 }
00075
00076 int mxRegularFont::printTextWidth_64(int *depth, mxSurface &surface, int x, int y, int width, unsigned int color, const char *src) {
00077 SDL_PrintTextWidth(depth, surface.getSurface(), font, x, y, width, color, src);
00078 return *depth;
00079 }
00080
00081 int mxRegularFont::printTextDepth(mxSurface &surface, unsigned int x, unsigned int y, unsigned int color, std::string text) {
00082 int depth = 0;
00083 SDL_PrintTextDepth(&depth,surface.getSurface(), font, x, y, color, text.c_str());
00084 return depth;
00085 }
00086
00087 }
00088
00089
00090
00091
00092
00093
00094