From b6acfe868ce4b614bfdc9d510e10e35923a7fed6 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Sun, 10 Jul 2016 18:56:05 +0200 Subject: MACVENTURE: Fix click-through and refactor --- engines/macventure/gui.cpp | 32 +++++++++++++++++--------------- engines/macventure/gui.h | 3 ++- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'engines/macventure') diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 5a26482e9d..880ec286d0 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -906,13 +906,20 @@ WindowReference Gui::findObjWindow(ObjID objID) { return kNoWindow; } -void Gui::checkSelect(ObjID obj, const Common::Event &event, const Common::Rect & clickRect, WindowReference ref) { - if (_engine->isObjVisible(obj) && - _engine->isObjClickable(obj) && - isRectInsideObject(clickRect, obj)) - { - selectDraggable(obj, ref, event.mouse); +bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { + return (_engine->isObjVisible(obj) && + _engine->isObjClickable(obj) && + isRectInsideObject(clickRect, obj)); +} + +void Gui::checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref) { + ObjID child; + for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { + if (canBeSelected((*it).obj, event, clickRect, ref)) { + child = (*it).obj; + } } + if (child != 0) selectDraggable(child, ref, event.mouse); } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { @@ -1182,14 +1189,11 @@ bool MacVenture::Gui::processMainGameEvents(WindowClick click, Common::Event & e if (click == kBorderInner && event.type == Common::EVENT_LBUTTONDOWN) { WindowData &data = findWindowData(kMainGameWindow); - ObjID child; + ObjID child = 0; Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, _mainGameWindow->getDimensions()); - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - child = (*it).obj; - checkSelect(child, event, clickRect, kMainGameWindow); - } + checkSelect(data, event, clickRect, kMainGameWindow); } return false; } @@ -1262,10 +1266,8 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { Common::Point pos; // Click rect to local coordinates. We assume the click is inside the window ^ Common::Rect clickRect = calculateClickRect(event.mouse, win->getDimensions()); - for (Common::Array::const_iterator it = data.children.begin(); it != data.children.end(); it++) { - child = (*it).obj; - checkSelect(child, event, clickRect, (WindowReference)ref); - } + checkSelect(data, event, clickRect, (WindowReference)ref); + } return true; } diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 55dd180029..cd8c162a1d 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -314,7 +314,8 @@ private: // Methods Graphics::MacWindow *findWindow(WindowReference reference); // Utils - void checkSelect(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); + bool canBeSelected(ObjID obj, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); + void checkSelect(const WindowData &data, const Common::Event &event, const Common::Rect &clickRect, WindowReference ref); bool isRectInsideObject(Common::Rect target, ObjID obj); void selectDraggable(ObjID child, WindowReference origin, Common::Point startPos); void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); -- cgit v1.2.3