diff --git a/data/skins/default/minifont.png b/data/skins/default/minifont.png new file mode 100644 index 000000000..6f4e9e745 Binary files /dev/null and b/data/skins/default/minifont.png differ diff --git a/src/commands/cmd_refresh.cpp b/src/commands/cmd_refresh.cpp index 5ef65a0cc..3b688be3e 100644 --- a/src/commands/cmd_refresh.cpp +++ b/src/commands/cmd_refresh.cpp @@ -21,8 +21,8 @@ #include #include #if defined ALLEGRO_WINDOWS && defined DEBUGMODE -#include -#include + #include + #include #endif #include "app.h" diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index e502eee59..596c795ad 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -38,6 +38,9 @@ Theme::Theme() Theme::~Theme() { + if (default_font && default_font != font) + destroy_font(default_font); + if (current_theme == this) CurrentTheme::set(NULL); } diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index 57fa83bdf..d0da92d88 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -150,14 +150,13 @@ static volatile int next_idle_flags = 0; static volatile int restored_width = 0; static volatile int restored_height = 0; -/* default GUI screen configuration */ +// Default GUI screen configuration static bool double_buffering; static int screen_scaling; -static void destroy_default_font(); static void reload_default_font(); -/* load & save graphics configuration */ +// Load & save graphics configuration static void load_gui_config(int& w, int& h, int& bpp, bool& fullscreen, bool& maximized); static void save_gui_config(); @@ -359,9 +358,6 @@ void exit_module_gui() jmanager_free(manager); - // Destroy the default font of the current theme - destroy_default_font(); - // Now we can destroy theme CurrentTheme::set(NULL); delete ase_theme; @@ -602,48 +598,13 @@ void gui_setup_screen(bool reload_font) save_gui_config(); } -static void destroy_default_font() -{ - Theme* theme = CurrentTheme::get(); - - // No font for now - if (theme->default_font && theme->default_font != font) - destroy_font(theme->default_font); - - theme->default_font = NULL; -} - static void reload_default_font() { Theme* theme = CurrentTheme::get(); SkinTheme* skin_theme = static_cast(theme); - const char *user_font; - destroy_default_font(); - - // Directories - ResourceFinder rf; - - user_font = get_config_string("Options", "UserFont", ""); - if ((user_font) && (*user_font)) - rf.addPath(user_font); - - // TODO This should be in SkinTheme class - rf.findInDataDir(skin_theme->get_font_filename().c_str()); - - // Try to load the font - while (const char* path = rf.next()) { - theme->default_font = ji_font_load(path); - if (theme->default_font) { - if (ji_font_is_scalable(theme->default_font)) - ji_font_set_size(theme->default_font, 8*jguiscale()); - break; - } - } - - // default font: the Allegro one - if (!theme->default_font) - theme->default_font = font; + // Reload theme fonts + skin_theme->reload_fonts(); // Set all widgets fonts _ji_set_font_of_all_widgets(theme->default_font); diff --git a/src/skin/skin_theme.cpp b/src/skin/skin_theme.cpp index 724bc3a14..7201a15f8 100644 --- a/src/skin/skin_theme.cpp +++ b/src/skin/skin_theme.cpp @@ -80,6 +80,7 @@ SkinTheme::SkinTheme() { this->name = "Skin Theme"; m_selected_skin = get_config_string("Skin", "Selected", "default"); + m_minifont = font; // Initialize all graphics in NULL (these bitmaps are loaded from the skin) m_sheet_bmp = NULL; @@ -220,6 +221,10 @@ SkinTheme::~SkinTheme() destroy_bitmap(m_sheet_bmp); sheet_mapping.clear(); + + // Destroy the minifont + if (m_minifont && m_minifont != font) + destroy_font(m_minifont); } // Call ji_regen_theme after this @@ -253,9 +258,16 @@ void SkinTheme::reload_skin() throw base::Exception("Error loading %s file", sheet_filename.c_str()); } -std::string SkinTheme::get_font_filename() const +void SkinTheme::reload_fonts() { - return "skins/" + m_selected_skin + "/font.png"; + if (default_font && default_font != font) + destroy_font(default_font); + + if (m_minifont && m_minifont != font) + destroy_font(m_minifont); + + default_font = loadFont("UserFont", "skins/" + m_selected_skin + "/font.png"); + m_minifont = loadFont("UserMiniFont", "skins/" + m_selected_skin + "/minifont.png"); } void SkinTheme::onRegenerate() @@ -2072,3 +2084,27 @@ bool SkinTheme::theme_frame_button_msg_proc(JWidget widget, JMessage msg) return false; } + +FONT* SkinTheme::loadFont(const char* userFont, const std::string& path) +{ + // Directories + ResourceFinder rf; + + const char* user_font = get_config_string("Options", userFont, ""); + if (user_font && *user_font) + rf.addPath(user_font); + + rf.findInDataDir(path.c_str()); + + // Try to load the font + while (const char* path = rf.next()) { + FONT* font = ji_font_load(path); + if (font) { + if (ji_font_is_scalable(font)) + ji_font_set_size(font, 8*jguiscale()); + return font; + } + } + + return font; // Use Allegro font by default +} diff --git a/src/skin/skin_theme.h b/src/skin/skin_theme.h index d00e67672..52d056347 100644 --- a/src/skin/skin_theme.h +++ b/src/skin/skin_theme.h @@ -42,14 +42,16 @@ class SkinTheme : public Theme BITMAP* m_cursors[JI_CURSORS]; BITMAP* m_part[PARTS]; std::map m_toolicon; + FONT* m_minifont; public: SkinTheme(); ~SkinTheme(); - void reload_skin(); + FONT* getMiniFont() const { return m_minifont; } - std::string get_font_filename() const; + void reload_skin(); + void reload_fonts(); BITMAP* set_cursor(int type, int* focus_x, int* focus_y); void init_widget(JWidget widget); @@ -180,6 +182,8 @@ private: static bool theme_frame_button_msg_proc(JWidget widget, JMessage msg); static bool theme_combobox_button_msg_proc(JWidget widget, JMessage msg); + static FONT* loadFont(const char* userFont, const std::string& path); + }; #endif diff --git a/src/widgets/color_button.cpp b/src/widgets/color_button.cpp index fc3832e9d..ed32d5cf7 100644 --- a/src/widgets/color_button.cpp +++ b/src/widgets/color_button.cpp @@ -28,6 +28,7 @@ #include "modules/gfx.h" #include "modules/gui.h" #include "raster/sprite.h" +#include "skin/skin_theme.h" #include "widgets/color_bar.h" #include "widgets/color_button.h" #include "widgets/color_selector.h" @@ -49,6 +50,8 @@ ColorButton::ColorButton(const Color& color, int imgtype) , m_frame(NULL) { jwidget_focusrest(this, true); + + setFont(static_cast(getTheme())->getMiniFont()); } ColorButton::~ColorButton()