diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-30 14:08:37 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-30 14:08:37 +0300 |
commit | 1cffd95a2d98736c2d0dc2f382995889ceaef86a (patch) | |
tree | 9bb16984a2cc28daf7521beb2f9125f0b0ea77da /src/gui | |
parent | 27a4c8b4acdf5f433f42b5dce97f95f391e36cbf (diff) | |
download | mv-1cffd95a2d98736c2d0dc2f382995889ceaef86a.tar.gz mv-1cffd95a2d98736c2d0dc2f382995889ceaef86a.tar.bz2 mv-1cffd95a2d98736c2d0dc2f382995889ceaef86a.tar.xz mv-1cffd95a2d98736c2d0dc2f382995889ceaef86a.zip |
add support for set fonts and font sizes from themes.
Changed default font size from 11 to 12 px.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/setup_theme.cpp | 39 | ||||
-rw-r--r-- | src/gui/setup_theme.h | 1 | ||||
-rw-r--r-- | src/gui/theme.cpp | 34 | ||||
-rw-r--r-- | src/gui/theme.h | 18 |
4 files changed, 78 insertions, 14 deletions
diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index db0b7b6f9..f0cacf8af 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -195,6 +195,7 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) : mThemesModel(new ThemesModel), mThemeDropDown(new DropDown(this, mThemesModel)), mTheme(config.getStringValue("theme")), + mInfo(Theme::loadInfo(mTheme)), mFontsModel(new FontsModel), mFontLabel(new Label(this, _("Main Font"))), mFontDropDown(new DropDown(this, mFontsModel)), @@ -318,6 +319,9 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) : Setup_Theme::~Setup_Theme() { + delete mInfo; + mInfo = nullptr; + delete mThemesModel; mThemesModel = nullptr; @@ -336,11 +340,11 @@ Setup_Theme::~Setup_Theme() void Setup_Theme::updateInfo() { - ThemeInfo *info = Theme::loadInfo(mTheme); - if (info) + mInfo = Theme::loadInfo(mTheme); + if (mInfo) { - mThemeInfo = std::string("Name: ").append(info->name) - .append("\nCopyright:\n").append(info->copyright); + mThemeInfo = std::string("Name: ").append(mInfo->name) + .append("\nCopyright:\n").append(mInfo->copyright); } else { @@ -348,7 +352,6 @@ void Setup_Theme::updateInfo() } replaceAll(mThemeInfo, "\\n", "\n"); mInfoButton->setEnabled(!mThemeInfo.empty()); - delete info; } void Setup_Theme::action(const gcn::ActionEvent &event) @@ -413,6 +416,9 @@ void Setup_Theme::cancel() mJapanFont = getFileName(config.getStringValue("japanFont")); } +#define updateField(name1, name2) if (!mInfo->name1.empty()) \ + name2 = mInfo->name1; + void Setup_Theme::apply() { if (config.getStringValue("theme") != mTheme) @@ -422,6 +428,27 @@ void Setup_Theme::apply() } config.setValue("selectedSkin", ""); + if (config.getStringValue("theme") != mTheme) + { + updateField(font, mFont); + updateField(boldFont, mBoldFont); + updateField(particleFont, mParticleFont); + updateField(helpFont, mHelpFont); + updateField(secureFont, mSecureFont); + updateField(japanFont, mJapanFont); + if (mInfo->fontSize) + { + const int size = mInfo->fontSize - 9; + if (size >= 0) + mFontSizeDropDown->setSelected(size); + } + if (mInfo->npcfontSize) + { + const int size = mInfo->npcfontSize - 9; + if (size >= 0) + mNpcFontSizeDropDown->setSelected(size); + } + } config.setValue("theme", mTheme); config.setValue("lang", mLang); if (config.getValue("font", "dejavusans.ttf") != mFont @@ -447,3 +474,5 @@ void Setup_Theme::apply() gui->updateFonts(); } } + +#undef updateField diff --git a/src/gui/setup_theme.h b/src/gui/setup_theme.h index 030a87193..d5f50afbb 100644 --- a/src/gui/setup_theme.h +++ b/src/gui/setup_theme.h @@ -58,6 +58,7 @@ class Setup_Theme final : public SetupTab ThemesModel *mThemesModel; DropDown *mThemeDropDown; std::string mTheme; + ThemeInfo *mInfo; FontsModel *mFontsModel; Label *mFontLabel; diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 27945b808..db3b247cb 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -1147,6 +1147,14 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name, return nullptr; } +#define readValue(name) \ + info->name = reinterpret_cast<const char*>(\ + xmlNodeGetContent(infoNode)) + +#define readIntValue(name) \ + info->name = atoi(reinterpret_cast<const char*>(\ + xmlNodeGetContent(infoNode))) + ThemeInfo *Theme::loadInfo(const std::string &themeName) { std::string path; @@ -1171,15 +1179,25 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName) for_each_xml_child_node(infoNode, rootNode) { if (xmlNameEqual(infoNode, "name")) - { - info->name = reinterpret_cast<const char*>( - xmlNodeGetContent(infoNode)); - } + readValue(name); else if (xmlNameEqual(infoNode, "copyright")) - { - info->copyright = reinterpret_cast<const char*>( - xmlNodeGetContent(infoNode)); - } + readValue(copyright); + else if (xmlNameEqual(infoNode, "font")) + readValue(font); + else if (xmlNameEqual(infoNode, "boldFont")) + readValue(boldFont); + else if (xmlNameEqual(infoNode, "particleFont")) + readValue(particleFont); + else if (xmlNameEqual(infoNode, "helpFont")) + readValue(helpFont); + else if (xmlNameEqual(infoNode, "secureFont")) + readValue(secureFont); + else if (xmlNameEqual(infoNode, "japanFont")) + readValue(japanFont); + else if (xmlNameEqual(infoNode, "fontSize")) + readIntValue(fontSize); + else if (xmlNameEqual(infoNode, "npcfontSize")) + readIntValue(npcfontSize); } return info; } diff --git a/src/gui/theme.h b/src/gui/theme.h index fcd0f5614..222d0d098 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -45,11 +45,27 @@ struct ThemeInfo final { ThemeInfo() : name(), - copyright() + copyright(), + font(), + boldFont(), + particleFont(), + helpFont(), + secureFont(), + japanFont(), + fontSize(0), + npcfontSize(0) { } std::string name; std::string copyright; + std::string font; + std::string boldFont; + std::string particleFont; + std::string helpFont; + std::string secureFont; + std::string japanFont; + int fontSize; + int npcfontSize; }; class Skin final |