diff options
author | Max Horn | 2009-01-18 14:48:00 +0000 |
---|---|---|
committer | Max Horn | 2009-01-18 14:48:00 +0000 |
commit | c9e97bf6f9e5de0c7b1bf8bf8292661b2ea1e353 (patch) | |
tree | d7233f66570ce89e97cc94b4da535120a9f8211e | |
parent | c69638d915ddcd6df2c87fed1a969a1ae51fd379 (diff) | |
download | scummvm-rg350-c9e97bf6f9e5de0c7b1bf8bf8292661b2ea1e353.tar.gz scummvm-rg350-c9e97bf6f9e5de0c7b1bf8bf8292661b2ea1e353.tar.bz2 scummvm-rg350-c9e97bf6f9e5de0c7b1bf8bf8292661b2ea1e353.zip |
GUI: Some cleanup and renaming; moved some parsing code from ThemeEngine to ThemeParser
svn-id: r35898
-rw-r--r-- | gui/ThemeEngine.cpp | 74 | ||||
-rw-r--r-- | gui/ThemeEngine.h | 22 | ||||
-rw-r--r-- | gui/ThemeParser.cpp | 42 |
3 files changed, 71 insertions, 67 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 6c627419fa..d993e5c52b 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -62,7 +62,7 @@ struct WidgetDrawData { /** List of all the steps needed to draw this widget */ Common::List<Graphics::DrawStep> _steps; - int _textDataId; + TextData _textDataId; Graphics::TextAlign _textAlignH; GUI::ThemeEngine::TextAlignVertical _textAlignV; @@ -72,6 +72,16 @@ struct WidgetDrawData { uint16 _backgroundOffset; bool _buffer; + + + /** + * Calculates the background threshold offset of a given DrawData item. + * After fully loading all DrawSteps of a DrawData item, this function must be + * called in order to calculate if such draw steps would be drawn outside of + * the actual widget drawing zone (e.g. shadows). If this is the case, a constant + * value will be added when restoring the background of the widget. + */ + void calcBackgroundOffset(); }; class ThemeItem { @@ -191,21 +201,6 @@ static const DrawDataInfo kDrawDataDefaults[] = { {kDDSeparator, "separator", true, kDDNone}, }; -struct TextDataInfo { - TextData id; - const char *name; -}; - -static const TextDataInfo kTextDataDefaults[] = { - {kTextDataDefault, "text_default"}, - {kTextDataHover, "text_hover"}, - {kTextDataDisabled, "text_disabled"}, - {kTextDataInverted, "text_inverted"}, - {kTextDataButton, "text_button"}, - {kTextDataButtonHover, "text_button_hover"}, - {kTextDataNormalFont, "text_normal"} -}; - /********************************************************** * ThemeItem functions for drawing queues. @@ -486,10 +481,10 @@ void ThemeEngine::setGraphicsMode(GraphicsMode mode) { _vectorRenderer->setSurface(&_screen); } -void ThemeEngine::calcBackgroundOffset(DrawData type) { +void WidgetDrawData::calcBackgroundOffset() { uint maxShadow = 0; - for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[type]->_steps.begin(); - step != _widgets[type]->_steps.end(); ++step) { + for (Common::List<Graphics::DrawStep>::const_iterator step = _steps.begin(); + step != _steps.end(); ++step) { if ((step->autoWidth || step->autoHeight) && step->shadow > maxShadow) maxShadow = step->shadow; @@ -497,7 +492,7 @@ void ThemeEngine::calcBackgroundOffset(DrawData type) { maxShadow = step->bevel; } - _widgets[type]->_backgroundOffset = maxShadow; + _backgroundOffset = maxShadow; } void ThemeEngine::restoreBackground(Common::Rect r) { @@ -511,15 +506,14 @@ void ThemeEngine::restoreBackground(Common::Rect r) { * Theme elements management *********************************************************/ void ThemeEngine::addDrawStep(const Common::String &drawDataId, const Graphics::DrawStep &step) { - DrawData id = getDrawDataId(drawDataId); + DrawData id = parseDrawDataId(drawDataId); assert(_widgets[id] != 0); _widgets[id]->_steps.push_back(step); } -bool ThemeEngine::addTextData(const Common::String &drawDataId, const Common::String &textDataId, Graphics::TextAlign alignH, TextAlignVertical alignV) { - DrawData id = getDrawDataId(drawDataId); - TextData textId = getTextDataId(textDataId); +bool ThemeEngine::addTextData(const Common::String &drawDataId, TextData textId, Graphics::TextAlign alignH, TextAlignVertical alignV) { + DrawData id = parseDrawDataId(drawDataId); if (id == -1 || textId == -1 || !_widgets[id]) return false; @@ -531,9 +525,7 @@ bool ThemeEngine::addTextData(const Common::String &drawDataId, const Common::St return true; } -bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &file, int r, int g, int b) { - TextData textId = getTextDataId(fontId); - +bool ThemeEngine::addFont(TextData textId, const Common::String &file, int r, int g, int b) { if (textId == -1) return false; @@ -551,7 +543,7 @@ bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &fi _texts[textId]->_fontPtr = loadFont(file); if (!_texts[textId]->_fontPtr) - error("Couldn't load %s font '%s'", fontId.c_str(), file.c_str()); + error("Couldn't load font '%s'", file.c_str()); FontMan.assignFontToName(file, _texts[textId]->_fontPtr); } @@ -587,17 +579,17 @@ bool ThemeEngine::addBitmap(const Common::String &filename) { } bool ThemeEngine::addDrawData(const Common::String &data, bool cached) { - DrawData data_id = getDrawDataId(data); + DrawData id = parseDrawDataId(data); - if (data_id == -1) + if (id == -1) return false; - if (_widgets[data_id] != 0) - delete _widgets[data_id]; + if (_widgets[id] != 0) + delete _widgets[id]; - _widgets[data_id] = new WidgetDrawData; - _widgets[data_id]->_buffer = kDrawDataDefaults[data_id].buffer; - _widgets[data_id]->_textDataId = -1; + _widgets[id] = new WidgetDrawData; + _widgets[id]->_buffer = kDrawDataDefaults[id].buffer; + _widgets[id]->_textDataId = kTextDataNone; return true; } @@ -625,7 +617,7 @@ void ThemeEngine::loadTheme(const Common::String &themeId) { if (_widgets[i] == 0) { warning("Missing data asset: '%s'", kDrawDataDefaults[i].name); } else { - calcBackgroundOffset((DrawData)i); + _widgets[i]->calcBackgroundOffset(); } } } @@ -1221,7 +1213,7 @@ TextData ThemeEngine::getTextData(DrawData ddId) const { } -DrawData ThemeEngine::getDrawDataId(const Common::String &name) const { +DrawData ThemeEngine::parseDrawDataId(const Common::String &name) const { for (int i = 0; i < kDrawDataMAX; ++i) if (name.compareToIgnoreCase(kDrawDataDefaults[i].name) == 0) return kDrawDataDefaults[i].id; @@ -1229,14 +1221,6 @@ DrawData ThemeEngine::getDrawDataId(const Common::String &name) const { return kDDNone; } -TextData ThemeEngine::getTextDataId(const Common::String &name) const { - for (int i = 0; i < kTextDataMAX; ++i) - if (name.compareToIgnoreCase(kTextDataDefaults[i].name) == 0) - return kTextDataDefaults[i].id; - - return kTextDataNone; -} - /********************************************************** * External data loading *********************************************************/ diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index cb1b3dfd07..788f8b2ced 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -100,6 +100,7 @@ enum DrawData { kDDNone = -1 }; +// FIXME: TextData is really a bad name, not conveying what this enum is about. enum TextData { kTextDataNone = -1, kTextDataDefault = 0, @@ -334,9 +335,7 @@ public: * @param name The representing name, as found on Theme Description XML files. * @see kDrawDataDefaults[] */ - DrawData getDrawDataId(const Common::String &name) const; - - TextData getTextDataId(const Common::String &name) const; + DrawData parseDrawDataId(const Common::String &name) const; TextData getTextData(DrawData ddId) const; @@ -372,7 +371,7 @@ public: * @param file Name of the font file. * @param r, g, b Color of the font. */ - bool addFont(const Common::String &fontName, const Common::String &file, int r, int g, int b); + bool addFont(TextData textId, const Common::String &file, int r, int g, int b); /** @@ -385,9 +384,9 @@ public: /** * Adds a new TextStep from the ThemeParser. This will be deprecated/removed once the - * new Font API is in place. + * new Font API is in place. FIXME: Is that so ??? */ - bool addTextData(const Common::String &drawDataId, const Common::String &textDataId, Graphics::TextAlign alignH, TextAlignVertical alignV); + bool addTextData(const Common::String &drawDataId, TextData textId, Graphics::TextAlign alignH, TextAlignVertical alignV); protected: /** @@ -504,17 +503,6 @@ protected: void renderDirtyScreen(); /** - * Calculates the background threshold offset of a given DrawData item. - * After fully loading all DrawSteps of a DrawData item, this function must be - * called in order to calculate if such draw steps would be drawn outside of - * the actual widget drawing zone (e.g. shadows). If this is the case, a constant - * value will be added when restoring the background of the widget. - * - * @param type DrawData type of the widget. - */ - void calcBackgroundOffset(DrawData type); - - /** * Generates a DrawQueue item and enqueues it so it's drawn to the screen * when the drawing queue is processed. * diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 72f841a7a9..fcba466dc4 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -38,6 +38,31 @@ namespace GUI { +struct TextDataInfo { + TextData id; + const char *name; +}; + +static const TextDataInfo kTextDataDefaults[] = { + {kTextDataDefault, "text_default"}, + {kTextDataHover, "text_hover"}, + {kTextDataDisabled, "text_disabled"}, + {kTextDataInverted, "text_inverted"}, + {kTextDataButton, "text_button"}, + {kTextDataButtonHover, "text_button_hover"}, + {kTextDataNormalFont, "text_normal"} +}; + + +static TextData parseTextDataId(const Common::String &name) { + for (int i = 0; i < kTextDataMAX; ++i) + if (name.compareToIgnoreCase(kTextDataDefaults[i].name) == 0) + return kTextDataDefaults[i].id; + + return kTextDataNone; +} + + ThemeParser::ThemeParser(ThemeEngine *parent) : XMLParser() { _drawFunctions["circle"] = &Graphics::VectorRenderer::drawCallback_CIRCLE; @@ -134,7 +159,8 @@ bool ThemeParser::parserCallback_font(ParserNode *node) { else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue)) return parserError("Error parsing color value for font definition."); - if (!_theme->addFont(node->values["id"], node->values["file"], red, green, blue)) + TextData textDataId = parseTextDataId(node->values["id"]); + if (!_theme->addFont(textDataId, node->values["file"], red, green, blue)) return parserError("Error loading Font in theme engine."); return true; @@ -186,7 +212,8 @@ bool ThemeParser::parserCallback_text(ParserNode *node) { alignH = Graphics::kTextAlignRight; else if (node->values["horizontal_align"] == "center") alignH = Graphics::kTextAlignCenter; - else return parserError("Invalid value for text alignment."); + else + return parserError("Invalid value for text alignment."); if (node->values["vertical_align"] == "top") alignV = GUI::ThemeEngine::kTextAlignVTop; @@ -194,10 +221,14 @@ bool ThemeParser::parserCallback_text(ParserNode *node) { alignV = GUI::ThemeEngine::kTextAlignVCenter; else if (node->values["vertical_align"] == "bottom") alignV = GUI::ThemeEngine::kTextAlignVBottom; - else return parserError("Invalid value for text alignment."); + else + return parserError("Invalid value for text alignment."); + + Common::String id = getParentNode(node)->values["id"]; + TextData textDataId = parseTextDataId(node->values["font"]); - if (!_theme->addTextData(getParentNode(node)->values["id"], node->values["font"], alignH, alignV)) - return parserError("Error adding Text Data for '%s'.", getParentNode(node)->values["id"].c_str()); + if (!_theme->addTextData(id, textDataId, alignH, alignV)) + return parserError("Error adding Text Data for '%s'.", id.c_str()); return true; } @@ -506,6 +537,7 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { return parserError("Error parsing Layout properties of '%s'.", var.c_str()); } else { + // FIXME: Shouldn't we distinguish the name/id and the label of a widget? var = node->values["name"]; int width = -1; int height = -1; |