Iām trying to make a dictionary of fonts with SDL_ttf, just like I made a dictionary with SDL_image. Since fonts are stored with a pnt_size
I made a struct containing this info:
struct fontinfo
{
string assetname;
int size;
};
Followed by both dictionaries:
map<string, SDL_Surface*> imageDictionary;
map<fontinfo*, TTF_Font*> fontDictionary;
The difference between the two is that the font dictionary not only needs to contain the string to the file but also the size of the font.
Then when a image or font gets requested by an object it calls the get
function for it. Now the getSprite
works fine:
SDL_Surface* ResourceManager::getSprite(string assetname)
{
if (assetname == "")
return NULL;
map<string, SDL_Surface*>::iterator it = imageDictionary.find(assetname);
if (it != imageDictionary.end())
return it->second;
else
{
SDL_Surface* image = Load_Image(assetname);
if (image != NULL)
imageDictionary.insert(make_pair(assetname, image));
return image;
}
}
The getFont
method is almost identical except for the fact that it uses a fontinfo
instead of a string
:
TTF_Font* ResourceManager::getFont(string assetname, int size)
{
if (assetname == "" || size < 0)
return NULL;
fontinfo* info = new fontinfo();
info->assetname = assetname;
info->size = size;
map<fontinfo*, TTF_Font*>::iterator it = fontDictionary.find(info);
if (it != fontDictionary.end())
return it->second;
else
{
TTF_Font* font = Load_Font(assetname, size);
if (font != NULL)
fontDictionary.insert(make_pair(info, font));
return font;
}
}
The compiler tells me identifier not found and make_pair
is undefined, but only for the make_pair
function from getFont
. No problems for the make_pair
in getSprite
.