#include <font.h>
Collaboration diagram for Font:
Public Member Functions | |
~Font () | |
bool | Load (const std::string &filename, int size) |
void | WriteLeft (const Point2i &pos, const std::string &txt, const Color &color) |
void | WriteLeftBottom (const Point2i &pos, const std::string &txt, const Color &color) |
void | WriteRight (const Point2i &pos, const std::string &txt, const Color &color) |
void | WriteCenterTop (const Point2i &pos, const std::string &txt, const Color &color) |
void | WriteCenter (const Point2i &pos, const std::string &txt, const Color &color) |
int | GetWidth (const std::string &txt) |
int | GetHeight () |
int | GetHeight (const std::string &txt) |
Point2i | GetSize (const std::string &txt) |
Surface | Render (const std::string &txt, const Color &color, bool cache=false) |
Surface | CreateSurface (const std::string &txt, const Color &color) |
void | SetBold () |
void | SetItalic () |
Static Public Member Functions | |
static Font * | GetInstance (int type, int font_style=NORMAL) |
Static Public Attributes | |
static const int | FONT_HUGE = 0 |
static const int | FONT_LARGE = 1 |
static const int | FONT_BIG = 2 |
static const int | FONT_NORMAL = 3 |
static const int | FONT_SMALL = 4 |
static const int | FONT_TINY = 5 |
static const int | NORMAL = 0 |
static const int | BOLD = 1 |
static const int | ITALIC = 2 |
Private Types | |
typedef std::map< std::string, Surface >::value_type | txt_sample |
typedef std::map< std::string, Surface >::iterator | txt_iterator |
Private Member Functions | |
void | Write (const Point2i &pos, Surface &surface) |
Font (int size) | |
Private Attributes | |
std::map< std::string, Surface > | surface_text_table |
TTF_Font * | m_font |
Static Private Attributes | |
static const int | FONT_SIZE [] = {40, 32, 24, 16, 12, 8} |
static Font * | FONT_ARRAY [6] = {NULL, NULL, NULL, NULL, NULL, NULL} |
static Font * | FONT_ARRAY_BOLD [6] = {NULL, NULL, NULL, NULL, NULL, NULL} |
static Font * | FONT_ARRAY_ITALIC [6] = {NULL, NULL, NULL, NULL, NULL, NULL} |
Definition at line 31 of file font.h.
typedef std::map<std::string, Surface>::iterator Font::txt_iterator [private] |
typedef std::map<std::string, Surface>::value_type Font::txt_sample [private] |
Font::Font | ( | int | size | ) | [private] |
Definition at line 78 of file font.cpp.
00078 { 00079 m_font = NULL; 00080 bool ok = Load(Config::GetInstance()->GetTtfFilename(), size); 00081 00082 if( !ok ) 00083 Error("Error during initialisation of a font!"); 00084 }
Here is the call graph for this function:
Here is the caller graph for this function:
Font::~Font | ( | ) |
Definition at line 86 of file font.cpp.
00086 { 00087 if( m_font != NULL ){ 00088 TTF_CloseFont(m_font); 00089 m_font = NULL; 00090 } 00091 00092 txt_iterator it; 00093 00094 for( it = surface_text_table.begin(); 00095 it != surface_text_table.end(); 00096 ++it ){ 00097 //SDL_FreeSurface(it->second); 00098 surface_text_table.erase(it->first); 00099 } 00100 }
Definition at line 166 of file font.cpp.
00166 { 00167 return Surface( TTF_RenderUTF8_Blended(m_font, txt.c_str(), color.GetSDLColor()) ); 00168 }
Here is the call graph for this function:
Here is the caller graph for this function:
int Font::GetHeight | ( | const std::string & | txt | ) |
int Font::GetHeight | ( | ) |
Definition at line 54 of file font.cpp.
00054 { 00055 Font * font; 00056 if (FONT_ARRAY[type] == NULL) { 00057 switch(font_style) { 00058 case BOLD: 00059 font = FONT_ARRAY_BOLD[type] = new Font(FONT_SIZE[type]); 00060 font->SetBold(); 00061 break; 00062 case ITALIC: 00063 font = FONT_ARRAY_ITALIC[type] = new Font(FONT_SIZE[type]); 00064 font->SetItalic(); 00065 break; 00066 default: font = FONT_ARRAY[type] = new Font(FONT_SIZE[type]); break; 00067 } 00068 } else { 00069 switch(font_style) { 00070 case BOLD: font = FONT_ARRAY_BOLD[type]; break; 00071 case ITALIC: font = FONT_ARRAY_ITALIC[type]; break; 00072 default : font = FONT_ARRAY[type]; break; 00073 } 00074 } 00075 return font; 00076 }
Here is the call graph for this function:
Here is the caller graph for this function:
Point2i Font::GetSize | ( | const std::string & | txt | ) |
int Font::GetWidth | ( | const std::string & | txt | ) |
bool Font::Load | ( | const std::string & | filename, | |
int | size | |||
) |
Definition at line 102 of file font.cpp.
00102 { 00103 bool ok = false; 00104 00105 if( IsFileExist(filename) ){ 00106 m_font = TTF_OpenFont(filename.c_str(), size); 00107 ok = (m_font != NULL); 00108 } 00109 00110 if( !ok ){ 00111 std::cout << "Error: Font " << filename << " can't be found!" << std::endl; 00112 return false; 00113 } 00114 00115 TTF_SetFontStyle(m_font, TTF_STYLE_NORMAL); 00116 00117 return true; 00118 }
Here is the call graph for this function:
Here is the caller graph for this function:
Definition at line 170 of file font.cpp.
00170 { 00171 Surface surface; 00172 00173 if( cache ){ 00174 txt_iterator p = surface_text_table.find(txt); 00175 if( p == surface_text_table.end() ){ 00176 if( surface_text_table.size() > 5 ){ 00177 //SDL_FreeSurface( surface_text_table.begin()->second ); 00178 surface_text_table.erase( surface_text_table.begin() ); 00179 } 00180 surface = CreateSurface(txt, color); 00181 surface_text_table.insert( txt_sample(txt, surface) ); 00182 } else { 00183 txt_iterator p = surface_text_table.find( txt ); 00184 surface = p->second; 00185 } 00186 } else 00187 surface = CreateSurface(txt, color); 00188 00189 assert( !surface.IsNull() ); 00190 return surface; 00191 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Font::SetBold | ( | ) |
void Font::SetItalic | ( | ) |
Definition at line 130 of file font.cpp.
00130 { 00131 AppWormux::GetInstance()->video.window.Blit(surface, pos); 00132 00133 // TODO: Remove this line! (and use GameFont instead of Font) 00134 world.ToRedrawOnScreen( Rectanglei(pos, surface.GetSize()) ); 00135 }
Here is the call graph for this function:
Here is the caller graph for this function:
const int Font::BOLD = 1 [static] |
Font * Font::FONT_ARRAY = {NULL, NULL, NULL, NULL, NULL, NULL} [static, private] |
Font * Font::FONT_ARRAY_BOLD = {NULL, NULL, NULL, NULL, NULL, NULL} [static, private] |
Font * Font::FONT_ARRAY_ITALIC = {NULL, NULL, NULL, NULL, NULL, NULL} [static, private] |
const int Font::FONT_BIG = 2 [static] |
const int Font::FONT_HUGE = 0 [static] |
const int Font::FONT_LARGE = 1 [static] |
const int Font::FONT_NORMAL = 3 [static] |
const int Font::FONT_SIZE = {40, 32, 24, 16, 12, 8} [static, private] |
const int Font::FONT_SMALL = 4 [static] |
const int Font::FONT_TINY = 5 [static] |
const int Font::ITALIC = 2 [static] |
TTF_Font* Font::m_font [private] |
const int Font::NORMAL = 0 [static] |
std::map<std::string, Surface> Font::surface_text_table [private] |