diff options
| author | Max Horn | 2008-12-31 15:07:30 +0000 | 
|---|---|---|
| committer | Max Horn | 2008-12-31 15:07:30 +0000 | 
| commit | 167a9cb767737077cc5b8a70d905a1840a726949 (patch) | |
| tree | ebc7a1c7090af21122bfd14a030d0c6081083e2f | |
| parent | 693b9df09897752a6ad3a826ad82110d47308935 (diff) | |
| download | scummvm-rg350-167a9cb767737077cc5b8a70d905a1840a726949.tar.gz scummvm-rg350-167a9cb767737077cc5b8a70d905a1840a726949.tar.bz2 scummvm-rg350-167a9cb767737077cc5b8a70d905a1840a726949.zip  | |
ThemeEngine:
* more cleanup, esp. of Doxygen comments
* completely got rid of ImageMan, instead use the same Common::Archive to load bitmaps and XML data from
svn-id: r35636
| -rw-r--r-- | gui/ThemeEngine.cpp | 59 | ||||
| -rw-r--r-- | gui/ThemeEngine.h | 24 | 
2 files changed, 55 insertions, 28 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index abc419c428..6ae3524e99 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -33,7 +33,7 @@  #include "graphics/surface.h"  #include "graphics/colormasks.h" -#include "graphics/imageman.h" +#include "graphics/imagedec.h"  #include "graphics/cursorman.h"  #include "graphics/VectorRenderer.h" @@ -72,6 +72,7 @@ ThemeEngine::ThemeEngine(Common::String fileName, GraphicsMode mode) :  	_graphicsMode = mode;  	_themeFileName = fileName; +	_themeArchive = 0;  	_initOk = false;  } @@ -81,17 +82,10 @@ ThemeEngine::~ThemeEngine() {  	delete _parser;  	delete _themeEval;  	delete[] _cursor; - -	for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) -		ImageMan.unregisterSurface(i->_key); - -	ImageMan.removeArchive(_themeFileName);  } - -  /**********************************************************   *	Rendering mode management   *********************************************************/ @@ -192,10 +186,18 @@ void ThemeEngine::unloadTheme() {  		_texts[i] = 0;  	} -	for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) -		ImageMan.unregisterSurface(i->_key); - -	ImageMan.removeArchive(_themeFileName); +	// 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; @@ -387,13 +389,27 @@ bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &fi  }  bool ThemeEngine::addBitmap(const Common::String &filename) { -	if (_bitmaps.contains(filename)) -		ImageMan.unregisterSurface(filename); - -	ImageMan.registerSurface(filename, 0); -	_bitmaps[filename] = ImageMan.getSurface(filename); +	// Release any existing surface with that name. +	Graphics::Surface *surf = _bitmaps[filename]; +	if (surf) { +		surf->free(); +		delete surf; +	} +	 +	// Now try to load the bitmap via the ImageDecoder class. +	surf = Graphics::ImageDecoder::loadFile(filename); +	if (!surf && _themeArchive) { +		Common::SeekableReadStream *stream = _themeArchive->openFile(filename); +		if (stream) { +			surf = Graphics::ImageDecoder::loadFile(*stream); +			delete stream; +		} +	} -	return _bitmaps[filename] != 0; +	// Store the surface into our hashmap (attention, may store NULL entries!) +	_bitmaps[filename] = surf; +	 +	return surf != 0;  }  bool ThemeEngine::addDrawData(const Common::String &data, bool cached) { @@ -423,7 +439,7 @@ bool ThemeEngine::loadTheme(const Common::String &fileName) {  	bool tryAgain = false;  	if (fileName != "builtin") { -		ImageMan.addArchive(fileName); +		// Load the archive containing image and XML data  		if (!loadThemeXML(fileName)) {  			warning("Could not parse custom theme '%s'. Falling back to default theme", fileName.c_str());  			tryAgain = true;	// Fall back to default builtin theme @@ -530,11 +546,14 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) {  		return false;  	} +	_themeArchive = archive; +  	// Loop over all STX files  	for (Common::ArchiveMemberList::iterator i = members.begin(); i != members.end(); ++i) {  		assert((*i)->getName().hasSuffix(".stx"));  		if (_parser->loadStream((*i)->open()) == false) { +			_themeArchive = 0;  			delete archive;  			warning("Failed to load STX file '%s'", (*i)->getDisplayName().c_str());  			_parser->close(); @@ -542,6 +561,7 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) {  		}  		if (_parser->parse() == false) { +			_themeArchive = 0;  			delete archive;  			warning("Failed to parse STX file '%s'", (*i)->getDisplayName().c_str());  			_parser->close(); @@ -551,7 +571,6 @@ bool ThemeEngine::loadThemeXML(const Common::String &themeName) {  		_parser->close();  	} -	delete archive;  	assert(!_themeName.empty());  	return true;  } diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index 4435848fb3..56a288f9d4 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -135,10 +135,12 @@ protected:  		kTextDataMAX  	}; -	static const struct TextDataInfo { +	struct TextDataInfo {  		TextData id;  		const char *name; -	} kTextDataDefaults[]; +	}; +	 +	static const TextDataInfo kTextDataDefaults[];  public:  	//! Vertical alignment of the text. @@ -268,9 +270,8 @@ public:  	void updateScreen(); -	/** -	 *	FONT MANAGEMENT METHODS -	 */ +	/** @name FONT MANAGEMENT METHODS */ +	//@{  	TextData fontStyleToData(FontStyle font) const {  		if (font == kFontStyleNormal) @@ -286,10 +287,12 @@ public:  	int getCharWidth(byte c, FontStyle font = kFontStyleBold) const; +	//@} + + +	/** @name WIDGET DRAWING METHODS */ +	//@{ -	/** -	 *	WIDGET DRAWING METHODS -	 */  	void drawWidgetBackground(const Common::Rect &r, uint16 hints,  		WidgetBackground background = kWidgetBackgroundPlain, WidgetStateInfo state = kStateEnabled); @@ -326,6 +329,10 @@ public:  	void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state = kStateEnabled); +	//@} + + +  	/**  	 *	Actual implementation of a Dirty Rect drawing routine.  	 *	Dirty rectangles are queued on a list and are later merged/calculated @@ -657,6 +664,7 @@ protected:  	Common::String _themeName; //!< Name of the currently loaded theme  	Common::String _themeFileName; +	Common::Archive *_themeArchive;  	/** Custom Cursor Management */  	void setUpCursor();  | 
