aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-04-10 17:09:22 -0400
committerPaul Gilbert2016-07-10 16:10:52 -0400
commitcf785a19e3dbe52eb71b253a5dcdcd7ba77b47ca (patch)
treea294e26f39bf157d4a6e2abbc8eb29ae9df5ed46 /engines/titanic
parent91336a86115f600e626c333441aa1369b435ab92 (diff)
downloadscummvm-rg350-cf785a19e3dbe52eb71b253a5dcdcd7ba77b47ca.tar.gz
scummvm-rg350-cf785a19e3dbe52eb71b253a5dcdcd7ba77b47ca.tar.bz2
scummvm-rg350-cf785a19e3dbe52eb71b253a5dcdcd7ba77b47ca.zip
TITANIC: Implement drag&drop dropping
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/input_handler.cpp38
-rw-r--r--engines/titanic/input_handler.h2
-rw-r--r--engines/titanic/pet_control/pet_control.h14
-rw-r--r--engines/titanic/pet_control/pet_inventory.cpp5
-rw-r--r--engines/titanic/pet_control/pet_inventory.h5
-rw-r--r--engines/titanic/pet_control/pet_section.h7
6 files changed, 64 insertions, 7 deletions
diff --git a/engines/titanic/input_handler.cpp b/engines/titanic/input_handler.cpp
index 0657ebec94..082bdd080e 100644
--- a/engines/titanic/input_handler.cpp
+++ b/engines/titanic/input_handler.cpp
@@ -88,8 +88,8 @@ void CInputHandler::processMessage(CMessage *msg) {
} else {
if (mouseMsg->isButtonUpMsg() && _dragItem) {
// Mouse drag ended
- dragEnd(_mousePos, _dragItem);
- CMouseDragEndMsg endMsg(_mousePos, _dragItem);
+ CTreeItem *target = dragEnd(_mousePos, _dragItem);
+ CMouseDragEndMsg endMsg(_mousePos, target);
endMsg.execute(_dragItem);
}
@@ -134,8 +134,36 @@ void CInputHandler::dispatchMessage(CMessage *msg) {
}
}
-void CInputHandler::dragEnd(const Point &mousePos, CTreeItem *dragItem) {
- warning("TODO CInputHandler::dragEnd");
+CTreeItem *CInputHandler::dragEnd(const Point &pt, CTreeItem *dragItem) {
+ CViewItem *view = _gameManager->getView();
+ if (!view)
+ return nullptr;
+
+ // Scan through the view items to find the item being dropped on
+ CTreeItem *target = nullptr;
+ for (CTreeItem *treeItem = view->scan(view); treeItem; treeItem = treeItem->scan(view)) {
+ CGameObject *gameObject = static_cast<CGameObject *>(treeItem);
+ if (gameObject && gameObject != dragItem) {
+ if (gameObject->checkPoint(pt))
+ target = gameObject;
+ }
+ }
+
+ if (target) {
+ // Check if the cursor is on the PET. If so, pass to the PET
+ // to see what specific element the drag ended on
+ CProjectItem *project = view->getRoot();
+ if (project) {
+ CPetControl *petControl = project->getPetControl();
+ if (petControl && petControl->contains(pt)) {
+ target = petControl->dragEnd(pt);
+ if (!target)
+ target = petControl;
+ }
+ }
+ }
+
+ return target;
}
-} // End of namespace Titanic z
+} // End of namespace Titanic
diff --git a/engines/titanic/input_handler.h b/engines/titanic/input_handler.h
index 4e8966fdc4..05838e88c0 100644
--- a/engines/titanic/input_handler.h
+++ b/engines/titanic/input_handler.h
@@ -46,7 +46,7 @@ private:
/**
* Called when a drag operation has ended
*/
- void dragEnd(const Point &mousePos, CTreeItem *dragItem);
+ CTreeItem *dragEnd(const Point &pt, CTreeItem *dragItem);
public:
CGameManager *_gameManager;
CInputTranslator *_inputTranslator;
diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h
index 172cec9bf7..39bc5fb41b 100644
--- a/engines/titanic/pet_control/pet_control.h
+++ b/engines/titanic/pet_control/pet_control.h
@@ -182,6 +182,20 @@ public:
* Draws the indent
*/
void drawIndent(CScreenManager *screenManager, int indent);
+
+ /**
+ * Returns true if the point is within the PET's draw bounds
+ */
+ bool contains(const Point &pt) const {
+ return _drawBounds.contains(pt);
+ }
+
+ /**
+ * Handles drag ends within the PET
+ */
+ CTreeItem *dragEnd(const Point &pt) const {
+ return _currentArea == PET_INVENTORY ? _inventory.dragEnd(pt) : nullptr;
+ }
};
} // End of namespace Titanic
diff --git a/engines/titanic/pet_control/pet_inventory.cpp b/engines/titanic/pet_control/pet_inventory.cpp
index 66d093f513..79923bdb41 100644
--- a/engines/titanic/pet_control/pet_inventory.cpp
+++ b/engines/titanic/pet_control/pet_inventory.cpp
@@ -64,6 +64,11 @@ void CPetInventory::load(SimpleFile *file, int param) {
_field298 = file->readNumber();
}
+CTreeItem *CPetInventory::dragEnd(const Point &pt) const {
+ warning("TODO: CPetInventory::dragEnd");
+ return nullptr;
+}
+
bool CPetInventory::isValid(CPetControl *petControl) {
// TODO
return true;
diff --git a/engines/titanic/pet_control/pet_inventory.h b/engines/titanic/pet_control/pet_inventory.h
index 01f9ebb8d3..a0a9304fd6 100644
--- a/engines/titanic/pet_control/pet_inventory.h
+++ b/engines/titanic/pet_control/pet_inventory.h
@@ -82,6 +82,11 @@ public:
virtual void load(SimpleFile *file, int param);
/**
+ * Returns item a drag-drop operation has dropped on, if any
+ */
+ virtual CTreeItem *dragEnd(const Point &pt) const;
+
+ /**
* Returns true if the object is in a valid state
*/
virtual bool isValid(CPetControl *petControl);
diff --git a/engines/titanic/pet_control/pet_section.h b/engines/titanic/pet_control/pet_section.h
index e20c03c3d5..bc24737b1d 100644
--- a/engines/titanic/pet_control/pet_section.h
+++ b/engines/titanic/pet_control/pet_section.h
@@ -90,7 +90,12 @@ public:
virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; }
virtual int proc14() { return 0; }
- virtual int proc15() { return 0; }
+
+ /**
+ * Returns item a drag-drop operation has dropped on, if any
+ */
+ virtual CTreeItem *dragEnd(const Point &pt) const { return nullptr; }
+
virtual void proc16();
/**