diff options
author | Vicent Marti | 2008-10-18 01:27:33 +0000 |
---|---|---|
committer | Vicent Marti | 2008-10-18 01:27:33 +0000 |
commit | 46b036ab6aea23319ac4a3fdfb0faa13bc3cc3dd (patch) | |
tree | c1951b62b6f2a455ef06a4b5e0e72eb823fbdcd4 /gui | |
parent | 3644910f0d7d0ccf09b9453e8a9d8898c668b870 (diff) | |
download | scummvm-rg350-46b036ab6aea23319ac4a3fdfb0faa13bc3cc3dd.tar.gz scummvm-rg350-46b036ab6aea23319ac4a3fdfb0faa13bc3cc3dd.tar.bz2 scummvm-rg350-46b036ab6aea23319ac4a3fdfb0faa13bc3cc3dd.zip |
ImageManager: Added support for generic archives (zips and folders).
Theme Font Loading: Added support for generic archives.
ThemeEngine: Removed dependency on Common::File and File::AddDefaultPath for image and font loading.
svn-id: r34815
Diffstat (limited to 'gui')
-rw-r--r-- | gui/ThemeEngine.cpp | 13 | ||||
-rw-r--r-- | gui/theme.cpp | 57 | ||||
-rw-r--r-- | gui/theme.h | 1 |
3 files changed, 41 insertions, 30 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index f26d35ba58..9c49bfdeb8 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -251,10 +251,7 @@ void ThemeEngine::unloadTheme() { for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) ImageMan.unregisterSurface(i->_key); - if (_themeFileName.hasSuffix(".zip")) - ImageMan.removeArchive(_themeFileName); - - Common::File::resetDefaultDirectories(); + ImageMan.removeArchive(_themeFileName); _themeEval->reset(); _themeOk = false; @@ -463,12 +460,8 @@ bool ThemeEngine::addDrawData(const Common::String &data, bool cached) { bool ThemeEngine::loadTheme(Common::String fileName) { unloadTheme(); - if (fileName != "builtin") { - if (fileName.hasSuffix(".zip")) - ImageMan.addArchive(fileName); - else - Common::File::addDefaultDirectory(fileName); - } + if (fileName != "builtin") + ImageMan.addArchive(fileName); if (fileName == "builtin") { if (!loadDefaultXML()) diff --git a/gui/theme.cpp b/gui/theme.cpp index 8e05ca8479..2d21339f4c 100644 --- a/gui/theme.cpp +++ b/gui/theme.cpp @@ -33,26 +33,51 @@ Theme::Theme() : _loadedThemeX(0), _loadedThemeY(0) {} Theme::~Theme() {} -const Graphics::Font *Theme::loadFont(const Common::String &filename) { +const Graphics::Font *Theme::loadFontFromArchive(const Common::String &filename) { + Common::Archive *arch = 0; const Graphics::NewFont *font = 0; + + if (getThemeFileName().hasSuffix(".zip")) { +#ifdef USE_ZLIB + Common::ZipArchive *zip = new Common::ZipArchive(getThemeFileName()); + if (!zip || !zip->isOpen()) + return 0; + + arch = zip; +#else + return 0; +#endif + } else { + Common::FSDirectory *dir = new Common::FSDirectory(getThemeFileName()); + if (!dir || !dir->getFSNode().isDirectory()) + return 0; + + arch = dir; + } + + Common::SeekableReadStream *stream(arch->openFile(filename)); + if (stream) { + font = Graphics::NewFont::loadFromCache(*stream); + delete stream; + } + + delete arch; + return font; +} + +const Graphics::Font *Theme::loadFont(const Common::String &filename) { + const Graphics::Font *font = 0; Common::String cacheFilename = genCacheFilename(filename.c_str()); Common::File fontFile; if (!cacheFilename.empty()) { if (fontFile.open(cacheFilename)) font = Graphics::NewFont::loadFromCache(fontFile); + if (font) return font; -#ifdef USE_ZLIB - Common::ZipArchive zipArchive(getThemeFileName()); - Common::SeekableReadStream *stream(zipArchive.openFile(cacheFilename)); - if (stream) { - font = Graphics::NewFont::loadFromCache(*stream); - delete stream; - } -#endif - if (font) + if ((font = loadFontFromArchive(cacheFilename))) return font; } @@ -61,21 +86,13 @@ const Graphics::Font *Theme::loadFont(const Common::String &filename) { font = Graphics::NewFont::loadFont(fontFile); } -#ifdef USE_ZLIB if (!font) { - Common::ZipArchive zipArchive(getThemeFileName()); - - Common::SeekableReadStream *stream(zipArchive.openFile(filename)); - if (stream) { - font = Graphics::NewFont::loadFont(*stream); - delete stream; - } + font = loadFontFromArchive(filename); } -#endif if (font) { if (!cacheFilename.empty()) { - if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) { + if (!Graphics::NewFont::cacheFontData(*(Graphics::NewFont*)font, cacheFilename)) { warning("Couldn't create cache file for font '%s'", filename.c_str()); } } diff --git a/gui/theme.h b/gui/theme.h index 3d114ae207..45c81a06cf 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -337,6 +337,7 @@ public: protected: const Graphics::Font *loadFont(const Common::String &filename); + const Graphics::Font *loadFontFromArchive(const Common::String &filename); Common::String genCacheFilename(const char *filename); public: |