-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFontCache.cpp
71 lines (61 loc) · 1.71 KB
/
FontCache.cpp
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
/**
* Implementation of FontCache as declared in FontCache.h
*
* Author: Skylar Payne
* Date: 7/24/2013
* File: FontCache.cpp
**/
#include "FontCache.h"
#include "Logger.h"
/**
* @brief FontCache::Add adds a font into the cache
* @param file the font to add
* @return true if font was successfully added or already added, false otherwise
*/
bool FontCache::Add(const char *file)
{
FontMap::iterator it = _Resources.find(file);
if(it != _Resources.end())
{
g_Logger << __FILE__ << ": " << __LINE__ << "-Error: " << file << " already exists in FontCache\n";
return true;
}
sf::Font* newFont = new sf::Font();
if(!newFont->loadFromFile(file))
{
delete newFont;
newFont = nullptr;
g_Logger << __FILE__ << ": " << __LINE__ << "-Error: " << file << " failed to load\n";
return false;
}
_Resources[file] = newFont;
g_Logger << __FILE__ << ": " << __LINE__ << "-" << file << " was successfullly added to FontCache\n";
return true;
}
/**
* @brief FontCache::Remove removes a font from the cache
* @param file the font to remove
*/
void FontCache::Remove(const char *file)
{
FontMap::iterator it = _Resources.find(file);
if(it != _Resources.end())
{
_Resources.erase(it);
g_Logger << __FILE__ << ": " << __LINE__ << "-" << file << " was removed from FontCache\n";
}
}
/**
* @brief FontCache::Get gets a font from the cache
* @param file the font to get
* @return the font, if found, nullptr otherwise
*/
sf::Font* FontCache::Get(const char *file)
{
FontMap::iterator it = _Resources.find(file);
if(it == _Resources.end())
{
return nullptr;
}
return _Resources[file];
}