Initial commit. Not even a game yet :P
[cToan.git] / src / SDLWrap_Font.cpp
blobf9931facb49597ac02d044c5edfe7b2881c7bce5
1 #include "SDLWrap_Font.hpp"
3 namespace SDLWrap {
5 int Font::FontCount = 0;
7 Font::Font(const std::string TTFFilePath, const int FontSize)
8 try {
9 this->me = NULL;
11 if (!TTF_WasInit() && TTF_Init() == -1)
12 throw TTFError();
14 if ( (this->me = TTF_OpenFont(TTFFilePath.c_str(), FontSize)) == NULL )
15 throw TTFError();
17 this->FilePath = TTFFilePath;
18 FontCount++;
20 catch (TTFError)
22 std::string Error = "Font::Font(char*) constructor threw a TTFError! ";
23 if (TTF_WasInit()) {
24 Error += "The TTF core was initialized.\n";
25 } else {
26 Error += "The TTF core was not initialized.\n";
28 ErrorHandler::OutputError(ErrorHandler::FATAL_CONSTRUCTOR_ERROR, Error);
31 Font::~Font()
33 TTF_CloseFont(this->me);
34 FontCount--;
37 void
38 Font::Shutdown()
40 if (FontCount == 0) {
41 TTF_Quit();
42 } else {
43 // I dunno, do something useful <_<
44 // Maybe leave it to the ErrorHandler to report the error somehow?