game/sdlpp/sdlpp_font.cpp

53 lines
1.3 KiB
C++
Raw Normal View History

2020-11-21 19:57:40 +00:00
#include "sdlpp_font.hpp"
namespace SDLPP {
Font::Font( const std::string &font ) : font_path( font ) {}
Font::Font( const std::string &font, int size ) : Font( font ) {
2020-12-18 14:08:21 +00:00
original_size = size;
font_ptr = TTF_OpenFont( font_path.c_str(), size );
checkFont();
2020-11-21 19:57:40 +00:00
}
Font::~Font() {
2020-12-18 14:08:21 +00:00
closeFont();
2020-11-21 19:57:40 +00:00
}
const TTF_Font *Font::getFont() const {
return font_ptr;
}
TTF_Font *Font::getFont() {
return font_ptr;
}
void Font::setOutline( int size ) {
TTF_SetFontOutline( font_ptr, size );
}
int Font::getOutline() {
return TTF_GetFontOutline( font_ptr );
}
void Font::setStyle( int style ) {
TTF_SetFontStyle( font_ptr, style );
}
void Font::setHinting( int hinting ) {
TTF_SetFontHinting( font_ptr, hinting );
}
2020-12-18 14:08:21 +00:00
void Font::changeFontSize( int size ) {
closeFont();
font_ptr = TTF_OpenFont( font_path.c_str(), size );
checkFont();
}
void Font::revertSize() {
closeFont();
font_ptr = TTF_OpenFont( font_path.c_str(), original_size );
checkFont();
}
void Font::closeFont() {
TTF_CloseFont( font_ptr );
}
void Font::checkFont() {
if ( font_ptr == NULL ) {
std::cerr << "Unable to load font '" << font_path
<< "': TTF Error: " << TTF_GetError() << std::endl;
throw "TTF_OpenFont error";
}
}
2020-11-21 19:57:40 +00:00
} // namespace SDLPP