diff options
| author | Paul Gilbert | 2016-03-18 23:15:31 -0400 | 
|---|---|---|
| committer | Paul Gilbert | 2016-03-18 23:15:31 -0400 | 
| commit | 7a38b51357ba581fe51a392a031d09dd238039e8 (patch) | |
| tree | 1fc22be151b1c4355903c7c928675a1294e9a5ea | |
| parent | 9565fbaeac8f48ea0090ebbd751a18eacc6d1230 (diff) | |
| download | scummvm-rg350-7a38b51357ba581fe51a392a031d09dd238039e8.tar.gz scummvm-rg350-7a38b51357ba581fe51a392a031d09dd238039e8.tar.bz2 scummvm-rg350-7a38b51357ba581fe51a392a031d09dd238039e8.zip | |
TITANIC: Implemented drag/drop handling
| -rw-r--r-- | engines/titanic/game_manager.cpp | 2 | ||||
| -rw-r--r-- | engines/titanic/game_manager.h | 2 | ||||
| -rw-r--r-- | engines/titanic/game_state.cpp | 6 | ||||
| -rw-r--r-- | engines/titanic/game_state.h | 8 | ||||
| -rw-r--r-- | engines/titanic/input_handler.cpp | 88 | ||||
| -rw-r--r-- | engines/titanic/input_handler.h | 22 | ||||
| -rw-r--r-- | engines/titanic/messages/mouse_messages.h | 16 | 
7 files changed, 123 insertions, 21 deletions
| diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp index aeacd73890..a2732d8b1c 100644 --- a/engines/titanic/game_manager.cpp +++ b/engines/titanic/game_manager.cpp @@ -48,7 +48,7 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):  		_inputHandler(this), _inputTranslator(&_inputHandler),		  		_gameState(this), _sound(this), _musicRoom(this),  		_field30(0), _field34(0), _field4C(0),  -		_field50(0), _field54(0), _tickCount1(0), _tickCount2(0) { +		_dragItem(nullptr), _field54(0), _tickCount1(0), _tickCount2(0) {  	_videoSurface1 = nullptr;  	_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340); diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h index d132ff39ef..a331f3a0b4 100644 --- a/engines/titanic/game_manager.h +++ b/engines/titanic/game_manager.h @@ -61,7 +61,6 @@ private:  	int _field34;  	CVideoSurface *_videoSurface1;  	int _field4C; -	int _field50;  	int _field54;  	CVideoSurface *_videoSurface2;  	uint _tickCount1; @@ -72,6 +71,7 @@ public:  	Common::Rect _bounds;  	CInputHandler _inputHandler;  	CInputTranslator _inputTranslator; +	CTreeItem *_dragItem;  public:  	CGameManager(CProjectItem *project, CGameView *gameView);  	~CGameManager(); diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index 3ce8b2b42e..30185fc5f6 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -30,7 +30,7 @@ CGameState::CGameState(CGameManager *gameManager) :  		_gameManager(gameManager), _gameLocation(this),  		_field8(0), _fieldC(0), _mode(GSMODE_0), _field14(0), _field18(0),  		_field1C(0), _field20(0), _field24(0), _field28(0), _field2C(0), -		_field30(0), _field34(0), _field38(0) { +		_field38(0) {  }  void CGameState::save(SimpleFile *file) const { @@ -78,4 +78,8 @@ void CGameState::setMode(GameStateMode newMode) {  	_mode = newMode;  } +void CGameState::setMousePos(const Common::Point &pt) { +	_mousePos = pt; +} +  } // End of namespace Titanic z diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h index 3c3b720d95..1c0b750a44 100644 --- a/engines/titanic/game_state.h +++ b/engines/titanic/game_state.h @@ -56,8 +56,7 @@ public:  	int _field24;  	int _field28;  	int _field2C; -	int _field30; -	int _field34; +	Common::Point _mousePos;  	int _field38;  public:  	CGameState(CGameManager *gameManager); @@ -76,6 +75,11 @@ public:  	 * Sets a new mode  	 */  	void setMode(GameStateMode newMode); + +	/** +	 * Sets the current mouse position +	 */ +	void setMousePos(const Common::Point &pt);  };  } // End of namespace Titanic diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp index d7199215f7..5d50c00377 100644 --- a/engines/titanic/input_handler.cpp +++ b/engines/titanic/input_handler.cpp @@ -24,13 +24,13 @@  #include "titanic/game_manager.h"  #include "titanic/screen_manager.h"  #include "titanic/titanic.h" +#include "titanic/pet_control/pet_control.h"  namespace Titanic {  CInputHandler::CInputHandler(CGameManager *owner) : -		_gameManager(owner), _inputTranslator(nullptr), -		_field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0), -		_lockCount(0), _field24(0) { +		_gameManager(owner), _inputTranslator(nullptr), _dragging(false), +		_buttonDown(false), _dragItem(nullptr),  _lockCount(0), _field24(0) {  	CScreenManager::_screenManagerPtr->_inputHandler = this;  } @@ -51,15 +51,91 @@ void CInputHandler::decLockCount() {  void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) {  	if (!respectLock || _lockCount <= 0) {  		if (_gameManager->_gameState._mode == GSMODE_1) { -			processMessage(msg); +			processMessage(&msg);  		} else if (!msg.isMouseMsg()) {  			g_vm->_filesManager.fn1();  		}  	}  } -void CInputHandler::processMessage(const CMessage &msg) { -	warning("TODO: CInputHandler::processMessage"); +void CInputHandler::processMessage(const CMessage *msg) { +	const CMouseMsg *mouseMsg = dynamic_cast<const CMouseMsg *>(msg); +	_field24 = 0; +	dispatchMessage(msg); + +	if (_field24) { +		_field24 = 0; +	} else if (mouseMsg) { +		// Keep the game state mouse position up to date +		if (_mousePos != mouseMsg->_mousePos) { +			_mousePos = mouseMsg->_mousePos; +			_gameManager->_gameState.setMousePos(mouseMsg->_mousePos); +		} + +		// Set flag for whether a mouse button is currently being pressed +		if (mouseMsg->isButtonDownMsg()) +			_buttonDown = true; +		else if (mouseMsg->isButtonUpMsg()) +			_buttonDown = false; + +		// Drag events generation +		if (_dragging) { +			if (mouseMsg->isMouseMoveMsg()) { +				if (_dragItem) { +					CMouseDragMoveMsg moveMsg(_mousePos); +					moveMsg.execute(_dragItem); +				} +			} else { +				if (mouseMsg->isButtonUpMsg() && _dragItem) { +					// Mouse drag ended +					dragEnd(_mousePos, _dragItem); +					CMouseDragEndMsg endMsg(_mousePos, _dragItem); +					endMsg.execute(_dragItem); +				} + +				_dragging = false; +				_dragItem = nullptr; +			} +		} else if (_buttonDown) { +			if (!mouseMsg->isMouseMoveMsg()) { +				// Save where the drag movement started from +				_dragStartPos = _mousePos; +			} else { +				Common::Point delta = mouseMsg->_mousePos - _dragStartPos; +				int distance = (int)sqrt(double(delta.x * delta.x + delta.y * delta.y)); + +				if (distance > 4) { +					// We've moved far enough with the mouse button held down +					// to trigger an official dragging operation +					CMouseDragStartMsg startMsg(_dragStartPos); +					dispatchMessage(&startMsg); + +					// Set the drag item, if any, that a handler will have set on the message +					_dragItem = startMsg._dragItem; +					_gameManager->_dragItem = startMsg._dragItem; + +					if (_dragItem) { +						CMouseDragMoveMsg moveMsg(_dragStartPos); +						dispatchMessage(&moveMsg); +					} + +					_dragging = true; +				} +			} +		} +	} +} + +void CInputHandler::dispatchMessage(const CMessage *msg) { +	CPetControl *pet = _gameManager->_project->getPetControl(); +	if (!pet || !msg->execute(pet, nullptr, MSGFLAG_BREAK_IF_HANDLED)) { +		CViewItem *view = _gameManager->getView(); +		msg->execute(view); +	} +} + +void CInputHandler::dragEnd(const Common::Point &mousePos, CTreeItem *dragItem) { +	warning("TODO CInputHandler::dragEnd");  }  } // End of namespace Titanic z diff --git a/engines/titanic/input_handler.h b/engines/titanic/input_handler.h index 461011f63e..ad1ba86215 100644 --- a/engines/titanic/input_handler.h +++ b/engines/titanic/input_handler.h @@ -25,6 +25,7 @@  #include "common/rect.h"  #include "titanic/input_translator.h" +#include "titanic/core/tree_item.h"  namespace Titanic { @@ -35,15 +36,24 @@ private:  	/**  	 * Process and dispatch a passed message  	 */ -	void processMessage(const CMessage &msg); +	void processMessage(const CMessage *msg); + +	/** +	 * Dispatches a message to the project +	 */ +	void dispatchMessage(const CMessage *msg); + +	/** +	 * Called when a drag operation has ended +	 */ +	void dragEnd(const Common::Point &mousePos, CTreeItem *dragItem);  public:  	CGameManager *_gameManager;  	CInputTranslator *_inputTranslator; -	int _field4; -	int _field8; -	int _fieldC; -	int _field10; -	int _field14; +	bool _dragging; +	bool _buttonDown; +	CTreeItem *_dragItem; +	Common::Point _dragStartPos;  	Common::Point _mousePos;  	int _lockCount;  	int _field24; diff --git a/engines/titanic/messages/mouse_messages.h b/engines/titanic/messages/mouse_messages.h index e36b54dcc0..fff392e465 100644 --- a/engines/titanic/messages/mouse_messages.h +++ b/engines/titanic/messages/mouse_messages.h @@ -109,11 +109,15 @@ public:  class CMouseDragMsg : public CMouseMsg {  public:  	CLASSDEF +	CMouseDragMsg() : CMouseMsg() {} +	CMouseDragMsg(const Common::Point &pt) : CMouseMsg(pt, 0) {}  };  class CMouseDragMoveMsg : public CMouseDragMsg {  public:  	CLASSDEF +	CMouseDragMoveMsg() : CMouseDragMsg() {} +	CMouseDragMoveMsg(const Common::Point &pt) : CMouseDragMsg(pt) {}  	virtual bool handleMessage(const CMouseDragMoveMsg &msg) { return false; }  	virtual bool perform(CTreeItem *treeItem) {  @@ -125,11 +129,13 @@ public:  MSGTARGET(CMouseDragStartMsg);  class CMouseDragStartMsg : public CMouseDragMsg {  public: -	int _field10; +	CTreeItem *_dragItem;  	int _field14;  public:  	CLASSDEF -	CMouseDragStartMsg() : CMouseDragMsg(), _field10(0), _field14(0) {} +	CMouseDragStartMsg() : CMouseDragMsg(), _dragItem(nullptr), _field14(0) {} +	CMouseDragStartMsg(const Common::Point &pt) : CMouseDragMsg(pt), +		_dragItem(nullptr), _field14(0) {}  	virtual bool handleMessage(const CMouseDragStartMsg &msg) { return false; }  	virtual bool perform(CTreeItem *treeItem) {  @@ -141,10 +147,12 @@ public:  MSGTARGET(CMouseDragEndMsg);  class CMouseDragEndMsg : public CMouseDragMsg {  public: -	int _field10; +	CTreeItem *_dragItem;  public:  	CLASSDEF -	CMouseDragEndMsg() : CMouseDragMsg(), _field10(0) {} +	CMouseDragEndMsg() : CMouseDragMsg(), _dragItem(nullptr) {} +	CMouseDragEndMsg(const Common::Point &pt, CTreeItem *dragItem = nullptr) : +		CMouseDragMsg(pt), _dragItem(dragItem) {}  	virtual bool handleMessage(const CMouseDragEndMsg &msg) { return false; }  	virtual bool perform(CTreeItem *treeItem) { | 
