1 /***************************************************************************
2                           font_manager.cpp  -  description
3                              -------------------
4     begin                : Jun 13 2007
5     copyright            : (C) 2007 by Giuseppe D'Aqui'
6     email                : kumber@tiscalinet.it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License, Version 2,      *
13  *   as published by the Free Software Foundation.                         *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #include "font_manager.h"
18 #include "font_factory.h"
19 #include <cassert>
20 
21 
init()22 void Font_Manager::init()
23 {
24 	add_font(Font_Factory::instance()->create_font(Font_Factory::MENU_FONT));
25 	add_font(Font_Factory::instance()->create_font(Font_Factory::GAME_FONT));
26 	add_font(Font_Factory::instance()->create_font(Font_Factory::CREDITS_FONT));
27 	add_font(Font_Factory::instance()->create_font(Font_Factory::TIME_FONT));
28 }
29 
add_font(Font * font)30 Font_Handle Font_Manager::add_font(Font* font)
31 {
32 	Font_Handle f_handle = m_fonts.size();
33 	m_fonts.push_back(font);
34 	return f_handle;
35 }
36 
get_font(Font_Handle handle)37 Font* Font_Manager::get_font(Font_Handle handle)
38 {
39 	assert((m_fonts.size()>handle) && "Error: Accessing non-existent font.");
40 	return m_fonts[handle];
41 }
42 
deinit()43 void Font_Manager::deinit()
44 {
45 	if(m_fonts.size()>1)
46 	{
47 		// start from the beginning of the array
48   		std::vector<Font*>::iterator itPos = m_fonts.begin();
49 
50   		// clear all elements from the array
51   		for(; itPos < m_fonts.end(); itPos++)
52     		delete *itPos;    // free the element from memory
53 
54    		// finally, clear all elements from the array
55   		m_fonts.clear();
56 	}
57 }
58 
59 // begin Singleton stuff
60 
61 Font_Manager* Font_Manager::_instance = 0;
62 
instance()63 Font_Manager* Font_Manager::instance()
64 {
65 	if (_instance == 0)
66 	{
67 		_instance = new Font_Manager();
68 		_instance->init();
69 	}
70 	return _instance;
71 }
72 
73 //end Singleton stuff
74