aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/xmlparser.cpp3
-rw-r--r--common/xmlparser.h6
-rw-r--r--gui/InterfaceManager.cpp45
-rw-r--r--gui/InterfaceManager.h20
-rw-r--r--gui/ThemeParser.cpp4
5 files changed, 70 insertions, 8 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index b2178afbd0..6cb3a8a441 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -148,6 +148,9 @@ bool XMLParser::parseKeyValue(Common::String keyName) {
bool XMLParser::parse() {
+ if (_text.ready() == false)
+ return parserError("XML stream not ready for reading.");
+
bool activeClosure = false;
bool selfClosure = false;
diff --git a/common/xmlparser.h b/common/xmlparser.h
index bfbc03b97b..3eb87efd31 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -70,6 +70,10 @@ public:
delete _stream;
_stream = s;
}
+
+ bool ready() {
+ return _stream != 0;
+ }
};
/**
@@ -116,7 +120,7 @@ public:
int depth;
};
- virtual bool loadFile(const char *filename) {
+ virtual bool loadFile(Common::String filename) {
Common::File *f = new Common::File;
if (!f->open(filename, Common::File::kFileReadMode))
diff --git a/gui/InterfaceManager.cpp b/gui/InterfaceManager.cpp
index 5ee3a014ed..0afb71bfd5 100644
--- a/gui/InterfaceManager.cpp
+++ b/gui/InterfaceManager.cpp
@@ -28,6 +28,7 @@
#include "graphics/colormasks.h"
#include "common/system.h"
#include "common/events.h"
+#include "common/config-manager.h"
#include "gui/InterfaceManager.h"
#include "graphics/VectorRenderer.h"
@@ -69,8 +70,9 @@ const char *InterfaceManager::kDrawDataStrings[] = {
InterfaceManager::InterfaceManager() :
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
- _screen(0), _bytesPerPixel(0) {
+ _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false) {
_system = g_system;
+ _parser = new ThemeParser();
for (int i = 0; i < kDrawDataMAX; ++i) {
_widgets[i] = 0;
@@ -126,11 +128,50 @@ bool InterfaceManager::addDrawData(DrawData data_id, bool cached) {
_widgets[data_id] = new WidgetDrawData;
_widgets[data_id]->_cached = cached;
_widgets[data_id]->_type = data_id;
- _widgets[data_id]->_scaled = false;
return true;
}
+bool InterfaceManager::loadTheme(Common::String &themeName) {
+ if (!loadThemeXML(themeName)) {
+ warning("Could not parse custom theme '%s'.", themeName.c_str());
+ return false;
+ }
+
+ for (int i = 0; i < kDrawDataMAX; ++i) {
+ if (_widgets[i] == 0) {
+#ifdef REQUIRE_ALL_DD_SETS
+ warning("Error when parsing custom theme '%s': Missing data assets.", themeName.c_str());
+ return false;
+#endif
+ } else if (_widgets[i]->_cached) {
+ // draw the cached widget to the cache surface
+ }
+ }
+
+ _themeOk = true;
+ return true;
+}
+
+bool InterfaceManager::loadThemeXML(Common::String &themeName) {
+ assert(_parser);
+
+ if (ConfMan.hasKey("themepath"))
+ Common::File::addDefaultDirectory(ConfMan.get("themepath"));
+
+#ifdef DATA_PATH
+ Common::File::addDefaultDirectoryRecursive(DATA_PATH);
+#endif
+
+ if (ConfMan.hasKey("extrapath"))
+ Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
+
+ if (!parser()->loadFile(themeName + ".xml"))
+ return false;
+
+ return parser()->parse();
+}
+
bool InterfaceManager::init() {
return false;
}
diff --git a/gui/InterfaceManager.h b/gui/InterfaceManager.h
index 00441a9efc..97af6732e0 100644
--- a/gui/InterfaceManager.h
+++ b/gui/InterfaceManager.h
@@ -33,6 +33,7 @@
#include "graphics/surface.h"
#include "graphics/fontman.h"
+#include "gui/ThemeParser.h"
#include "graphics/VectorRenderer.h"
namespace GUI {
@@ -143,6 +144,7 @@ public:
~InterfaceManager() {
freeRenderer();
freeScreen();
+ delete _parser;
}
void setGraphicsMode(Graphics_Mode mode);
@@ -180,9 +182,21 @@ public:
void addDrawStep(Common::String &drawDataId, Graphics::DrawStep *step);
bool addDrawData(DrawData data_id, bool cached);
+ ThemeParser *parser() {
+ return _parser;
+ }
+
+ bool ready() {
+ return _initOk && _themeOk;
+ }
+
+ bool loadTheme(Common::String &themeName);
+
protected:
template<typename PixelType> void screenInit();
+ bool loadThemeXML(Common::String &themeName);
+
void freeRenderer() {
delete _vectorRenderer;
_vectorRenderer = 0;
@@ -205,6 +219,7 @@ protected:
OSystem *_system;
Graphics::VectorRenderer *_vectorRenderer;
Graphics::Surface *_screen;
+ GUI::ThemeParser *_parser;
int _bytesPerPixel;
Graphics_Mode _graphicsMode;
@@ -215,17 +230,16 @@ protected:
WidgetDrawData *_widgets[kDrawDataMAX];
bool _initOk;
+ bool _themeOk;
bool _caching;
};
struct WidgetDrawData {
- Common::Rect _realSize;
- bool _scaled;
-
Common::Array<Graphics::DrawStep*> _steps;
bool _cached;
Graphics::Surface *_surfaceCache;
+ uint32 _cachedW, _cachedH;
InterfaceManager::DrawData _type;
};
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index d9d8c9cd7c..6e60d8a499 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -237,7 +237,7 @@ bool ThemeParser::parserCallback_DRAWSTEP() {
else if (val == "right")
drawstep->extraData = VectorRenderer::kTriangleRight;
else
- return parserError("'%s' is not a valid value for triangle orientation.", stepNode->values["orientation"].c_str());
+ return parserError("'%s' is not a valid value for triangle orientation.", val.c_str());
}
}
@@ -289,7 +289,7 @@ bool ThemeParser::parserCallback_DRAWDATA() {
InterfaceManager::DrawData id = g_InterfaceManager.getDrawDataId(drawdataNode->values["id"]);
if (id == -1)
- return parserError("%d is not a valid DrawData set identifier.", drawdataNode->values["id"].c_str());
+ 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;