mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-26 18:35:30 +02:00
Allow the skin to change the font and font size
This commit is contained in:
parent
c8cf37787b
commit
af258530db
13
src/font.cpp
13
src/font.cpp
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -349,8 +349,16 @@ void GMenu2X::initBG() {
|
||||
}
|
||||
|
||||
void GMenu2X::initFont() {
|
||||
delete font;
|
||||
font = Font::defaultFont();
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user