mirror of https://github.com/aseprite/aseprite.git
Fix loading of non-default themes with missing parts
This commit is contained in:
parent
fedbe66980
commit
09e18ddf2b
|
@ -144,7 +144,6 @@ SkinTheme* SkinTheme::instance()
|
||||||
SkinTheme::SkinTheme()
|
SkinTheme::SkinTheme()
|
||||||
: m_cursors(ui::kCursorTypes, NULL)
|
: m_cursors(ui::kCursorTypes, NULL)
|
||||||
{
|
{
|
||||||
m_selected_skin = Preferences::instance().theme.selected();
|
|
||||||
m_defaultFont = nullptr;
|
m_defaultFont = nullptr;
|
||||||
m_miniFont = nullptr;
|
m_miniFont = nullptr;
|
||||||
|
|
||||||
|
@ -176,9 +175,29 @@ SkinTheme::~SkinTheme()
|
||||||
m_miniFont->dispose();
|
m_miniFont->dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinTheme::loadSheet()
|
void SkinTheme::onRegenerate()
|
||||||
{
|
{
|
||||||
TRACE("SkinTheme::loadSheet()\n");
|
Preferences& pref = Preferences::instance();
|
||||||
|
|
||||||
|
// First we load the skin from default theme, which is more proper
|
||||||
|
// to have every single needed skin part/color/dimension.
|
||||||
|
loadAll(pref.theme.selected.defaultValue());
|
||||||
|
|
||||||
|
// Then we load the selected theme to redefine default theme parts.
|
||||||
|
if (pref.theme.selected.defaultValue() != pref.theme.selected())
|
||||||
|
loadAll(pref.theme.selected());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkinTheme::loadAll(const std::string& skinId)
|
||||||
|
{
|
||||||
|
loadSheet(skinId);
|
||||||
|
loadFonts(skinId);
|
||||||
|
loadXml(skinId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkinTheme::loadSheet(const std::string& skinId)
|
||||||
|
{
|
||||||
|
TRACE("SkinTheme::loadSheet(%s)\n", skinId.c_str());
|
||||||
|
|
||||||
if (m_sheet) {
|
if (m_sheet) {
|
||||||
m_sheet->dispose();
|
m_sheet->dispose();
|
||||||
|
@ -186,7 +205,7 @@ void SkinTheme::loadSheet()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the skin sheet
|
// Load the skin sheet
|
||||||
std::string sheet_filename("skins/" + m_selected_skin + "/sheet.png");
|
std::string sheet_filename("skins/" + skinId + "/sheet.png");
|
||||||
|
|
||||||
ResourceFinder rf;
|
ResourceFinder rf;
|
||||||
rf.includeDataDir(sheet_filename.c_str());
|
rf.includeDataDir(sheet_filename.c_str());
|
||||||
|
@ -201,26 +220,25 @@ void SkinTheme::loadSheet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinTheme::loadFonts()
|
void SkinTheme::loadFonts(const std::string& skinId)
|
||||||
{
|
{
|
||||||
TRACE("SkinTheme::loadFonts()\n");
|
TRACE("SkinTheme::loadFonts(%s)\n", skinId.c_str());
|
||||||
|
|
||||||
if (m_defaultFont) m_defaultFont->dispose();
|
if (m_defaultFont) m_defaultFont->dispose();
|
||||||
if (m_miniFont) m_miniFont->dispose();
|
if (m_miniFont) m_miniFont->dispose();
|
||||||
|
|
||||||
Preferences& pref = Preferences::instance();
|
Preferences& pref = Preferences::instance();
|
||||||
|
|
||||||
m_defaultFont = loadFont(pref.theme.font(), "skins/" + m_selected_skin + "/font.png");
|
m_defaultFont = loadFont(pref.theme.font(), "skins/" + skinId + "/font.png");
|
||||||
m_miniFont = loadFont(pref.theme.miniFont(), "skins/" + m_selected_skin + "/minifont.png");
|
m_miniFont = loadFont(pref.theme.miniFont(), "skins/" + skinId + "/minifont.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkinTheme::onRegenerate()
|
void SkinTheme::loadXml(const std::string& skinId)
|
||||||
{
|
{
|
||||||
loadSheet();
|
TRACE("SkinTheme::loadXml(%s)\n", skinId.c_str());
|
||||||
loadFonts();
|
|
||||||
|
|
||||||
// Load the skin XML
|
// Load the skin XML
|
||||||
std::string xml_filename = "skins/" + m_selected_skin + "/skin.xml";
|
std::string xml_filename = "skins/" + skinId + "/skin.xml";
|
||||||
ResourceFinder rf;
|
ResourceFinder rf;
|
||||||
rf.includeDataDir(xml_filename.c_str());
|
rf.includeDataDir(xml_filename.c_str());
|
||||||
if (!rf.findFirst())
|
if (!rf.findFirst())
|
||||||
|
|
|
@ -119,8 +119,10 @@ namespace app {
|
||||||
void onRegenerate() override;
|
void onRegenerate() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadSheet();
|
void loadAll(const std::string& skinId);
|
||||||
void loadFonts();
|
void loadSheet(const std::string& skinId);
|
||||||
|
void loadFonts(const std::string& skinId);
|
||||||
|
void loadXml(const std::string& skinId);
|
||||||
|
|
||||||
she::Surface* sliceSheet(she::Surface* sur, const gfx::Rect& bounds);
|
she::Surface* sliceSheet(she::Surface* sur, const gfx::Rect& bounds);
|
||||||
gfx::Color getWidgetBgColor(ui::Widget* widget);
|
gfx::Color getWidgetBgColor(ui::Widget* widget);
|
||||||
|
@ -133,7 +135,6 @@ namespace app {
|
||||||
|
|
||||||
she::Font* loadFont(const std::string& userFont, const std::string& themeFont);
|
she::Font* loadFont(const std::string& userFont, const std::string& themeFont);
|
||||||
|
|
||||||
std::string m_selected_skin;
|
|
||||||
she::Surface* m_sheet;
|
she::Surface* m_sheet;
|
||||||
std::map<std::string, SkinPartPtr> m_parts_by_id;
|
std::map<std::string, SkinPartPtr> m_parts_by_id;
|
||||||
std::map<std::string, she::Surface*> m_toolicon;
|
std::map<std::string, she::Surface*> m_toolicon;
|
||||||
|
|
Loading…
Reference in New Issue