Diffstat (limited to 'noncore/games/sfcave-sdl/font.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/font.cpp | 72 |
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 | |||
5 | BFont *FontHandler :: menuSelFont; | ||
6 | BFont *FontHandler :: menuUnSelFont; | ||
7 | BFont *FontHandler :: whiteFont; | ||
8 | BFont *FontHandler :: colouredFont; | ||
9 | BFont *FontHandler :: helpFont; | ||
10 | |||
11 | void 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 | |||
22 | void FontHandler :: cleanUp() | ||
23 | { | ||
24 | delete menuSelFont; | ||
25 | delete menuUnSelFont; | ||
26 | delete whiteFont; | ||
27 | delete helpFont; | ||
28 | |||
29 | if ( colouredFont ) | ||
30 | delete colouredFont; | ||
31 | } | ||
32 | |||
33 | int FontHandler :: TextWidth( int font, const char *text ) | ||
34 | { | ||
35 | return getFont( font )->TextWidth( text ); | ||
36 | } | ||
37 | |||
38 | int FontHandler :: FontHeight( int font ) | ||
39 | { | ||
40 | return getFont( font )->FontHeight(); | ||
41 | } | ||
42 | |||
43 | void 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 | |||
51 | void 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 | |||
60 | BFont *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 | } | ||