diff options
author | Bastien Bouclet | 2017-01-28 14:05:26 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-03 08:50:10 +0200 |
commit | 286cdef658dbd18a6bb3b71fdfa9b133efb6a8e4 (patch) | |
tree | a78d0eff08a2414a19a0d6f1b1d74305e79c59e6 /engines | |
parent | 92e03a7b684c019d7670a56feb8e3a6cfd2e85b2 (diff) | |
download | scummvm-rg350-286cdef658dbd18a6bb3b71fdfa9b133efb6a8e4.tar.gz scummvm-rg350-286cdef658dbd18a6bb3b71fdfa9b133efb6a8e4.tar.bz2 scummvm-rg350-286cdef658dbd18a6bb3b71fdfa9b133efb6a8e4.zip |
MOHAWK: Add basic mouse handling to RivenStack
Diffstat (limited to 'engines')
-rw-r--r-- | engines/mohawk/riven.cpp | 6 | ||||
-rw-r--r-- | engines/mohawk/riven_card.cpp | 26 | ||||
-rw-r--r-- | engines/mohawk/riven_card.h | 6 | ||||
-rw-r--r-- | engines/mohawk/riven_stack.cpp | 43 | ||||
-rw-r--r-- | engines/mohawk/riven_stack.h | 15 |
5 files changed, 72 insertions, 24 deletions
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<uint32> _cardIdMap; CommandsMap _commands; + + bool _mouseIsDown; + Common::Point _mousePosition; + Common::Point _mouseDragStartPosition; }; namespace RivenStacks { |