aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-01-02 01:32:40 +0000
committerMax Horn2009-01-02 01:32:40 +0000
commit903f52cff878bf4584bdcfd5ceb1b6885504196a (patch)
tree3539c65419c3a271a8fcb6580dc769833de31f1c
parente7bf64744b13b86cce707cc4de3516cd8723c90e (diff)
downloadscummvm-rg350-903f52cff878bf4584bdcfd5ceb1b6885504196a.tar.gz
scummvm-rg350-903f52cff878bf4584bdcfd5ceb1b6885504196a.tar.bz2
scummvm-rg350-903f52cff878bf4584bdcfd5ceb1b6885504196a.zip
GUI: Create the _themeArchive once and then keep it; also do not reload theme bitmaps needlessly
svn-id: r35663
-rw-r--r--gui/ThemeEngine.cpp85
1 files changed, 39 insertions, 46 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index be381184c2..4d20ef6dd1 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -82,9 +82,21 @@ ThemeEngine::~ThemeEngine() {
_backBuffer.free();
unloadTheme();
+
+ // Release all graphics surfaces
+ for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) {
+ Graphics::Surface *surf = i->_value;
+ if (surf) {
+ surf->free();
+ delete surf;
+ }
+ }
+ _bitmaps.clear();
+
delete _parser;
delete _themeEval;
delete[] _cursor;
+ delete _themeArchive;
}
@@ -151,6 +163,27 @@ bool ThemeEngine::init() {
_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
}
+ // Try to create a Common::Archive with the files of the theme.
+ if (!_themeArchive && _themeId != "builtin") {
+ Common::FSNode node(_themeId);
+ if (node.getName().hasSuffix(".zip") && !node.isDirectory()) {
+ #ifdef USE_ZLIB
+ Common::ZipArchive *zipArchive = new Common::ZipArchive(node);
+
+ if (!zipArchive || !zipArchive->isOpen()) {
+ delete zipArchive;
+ zipArchive = 0;
+ warning("Failed to open Zip archive '%s'.", node.getPath().c_str());
+ }
+ _themeArchive = zipArchive;
+
+ #endif
+ } else if (node.isDirectory()) {
+ _themeArchive = new Common::FSDirectory(node);
+ }
+ }
+
+ // Load the theme
loadTheme(_themeId);
return ready();
@@ -321,14 +354,12 @@ bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &fi
}
bool ThemeEngine::addBitmap(const Common::String &filename) {
- // Release any existing surface with that name.
+ // Nothing has to be done if the bitmap already has been loaded.
Graphics::Surface *surf = _bitmaps[filename];
- if (surf) {
- surf->free();
- delete surf;
- }
+ if (surf)
+ return true;
- // Now try to load the bitmap via the ImageDecoder class.
+ // If not, try to load the bitmap via the ImageDecoder class.
surf = Graphics::ImageDecoder::loadFile(filename);
if (!surf && _themeArchive) {
Common::SeekableReadStream *stream = _themeArchive->openFile(filename);
@@ -377,8 +408,6 @@ void ThemeEngine::loadTheme(const Common::String &themeId) {
}
if (!_themeOk) {
- delete _themeArchive;
- _themeArchive = 0;
warning("Failed to load theme '%s'", themeId.c_str());
return;
}
@@ -409,19 +438,6 @@ void ThemeEngine::unloadTheme() {
_texts[i] = 0;
}
- // Release all graphics surfaces
- for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) {
- Graphics::Surface *surf = i->_value;
- if (surf) {
- surf->free();
- delete surf;
- }
- }
- _bitmaps.clear();
-
- delete _themeArchive;
- _themeArchive = 0;
-
_themeEval->reset();
_themeOk = false;
}
@@ -457,33 +473,10 @@ bool ThemeEngine::loadDefaultXML() {
bool ThemeEngine::loadThemeXML(const Common::String &themeId) {
assert(_parser);
- _themeName.clear();
-
- //
- // Try to create a Common::Archive with the files of the theme
- //
- Common::FSNode node(themeId);
- if (!node.exists() || !node.isReadable())
- return false;
-
- if (node.getName().hasSuffix(".zip") && !node.isDirectory()) {
-#ifdef USE_ZLIB
- Common::ZipArchive *zipArchive = new Common::ZipArchive(node);
-
- if (!zipArchive || !zipArchive->isOpen()) {
- delete zipArchive;
- zipArchive = 0;
- warning("Failed to open Zip archive '%s'.", themeId.c_str());
- }
- _themeArchive = zipArchive;
+ assert(_themeArchive);
-#endif
- } else if (node.isDirectory()) {
- _themeArchive = new Common::FSDirectory(node);
- }
+ _themeName.clear();
- if (!_themeArchive)
- return false;
//
// Now that we have a Common::Archive, verify that it contains a valid THEMERC File