summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/font.cpp
Unidiff
Diffstat (limited to 'noncore/games/sfcave-sdl/font.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/font.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/noncore/games/sfcave-sdl/font.cpp b/noncore/games/sfcave-sdl/font.cpp
new file mode 100644
index 0000000..2976d48
--- a/dev/null
+++ b/noncore/games/sfcave-sdl/font.cpp
@@ -0,0 +1,72 @@
1#include "font.h"
2
3#include "constants.h"
4
5BFont *FontHandler :: menuSelFont;
6BFont *FontHandler :: menuUnSelFont;
7BFont *FontHandler :: whiteFont;
8BFont *FontHandler :: colouredFont;
9BFont *FontHandler :: helpFont;
10
11void FontHandler :: init()
12{
13 // Load font images
14 // Convert to fonts
15 menuSelFont = new BFont( IMAGES_PATH "sel_menu_font.bmp" );
16 menuUnSelFont = new BFont( IMAGES_PATH "unsel_menu_font.bmp" );
17 whiteFont = new BFont( IMAGES_PATH "score_font.bmp" );
18 helpFont = new BFont( IMAGES_PATH "help_font.bmp" );
19 colouredFont = 0;
20}
21
22void FontHandler :: cleanUp()
23{
24 delete menuSelFont;
25 delete menuUnSelFont;
26 delete whiteFont;
27 delete helpFont;
28
29 if ( colouredFont )
30 delete colouredFont;
31}
32
33int FontHandler :: TextWidth( int font, const char *text )
34{
35 return getFont( font )->TextWidth( text );
36}
37
38int FontHandler :: FontHeight( int font )
39{
40 return getFont( font )->FontHeight();
41}
42
43void FontHandler :: draw( SDL_Surface *screen, int font, const char *text, int x, int y )
44{
45 if ( x == -1 )
46 getFont( font )->CenteredPutString( screen, y, text );
47 else
48 getFont( font )->PutString( screen, x, y, text );
49}
50
51void FontHandler :: changeColor( int font, int r, int g, int b )
52{
53 if ( colouredFont )
54 delete colouredFont;
55
56 colouredFont = getFont( font )->SetFontColor( r, g, b );
57}
58
59
60BFont *FontHandler :: getFont( int font )
61{
62 if ( font == FONT_MENU_HIGHLIGHTED )
63 return menuSelFont;
64 else if ( font == FONT_MENU_UNHIGHLIGHTED )
65 return menuUnSelFont;
66 else if ( font == FONT_COLOURED_TEXT )
67 return colouredFont;
68 else if ( font == FONT_HELP_FONT )
69 return helpFont;
70 else
71 return whiteFont;
72}