TITANIC: Implement drag&drop dropping

This commit is contained in:
Paul Gilbert 2016-04-10 17:09:22 -04:00
parent 91336a8611
commit cf785a19e3
6 changed files with 64 additions and 7 deletions

View file

@ -88,8 +88,8 @@ void CInputHandler::processMessage(CMessage *msg) {
} else { } else {
if (mouseMsg->isButtonUpMsg() && _dragItem) { if (mouseMsg->isButtonUpMsg() && _dragItem) {
// Mouse drag ended // Mouse drag ended
dragEnd(_mousePos, _dragItem); CTreeItem *target = dragEnd(_mousePos, _dragItem);
CMouseDragEndMsg endMsg(_mousePos, _dragItem); CMouseDragEndMsg endMsg(_mousePos, target);
endMsg.execute(_dragItem); endMsg.execute(_dragItem);
} }
@ -134,8 +134,36 @@ void CInputHandler::dispatchMessage(CMessage *msg) {
} }
} }
void CInputHandler::dragEnd(const Point &mousePos, CTreeItem *dragItem) { CTreeItem *CInputHandler::dragEnd(const Point &pt, CTreeItem *dragItem) {
warning("TODO CInputHandler::dragEnd"); 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

View file

@ -46,7 +46,7 @@ private:
/** /**
* Called when a drag operation has ended * Called when a drag operation has ended
*/ */
void dragEnd(const Point &mousePos, CTreeItem *dragItem); CTreeItem *dragEnd(const Point &pt, CTreeItem *dragItem);
public: public:
CGameManager *_gameManager; CGameManager *_gameManager;
CInputTranslator *_inputTranslator; CInputTranslator *_inputTranslator;

View file

@ -182,6 +182,20 @@ public:
* Draws the indent * Draws the indent
*/ */
void drawIndent(CScreenManager *screenManager, int 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 } // End of namespace Titanic

View file

@ -64,6 +64,11 @@ void CPetInventory::load(SimpleFile *file, int param) {
_field298 = file->readNumber(); _field298 = file->readNumber();
} }
CTreeItem *CPetInventory::dragEnd(const Point &pt) const {
warning("TODO: CPetInventory::dragEnd");
return nullptr;
}
bool CPetInventory::isValid(CPetControl *petControl) { bool CPetInventory::isValid(CPetControl *petControl) {
// TODO // TODO
return true; return true;

View file

@ -81,6 +81,11 @@ public:
*/ */
virtual void load(SimpleFile *file, int param); 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 * Returns true if the object is in a valid state
*/ */

View file

@ -90,7 +90,12 @@ public:
virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; } virtual bool VirtualKeyCharMsg(CVirtualKeyCharMsg *msg) { return false; }
virtual int proc14() { return 0; } 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(); virtual void proc16();
/** /**