-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFontFactory.cpp
More file actions
39 lines (34 loc) · 840 Bytes
/
Copy pathFontFactory.cpp
File metadata and controls
39 lines (34 loc) · 840 Bytes
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
#include "FontFactory.h"
#include "SDL_ttf.h"
std::vector<std::pair<char*, TTF_Font*>> FontFactory::fonts;
FontFactory::FontFactory(void)
{
}
void FontFactory::initializeFont(char* fontName, char* fontFile, int pxSize)
{
int returned = TTF_Init();
TTF_Font* font;
std::pair<char*, TTF_Font*> fontPair;
fontPair.first = fontName;
font = TTF_OpenFont(fontFile, pxSize);
fontPair.second = font;
fonts.push_back(fontPair);
}
TTF_Font* FontFactory::getFont(char* fontName)
{
std::vector<std::pair<char*, TTF_Font*>>::iterator it = fonts.begin();
do
{
if((*it).first == fontName)
return (*it).second;
it++;
} while(it != fonts.end());
return NULL;
}
FontFactory::~FontFactory(void)
{
for(std::vector<std::pair<char*, TTF_Font*>>::iterator it = fonts.begin(); it<fonts.end(); it++)
{
TTF_CloseFont((*it).second);
}
}