diff options
Diffstat (limited to 'src/resources/theme.cpp')
-rw-r--r-- | src/resources/theme.cpp | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 8e4a07be..0c332902 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -25,7 +25,6 @@ #include "configuration.h" #include "log.h" -#include "textrenderer.h" #include "resources/dye.h" #include "resources/image.h" @@ -75,7 +74,7 @@ ThemeInfo::ThemeInfo(const std::string &path) if (rootNode.attribute("name", name) && !name.empty()) this->doc = std::move(doc); else - logger->log("Error: Theme '%s' has no name!", path.c_str()); + Log::error("Theme '%s' has no name!", path.c_str()); } std::string ThemeInfo::getFullPath() const @@ -228,15 +227,14 @@ void Skin::updateAlpha(float alpha) Theme::Theme(const ThemeInfo &themeInfo) : mThemePath(themeInfo.getFullPath()) - , mProgressColors(THEME_PROG_END) { listen(Event::ConfigChannel); readTheme(themeInfo); if (mPalettes.empty()) { - logger->log("Error, theme did not define any palettes: %s", - themeInfo.getPath().c_str()); + Log::info("Error, theme did not define any palettes: %s", + themeInfo.getPath().c_str()); // Avoid crashing mPalettes.emplace_back(THEME_COLORS_END); @@ -377,9 +375,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,17 +409,21 @@ 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; - TextRenderer::renderText(graphics, - text, - textX, - textY, - gcn::Graphics::CENTER, - font, - skinState->textFormat); + graphics->drawText(text, + textX, + textY, + gcn::Graphics::CENTER, + font, + *textFormat); } } @@ -479,7 +484,7 @@ static bool check(bool value, const char *msg, ...) { va_list ap; va_start(ap, msg); - logger->vlog(msg, ap); + Log::vinfo(msg, ap); va_end(ap); } return !value; @@ -487,9 +492,9 @@ static bool check(bool value, const char *msg, ...) bool Theme::readTheme(const ThemeInfo &themeInfo) { - logger->log("Loading %s theme from '%s'...", - themeInfo.getName().c_str(), - themeInfo.getPath().c_str()); + Log::info("Loading %s theme from '%s'...", + themeInfo.getName().c_str(), + themeInfo.getPath().c_str()); XML::Node rootNode = themeInfo.getDocument().rootNode(); @@ -507,10 +512,10 @@ bool Theme::readTheme(const ThemeInfo &themeInfo) else if (childNode.name() == "icon") readIconNode(childNode); else - logger->log("Theme: Unknown node '%s'!", childNode.name().data()); + Log::info("Theme: Unknown node '%s'!", childNode.name().data()); } - logger->log("Finished loading theme."); + Log::info("Finished loading theme."); for (auto &[_, skin] : mSkins) skin.updateAlpha(mAlpha); @@ -588,9 +593,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 +629,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)); @@ -689,7 +693,7 @@ void Theme::readSkinStateImgNode(XML::Node node, SkinState &state) const border.right = right; border.top = top; border.bottom = bottom; - border.image = image->getSubImage(x, y, width, height); + border.image.reset(image->getSubImage(x, y, width, height)); node.attribute("fill", border.fillMode); } @@ -705,7 +709,7 @@ inline void fromString(const char *str, gcn::Color &value) if (strlen(str) < 7 || str[0] != '#') { error: - logger->log("Error, invalid theme color palette: %s", str); + Log::info("Error, invalid theme color palette: %s", str); value = gcn::Color(0, 0, 0); return; } @@ -788,6 +792,7 @@ static int readColorId(const std::string &id) "WHISPER_TAB", "BACKGROUND", "HIGHLIGHT", + "HIGHLIGHT_TEXT", "TAB_FLASH", "SHOP_WARNING", "ITEM_EQUIPPED", @@ -873,7 +878,7 @@ void Theme::readPaletteNode(XML::Node node) { int paletteId; if (node.attribute("id", paletteId) && static_cast<size_t>(paletteId) != mPalettes.size()) - logger->log("Theme: Non-consecutive palette 'id' attribute with value %d!", paletteId); + Log::info("Theme: Non-consecutive palette 'id' attribute with value %d!", paletteId); Palette &palette = mPalettes.emplace_back(THEME_COLORS_END); @@ -882,7 +887,7 @@ void Theme::readPaletteNode(XML::Node node) if (childNode.name() == "color") readColorNode(childNode, palette); else - logger->log("Theme: Unknown node '%s'!", childNode.name().data()); + Log::info("Theme: Unknown node '%s'!", childNode.name().data()); } } @@ -916,5 +921,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()); + } } |