diff options
author | Vicent Marti | 2008-08-01 15:45:02 +0000 |
---|---|---|
committer | Vicent Marti | 2008-08-01 15:45:02 +0000 |
commit | a15ebfb73a1863636ed2ab6aba000118cfb6af54 (patch) | |
tree | 92ebc04db82d809677f748f1f2c18f0e5d0281f1 /gui | |
parent | 262cc33dc7c883e8071e6913f71d02eab443d63c (diff) | |
download | scummvm-rg350-a15ebfb73a1863636ed2ab6aba000118cfb6af54.tar.gz scummvm-rg350-a15ebfb73a1863636ed2ab6aba000118cfb6af54.tar.bz2 scummvm-rg350-a15ebfb73a1863636ed2ab6aba000118cfb6af54.zip |
Theme Layout parsing, WIP.
svn-id: r33494
Diffstat (limited to 'gui')
-rw-r--r-- | gui/ThemeDefaultXML.cpp | 16 | ||||
-rw-r--r-- | gui/ThemeEval.h | 2 | ||||
-rw-r--r-- | gui/ThemeParser.cpp | 107 | ||||
-rw-r--r-- | gui/ThemeParser.h | 6 |
4 files changed, 121 insertions, 10 deletions
diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp index 4fdcbc8d58..630445a6fd 100644 --- a/gui/ThemeDefaultXML.cpp +++ b/gui/ThemeDefaultXML.cpp @@ -169,13 +169,23 @@ bool ThemeRenderer::loadDefaultXML() { "<widget name = 'Console' padding = '7, 5, 5, 5' />" "<widget name = 'TabWidget'>" - "<child name = 'Tab' size = '75, 27' />" + "<child name = 'Tab' size = '75, 27' padding = '0, 0, 8, 0' />" "<child name = 'NavButton' size = '15, 18' padding = '0, 3, 4, 0' />" "</widget>" "</globals>" - "<dialog name = 'GlobalOptions'>" - "<widget name = 'scrollbar' />" + "<dialog name = 'Launcher'>" + "<widget name = 'Version' pos = 'center, 21' size = '247, Globals.Line.Height' />" + "<widget name = 'Logo' pos = 'center, 5' size = '283, 80' />" + "<widget name = 'GameList' pos = 'Globals.Inset.X, Globals.Inset.Y' size = 'Globals.Inset.Width, Globals.Inset.Height' />" + + "<widget name = 'StartButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'AddGameButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'EditGameButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'RemoveGameButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'OptionsButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'AboutButton' size = 'Globals.Button.Width, Globals.Button.Height' />" + "<widget name = 'QuittButton' size = 'Globals.Button.Width, Globals.Button.Height' />" "</dialog>" "</layout_info>"; diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h index 4f08148c7b..c5471bb10d 100644 --- a/gui/ThemeEval.h +++ b/gui/ThemeEval.h @@ -62,6 +62,8 @@ public: void setVar(const String &name, int val) { _vars[name] = val; } + bool hasVar(const Common::String &name) { return _vars.contains(name); } + void debugPrint() { printf("Debug variable list:\n"); diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 4ac6a65932..ab4ca8e553 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -460,12 +460,65 @@ bool ThemeParser::parserCallback_widget(ParserNode *node) { return true; } +bool ThemeParser::parserCallback_child(ParserNode *node) { + Common::String var = "Globals." + getParentNode(node)->values["name"] + "." + node->values["name"] + "."; + + if (!parseCommonLayoutProps(node, var)) + return parserError("Error when parsing Layout properties of '%s'.", var.c_str()); + + return true; +} + +bool ThemeParser::parserCallback_dialog(ParserNode *node) { + Common::String var = "Dialog." + node->values["name"] + "."; + + if (!parseCommonLayoutProps(node, var)) + return parserError("Error when parsing Layout properties of '%s'.", var.c_str()); + + return true; +} + bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String &var) { if (node->values.contains("size")) { int width, height; - if (!parseIntegerKey(node->values["size"].c_str(), 2, &width, &height)) - return false; + if (!parseIntegerKey(node->values["size"].c_str(), 2, &width, &height)) { + Common::StringTokenizer tokenizer(node->values["size"], " ,"); + Common::String wtoken, htoken; + char *parseEnd; + + wtoken = tokenizer.nextToken(); + + if (_theme->themeEval()->hasVar(wtoken)) { + width = _theme->themeEval()->getVar(wtoken); + } else { + width = strtol(wtoken.c_str(), &parseEnd, 10); + + if (*parseEnd != 0 && !(*parseEnd == '%' && *(parseEnd + 1) == 0)) + return false; + + if (wtoken.lastChar() == '%') + width = g_system->getOverlayWidth() * width / 100; + } + + htoken = tokenizer.nextToken(); + + if (_theme->themeEval()->hasVar(htoken)) { + height = _theme->themeEval()->getVar(htoken); + } else { + height = strtol(htoken.c_str(), &parseEnd, 10); + + if (*parseEnd != 0 && !(*parseEnd == '%' && *(parseEnd + 1) == 0)) + return false; + + if (htoken.lastChar() == '%') + height = g_system->getOverlayHeight() * height / 100; + } + + if (!tokenizer.empty()) + return false; + } + _theme->themeEval()->setVar(var + "Width", width); _theme->themeEval()->setVar(var + "Height", height); @@ -474,8 +527,54 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (node->values.contains("pos")) { int x, y; - if (!parseIntegerKey(node->values["pos"].c_str(), 2, &x, &y)) - return false; + if (!parseIntegerKey(node->values["pos"].c_str(), 2, &x, &y)) { + Common::StringTokenizer tokenizer(node->values["pos"], " ,"); + Common::String xpos, ypos; + char *parseEnd; + + xpos = tokenizer.nextToken(); + + if (xpos == "center") { + if (!_theme->themeEval()->hasVar(var + "Width")) + return false; + + x = (g_system->getOverlayWidth() / 2) - (_theme->themeEval()->getVar(var + "Width") / 2); + + } else if (_theme->themeEval()->hasVar(xpos)) { + x = _theme->themeEval()->getVar(xpos); + } else { + x = strtol(xpos.c_str(), &parseEnd, 10); + + if (*parseEnd != 0 && !(*parseEnd == 'r' && *(parseEnd + 1) == 0)) + return false; + + if (xpos.lastChar() == 'r') + x = g_system->getOverlayWidth() - x; + } + + ypos = tokenizer.nextToken(); + + if (ypos == "center") { + if (!_theme->themeEval()->hasVar(var + "Height")) + return false; + + y = (g_system->getOverlayHeight() / 2) - (_theme->themeEval()->getVar(var + "Height") / 2); + + } else if (_theme->themeEval()->hasVar(ypos)) { + y = _theme->themeEval()->getVar(ypos); + } else { + y = strtol(ypos.c_str(), &parseEnd, 10); + + if (*parseEnd != 0 && !(*parseEnd == 'b' && *(parseEnd + 1) == 0)) + return false; + + if (ypos.lastChar() == 'b') + y = g_system->getOverlayHeight() - y; + } + + if (!tokenizer.empty()) + return false; + } _theme->themeEval()->setVar(var + "X", x); _theme->themeEval()->setVar(var + "Y", y); diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index c4e744c44c..6f1f8477ae 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -312,7 +312,7 @@ class ThemeRenderer; class ThemeParser : public XMLParser { typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &); - + public: ThemeParser(GUI::ThemeRenderer *parent); @@ -460,8 +460,8 @@ protected: bool parserCallback_globals(ParserNode *node) { return true; } bool parserCallback_def(ParserNode *node); bool parserCallback_widget(ParserNode *node); - bool parserCallback_dialog(ParserNode *node) { return true; } - bool parserCallback_child(ParserNode *node) { return true; } + bool parserCallback_dialog(ParserNode *node); + bool parserCallback_child(ParserNode *node); void cleanup(); |