diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 7 | ||||
-rw-r--r-- | src/gui/widgets/tab.cpp | 15 | ||||
-rw-r--r-- | src/resources/theme.cpp | 36 | ||||
-rw-r--r-- | src/resources/theme.h | 9 |
4 files changed, 50 insertions, 17 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 5cf1b05a..502ab686 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -83,11 +83,16 @@ void ProgressBar::draw(gcn::Graphics *graphics) rect.x = 0; rect.y = 0; + Theme::ProgressPalette palette = Theme::THEME_PROG_END; + if (mProgressPalette >= 0) + palette = static_cast<Theme::ProgressPalette>(mProgressPalette); + gui->getTheme()->drawProgressBar(static_cast<Graphics *>(graphics), rect, mColor, mProgress, - mText); + mText, + palette); } void ProgressBar::setProgress(float progress) diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index b2779c4f..0f6ca4e5 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -73,18 +73,27 @@ void Tab::draw(gcn::Graphics *graphics) if (mTabbedArea && mTabbedArea->isTabSelected(this)) flags |= STATE_SELECTED; - auto &skin = gui->getTheme()->getSkin(SkinType::Tab); + auto theme = gui->getTheme(); + auto &palette = theme->getPalette(0); + auto &skin = theme->getSkin(SkinType::Tab); + if (auto state = skin.getState(flags)) { gcn::Color foregroundColor = state->textFormat.color; + auto outlineColor = state->textFormat.outlineColor; if (mFlash) - foregroundColor = Theme::getThemeColor(Theme::TAB_FLASH); + { + foregroundColor = palette.getColor(Theme::TAB_FLASH); + outlineColor = palette.getOutlineColor(Theme::TAB_FLASH); + } else if (mTabColor) + { foregroundColor = *mTabColor; + } auto label = static_cast<Label*>(mLabel); label->setForegroundColor(foregroundColor); - label->setOutlineColor(state->textFormat.outlineColor); + label->setOutlineColor(outlineColor); label->setShadowColor(state->textFormat.shadowColor); } diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index f11a5036..2845f91e 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -228,7 +228,6 @@ void Skin::updateAlpha(float alpha) Theme::Theme(const ThemeInfo &themeInfo) : mThemePath(themeInfo.getFullPath()) - , mProgressColors(THEME_PROG_END) { listen(Event::ConfigChannel); readTheme(themeInfo); @@ -377,9 +376,12 @@ void Theme::drawSkin(Graphics *graphics, SkinType type, const WidgetState &state getSkin(type).draw(graphics, state); } -void Theme::drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, - const gcn::Color &color, float progress, - const std::string &text) const +void Theme::drawProgressBar(Graphics *graphics, + const gcn::Rectangle &area, + const gcn::Color &color, + float progress, + const std::string &text, + ProgressPalette progressType) const { gcn::Font *oldFont = graphics->getFont(); gcn::Color oldColor = graphics->getColor(); @@ -408,7 +410,12 @@ void Theme::drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, { if (auto skinState = skin.getState(widgetState.flags)) { - auto font = skinState->textFormat.bold ? boldFont : gui->getFont(); + const TextFormat *textFormat = &skinState->textFormat; + + if (progressType < THEME_PROG_END && mProgressTextFormats[progressType]) + textFormat = &(*mProgressTextFormats[progressType]); + + auto font = textFormat->bold ? boldFont : gui->getFont(); const int textX = area.x + area.width / 2; const int textY = area.y + (area.height - font->getHeight()) / 2; @@ -418,7 +425,7 @@ void Theme::drawProgressBar(Graphics *graphics, const gcn::Rectangle &area, textY, gcn::Graphics::CENTER, font, - skinState->textFormat); + *textFormat); } } @@ -588,9 +595,8 @@ static void readSkinStateRectNode(XML::Node node, SkinState &state) node.attribute("fill", rect.filled); } -static void readSkinStateTextNode(XML::Node node, SkinState &state) +static void readTextNode(XML::Node node, TextFormat &textFormat) { - auto &textFormat = state.textFormat; node.attribute("bold", textFormat.bold); node.attribute("color", textFormat.color); node.attribute("outlineColor", textFormat.outlineColor); @@ -625,7 +631,7 @@ void Theme::readSkinStateNode(XML::Node node, Skin &skin) const else if (childNode.name() == "rect") readSkinStateRectNode(childNode, state); else if (childNode.name() == "text") - readSkinStateTextNode(childNode, state); + readTextNode(childNode, state.textFormat); } skin.addState(std::move(state)); @@ -916,5 +922,15 @@ void Theme::readProgressBarNode(XML::Node node) if (check(id >= 0, "Theme: 'progress' element has unknown 'id' attribute: '%s'!", idStr.c_str())) return; - mProgressColors[id] = std::make_unique<DyePalette>(node.getProperty("color", std::string())); + std::string color; + if (node.attribute("color", color)) + mProgressColors[id] = std::make_unique<DyePalette>(color); + + for (auto childNode : node.children()) + { + if (childNode.name() == "text") + readTextNode(childNode, mProgressTextFormats[id].emplace()); + else + Log::info("Theme: Unknown node '%s' in progressbar!", childNode.name().data()); + } } diff --git a/src/resources/theme.h b/src/resources/theme.h index bfd3b33a..85a720a2 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -30,6 +30,7 @@ #include "resources/image.h" #include "utils/xml.h" +#include <array> #include <map> #include <memory> #include <optional> @@ -283,7 +284,7 @@ class Theme : public EventListener static const gcn::Color &getThemeColor(int type); static gcn::Color getProgressColor(int type, float progress); - + const Palette &getPalette(size_t index) const; /** @@ -305,7 +306,8 @@ class Theme : public EventListener const gcn::Rectangle &area, const gcn::Color &color, float progress, - const std::string &text = std::string()) const; + const std::string &text = std::string(), + ProgressPalette progressType = ProgressPalette::THEME_PROG_END) const; const Skin &getSkin(SkinType skinType) const; @@ -357,5 +359,6 @@ class Theme : public EventListener float mAlpha = 1.0; std::vector<Palette> mPalettes; - std::vector<std::unique_ptr<DyePalette>> mProgressColors; + std::array<std::unique_ptr<DyePalette>, THEME_PROG_END> mProgressColors; + std::array<std::optional<TextFormat>, THEME_PROG_END> mProgressTextFormats; }; |