Font management
Before we start to build the structure of our graphical user interface, we need a way to manage and handle the loading and unloading of fonts automatically, just like we did with textures. The effort we put into the resource manager written back in Chapter 6, Set It in Motion! – Animating and Moving around Your World, is about to pay off. In order to manage fonts, all we need to do is create a FontManager.h
file and write the following code:
class FontManager : public ResourceManager<FontManager, sf::Font>{ public: FontManager() : ResourceManager("fonts.cfg"){} sf::Font* Load(const std::string& l_path){ sf::Font* font = new sf::Font(); if (!font->loadFromFile( Utils::GetWorkingDirectory() + l_path)) { delete font; font = nullptr; std::cerr << "! Failed to load font: " << l_path << std::endl; } return font; } };
This defines the font resource configuration file in the constructor, as well...