SDL_ttf++
C++wrapperfortheSDL_ttflibrary.
|
00001 00021 #ifndef SDL_TTF_H 00022 #define SDL_TTF_H 00023 00024 #include <stdexcept> 00025 00026 #include <SDL_ttf.h> 00027 00028 #include "sdlpp_ttf/ttf/Glyph.h" 00029 #include "sdlpp/video/Surface.h" 00030 00031 namespace sdl { 00032 namespace ttf { 00033 using namespace std; 00034 using namespace video; 00035 00040 enum Encodings { TEXT, UTF8, UNICODE }; 00041 00046 struct Font { 00050 Font (const string& filename, int pointSize) 00051 : font_ (TTF_OpenFont (filename.c_str (), pointSize), &TTF_CloseFont) { 00052 if (font_.get () == NULL) 00053 throw runtime_error (TTF_GetError ()); 00054 }; 00055 00059 ~Font () {}; 00060 00072 template<int Encoding, class RenderMode> 00073 Surface render (const string& text, const RenderMode& mode) const { 00074 return mode.render<Encoding> (*this, text); 00075 }; 00076 00086 template<int Encoding> 00087 void size (const string& text, int* height, int* width) const { 00088 TTF_SizeText (font_.get (), text.c_str (), width, height); 00089 }; 00090 00098 Glyph glyph (char c) const { return Glyph (*this, c); }; 00099 00105 TTF_Font* operator* () const { return font_.get (); }; 00106 00112 int height () const { return TTF_FontHeight (font_.get ()); }; 00113 00119 int ascent () const { return TTF_FontAscent (font_.get ()); }; 00120 00126 int descent () const { return TTF_FontDescent (font_.get ()); }; 00127 00133 int lineSkip () const { return TTF_FontLineSkip (font_.get ()); }; 00134 00140 int getStyle () { return TTF_GetFontStyle (font_.get ()); }; 00141 00147 void setStyle (int style) { TTF_SetFontStyle (font_.get (), style); }; 00148 00149 private: 00153 boost::shared_ptr<TTF_Font> font_; 00154 }; //Font 00155 00156 //TEXT specialization 00157 template<> 00158 void Font::size<TEXT> (const string& text, int* height, int* width) const { 00159 TTF_SizeText (font_.get (), text.c_str (), width, height); 00160 }; 00161 00162 //UTF8 specialization 00163 template<> 00164 void Font::size<UTF8> (const string& text, int* height, int* width) const { 00165 TTF_SizeUTF8 (font_.get (), text.c_str (), width, height); 00166 }; 00167 00168 //UNICODE specialization 00169 template<> 00170 void Font::size<UNICODE> (const string& text, int* height, int* width) const { 00171 //TTF_SizeUNICODE (font_.get (), text.c_str (), width, height); 00172 }; 00173 }; //ttf 00174 }; //sdl 00175 00176 #endif //SDL_TTF_H 00177