[Scummvm-git-logs] scummvm master -> 380a9da4c9aed6ef0317a0029670b7aaaac8298c

dreammaster dreammaster at scummvm.org
Sun Aug 6 18:30:35 CEST 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
380a9da4c9 TITANIC: Changing arrow movement to be done via simulated mouse clicks


Commit: 380a9da4c9aed6ef0317a0029670b7aaaac8298c
    https://github.com/scummvm/scummvm/commit/380a9da4c9aed6ef0317a0029670b7aaaac8298c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-08-06T12:30:27-04:00

Commit Message:
TITANIC: Changing arrow movement to be done via simulated mouse clicks

Changed paths:
    engines/titanic/core/game_object.cpp
    engines/titanic/core/game_object.h
    engines/titanic/core/view_item.cpp
    engines/titanic/core/view_item.h


diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index ea3cb4d..27af509 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -289,6 +289,27 @@ bool CGameObject::checkPoint(const Point &pt, bool ignoreSurface, bool visibleOn
 	return pixel != transColor;
 }
 
+bool CGameObject::findPoint(Point &pt) {
+	// Start by checking a centroid point in the bounds
+	if (!_bounds.isEmpty()) {
+		pt = Point((_bounds.left + _bounds.right) / 2,
+			(_bounds.top + _bounds.bottom) / 2);
+		if (checkPoint(pt, false, true))
+			return true;
+	}
+
+	// Scan through all the area of the bounds to find a valid point
+	for (pt.y = _bounds.top; pt.y < _bounds.bottom; ++pt.y) {
+		for (pt.x = _bounds.left; pt.x < _bounds.right; ++pt.x) {
+			if (checkPoint(pt, false, true))
+				return true;
+		}
+	}
+
+	pt = Point(0, 0);
+	return false;
+}
+
 bool CGameObject::clipRect(const Rect &rect1, Rect &rect2) const {
 	if (!rect2.intersects(rect1))
 		return false;
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h
index d08ef4c..1c3cbf3 100644
--- a/engines/titanic/core/game_object.h
+++ b/engines/titanic/core/game_object.h
@@ -609,6 +609,13 @@ public:
 	bool checkPoint(const Point &pt, bool ignoreSurface = false, bool visibleOnly = false);
 
 	/**
+	 * Returns a point that falls within the object
+	 * @param pt	Return point
+	 * @returns		True if a point was found
+	 */
+	bool findPoint(Point &pt);
+
+	/**
 	 * Set the position of the object
 	 */
 	void setPosition(const Point &newPos);
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 979fea8..19e1a11 100644
--- a/engines/titanic/core/view_item.cpp
+++ b/engines/titanic/core/view_item.cpp
@@ -339,52 +339,43 @@ CString CViewItem::getNodeViewName() const {
 }
 
 bool CViewItem::MovementMsg(CMovementMsg *msg) {
-	Movement move = msg->_movement;
-	
+	Point pt;
+
 	// Iterate through the links to find an appropriate link
 	for (CTreeItem *treeItem = getFirstChild(); treeItem;
 			treeItem = treeItem->scan(this)) {
 		CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
-		if (!link)
+		CGameObject *gameObj = dynamic_cast<CGameObject *>(treeItem);
+
+		if (link) {
+			// Skip links that aren't for the desired direction
+			if (link->getMovement() != msg->_movement)
+				continue;
+
+			pt = Point((link->_bounds.left + link->_bounds.right) / 2,
+				(link->_bounds.top + link->_bounds.bottom) / 2);
+		} else if (gameObj) {
+			if (!gameObj->_visible || gameObj->getMovement() != msg->_movement)
+				continue;
+
+			if (!gameObj->findPoint(pt))
+				continue;
+		} else {
+			// Not a link or object, so ignore
 			continue;
-		
-		Movement m = link->getMovement();
-		if (move == m) {
-			// Found a matching link
-			CGameManager *gm = getGameManager();
-			gm->_gameState.triggerLink(link);
-			return true;
-		}
-	}
-
-	return false;
-}
-
-CursorId CViewItem::getLinkCursor(CLinkItem *link) {
-	// Pick the center of the link's region as a check point
-	Common::Point pt((link->_bounds.left + link->_bounds.right) / 2,
-		(link->_bounds.top + link->_bounds.bottom) / 2);
-	if (link->_bounds.isEmpty())
-		// Bridge doorway link has an empty bounds, so workaround it
-		pt = Common::Point(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
-
-	// Scan for a restricted object covering the link
-	Common::Array<CGameObject *> gameObjects;
-	for (CTreeItem *treeItem = scan(this); treeItem; treeItem = treeItem->scan(this)) {
-		CGameObject *gameObject = dynamic_cast<CGameObject *>(treeItem);
-		if (gameObject) {
-			if (gameObject->checkPoint(pt, false, true))
-				gameObjects.push_back(gameObject);
 		}
-	}
 
-	for (int idx = (int)gameObjects.size() - 1; idx >= 0; --idx) {
-		if (gameObjects[idx]->_cursorId == CURSOR_INVALID)
-			return CURSOR_INVALID;
+		// We've found a point on the object or link that has a
+		// cursor for the given direction. So simulate a mouse
+		// press and release on the desired point
+		CMouseButtonDownMsg downMsg(pt, MB_LEFT);
+		CMouseButtonUpMsg upMsg(pt, MB_LEFT);
+		MouseButtonDownMsg(&downMsg);
+		MouseButtonUpMsg(&upMsg);
+		return true;
 	}
 
-	// No obscuring objects, so we're free to return the link's cursor
-	return link->_cursorId;
+	return false;
 }
 
 } // End of namespace Titanic
diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h
index c32a7b4..253294d 100644
--- a/engines/titanic/core/view_item.h
+++ b/engines/titanic/core/view_item.h
@@ -54,12 +54,6 @@ private:
 	 * Handles mouse button up messages
 	 */
 	void handleButtonUpMsg(CMouseButtonUpMsg *msg);
-
-	/**
-	 * Gets the cursor for a link, taking into account any
-	 * "restricted" surface that may be covering it
-	 */
-	CursorId getLinkCursor(CLinkItem *link);
 protected:
 	int _field24;
 	CResourceKey _resourceKey;





More information about the Scummvm-git-logs mailing list