font_manager.cpp

Go to the documentation of this file.
00001 /* MANTAINER: Bernard */
00002 
00003 #include "font.h"
00004 #include "font_ttf.h"
00005 #include "font_ftgl.h"
00006 #include "font_manager.h"
00007 #include "platform.h"
00008 #include "log.h"
00009 #include "conversions.h"
00010 
00011 // This is temorary here not to forget about FTGLTextureFont    
00012 /*
00013         getAppClient().getGFX().set3DOpenGL();
00014         glDisable( GL_DEPTH_TEST);
00015         glEnable( GL_TEXTURE_2D);
00016         FTGLTextureFont fonttex(locateFile("FreeMono.ttf").c_str());
00017         fonttex.FaceSize(20);
00018         glLoadIdentity();
00019         glNormal3f( 0.0, 0.0, 1.0);
00020         glTranslatef( -1.5f, 0.0f, -90.0f );
00021         glColor3f( 1.0, 1.0, 0.0);
00022         glPushMatrix();
00023         fonttex.Render("Hello - texture");
00024         glPopMatrix();
00025         glEnable(GL_DEPTH_TEST);
00026 */
00027 
00028 using namespace std;
00029 
00030 FontManager::FontManager()
00031 {
00032         mNextCleanup = 2000;
00033 }
00034 
00035 FontManager::~FontManager()
00036 {
00037 
00038 }
00039 
00040 FontManager::TUniversalManager::TRef FontManager::get(const char* font_name, int size)
00041 {
00042         string key = font_name;
00043         key.append(":").append(xtos(size));
00044         
00045         // I. FIND
00046         ManagedItem * pmi;
00047         if ((pmi = find(key)) != 0)
00048                 return pmi;
00049 
00050     // II. INIT
00051         Font* font = new FontTTF(locateFile(font_name).c_str(), size);
00052 //      Font* font = new FontFTGL(locateFile(font_name).c_str(), size);
00053         if (!font)
00054         {
00055                 LOGE << "Loading font failed!" << endl;
00056                 DIE();
00057         }
00058 
00059         // III. REGISTER
00060         return createAndRegister(key, font);
00061 }
00062 
00063 void FontManager::update(int dtime, int atime)
00064 {
00065         mNextCleanup -= dtime;
00066         if (mNextCleanup <= 0)
00067         {
00068                 LOGT << "Cleaning font chache" << endl;
00069                 mNextCleanup = 2000;    
00070                 // call 
00071                 for (TContainer::iterator it = mRegister.begin(), ite = mRegister.end(); it != ite; ++it)
00072                 {
00073                         ManagedItem * pmi = it->second;
00074                         pmi->getPtr()->cleanCache();
00075                         
00076                 }
00077         }
00078 }

Generated on Wed Apr 12 13:55:28 2006 for bjs by  doxygen 1.4.5