Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

font.cpp

Go to the documentation of this file.
00001 #include "font.h"
00002 
00003 #include "constants.h"
00004 
00005 BFont *FontHandler :: menuSelFont;
00006 BFont *FontHandler :: menuUnSelFont;
00007 BFont *FontHandler :: whiteFont;
00008 BFont *FontHandler :: colouredFont;
00009 BFont *FontHandler :: helpFont;
00010 
00011 bool FontHandler :: init()
00012 {
00013         // Load font images
00014         // Convert to fonts
00015         menuSelFont = new BFont( IMAGES_PATH "sel_menu_font.bmp" );
00016         menuUnSelFont = new BFont( IMAGES_PATH "unsel_menu_font.bmp" );
00017         whiteFont = new BFont( IMAGES_PATH "score_font.bmp" );
00018         helpFont = new BFont( IMAGES_PATH "help_font.bmp" );
00019         colouredFont = 0;
00020         
00021         // Check if we are installed correctly (we need fonts to function)
00022         if ( menuSelFont == 0 || menuUnSelFont == 0 || whiteFont == 0 || helpFont == 0 )
00023         {
00024            printf( "One or more fonts are not installed correctly\n" );
00025            return false;
00026         }
00027         
00028         return true;
00029 }
00030 
00031 void FontHandler :: cleanUp()
00032 {
00033         if ( menuSelFont )
00034                 delete menuSelFont;
00035         if ( menuUnSelFont )
00036                 delete menuUnSelFont;
00037         if ( whiteFont )
00038                 delete whiteFont;
00039         if ( helpFont )
00040                 delete helpFont;
00041         if ( colouredFont )
00042                 delete colouredFont;
00043 }
00044 
00045 int  FontHandler :: TextWidth( int font, const char *text )
00046 {
00047         return getFont( font )->TextWidth( text );
00048 }
00049 
00050 int  FontHandler :: FontHeight( int font )
00051 {
00052         return getFont( font )->FontHeight();
00053 }
00054 
00055 void FontHandler :: draw( SDL_Surface *screen, int font, const char *text, int x, int y )
00056 {
00057         if ( x == -1 )
00058                 getFont( font )->CenteredPutString( screen, y, text );
00059         else
00060                 getFont( font )->PutString( screen, x, y, text );
00061 }
00062 
00063 void FontHandler :: changeColor( int font, int r, int g, int b )
00064 {
00065         if ( colouredFont )
00066                 delete colouredFont;
00067 
00068         colouredFont = getFont( font )->SetFontColor( r, g, b );
00069 }
00070 
00071 
00072 BFont *FontHandler :: getFont( int font )
00073 {
00074         if ( font == FONT_MENU_HIGHLIGHTED )
00075                 return menuSelFont;
00076         else if ( font == FONT_MENU_UNHIGHLIGHTED )
00077                 return menuUnSelFont;
00078         else if ( font == FONT_COLOURED_TEXT )
00079                 return colouredFont;
00080         else if ( font == FONT_HELP_FONT )
00081                 return helpFont;
00082         else
00083                 return whiteFont;
00084 }

Generated on Sat Nov 5 16:17:24 2005 for OPIE by  doxygen 1.4.2