aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/xmlparser.cpp3
-rw-r--r--common/xmlparser.h42
-rw-r--r--gui/ThemeEval.cpp8
-rw-r--r--gui/ThemeEval.h16
-rw-r--r--gui/ThemeParser.cpp9
-rw-r--r--gui/ThemeParser.h9
-rw-r--r--gui/ThemeRenderer.cpp14
-rw-r--r--gui/ThemeRenderer.h11
8 files changed, 78 insertions, 34 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 6c6bc4b7f8..900f2f81ab 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -191,6 +191,9 @@ bool XMLParser::parse() {
if (_XMLkeys == 0)
buildLayout();
+ while (!_activeKey.empty())
+ delete _activeKey.pop();
+
cleanup();
bool activeClosure = false;
diff --git a/common/xmlparser.h b/common/xmlparser.h
index d1abd321e7..b7a7093bc5 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -179,13 +179,13 @@ namespace Common {
for a working sample of a Custom XML Parser.
*/
-
+
#define XML_KEY(keyName) {\
- lay = new XMLKeyLayout; \
- lay->custom = new kLocalParserName::CustomParserCallback; \
- ((kLocalParserName::CustomParserCallback*)(lay->custom))->callback = (&kLocalParserName::parserCallback_##keyName); \
- layout.top()->children[#keyName] = lay; \
+ lay = new CustomXMLKeyLayout;\
+ lay->callback = (&kLocalParserName::parserCallback_##keyName);\
+ layout.top()->children[#keyName] = lay;\
layout.push(lay); \
+ _layoutList.push_back(lay);\
for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator p = globalProps.begin(); p != globalProps.end(); ++p){\
layout.top()->properties.push_back(*p);}
@@ -209,16 +209,18 @@ namespace Common {
#define CUSTOM_XML_PARSER(parserName) \
protected: \
- typedef bool (parserName::*ParserCallback)(ParserNode *node); \
typedef parserName kLocalParserName; \
- struct CustomParserCallback { ParserCallback callback; }; \
- bool keyCallback(ParserNode *node) {return (this->*(((parserName::CustomParserCallback*)(node->layout->custom))->callback))(node);}\
+ bool keyCallback(ParserNode *node) {return node->layout->doCallback(this, node); }\
+ struct CustomXMLKeyLayout : public XMLKeyLayout {\
+ typedef bool (parserName::*ParserCallback)(ParserNode *node);\
+ ParserCallback callback;\
+ bool doCallback(XMLParser *parent, ParserNode *node) {return ((kLocalParserName*)parent->*callback)(node);} };\
virtual void buildLayout() { \
Common::Stack<XMLKeyLayout*> layout; \
- XMLKeyLayout *lay = 0; \
+ CustomXMLKeyLayout *lay = 0; \
XMLKeyLayout::XMLKeyProperty prop; \
Common::List<XMLKeyLayout::XMLKeyProperty> globalProps; \
- _XMLkeys = new XMLKeyLayout; \
+ _XMLkeys = new CustomXMLKeyLayout; \
layout.push(_XMLkeys);
#define PARSER_END() layout.clear(); }
@@ -280,8 +282,14 @@ public:
virtual ~XMLParser() {
while (!_activeKey.empty())
delete _activeKey.pop();
-
+
delete _XMLkeys;
+
+ for (Common::List<XMLKeyLayout*>::iterator i = _layoutList.begin();
+ i != _layoutList.end(); ++i)
+ delete *i;
+
+ _layoutList.clear();
}
/** Active state for the parser */
@@ -297,12 +305,12 @@ public:
};
struct XMLKeyLayout;
+ struct ParserNode;
typedef Common::HashMap<Common::String, XMLParser::XMLKeyLayout*, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ChildMap;
/** nested struct representing the layout of the XML file */
struct XMLKeyLayout {
- void *custom;
struct XMLKeyProperty {
Common::String name;
bool required;
@@ -311,9 +319,10 @@ public:
Common::List<XMLKeyProperty> properties;
ChildMap children;
- ~XMLKeyLayout() {
+ virtual bool doCallback(XMLParser *parent, ParserNode *node) = 0;
+
+ virtual ~XMLKeyLayout() {
properties.clear();
- children.clear();
}
} *_XMLkeys;
@@ -336,8 +345,10 @@ public:
bool loadFile(Common::String filename) {
Common::File *f = new Common::File;
- if (!f->open(filename))
+ if (!f->open(filename)) {
+ delete f;
return false;
+ }
_fileName = filename;
_text.loadStream(f);
@@ -564,6 +575,7 @@ protected:
*/
virtual void cleanup() {}
+ Common::List<XMLKeyLayout*> _layoutList;
private:
int _pos; /** Current position on the XML buffer. */
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index fe520eb80b..ec866cc626 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -178,11 +178,14 @@ void ThemeLayoutHorizontal::reflowLayout() {
_w += _children[i]->getWidth() + _spacing;
}
-
_h = MAX(_h, (int16)(_children[i]->getHeight() + _paddingTop + _paddingBottom));
}
}
+ThemeEval::~ThemeEval() {
+ reset();
+}
+
void ThemeEval::buildBuiltinVars() {
_builtin["kThumbnailWidth"] = kThumbnailWidth;
_builtin["kThumbnailHeight"] = kThumbnailHeight1;
@@ -236,6 +239,9 @@ void ThemeEval::addDialog(const Common::String &name, const Common::String &over
if (!layout)
error("Error when loading dialog position for '%s'", overlays.c_str());
+
+ if (_layouts.contains(name))
+ delete _layouts[name];
_layouts[name] = layout;
diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h
index c12fa12fa9..aaab4cb2bf 100644
--- a/gui/ThemeEval.h
+++ b/gui/ThemeEval.h
@@ -55,7 +55,8 @@ public:
_centered(false), _defaultW(-1), _defaultH(-1) { }
virtual ~ThemeLayout() {
- _children.clear();
+ for (uint i = 0; i < _children.size(); ++i)
+ delete _children[i];
}
virtual void reflowLayout() = 0;
@@ -305,7 +306,8 @@ public:
ThemeEval() {
buildBuiltinVars();
}
- ~ThemeEval() {}
+
+ ~ThemeEval();
void buildBuiltinVars();
@@ -379,6 +381,16 @@ public:
// _layouts["Dialog.GameOptions_Graphics"]->debugDraw(screen, font);
}
+ void reset() {
+ _vars.clear();
+ _builtin.clear();
+ _curDialog.clear();
+ _curLayout.clear();
+
+ for (LayoutsMap::iterator i = _layouts.begin(); i != _layouts.end(); ++i)
+ delete i->_value;
+ }
+
private:
VariablesMap _vars;
VariablesMap _builtin;
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index d9275b1df0..21554f4c7a 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -97,12 +97,12 @@ Graphics::DrawStep *ThemeParser::defaultDrawStep() {
Graphics::DrawStep *ThemeParser::newDrawStep() {
assert(_defaultStepGlobal);
- Graphics::DrawStep *step = new DrawStep;
+ Graphics::DrawStep *step = 0 ; //new DrawStep;
if (_defaultStepLocal) {
- memcpy(step, _defaultStepLocal, sizeof(DrawStep));
+ step = new DrawStep(*_defaultStepLocal);
} else {
- memcpy(step, _defaultStepGlobal, sizeof(DrawStep));
+ step = new DrawStep(*_defaultStepGlobal);
}
return step;
@@ -116,9 +116,8 @@ bool ThemeParser::parserCallback_defaults(ParserNode *node) {
step = _defaultStepGlobal;
} else if (parentNode->name == "drawdata") {
if (_defaultStepLocal == 0)
- _defaultStepLocal = new DrawStep;
+ _defaultStepLocal = new DrawStep(*_defaultStepLocal);
- memcpy(_defaultStepLocal, _defaultStepGlobal, sizeof(DrawStep));
step = _defaultStepLocal;
} else {
return parserError("<default> key out of scope. Must be inside <drawdata> or <render_info> keys.");
diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h
index bae015cf25..78423652bc 100644
--- a/gui/ThemeParser.h
+++ b/gui/ThemeParser.h
@@ -312,10 +312,17 @@ class ThemeRenderer;
class ThemeParser : public XMLParser {
typedef void (VectorRenderer::*DrawingFunctionCallback)(const Common::Rect &, const DrawStep &);
-
+
public:
ThemeParser(GUI::ThemeRenderer *parent);
+ virtual ~ThemeParser() {
+ delete _defaultStepGlobal;
+ delete _defaultStepLocal;
+ _palette.clear();
+ _drawFunctions.clear();
+ }
+
bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) {
if (!_palette.contains(name))
return false;
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index fc6f34fa9c..679db6c3e7 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -123,6 +123,15 @@ ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
_themeName = themeName;
}
+ThemeRenderer::~ThemeRenderer() {
+ freeRenderer();
+ freeScreen();
+ freeBackbuffer();
+ unloadTheme();
+ delete _parser;
+ delete _themeEval;
+}
+
bool ThemeRenderer::init() {
// reset everything and reload the graphics
deinit();
@@ -174,17 +183,16 @@ void ThemeRenderer::disable() {
template<typename PixelType>
void ThemeRenderer::screenInit(bool backBuffer) {
- freeScreen();
- freeBackbuffer();
-
uint32 width = _system->getOverlayWidth();
uint32 height = _system->getOverlayHeight();
if (backBuffer) {
+ freeBackbuffer();
_backBuffer = new Surface;
_backBuffer->create(width, height, sizeof(PixelType));
}
+ freeScreen();
_screen = new Surface;
_screen->create(width, height, sizeof(PixelType));
_system->clearOverlay();
diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h
index b131b6b5e7..55c75bd76e 100644
--- a/gui/ThemeRenderer.h
+++ b/gui/ThemeRenderer.h
@@ -35,13 +35,15 @@
#include "gui/dialog.h"
#include "gui/ThemeParser.h"
-#include "gui/ThemeEval.h"
#include "graphics/VectorRenderer.h"
+#include "gui/ThemeEval.h"
+
namespace GUI {
struct WidgetDrawData;
struct DrawDataInfo;
+class ThemeEval;
struct TextDrawData {
const Graphics::Font *_fontPtr;
@@ -210,12 +212,7 @@ public:
ThemeRenderer(Common::String themeName, GraphicsMode mode);
/** Default destructor */
- ~ThemeRenderer() {
- freeRenderer();
- freeScreen();
- unloadTheme();
- delete _parser;
- }
+ ~ThemeRenderer();
GUI::ThemeEval *themeEval() { return _themeEval; }