-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcFontMgr.cpp
More file actions
86 lines (77 loc) · 1.81 KB
/
cFontMgr.cpp
File metadata and controls
86 lines (77 loc) · 1.81 KB
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
85
86
/*
== == == == == == == == =
cFontMgr.h
- Header file for class definition - SPECIFICATION
- Header file for the InputMgr class
== == == == == == == == =
*/
#include "cFontMgr.h"
cFontMgr* cFontMgr::pInstance = NULL;
/*
=================================================================================
Singleton Design Pattern
=================================================================================
*/
cFontMgr* cFontMgr::getInstance()
{
if (pInstance == NULL)
{
pInstance = new cFontMgr();
}
return cFontMgr::pInstance;
}
/*
=================================================================================
Constructor
=================================================================================
*/
cFontMgr::cFontMgr()
{
}
cFontMgr::~cFontMgr() // Destructor.
{
deleteFont();
TTF_Quit();
}
bool cFontMgr::initFontLib()
{
// Initialize SDL_ttf library
if (TTF_Init() != 0)
{
cout << "TTF_Init() Failed: " << SDL_GetError() << endl;
return false;
}
else
{
return true;
}
}
void cFontMgr::addFont(LPCSTR fontName, LPCSTR fileName, int fontSize) // add font to the Font collection
{
if (!getFont(fontName))
{
cFont * newFont = new cFont();
newFont->loadFont(fileName, fontSize);
fontList.insert(make_pair(fontName, newFont));
}
}
cFont* cFontMgr::getFont(LPCSTR fontName) // return the font for use
{
map<LPCSTR, cFont*>::iterator theFont = fontList.find(fontName);
if (theFont != fontList.end())
{
return theFont->second;
}
else
{
return NULL;
}
}
void cFontMgr::deleteFont() // delete font.
{
for (map<LPCSTR, cFont*>::const_iterator theFont = fontList.begin(); theFont != fontList.end(); theFont++)
{
TTF_CloseFont(theFont->second->getFont());
delete theFont->second;
}
}