1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:05:20 +02:00

Allow the skin to change the font and font size

This commit is contained in:
Paul Cercueil 2014-01-15 20:32:17 +01:00
parent c8cf37787b
commit af258530db
3 changed files with 20 additions and 6 deletions

View File

@ -15,19 +15,24 @@
using namespace std;
Font *Font::defaultFont()
{
return new Font(TTF_FONT, TTF_FONT_SIZE);
}
Font::Font(const std::string &path, unsigned int size)
{
if (!TTF_WasInit() && TTF_Init() < 0) {
ERROR("Unable to init SDL_ttf library\n");
return nullptr;
return;
}
TTF_Font *font = TTF_OpenFont(TTF_FONT, TTF_FONT_SIZE);
font = TTF_OpenFont(path.c_str(), size);
if (!font) {
ERROR("Unable to open font\n");
return nullptr;
return;
}
return new Font(font);
fontheight = TTF_FontHeight(font);
}
Font::Font(TTF_Font *font)

View File

@ -19,6 +19,7 @@ public:
* or nullptr if there was a problem creating it.
*/
static Font *defaultFont();
Font(const std::string &path, unsigned int size);
~Font();
int getTextWidth(const char *text);

View File

@ -349,8 +349,16 @@ void GMenu2X::initBG() {
}
void GMenu2X::initFont() {
delete font;
const string path = skinConfStr["font"];
if (!path.empty()) {
unsigned int size = skinConfInt["fontsize"];
if (!size)
size = 12;
font = new Font(path, size);
} else {
font = Font::defaultFont();
}
if (!font) {
ERROR("Cannot function without font; aborting...\n");
quit();