aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/main.cpp2
-rw-r--r--common/xmlparser.cpp2
-rw-r--r--common/xmlparser.h8
-rw-r--r--graphics/VectorRenderer.h15
-rw-r--r--gui/ThemeDefaultXML.cpp2
-rw-r--r--gui/ThemeParser.cpp9
-rw-r--r--gui/ThemeParser.h2
-rw-r--r--gui/ThemeRenderer.cpp76
-rw-r--r--gui/ThemeRenderer.h49
-rw-r--r--gui/newgui.cpp7
10 files changed, 104 insertions, 68 deletions
diff --git a/base/main.cpp b/base/main.cpp
index 9b76e0514a..b7d30d30f8 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -70,7 +70,7 @@ static bool launcherDialog(OSystem &system) {
// Clear the main screen
system.clearScreen();
- GUI::ThemeRenderer *test = new GUI::ThemeRenderer;
+// GUI::ThemeRenderer *test = new GUI::ThemeRenderer("modern", GUI::ThemeRenderer::kGfxAntialias16bit);
#if defined LOL
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp
index 8ff93a4c59..3452db9e00 100644
--- a/common/xmlparser.cpp
+++ b/common/xmlparser.cpp
@@ -134,6 +134,8 @@ bool XMLParser::parse() {
if (_text.ready() == false)
return parserError("XML stream not ready for reading.");
+ cleanup();
+
bool activeClosure = false;
bool selfClosure = false;
diff --git a/common/xmlparser.h b/common/xmlparser.h
index 4850dc5113..d31c69ebee 100644
--- a/common/xmlparser.h
+++ b/common/xmlparser.h
@@ -332,6 +332,14 @@ protected:
return (*key == 0);
}
+ /**
+ * Internal state cleanup. Overload this if your parser needs
+ * to clean itself up before doing a second parse.
+ * E.g. the Theme Parser cleans the color palette after parsing
+ * a theme.
+ */
+ virtual void cleanup() {}
+
int _pos; /** Current position on the XML buffer. */
XMLStream _text; /** Buffer with the text being parsed */
Common::String _fileName;
diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h
index 3267d44687..0b9ccc4836 100644
--- a/graphics/VectorRenderer.h
+++ b/graphics/VectorRenderer.h
@@ -406,7 +406,8 @@ public:
*
* @param sys Pointer to the global System class
*/
- virtual void copyFrame(OSystem *sys, Common::Rect &r) = 0;
+ virtual void copyFrame(OSystem *sys, const Common::Rect &r) = 0;
+ virtual void copyWholeFrame(OSystem *sys) = 0;
/**
* Blits a given graphics surface on top of the current drawing surface.
@@ -533,7 +534,7 @@ public:
/**
* @see VectorRenderer::copyFrame()
*/
- virtual void copyFrame(OSystem *sys, Common::Rect &r) {
+ virtual void copyFrame(OSystem *sys, const Common::Rect &r) {
#ifdef OVERLAY_MULTIPLE_DEPTHS // TODO: change OSystem to support templated copyRectToOverlay
sys->copyRectToOverlay((const PixelType*)_activeSurface->pixels,
_activeSurface->pitch, r.top, r.left, r.width(), r.height());
@@ -543,6 +544,16 @@ public:
#endif
}
+ virtual void copyWholeFrame(OSystem *sys) {
+#ifdef OVERLAY_MULTIPLE_DEPTHS
+ sys->copyRectToOverlay((const PixelType*)_activeSurface->getBasePtr(0, 0),
+ _activeSurface->w, 0, 0, _activeSurface->w, _activeSurface->h);
+#else
+ sys->copyRectToOverlay((const OverlayColor*)_activeSurface->getBasePtr(0, 0),
+ _activeSurface->w, 0, 0, _activeSurface->w, _activeSurface->h);
+#endif
+ }
+
/**
* @see VectorRenderer::blitSurface()
*/
diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp
index 4b48e11991..43b3e249a0 100644
--- a/gui/ThemeDefaultXML.cpp
+++ b/gui/ThemeDefaultXML.cpp
@@ -58,7 +58,7 @@ bool ThemeRenderer::loadDefaultXML() {
"<layout_info>"
"</layout_info>";
- if (!parser()->loadBuffer(defaultXML, true))
+ if (!parser()->loadBuffer(defaultXML, false))
return false;
return parser()->parse();
diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp
index 1bdf1c487c..cd9ebc83a4 100644
--- a/gui/ThemeParser.cpp
+++ b/gui/ThemeParser.cpp
@@ -63,6 +63,15 @@ ThemeParser::ThemeParser(ThemeRenderer *parent) : XMLParser() {
_theme = parent;
}
+void ThemeParser::cleanup() {
+ delete _defaultStepGlobal;
+ delete _defaultStepLocal;
+
+ _defaultStepGlobal = defaultDrawStep();
+ _defaultStepLocal = 0;
+ _palette.clear();
+}
+
bool ThemeParser::keyCallback(Common::String keyName) {
// automatically handle with a function from the hash table.
if (!_callbacks.contains(_activeKey.top()->name))
diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h
index d3a9503b8d..cddb91b21e 100644
--- a/gui/ThemeParser.h
+++ b/gui/ThemeParser.h
@@ -329,6 +329,8 @@ protected:
bool parserCallback_layoutInfo();
bool parserCallback_defaultSet();
+ void cleanup();
+
Graphics::DrawStep *newDrawStep();
Graphics::DrawStep *defaultDrawStep();
bool parseDrawStep(ParserNode *stepNode, Graphics::DrawStep *drawstep, bool functionSpecific);
diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp
index 283860341b..7b14b93b23 100644
--- a/gui/ThemeRenderer.cpp
+++ b/gui/ThemeRenderer.cpp
@@ -68,10 +68,9 @@ const char *ThemeRenderer::kDrawDataStrings[] = {
"separator"
};
-ThemeRenderer::ThemeRenderer() :
+ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled),
- _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false),
- _needThemeLoad(false), _enabled(false) {
+ _screen(0), _bytesPerPixel(0), _initOk(false), _themeOk(false) {
_system = g_system;
_parser = new ThemeParser(this);
@@ -79,8 +78,50 @@ ThemeRenderer::ThemeRenderer() :
_widgets[i] = 0;
}
- _graphicsMode = kGfxAntialias16bit; // default GFX mode
- // TODO: load this from a config file
+ _graphicsMode = mode;
+ setGraphicsMode(_graphicsMode);
+
+ if (isThemeLoadingRequired())
+ loadTheme(themeName);
+
+ _initOk = true;
+ _themeName = themeName;
+}
+
+bool ThemeRenderer::init() {
+ // reset everything and reload the graphics
+ deinit();
+ setGraphicsMode(_graphicsMode);
+
+ if (_screen->pixels) {
+ _initOk = true;
+ clearAll();
+ resetDrawArea();
+ }
+
+ if (isThemeLoadingRequired())
+ loadTheme(_themeName);
+
+ return true;
+}
+
+void ThemeRenderer::deinit() {
+ if (_initOk) {
+ _system->hideOverlay();
+ freeRenderer();
+ freeScreen();
+ unloadTheme();
+ _initOk = false;
+ }
+}
+
+void ThemeRenderer::clearAll() {
+ if (!_initOk)
+ return;
+
+ _vectorRenderer->clearSurface();
+ _vectorRenderer->copyWholeFrame(_system);
+ _system->updateScreen();
}
template<typename PixelType>
@@ -92,16 +133,7 @@ void ThemeRenderer::screenInit() {
_system->clearOverlay();
}
-void ThemeRenderer::setGraphicsMode(Graphics_Mode mode) {
-
- // FIXME: reload theme everytime we change resolution...
- // what if we change the renderer too?
- // ...We may need to reload it to re-cache the widget
- // surfaces
- if (_system->getOverlayWidth() != _screen->w ||
- _system->getOverlayHeight() != _screen->h)
- _needThemeLoad = true;
-
+void ThemeRenderer::setGraphicsMode(GraphicsMode mode) {
switch (mode) {
case kGfxStandard16bit:
case kGfxAntialias16bit:
@@ -133,6 +165,7 @@ bool ThemeRenderer::addDrawData(DrawData data_id, bool cached) {
_widgets[data_id] = new WidgetDrawData;
_widgets[data_id]->_cached = cached;
+ _widgets[data_id]->_surfaceCache = 0;
return true;
}
@@ -158,7 +191,6 @@ bool ThemeRenderer::loadTheme(Common::String themeName) {
}
}
- _needThemeLoad = false;
_themeOk = true;
return true;
}
@@ -182,18 +214,6 @@ bool ThemeRenderer::loadThemeXML(Common::String themeName) {
return parser()->parse();
}
-bool ThemeRenderer::init() {
- if (!_screen || _system->getOverlayWidth() != _screen->w ||
- _system->getOverlayHeight() != _screen->h )
- setGraphicsMode(_graphicsMode);
-
- if (needThemeReload())
- loadTheme();
-
- _initOk = true;
- return true;
-}
-
bool ThemeRenderer::isWidgetCached(DrawData type, const Common::Rect &r) {
return _widgets[type] && _widgets[type]->_cached &&
_widgets[type]->_surfaceCache->w == r.width() &&
diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h
index af89bd6732..8d3f57b547 100644
--- a/gui/ThemeRenderer.h
+++ b/gui/ThemeRenderer.h
@@ -73,7 +73,7 @@ class ThemeRenderer : public Theme {
static const int kMaxDialogDepth = 4;
public:
- enum Graphics_Mode {
+ enum GraphicsMode {
kGfxDisabled = 0,
kGfxStandard16bit,
kGfxAntialias16bit
@@ -109,34 +109,31 @@ public:
kDrawDataMAX
};
- ThemeRenderer();
+ ThemeRenderer(Common::String themeName, GraphicsMode mode);
~ThemeRenderer() {
freeRenderer();
freeScreen();
unloadTheme();
delete _parser;
-
- while (!_dialogStack.empty())
- delete _dialogStack.pop();
}
// virtual methods from Theme
bool init();
- void deinit() {}
+ void deinit();
+ void clearAll();
+
void refresh() {}
void enable() {}
void disable() {}
void openDialog() {}
void closeAllDialogs() {}
- void clearAll() {}
+
+
void updateScreen() {}
void resetDrawArea() {}
- void openDialog(bool top) {}
- virtual bool isDynamic() {
- return true;
- }
+ void openDialog(bool top) {}
/** Font management */
const Graphics::Font *getFont(FontStyle font) const { return _font; }
@@ -185,7 +182,8 @@ public:
return _initOk && _themeOk;
}
- bool loadTheme() {
+ // REMOVED: theme name is looked up in NewGUI and passed to the constructor
+/* bool loadTheme() {
ConfMan.registerDefault("gui_theme", "default");
Common::String style(ConfMan.get("gui_theme"));
@@ -193,16 +191,10 @@ public:
style = "modern";
return loadTheme(style);
- }
+ } */
bool loadTheme(Common::String themeName);
-
- void closeTopDialog() {
- assert(_dialogStack.empty() == false);
- delete _dialogStack.pop();
- }
-
- void setGraphicsMode(Graphics_Mode mode);
+ void setGraphicsMode(GraphicsMode mode);
protected:
template<typename PixelType> void screenInit();
@@ -236,16 +228,6 @@ protected:
}
}
- Dialog *getTopDialog() const {
- if (_dialogStack.empty())
- return 0;
- return _dialogStack.top();
- }
-
- bool needThemeReload() {
- return (_themeOk == false || _needThemeLoad == true);
- }
-
bool needRedraw() {
return true;
}
@@ -275,20 +257,19 @@ protected:
Graphics::Surface *_screen;
int _bytesPerPixel;
- Graphics_Mode _graphicsMode;
+ GraphicsMode _graphicsMode;
Common::String _fontName;
const Graphics::Font *_font;
WidgetDrawData *_widgets[kDrawDataMAX];
- Common::FixedStack<Dialog *, kMaxDialogDepth> _dialogStack;
Common::Array<Common::Rect> _dirtyScreen;
bool _initOk;
bool _themeOk;
bool _caching;
- bool _needThemeLoad;
- bool _enabled;
+
+ Common::String _themeName;
};
} // end of namespace GUI.
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index 0bf61d084f..4d0b3905b9 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -31,6 +31,7 @@
#include "gui/eval.h"
#include "gui/ThemeModern.h"
#include "gui/ThemeClassic.h"
+#include "gui/ThemeRenderer.h"
#include "common/config-manager.h"
@@ -142,7 +143,7 @@ bool NewGui::loadNewTheme(const Common::String &style) {
delete _theme;
_theme = 0;
- if (style.compareToIgnoreCase("classic (builtin)") == 0 ||
+/* if (style.compareToIgnoreCase("classic (builtin)") == 0 ||
style.compareToIgnoreCase("classic") == 0) {
_theme = new ThemeClassic(_system, style);
} else {
@@ -159,7 +160,9 @@ bool NewGui::loadNewTheme(const Common::String &style) {
warning("Config '%s' is NOT usable for themes or not found", style.c_str());
}
}
- cfg.clear();
+ cfg.clear(); */
+
+ _theme = new ThemeRenderer(style, GUI::ThemeRenderer::kGfxAntialias16bit);
if (!_theme)
return (!oldTheme.empty() ? loadNewTheme(oldTheme) : false);