From 286cdef658dbd18a6bb3b71fdfa9b133efb6a8e4 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 28 Jan 2017 14:05:26 +0100 Subject: MOHAWK: Add basic mouse handling to RivenStack --- engines/mohawk/riven.cpp | 6 +++--- engines/mohawk/riven_card.cpp | 26 ++++++++++--------------- engines/mohawk/riven_card.h | 6 +++--- engines/mohawk/riven_stack.cpp | 43 +++++++++++++++++++++++++++++++++++++++++- engines/mohawk/riven_stack.h | 15 ++++++++++++++- 5 files changed, 72 insertions(+), 24 deletions(-) (limited to 'engines/mohawk') diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index c387772f2c..e1581b0cb0 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -197,7 +197,7 @@ void MohawkEngine_Riven::handleEvents() { while (_eventMan->pollEvent(event)) { switch (event.type) { case Common::EVENT_MOUSEMOVE: - _card->onMouseMove(event.mouse); + _stack->onMouseMove(event.mouse); if (!(getFeatures() & GF_DEMO)) { // Check to show the inventory, but it is always "showing" in the demo @@ -213,10 +213,10 @@ void MohawkEngine_Riven::handleEvents() { if (_card->getCurHotspot()) { checkSunnerAlertClick(); } - _card->onMouseDown(_eventMan->getMousePos()); + _stack->onMouseDown(_eventMan->getMousePos()); break; case Common::EVENT_LBUTTONUP: - _card->onMouseUp(_eventMan->getMousePos()); + _stack->onMouseUp(_eventMan->getMousePos()); _inventory->checkClick(_eventMan->getMousePos()); break; case Common::EVENT_KEYDOWN: diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index 894cb4c62a..93f194c610 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -346,37 +346,31 @@ RivenHotspot *RivenCard::getCurHotspot() const { return _hoveredHotspot; } -void RivenCard::onMouseDown(const Common::Point &mouse) { - onMouseMove(mouse); +RivenScriptPtr RivenCard::onMouseDown(const Common::Point &mouse) { + RivenScriptPtr script = onMouseMove(mouse); _pressedHotspot = _hoveredHotspot; - RivenScriptPtr script; if (_pressedHotspot) { - script = _pressedHotspot->getScript(kMouseDownScript); + script += _pressedHotspot->getScript(kMouseDownScript); } - if (script) { - _vm->_scriptMan->runScript(script, false); - } + return script; } -void RivenCard::onMouseUp(const Common::Point &mouse) { - onMouseMove(mouse); +RivenScriptPtr RivenCard::onMouseUp(const Common::Point &mouse) { + RivenScriptPtr script = onMouseMove(mouse); - RivenScriptPtr script; if (_pressedHotspot && _pressedHotspot == _hoveredHotspot) { - script = _pressedHotspot->getScript(kMouseUpScript); + script += _pressedHotspot->getScript(kMouseUpScript); } _pressedHotspot = nullptr; - if (script) { - _vm->_scriptMan->runScript(script, false); - } + return script; } -void RivenCard::onMouseMove(const Common::Point &mouse) { +RivenScriptPtr RivenCard::onMouseMove(const Common::Point &mouse) { RivenHotspot *hotspot = getHotspotContainingPoint(mouse); RivenScriptPtr script = RivenScriptPtr(new RivenScript()); @@ -396,7 +390,7 @@ void RivenCard::onMouseMove(const Common::Point &mouse) { _hoveredHotspot = nullptr; } - _vm->_scriptMan->runScript(script, false); + return script; } void RivenCard::onMouseDragUpdate() { diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h index b02f5f7753..73c47b66aa 100644 --- a/engines/mohawk/riven_card.h +++ b/engines/mohawk/riven_card.h @@ -110,13 +110,13 @@ public: void activateWaterEffect(uint16 index); /** Handle a mouse down event */ - void onMouseDown(const Common::Point &mouse); + RivenScriptPtr onMouseDown(const Common::Point &mouse); /** Handle a mouse up event */ - void onMouseUp(const Common::Point &mouse); + RivenScriptPtr onMouseUp(const Common::Point &mouse); /** Handle a mouse move event */ - void onMouseMove(const Common::Point &mouse); + RivenScriptPtr onMouseMove(const Common::Point &mouse); /** Frame update handler for the mouse cursor */ void onMouseUpdate(); diff --git a/engines/mohawk/riven_stack.cpp b/engines/mohawk/riven_stack.cpp index c39464558c..6fa1b15ad5 100644 --- a/engines/mohawk/riven_stack.cpp +++ b/engines/mohawk/riven_stack.cpp @@ -36,7 +36,8 @@ namespace Mohawk { RivenStack::RivenStack(MohawkEngine_Riven *vm, uint16 id) : _vm(vm), - _id(id) { + _id(id), + _mouseIsDown(false) { loadResourceNames(); loadCardIdMap(); setCurrentStackVariable(); @@ -223,6 +224,46 @@ void RivenStack::installCardTimer() { } +void RivenStack::onMouseDown(const Common::Point &mouse) { + _mouseIsDown = true; + _mousePosition = mouse; + + if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) { + _mouseDragStartPosition = mouse; + + RivenScriptPtr script = _vm->getCard()->onMouseDown(mouse); + + if (!script->empty()) { + _vm->_scriptMan->runScript(script, false); + } + } +} + +void RivenStack::onMouseUp(const Common::Point &mouse) { + _mouseIsDown = false; + _mousePosition = mouse; + + if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) { + RivenScriptPtr script = _vm->getCard()->onMouseUp(mouse); + + if (!script->empty()) { + _vm->_scriptMan->runScript(script, false); + } + } +} + +void RivenStack::onMouseMove(const Common::Point &mouse) { + _mousePosition = mouse; + + if (_vm->getCard() && !_vm->_scriptMan->hasQueuedScripts()) { + RivenScriptPtr script = _vm->getCard()->onMouseMove(mouse); + + if (!script->empty()) { + _vm->_scriptMan->runScript(script, false); + } + } +} + RivenNameList::RivenNameList() { } diff --git a/engines/mohawk/riven_stack.h b/engines/mohawk/riven_stack.h index e1e5455c3b..b08052e4e8 100644 --- a/engines/mohawk/riven_stack.h +++ b/engines/mohawk/riven_stack.h @@ -25,6 +25,7 @@ #include "common/hash-str.h" #include "common/ptr.h" +#include "common/rect.h" #include "common/str-array.h" namespace Mohawk { @@ -110,6 +111,15 @@ public: /** Install a timer for the current card if one is defined */ virtual void installCardTimer(); + /** Handle a mouse down event */ + void onMouseDown(const Common::Point &mouse); + + /** Handle a mouse up event */ + void onMouseUp(const Common::Point &mouse); + + /** Handle a mouse move event */ + void onMouseMove(const Common::Point &mouse); + // Common external commands void xflies(uint16 argc, uint16 *argv); // Start the "flies" effect @@ -139,7 +149,6 @@ private: void loadCardIdMap(); void setCurrentStackVariable(); - uint16 _id; // Stack resource names @@ -152,6 +161,10 @@ private: Common::Array _cardIdMap; CommandsMap _commands; + + bool _mouseIsDown; + Common::Point _mousePosition; + Common::Point _mouseDragStartPosition; }; namespace RivenStacks { -- cgit v1.2.3