summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/font.cpp
blob: 1988252928205353f23165e269ea130ffcb66241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "font.h"

#include "constants.h"

BFont *FontHandler :: menuSelFont;
BFont *FontHandler :: menuUnSelFont;
BFont *FontHandler :: whiteFont;
BFont *FontHandler :: colouredFont;
BFont *FontHandler :: helpFont;

bool FontHandler :: init()
{
	// Load font images
	// Convert to fonts
	menuSelFont = new BFont( IMAGES_PATH "sel_menu_font.bmp" );
	menuUnSelFont = new BFont( IMAGES_PATH "unsel_menu_font.bmp" );
	whiteFont = new BFont( IMAGES_PATH "score_font.bmp" );
	helpFont = new BFont( IMAGES_PATH "help_font.bmp" );
	colouredFont = 0;
	
	// Check if we are installed correctly (we need fonts to function)
	if ( menuSelFont == 0 || menuUnSelFont == 0 || whiteFont == 0 || helpFont == 0 )
	{
	   printf( "One or more fonts are not installed correctly\n" );
	   return false;
	}
	
	return true;
}

void FontHandler :: cleanUp()
{
	if ( menuSelFont )
		delete menuSelFont;
	if ( menuUnSelFont )
		delete menuUnSelFont;
	if ( whiteFont )
		delete whiteFont;
	if ( helpFont )
		delete helpFont;
	if ( colouredFont )
		delete colouredFont;
}

int  FontHandler :: TextWidth( int font, const char *text )
{
	return getFont( font )->TextWidth( text );
}

int  FontHandler :: FontHeight( int font )
{
	return getFont( font )->FontHeight();
}

void FontHandler :: draw( SDL_Surface *screen, int font, const char *text, int x, int y )
{
	if ( x == -1 )
		getFont( font )->CenteredPutString( screen, y, text );
	else
		getFont( font )->PutString( screen, x, y, text );
}

void FontHandler :: changeColor( int font, int r, int g, int b )
{
	if ( colouredFont )
		delete colouredFont;

	colouredFont = getFont( font )->SetFontColor( r, g, b );
}


BFont *FontHandler :: getFont( int font )
{
	if ( font == FONT_MENU_HIGHLIGHTED )
		return menuSelFont;
	else if ( font == FONT_MENU_UNHIGHLIGHTED )
		return menuUnSelFont;
	else if ( font == FONT_COLOURED_TEXT )
		return colouredFont;
	else if ( font == FONT_HELP_FONT )
		return helpFont;
	else
		return whiteFont;
}