aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorBorja Lorente2016-06-25 22:53:11 +0200
committerBorja Lorente2016-08-14 18:40:47 +0200
commit8bee2a7b1c467a2b442cd0d8a35487ac9e963de9 (patch)
tree546f53b162c11dd1035191b986d4a917e2f02d18 /engines
parent45a2aa94b9e79bfe1e384d1240018abdc8df8f84 (diff)
downloadscummvm-rg350-8bee2a7b1c467a2b442cd0d8a35487ac9e963de9.tar.gz
scummvm-rg350-8bee2a7b1c467a2b442cd0d8a35487ac9e963de9.tar.bz2
scummvm-rg350-8bee2a7b1c467a2b442cd0d8a35487ac9e963de9.zip
MACVENTURE: Add inventory callback
Diffstat (limited to 'engines')
-rw-r--r--engines/macventure/gui.cpp67
-rw-r--r--engines/macventure/gui.h3
-rw-r--r--engines/macventure/macventure.cpp6
3 files changed, 54 insertions, 22 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index e1fb0beca3..04cc390546 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -726,6 +726,27 @@ Graphics::MacWindow * Gui::findWindow(WindowReference reference) {
return nullptr;
}
+bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) {
+ if (_assets.contains(obj) &&
+ _engine->isObjClickable(obj) &&
+ _engine->isObjVisible(obj)) {
+ Common::Rect bounds = _engine->getObjBounds(obj);
+ Common::Rect intersection = bounds.findIntersectingRect(target);
+ // We translate it to the image's coord system
+ intersection = Common::Rect(
+ intersection.left - bounds.left,
+ intersection.top - bounds.top,
+ intersection.left - bounds.left + intersection.width(),
+ intersection.top - bounds.top + intersection.height());
+
+
+ if (_assets[obj]->isRectInside(intersection)) {
+ return true;
+ }
+ }
+ return false;
+}
+
/* HANDLERS */
void Gui::handleMenuAction(MenuAction action) {
@@ -955,23 +976,8 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e
Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight);
for (Common::Array<DrawableObject>::const_iterator it = data.children.begin(); it != data.children.end(); it++) {
child = (*it).obj;
- if (_assets.contains(child) &&
- _engine->isObjClickable(child) &&
- _engine->isObjVisible(child)) {
- Common::Rect bounds = _engine->getObjBounds(child);
- Common::Rect intersection = bounds.findIntersectingRect(clickRect);
- // We translate it to the image's coord system
- intersection = Common::Rect(
- intersection.left - bounds.left,
- intersection.top - bounds.top,
- intersection.left - bounds.left + intersection.width(),
- intersection.top - bounds.top + intersection.height());
-
-
- if (_assets[child]->isRectInside(intersection)) {
- // select the first object clicked
- _engine->handleObjectSelect(child, kMainGameWindow, event);
- }
+ if (isRectInsideObject(clickRect, child)) {
+ _engine->handleObjectSelect(child, kMainGameWindow, event);
}
}
}
@@ -1011,7 +1017,32 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) {
if (_engine->needsClickToContinue())
return true;
- return false;
+ if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
+
+ // Find the appropriate window
+ uint ref = 0;
+ uint i;
+ for (uint i = 0; i < _inventoryWindows.size(); i++) {
+ if (_inventoryWindows[i]->hasAllFocus()) { // HACK
+ ref = i;
+ }
+ }
+
+ WindowData &data = findWindowData((WindowReference) ref);
+ ObjID child;
+ Common::Point pos;
+ // Click rect to local coordinates. We assume the click is inside the window ^
+ int left = event.mouse.x - _inventoryWindows[i]->getDimensions().left;
+ int top = event.mouse.y - _inventoryWindows[i]->getDimensions().top;
+ Common::Rect clickRect(left, top, left + kCursorWidth, top + kCursorHeight);
+ for (Common::Array<DrawableObject>::const_iterator it = data.children.begin(); it != data.children.end(); it++) {
+ child = (*it).obj;
+ if (isRectInsideObject(clickRect, child)) {
+ _engine->handleObjectSelect(child, (WindowReference)ref, event);
+ }
+ }
+ }
+ return true;
}
/* Ugly switches */
diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h
index 3569df7bbe..cd6fda7f72 100644
--- a/engines/macventure/gui.h
+++ b/engines/macventure/gui.h
@@ -245,6 +245,9 @@ private: // Methods
WindowData& findWindowData(WindowReference reference);
Graphics::MacWindow *findWindow(WindowReference reference);
+ // Utils
+ bool isRectInsideObject(Common::Rect target, ObjID obj);
+
};
class CommandButton {
diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp
index 012c9a7341..a87da312dd 100644
--- a/engines/macventure/macventure.cpp
+++ b/engines/macventure/macventure.cpp
@@ -291,16 +291,14 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, Comm
if (event.kbd.flags & Common::KBD_SHIFT) {
// Do shift ;)
- }
- else {
+ } else {
if (_selectedControl && _currentSelection.size() > 0 && getInvolvedObjects() > 1) {
if (objID == 0)
selectPrimaryObject(windata.objRef);
else
selectPrimaryObject(objID);
preparedToRun();
- }
- else {
+ } else {
if (objID == 0) {
unselectAll();
//if (windata.type == kAnimateBack) {