Date:2014-01-15 20:32:17 (7 months 15 days ago)
Author:Paul Cercueil
Commit:af258530db9dafaae40ed2cfd3d8e00ef60195e8
Message:Allow the skin to change the font and font size

Files: src/font.cpp (1 diff)
src/font.h (1 diff)
src/gmenu2x.cpp (1 diff)

Change Details

src/font.cpp
1616
1717Font *Font::defaultFont()
1818{
19    return new Font(TTF_FONT, TTF_FONT_SIZE);
20}
21
22Font::Font(const std::string &path, unsigned int size)
23{
1924    if (!TTF_WasInit() && TTF_Init() < 0) {
2025        ERROR("Unable to init SDL_ttf library\n");
21        return nullptr;
26        return;
2227    }
2328
24    TTF_Font *font = TTF_OpenFont(TTF_FONT, TTF_FONT_SIZE);
29    font = TTF_OpenFont(path.c_str(), size);
2530    if (!font) {
2631        ERROR("Unable to open font\n");
27        return nullptr;
32        return;
2833    }
2934
30    return new Font(font);
35    fontheight = TTF_FontHeight(font);
3136}
3237
3338Font::Font(TTF_Font *font)
src/font.h
1919     * or nullptr if there was a problem creating it.
2020     */
2121    static Font *defaultFont();
22    Font(const std::string &path, unsigned int size);
2223    ~Font();
2324
2425    int getTextWidth(const char *text);
src/gmenu2x.cpp
349349}
350350
351351void GMenu2X::initFont() {
352    delete font;
353    font = Font::defaultFont();
352    const string path = skinConfStr["font"];
353    if (!path.empty()) {
354        unsigned int size = skinConfInt["fontsize"];
355        if (!size)
356            size = 12;
357        font = new Font(path, size);
358    } else {
359        font = Font::defaultFont();
360    }
361
354362    if (!font) {
355363        ERROR("Cannot function without font; aborting...\n");
356364        quit();

Archive Download the corresponding diff file



interactive