mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +00:00
Add minifont in SkinTheme for color buttons.
This commit is contained in:
parent
450e97ef92
commit
19ea79b41e
BIN
data/skins/default/minifont.png
Normal file
BIN
data/skins/default/minifont.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -21,8 +21,8 @@
|
||||
#include <stdio.h>
|
||||
#include <allegro.h>
|
||||
#if defined ALLEGRO_WINDOWS && defined DEBUGMODE
|
||||
#include <winalleg.h>
|
||||
#include <psapi.h>
|
||||
#include <winalleg.h>
|
||||
#include <psapi.h>
|
||||
#endif
|
||||
|
||||
#include "app.h"
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<SkinTheme*>(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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -42,14 +42,16 @@ class SkinTheme : public Theme
|
||||
BITMAP* m_cursors[JI_CURSORS];
|
||||
BITMAP* m_part[PARTS];
|
||||
std::map<std::string, BITMAP*> 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
|
||||
|
@ -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<SkinTheme*>(getTheme())->getMiniFont());
|
||||
}
|
||||
|
||||
ColorButton::~ColorButton()
|
||||
|
Loading…
x
Reference in New Issue
Block a user