diff options
-rw-r--r-- | common/xmlparser.cpp | 6 | ||||
-rw-r--r-- | gui/InterfaceManager.cpp | 17 | ||||
-rw-r--r-- | gui/ThemeDefaultXML.cpp | 6 | ||||
-rw-r--r-- | gui/ThemeParser.cpp | 204 | ||||
-rw-r--r-- | gui/ThemeParser.h | 6 |
5 files changed, 150 insertions, 89 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 22b8b22e48..8ff93a4c59 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -61,10 +61,12 @@ bool XMLParser::parserError(const char *errorString, ...) { printf("%s%s%s\n", startFull ? "" : "...", endFull ? "" : "...", lineStr); + int cursor = MIN(_pos - lineStart, 70); + if (!startFull) - lineStart -= 3; + cursor += 3; - for (int i = 0; i < _pos - lineStart; ++i) + while (cursor--) printf(" "); printf("^\n"); diff --git a/gui/InterfaceManager.cpp b/gui/InterfaceManager.cpp index ac04e56bc0..43d2aa7864 100644 --- a/gui/InterfaceManager.cpp +++ b/gui/InterfaceManager.cpp @@ -261,23 +261,12 @@ int InterfaceManager::runGUI() { _system->showOverlay(); - Graphics::DrawStep *steps = new Graphics::DrawStep[2]; - - steps[0].gradColor1.r = 214; - steps[0].gradColor1.g = 113; - steps[0].gradColor1.b = 8; - steps[0].gradColor1.set = true; - steps[0].gradColor2.r = 240; - steps[0].gradColor2.g = 200; - steps[0].gradColor2.b = 25; - steps[0].gradColor2.set = true; - steps[0].fillMode = VectorRenderer::kFillGradient; - steps[0].drawingCall = &VectorRenderer::drawCallback_FILLSURFACE; - bool running = true; while (running) { // draw!! - _vectorRenderer->drawStep(Common::Rect(), steps[0]); + drawDD(kDDMainDialogBackground, Common::Rect()); + drawDD(kDDButtonIdle, Common::Rect(32, 32, 128, 128)); + _vectorRenderer->copyFrame(_system); Common::Event event; diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp index 406e05badf..6067a44545 100644 --- a/gui/ThemeDefaultXML.cpp +++ b/gui/ThemeDefaultXML.cpp @@ -43,8 +43,12 @@ bool InterfaceManager::loadDefaultXML() { "<color name = 'green' rgb = '0, 255, 0' />" "<color name = 'blue' rgb = '0, 0, 255' />" "</palette>" + "<default fill = 'gradient' fg_color = '255, 255, 255' />" "<drawdata id = 'mainmenu_bg' cache = false>" - "<drawstep func = 'roundedsq' radius = 8 fill = 'none' color = '0, 1, 2' size = 'auto' />" + "<drawstep func = 'fill' fill = 'gradient' gradient_start = '214, 113, 8' gradient_end = '240, 200, 25' />" + "</drawdata>" + "<drawdata id = 'button_idle' cache = false>" + "<drawstep func = 'roundedsq' radius = '8' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' />" "</drawdata>" "</render_info>"; diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 5c0d1cbbdc..6665154cd2 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -46,6 +46,7 @@ ThemeParser::ThemeParser() : XMLParser() { _callbacks["color"] = &ThemeParser::parserCallback_color; _callbacks["render_info"] = &ThemeParser::parserCallback_renderInfo; _callbacks["layout_info"] = &ThemeParser::parserCallback_layoutInfo; + _callbacks["default"] = &ThemeParser::parserCallback_defaultSet; _drawFunctions["circle"] = &Graphics::VectorRenderer::drawCallback_CIRCLE; _drawFunctions["square"] = &Graphics::VectorRenderer::drawCallback_SQUARE; @@ -55,6 +56,9 @@ ThemeParser::ThemeParser() : XMLParser() { _drawFunctions["triangle"] = &Graphics::VectorRenderer::drawCallback_TRIANGLE; _drawFunctions["fill"] = &Graphics::VectorRenderer::drawCallback_FILLSURFACE; _drawFunctions["void"] = &Graphics::VectorRenderer::drawCallback_VOID; + + _defaultStepGlobal = defaultDrawStep(); + _defaultStepLocal = 0; } bool ThemeParser::keyCallback(Common::String keyName) { @@ -65,8 +69,7 @@ bool ThemeParser::keyCallback(Common::String keyName) { return (this->*(_callbacks[_activeKey.top()->name]))(); } -Graphics::DrawStep *ThemeParser::newDrawStep() { - +Graphics::DrawStep *ThemeParser::defaultDrawStep() { Graphics::DrawStep *step = new DrawStep; step->fgColor.set = false; @@ -85,6 +88,42 @@ Graphics::DrawStep *ThemeParser::newDrawStep() { return step; } +Graphics::DrawStep *ThemeParser::newDrawStep() { + assert(_defaultStepGlobal); + Graphics::DrawStep *step = new DrawStep; + + if (_defaultStepLocal) { + memcpy(step, _defaultStepLocal, sizeof(DrawStep)); + } else { + memcpy(step, _defaultStepGlobal, sizeof(DrawStep)); + } + + return step; +} + +bool ThemeParser::parserCallback_defaultSet() { + ParserNode *defNode = getActiveNode(); + ParserNode *parentNode = getParentNode(defNode); + Graphics::DrawStep *step = 0; + + if (parentNode == 0) + return parserError("The <default> key must be contained inside <render_info> keys."); + + if (parentNode->name == "render_info") { + step = _defaultStepGlobal; + } else if (parentNode->name == "drawdata") { + if (_defaultStepLocal == 0) + _defaultStepLocal = new DrawStep; + + memcpy(_defaultStepLocal, _defaultStepGlobal, sizeof(DrawStep)); + step = _defaultStepLocal; + } else { + return parserError("<default> key out of scope. Must be inside <drawdata> or <render_info> keys."); + } + + return parseDrawStep(defNode, step, false); +} + bool ThemeParser::parserCallback_renderInfo() { ParserNode *infoNode = getActiveNode(); @@ -159,6 +198,10 @@ bool ThemeParser::parserCallback_DRAWSTEP() { assert(drawdataNode->values.contains("id")); Graphics::DrawStep *drawstep = newDrawStep(); + + if (!stepNode->values.contains("func")) + return parserError("All Draw Steps must contain a 'func' definition."); + Common::String functionName = stepNode->values["func"]; if (_drawFunctions.contains(functionName) == false) @@ -166,6 +209,56 @@ bool ThemeParser::parserCallback_DRAWSTEP() { drawstep->drawingCall = _drawFunctions[functionName]; + if (!parseDrawStep(stepNode, drawstep, true)) + return false; + + g_InterfaceManager.addDrawStep(drawdataNode->values["id"], drawstep); + return true; +} + +bool ThemeParser::parserCallback_DRAWDATA() { + ParserNode *drawdataNode = _activeKey.top(); + bool cached = false; + + assert(drawdataNode->name == "drawdata"); + + if (getParentNode(drawdataNode) == 0 || getParentNode(drawdataNode)->name != "render_info") + return parserError("DrawData keys must be contained inside a <render_info> section."); + + if (drawdataNode->values.contains("id") == false) + return parserError("DrawData keys must contain an identifier."); + + InterfaceManager::DrawData id = g_InterfaceManager.getDrawDataId(drawdataNode->values["id"]); + + if (id == -1) + return parserError("%s is not a valid DrawData set identifier.", drawdataNode->values["id"].c_str()); + + if (drawdataNode->values.contains("cached") && drawdataNode->values["cached"] == "true") { + cached = true; + } + + // Both Max and Johannes suggest using a non-platform specfic approach based on available + // resources and active resolution. getHostPlatformString() has been removed, so fix this. + +/* if (drawdataNode->values.contains("platform")) { + if (drawdataNode->values["platform"].compareToIgnoreCase(Common::getHostPlatformString()) != 0) { + drawdataNode->ignore = true; + return true; + } + }*/ + + if (g_InterfaceManager.addDrawData(id, cached) == false) + return parserError("Repeated DrawData: Only one set of Drawing Data for a widget may be specified on each platform."); + + if (_defaultStepLocal) { + delete _defaultStepLocal; + _defaultStepLocal = 0; + } + + return true; +} + +bool ThemeParser::parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific) { int red, green, blue, w, h; Common::String val; @@ -226,42 +319,47 @@ bool ThemeParser::parserCallback_DRAWSTEP() { __PARSER_ASSIGN_RGB(gradColor1, "gradient_start"); __PARSER_ASSIGN_RGB(gradColor2, "gradient_end"); - if (functionName == "roundedsq" || functionName == "circle") { - __PARSER_ASSIGN_INT(radius, "radius", true) - } + if (functionSpecific) { + assert(stepNode->values.contains("func")); + Common::String functionName = stepNode->values["func"]; - if (functionName == "bevelsq") { - __PARSER_ASSIGN_INT(extraData, "bevel", true); - } + if (functionName == "roundedsq" || functionName == "circle") { + __PARSER_ASSIGN_INT(radius, "radius", true) + } - if (functionName == "triangle") { - drawstep->extraData = VectorRenderer::kTriangleUp; - - if (stepNode->values.contains("orientation")) { - val = stepNode->values["orientation"]; - - if ( val == "top") - drawstep->extraData = VectorRenderer::kTriangleUp; - else if (val == "bottom") - drawstep->extraData = VectorRenderer::kTriangleDown; - else if (val == "left") - drawstep->extraData = VectorRenderer::kTriangleLeft; - else if (val == "right") - drawstep->extraData = VectorRenderer::kTriangleRight; - else - return parserError("'%s' is not a valid value for triangle orientation.", val.c_str()); + if (functionName == "bevelsq") { + __PARSER_ASSIGN_INT(extraData, "bevel", true); } - } - if (stepNode->values.contains("size")) { - if (stepNode->values["size"] == "auto") { - drawstep->fillArea = true; - } else if (sscanf(stepNode->values["size"].c_str(), "%d, %d", &w, &h) == 2) { - drawstep->fillArea = false; - drawstep->w = w; - drawstep->h = h; - } else { - return parserError("Invalid value in 'size' subkey: Valid options are 'auto' or 'X, X' to define width and height."); + if (functionName == "triangle") { + drawstep->extraData = VectorRenderer::kTriangleUp; + + if (stepNode->values.contains("orientation")) { + val = stepNode->values["orientation"]; + + if ( val == "top") + drawstep->extraData = VectorRenderer::kTriangleUp; + else if (val == "bottom") + drawstep->extraData = VectorRenderer::kTriangleDown; + else if (val == "left") + drawstep->extraData = VectorRenderer::kTriangleLeft; + else if (val == "right") + drawstep->extraData = VectorRenderer::kTriangleRight; + else + return parserError("'%s' is not a valid value for triangle orientation.", val.c_str()); + } + } + + if (stepNode->values.contains("size")) { + if (stepNode->values["size"] == "auto") { + drawstep->fillArea = true; + } else if (sscanf(stepNode->values["size"].c_str(), "%d, %d", &w, &h) == 2) { + drawstep->fillArea = false; + drawstep->w = w; + drawstep->h = h; + } else { + return parserError("Invalid value in 'size' subkey: Valid options are 'auto' or 'X, X' to define width and height."); + } } } @@ -282,44 +380,6 @@ bool ThemeParser::parserCallback_DRAWSTEP() { #undef __PARSER_ASSIGN_INT #undef __PARSER_ASSIGN_RGB - g_InterfaceManager.addDrawStep(drawdataNode->values["id"], drawstep); - return true; -} - -bool ThemeParser::parserCallback_DRAWDATA() { - ParserNode *drawdataNode = _activeKey.top(); - bool cached = false; - - assert(drawdataNode->name == "drawdata"); - - if (getParentNode(drawdataNode) == 0 || getParentNode(drawdataNode)->name != "render_info") - return parserError("DrawData keys must be contained inside a <render_info> section."); - - if (drawdataNode->values.contains("id") == false) - return parserError("DrawData keys must contain an identifier."); - - InterfaceManager::DrawData id = g_InterfaceManager.getDrawDataId(drawdataNode->values["id"]); - - if (id == -1) - return parserError("%s is not a valid DrawData set identifier.", drawdataNode->values["id"].c_str()); - - if (drawdataNode->values.contains("cached") && drawdataNode->values["cached"] == "true") { - cached = true; - } - - // Both Max and Johannes suggest using a non-platform specfic approach based on available - // resources and active resolution. getHostPlatformString() has been removed, so fix this. - -/* if (drawdataNode->values.contains("platform")) { - if (drawdataNode->values["platform"].compareToIgnoreCase(Common::getHostPlatformString()) != 0) { - drawdataNode->ignore = true; - return true; - } - }*/ - - if (g_InterfaceManager.addDrawData(id, cached) == false) - return parserError("Repeated DrawData: Only one set of Drawing Data for a widget may be specified on each platform."); - return true; } diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index 95d9135e12..2a7e0999d5 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -324,6 +324,7 @@ protected: bool parserCallback_color(); bool parserCallback_renderInfo(); bool parserCallback_layoutInfo(); + bool parserCallback_defaultSet(); bool validateKeyIntSigned(const char *key) { @@ -345,6 +346,11 @@ protected: } Graphics::DrawStep *newDrawStep(); + Graphics::DrawStep *defaultDrawStep(); + bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific); + + Graphics::DrawStep *_defaultStepGlobal; + Graphics::DrawStep *_defaultStepLocal; Common::HashMap<Common::String, DrawingFunctionCallback, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _drawFunctions; Common::HashMap<Common::String, ParserCallback, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _callbacks; |