mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 13:29:42 +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;
|
using namespace std;
|
||||||
|
|
||||||
Font *Font::defaultFont()
|
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) {
|
if (!TTF_WasInit() && TTF_Init() < 0) {
|
||||||
ERROR("Unable to init SDL_ttf library\n");
|
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) {
|
if (!font) {
|
||||||
ERROR("Unable to open font\n");
|
ERROR("Unable to open font\n");
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Font(font);
|
fontheight = TTF_FontHeight(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Font(TTF_Font *font)
|
Font::Font(TTF_Font *font)
|
||||||
|
@ -19,6 +19,7 @@ public:
|
|||||||
* or nullptr if there was a problem creating it.
|
* or nullptr if there was a problem creating it.
|
||||||
*/
|
*/
|
||||||
static Font *defaultFont();
|
static Font *defaultFont();
|
||||||
|
Font(const std::string &path, unsigned int size);
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
int getTextWidth(const char *text);
|
int getTextWidth(const char *text);
|
||||||
|
@ -349,8 +349,16 @@ void GMenu2X::initBG() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::initFont() {
|
void GMenu2X::initFont() {
|
||||||
delete font;
|
const string path = skinConfStr["font"];
|
||||||
font = Font::defaultFont();
|
if (!path.empty()) {
|
||||||
|
unsigned int size = skinConfInt["fontsize"];
|
||||||
|
if (!size)
|
||||||
|
size = 12;
|
||||||
|
font = new Font(path, size);
|
||||||
|
} else {
|
||||||
|
font = Font::defaultFont();
|
||||||
|
}
|
||||||
|
|
||||||
if (!font) {
|
if (!font) {
|
||||||
ERROR("Cannot function without font; aborting...\n");
|
ERROR("Cannot function without font; aborting...\n");
|
||||||
quit();
|
quit();
|
||||||
|
Loading…
Reference in New Issue
Block a user