[Scummvm-cvs-logs] SF.net SVN: scummvm:[35960] scummvm/trunk/backends/vkeybd

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Tue Jan 20 19:31:35 CET 2009


Revision: 35960
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35960&view=rev
Author:   lordhoto
Date:     2009-01-20 18:31:35 +0000 (Tue, 20 Jan 2009)

Log Message:
-----------
Removed ImageMan again, now the code uses Graphics::ImageDecoder directly.

Modified Paths:
--------------
    scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
    scummvm/trunk/backends/vkeybd/virtual-keyboard.cpp
    scummvm/trunk/backends/vkeybd/virtual-keyboard.h

Removed Paths:
-------------
    scummvm/trunk/backends/vkeybd/imageman.cpp
    scummvm/trunk/backends/vkeybd/imageman.h

Deleted: scummvm/trunk/backends/vkeybd/imageman.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/imageman.cpp	2009-01-20 17:38:48 UTC (rev 35959)
+++ scummvm/trunk/backends/vkeybd/imageman.cpp	2009-01-20 18:31:35 UTC (rev 35960)
@@ -1,138 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- */
-
-#ifdef ENABLE_VKEYBD
-
-#include "backends/vkeybd/imageman.h"
-
-#include "common/fs.h"
-#include "common/unzip.h"
-#include "graphics/imagedec.h"
-#include "graphics/surface.h"
-
-DECLARE_SINGLETON(Graphics::ImageManager);
-
-namespace Graphics {
-
-ImageManager::ImageManager() {
-}
-
-ImageManager::~ImageManager() {
-	for (Iterator pos = _surfaces.begin(); pos != _surfaces.end(); ++pos) {
-		(*pos)->surface->free();
-		delete (*pos)->surface;
-		delete *pos;
-		*pos = 0;
-	}
-	_surfaces.clear();
-}
-
-bool ImageManager::addArchive(const Common::String &name) {
-#ifdef USE_ZLIB
-	Common::ZipArchive *arch = new Common::ZipArchive(Common::FSNode(name));
-	if (!arch || !arch->isOpen())
-		return false;
-	_archives.add(name, arch);
-#endif
-	return true;
-}
-
-void ImageManager::removeArchive(const Common::String &name) {
-#ifdef USE_ZLIB
-	_archives.remove(name);
-#endif
-}
-
-bool ImageManager::registerSurface(const Common::String &name, Surface *surf) {
-	if (getSurface(name)) {
-		return false;
-	}
-
-	Entry *newHandle = new Entry;
-	if (!newHandle)
-		return false;
-
-	if (!surf)
-		surf = ImageDecoder::loadFile(name);
-
-#ifdef USE_ZLIB
-	if (!surf) {
-		Common::SeekableReadStream *stream = _archives.openFile(name);
-		if (stream) {
-			surf = ImageDecoder::loadFile(*stream);
-			delete stream;
-		}
-	}
-#endif
-
-	if (!surf)
-		return false;
-
-	newHandle->surface = surf;
-	newHandle->name = name;
-	_surfaces.push_back(newHandle);
-
-	return true;
-}
-
-bool ImageManager::unregisterSurface(const Common::String &name) {
-	Iterator pos = searchHandle(name);
-	if (pos == _surfaces.end()) {
-		// no surface handle it as success
-		return true;
-	}
-
-	(*pos)->surface->free();
-	delete (*pos)->surface;
-	delete *pos;
-	*pos = 0;
-
-	_surfaces.erase(pos);
-
-	return true;
-}
-
-Surface * ImageManager::getSurface(const Common::String &name) {
-	Iterator pos = searchHandle(name);
-	if (pos == _surfaces.end()) {
-		// no surface handle it as success
-		return 0;
-	}
-	return (*pos)->surface;
-}
-
-ImageManager::Iterator ImageManager::searchHandle(const Common::String &name) {
-	Iterator pos = _surfaces.begin();
-	while (pos != _surfaces.end()) {
-		if ((*pos)->name == name)
-			break;
-		++pos;
-	}
-	return pos;
-}
-
-} // end of namespace Graphics
-
-#endif // #ifdef ENABLE_VKEYBD
-

Deleted: scummvm/trunk/backends/vkeybd/imageman.h
===================================================================
--- scummvm/trunk/backends/vkeybd/imageman.h	2009-01-20 17:38:48 UTC (rev 35959)
+++ scummvm/trunk/backends/vkeybd/imageman.h	2009-01-20 18:31:35 UTC (rev 35960)
@@ -1,113 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- */
-
-#ifndef GRAPHICS_IMAGEMAN_H
-#define GRAPHICS_IMAGEMAN_H
-
-#ifdef ENABLE_VKEYBD
-
-#include "common/scummsys.h"
-#include "common/archive.h"
-#include "common/singleton.h"
-#include "common/str.h"
-#include "common/list.h"
-
-namespace Graphics {
-
-struct Surface;
-
-class ImageManager : public Common::Singleton<ImageManager> {
-public:
-	~ImageManager();
-
-	/**
-	 * adds an .zip archive to the pool where the ImageManager searches
-	 * for image files
-	 *
-	 * @param name the name of the archive
-	 * @return true on success and false on failure
-	 */
-	bool addArchive(const Common::String &name);
-
-	/**
-	 * deletes an .zip archive from the pool where the Image Manager searches
-	 * for image files
-	 *
-	 * @param name the name of the archive
-	 */
-	void removeArchive(const Common::String &name);
-
-	/**
-	 * registers a surface to the ImageManager.
-	 * surf->free(), also delete surf, will be called when the ImageManager will
-	 * be destroyed or if ImageManager::unregisterSurface is called.
-	 * if the parameter 'surf' is 0 the Manger will try to load an image with
-	 * the filename 'name'
-	 *
-	 * @param name the name of the new handle
-	 * @param surf the surface which should be associated to the given name
-	 * @return returns true on success and false on failure
-	 */
-	bool registerSurface(const Common::String &name, Surface *surf);
-
-	/**
-	 * unregisters a surface, after this the returned surface from
-	 * getSurface should NOT be used anymore
-	 *
-	 * @param name the handle
-	 * @return true on success, false on failure
-	 */
-	bool unregisterSurface(const Common::String &name);
-
-	/**
-	 * gets a surface registered to a handle
-	 *
-	 * @param name the name of the handle
-	 * @return returns an pointer to an Surface object or 0 on failure
-	 */
-	Surface *getSurface(const Common::String &name);
-private:
-	friend class Common::Singleton<SingletonBaseType>;
-	ImageManager();
-
-	struct Entry {
-		Common::String name;
-		Surface *surface;
-	};
-	typedef Common::List<Entry*>::iterator Iterator;
-
-	Iterator searchHandle(const Common::String &name);
-
-	Common::List<Entry*> _surfaces;
-	Common::SearchSet _archives;
-};
-
-} // end of namespace Graphics
-
-/** Shortcut for accessing the image manager. */
-#define ImageMan		(Graphics::ImageManager::instance())
-
-#endif // #ifdef ENABLE_VKEYBD
-
-#endif

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-20 17:38:48 UTC (rev 35959)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-20 18:31:35 UTC (rev 35960)
@@ -31,8 +31,10 @@
 #include "common/keyboard.h"
 #include "common/util.h"
 #include "common/system.h"
-#include "backends/vkeybd/imageman.h"
+#include "common/archive.h"
 
+#include "graphics/imagedec.h"
+
 namespace Common {
 
 VirtualKeyboardParser::VirtualKeyboardParser(VirtualKeyboard *kbd) 
@@ -150,8 +152,8 @@
 			return true;
 		} else {
 			// remove data relating to old resolution
-			ImageMan.unregisterSurface(_mode->bitmapName);
 			_mode->bitmapName.clear();
+			delete _mode->image;
 			_mode->image = 0;
 			_mode->imageMap.removeAllAreas();
 			delete _mode->displayArea;
@@ -249,16 +251,17 @@
 	}
 
 	_mode->bitmapName = node->values["bitmap"];
-	_mode->image = ImageMan.getSurface(_mode->bitmapName);
-	if (!_mode->image) {
-		if (!ImageMan.registerSurface(_mode->bitmapName, 0))
-			return parserError("Error loading bitmap '%s'", _mode->bitmapName.c_str());
 
-		_mode->image = ImageMan.getSurface(_mode->bitmapName);
-		if (!_mode->image)
-			return parserError("Error loading bitmap '%s'", _mode->bitmapName.c_str());
-	}
-	
+	SeekableReadStream *file = _keyboard->_fileArchive->openFile(_mode->bitmapName);
+	if (!file)
+		return parserError("Bitmap '%s' not found", _mode->bitmapName.c_str());
+
+	_mode->image = Graphics::ImageDecoder::loadFile(*file);
+	delete file;
+
+	if (!_mode->image)
+		return parserError("Error loading bitmap '%s'", _mode->bitmapName.c_str());
+
 	const Graphics::PixelFormat format = g_system->getOverlayFormat();
 	int r, g, b;
 	if (node->values.contains("transparent_color")) {

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard.cpp	2009-01-20 17:38:48 UTC (rev 35959)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard.cpp	2009-01-20 18:31:35 UTC (rev 35960)
@@ -27,7 +27,6 @@
 
 #include "backends/vkeybd/virtual-keyboard.h"
 
-#include "backends/vkeybd/imageman.h"
 #include "backends/vkeybd/virtual-keyboard-gui.h"
 #include "backends/vkeybd/virtual-keyboard-parser.h"
 #include "backends/vkeybd/keycode-descriptions.h"
@@ -47,13 +46,14 @@
 	_parser = new VirtualKeyboardParser(this);
 	_kbdGUI = new VirtualKeyboardGUI(this);
 	_submitKeys = _loaded = false;
-
+	_fileArchive = 0;
 }
 
 VirtualKeyboard::~VirtualKeyboard() {
 	deleteEvents();
 	delete _kbdGUI;
 	delete _parser;
+	delete _fileArchive;
 }
 
 void VirtualKeyboard::deleteEvents() {
@@ -80,6 +80,9 @@
 bool VirtualKeyboard::loadKeyboardPack(String packName) {
 	_kbdGUI->initSize(_system->getOverlayWidth(), _system->getOverlayHeight());
 
+	delete _fileArchive;
+	_fileArchive = 0;
+
 	FSNode vkDir;
 	if (ConfMan.hasKey("vkeybdpath"))
 		vkDir = FSNode(ConfMan.get("vkeybdpath"));
@@ -89,6 +92,8 @@
 		vkDir = FSNode(".");
 
 	if (vkDir.getChild(packName + ".xml").exists()) {
+		_fileArchive = new FSDirectory(vkDir, 1);
+
 		// uncompressed keyboard pack
 		if (!_parser->loadFile(vkDir.getChild(packName + ".xml")))
 			return false;
@@ -96,15 +101,14 @@
 	} else if (vkDir.getChild(packName + ".zip").exists()) {
 		// compressed keyboard pack
 #ifdef USE_ZLIB
-		ZipArchive arch(vkDir.getChild(packName + ".zip"));
-		if (arch.hasFile(packName + ".xml")) {
-			if (!_parser->loadStream(arch.openFile(packName + ".xml")))
+		_fileArchive = new ZipArchive(vkDir.getChild(packName + ".zip"));
+		if (_fileArchive->hasFile(packName + ".xml")) {
+			if (!_parser->loadStream(_fileArchive->openFile(packName + ".xml")))
 				return false;
 		} else {
 			warning("Could not find %s.xml file in %s.zip keyboard pack", packName.c_str(), packName.c_str());
 			return false;
 		}
-		ImageMan.addArchive(vkDir.getChild(packName + ".zip").getPath().c_str());
 #else
 		return false;
 #endif

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard.h
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard.h	2009-01-20 17:38:48 UTC (rev 35959)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard.h	2009-01-20 18:31:35 UTC (rev 35960)
@@ -44,6 +44,8 @@
 
 namespace Common {
 
+class Archive;
+
 class VirtualKeyboardGUI;
 class VirtualKeyboardParser;
 
@@ -118,7 +120,7 @@
 		OverlayColor		displayFontColor;
 
 		Mode() : image(0), displayArea(0) {}
-		~Mode() { delete displayArea; }
+		~Mode() { delete image; delete displayArea; }
 	};
 	
 	typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap;
@@ -219,6 +221,7 @@
 protected:	
 
 	OSystem *_system;
+	Archive *_fileArchive;
 
 	friend class VirtualKeyboardGUI;
 	VirtualKeyboardGUI	*_kbdGUI;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list