diff options
Diffstat (limited to 'engines/zvision')
| -rw-r--r-- | engines/zvision/cursor_manager.cpp | 119 | ||||
| -rw-r--r-- | engines/zvision/cursor_manager.h | 67 | ||||
| -rw-r--r-- | engines/zvision/events.cpp | 7 | ||||
| -rw-r--r-- | engines/zvision/module.mk | 1 | ||||
| -rw-r--r-- | engines/zvision/zvision.cpp | 6 | ||||
| -rw-r--r-- | engines/zvision/zvision.h | 4 | 
6 files changed, 202 insertions, 2 deletions
diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp new file mode 100644 index 0000000000..43d288ea4e --- /dev/null +++ b/engines/zvision/cursor_manager.cpp @@ -0,0 +1,119 @@ +/* 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. +* +*/ + +#include "common/scummsys.h" + +#include "common/system.h" +#include "graphics/pixelformat.h" + +#include "zvision/zvision.h" +#include "zvision/cursor_manager.h" + + +namespace ZVision { + +const char *CursorManager::_cursorNames[] = { "active", "arrow", "backward", "downarrow", "forward", "handpt", "handpu", "hdown", "hleft", +                                              "hright", "hup", "idle", "leftarrow", "rightarrow", "suggest_surround", "suggest_tilt", "turnaround", "zuparrow" }; + +const char *CursorManager::_zgiCursorFileNames[] = { "g0gbc011.zcr", "g0gac001.zcr", "g0gac021.zcr", "g0gac031.zcr", "g0gac041.zcr", "g0gac051.zcr", "g0gac061.zcr", "g0gac071.zcr", "g0gac081.zcr", +                                                     "g0gac091.zcr", "g0gac101.zcr", "g0gac011.zcr", "g0gac111.zcr", "g0gac121.zcr", "g0gac131.zcr", "g0gac141.zcr", "g0gac151.zcr", "g0gac161.zcr" }; + +const char *CursorManager::_zNemCursorFileNames[] = { "00act", "arrow", "back", "down", "forw", "handpt", "handpu", "hdown", "hleft", +                                                      "hright", "hup", "00idle", "left", "right", "ssurr", "stilt", "turn", "up" }; + + +CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat) +		: _engine(engine), +		  _pixelFormat(pixelFormat), +		  _cursorIsPushed(false), +		  _currentCursor("idle") { +	// WARNING: The index 11 is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly +	if (_engine->getGameId() == ZorkNemesis) { +		Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[11])); +		_idleCursor = ZorkCursor(name); +	} else if (_engine->getGameId() == ZorkGrandInquisitor) { +		_idleCursor = ZorkCursor(_zgiCursorFileNames[11]); +	} +} + +void CursorManager::initialize() { +	_engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); +	_engine->_system->showMouse(true); +} + +void CursorManager::changeCursor(Common::String &cursorName, bool pushed) { +	_cursorIsPushed = pushed; + +	if (cursorName == "idle" && !pushed) { +		revertToIdle(); +		return; +	} + +	// WARNING: The range of this loop is hardcoded to the length of _cursorNames +	for (int i = 0; i < 18; i++) { +		if (_engine->getGameId() == ZorkNemesis) { +			if (_cursorNames[i] == cursorName) { +				// ZNem uses a/b at the end of the file to signify not pushed/pushed respectively +				Common::String pushedFlag = pushed ? "b" : "a"; +				Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag); + +				changeCursor(ZorkCursor(name)); +				return; +			} +		} else if (_engine->getGameId() == ZorkGrandInquisitor) { +			if (_cursorNames[i] == cursorName) { +				if (!pushed) { +					changeCursor(ZorkCursor(_zgiCursorFileNames[i])); +				} else { +					// ZGI flips not pushed/pushed between a/c and b/d +					// It flips the 4th character of the name +					char buffer[25]; +					strcpy(buffer, _zgiCursorFileNames[i]); +					buffer[3] += 2; +				} +				return; +			} +		} +	} + +	// If we get here, something went wrong +	warning("No cursor found for identifier %s", cursorName.c_str()); +} + +void CursorManager::changeCursor(const ZorkCursor &cursor) { +	_engine->_system->setMouseCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat); +} + +void CursorManager::cursorDown(bool pushed) { +	if (_cursorIsPushed == pushed) +		return; + +	_cursorIsPushed = pushed; +	changeCursor(_currentCursor, pushed); +} + +void CursorManager::revertToIdle() { +	_currentCursor = "idle"; +	_engine->_system->setMouseCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); +} + +} // End of namespace ZVision diff --git a/engines/zvision/cursor_manager.h b/engines/zvision/cursor_manager.h new file mode 100644 index 0000000000..914538591d --- /dev/null +++ b/engines/zvision/cursor_manager.h @@ -0,0 +1,67 @@ +/* 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. + * + */ + +#ifndef ZVISION_CURSOR_MANAGER_H +#define ZVISION_CURSOR_MANAGER_H + +#include "common/types.h" + +#include "zvision/cursor.h" + + +namespace Graphics { +struct PixelFormat; +} + +namespace ZVision { + +class ZVision; + +class CursorManager { +public: +	CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat); + +private: +	ZVision *_engine; +	const Graphics::PixelFormat *_pixelFormat; +	ZorkCursor _idleCursor; +	Common::String _currentCursor; +	bool _cursorIsPushed; + +	static const char *_cursorNames[]; +	static const char *_zgiCursorFileNames[]; +	static const char *_zNemCursorFileNames[]; + +public: +	void initialize(); + +	void changeCursor(Common::String &cursorName, bool pushed); +	void cursorDown(bool pushed); +	void revertToIdle(); + +private: +	void changeCursor(const ZorkCursor &cursor); +}; + +} // End of namespace ZVision + +#endif diff --git a/engines/zvision/events.cpp b/engines/zvision/events.cpp index 3163563ad3..17f48db7fc 100644 --- a/engines/zvision/events.cpp +++ b/engines/zvision/events.cpp @@ -27,7 +27,7 @@  #include "common/events.h"  #include "engines/util.h" -#include "zvision/render_manager.h" +#include "zvision/cursor_manager.h"  namespace ZVision { @@ -39,6 +39,7 @@ void ZVision::processEvents() {  			break;  		case Common::EVENT_LBUTTONUP: +			onMouseUp(_event.mouse);  			break;  		case Common::EVENT_RBUTTONDOWN: @@ -78,7 +79,11 @@ void ZVision::processEvents() {  }  void ZVision::onMouseDown(const Common::Point &pos) { +	_cursorManager->cursorDown(true); +} +void ZVision::onMouseUp(const Common::Point &pos) { +	_cursorManager->cursorDown(false);  }  void ZVision::onMouseMove(const Common::Point &pos) { diff --git a/engines/zvision/module.mk b/engines/zvision/module.mk index feafad5e16..7e74b0bfdd 100644 --- a/engines/zvision/module.mk +++ b/engines/zvision/module.mk @@ -7,6 +7,7 @@ MODULE_OBJS := \  	console.o \  	control.o \  	cursor.o \ +	cursor_manager.o \  	detection.o \  	events.o \  	lzss_read_stream.o \ diff --git a/engines/zvision/zvision.cpp b/engines/zvision/zvision.cpp index 7cfa42e125..e1f719df0a 100644 --- a/engines/zvision/zvision.cpp +++ b/engines/zvision/zvision.cpp @@ -38,9 +38,9 @@  #include "zvision/console.h"  #include "zvision/script_manager.h"  #include "zvision/render_manager.h" +#include "zvision/cursor_manager.h"  #include "zvision/zfs_archive.h"  #include "zvision/detection.h" -#include "zvision/cursor.h"  #include "zvision/utility.h" @@ -81,6 +81,7 @@ ZVision::ZVision(OSystem *syst, const ZVisionGameDescription *gameDesc)  	// Create managers  	_scriptManager = new ScriptManager(this);  	_renderManager = new RenderManager(_system, _width, _height); +	_cursorManager = new CursorManager(this, &_pixelFormat);  	debug("ZVision::ZVision");  } @@ -90,6 +91,7 @@ ZVision::~ZVision() {  	// Dispose of resources  	delete _console; +	delete _cursorManager;  	delete _renderManager;  	delete _scriptManager;  	delete _rnd; @@ -114,6 +116,8 @@ void ZVision::initialize() {  	initGraphics(_width, _height, true, &_pixelFormat);  	_scriptManager->initialize(); +	// Has to be done after graphics has been initialized +	_cursorManager->initialize();  	// Create debugger console. It requires GFX to be initialized  	_console = new Console(this); diff --git a/engines/zvision/zvision.h b/engines/zvision/zvision.h index 29c1ddd651..0a4ed08974 100644 --- a/engines/zvision/zvision.h +++ b/engines/zvision/zvision.h @@ -47,6 +47,7 @@ struct ZVisionGameDescription;  class Console;  class ScriptManager;  class RenderManager; +class CursorManager;  // our engine debug channels  enum { @@ -76,6 +77,7 @@ private:  	// Managers  	ScriptManager *_scriptManager;  	RenderManager *_renderManager; +	CursorManager *_cursorManager;  	// Clock  	Clock _clock; @@ -91,6 +93,7 @@ public:  	ScriptManager *getScriptManager() const;  	RenderManager *getRenderManager() const; +	CursorManager *getCursorManager() const;  	Common::RandomSource *getRandomSource() const;  	ZVisionGameId getGameId() const; @@ -103,6 +106,7 @@ private:  	void processEvents();  	void onMouseDown(const Common::Point &pos); +	void onMouseUp(const Common::Point &pos);  	void onMouseMove(const Common::Point &pos);  	void onKeyDown(uint keyCode);  };  | 
