From e32c126348df69d8ec15ef3b67d6250935325860 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Wed, 13 Jul 2016 19:17:25 +0200 Subject: MACVENTURE: Refactor asset load checking --- engines/macventure/gui.cpp | 49 ++++++++++++++++++++-------------------------- engines/macventure/gui.h | 2 ++ 2 files changed, 23 insertions(+), 28 deletions(-) (limited to 'engines/macventure') diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 415e02e35b..a313e3e94d 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -580,9 +580,7 @@ void Gui::drawMainGameWindow() { _mainGameWindow->setDirty(true); if (data.objRef > 0 && data.objRef < 2000) { - if (!_assets.contains(objRef)) { - _assets[objRef] = new ImageAsset(objRef, _graphics); - } + ensureAssetLoaded(objRef); _assets[objRef]->blitInto( _mainGameWindow->getSurface(), @@ -665,10 +663,7 @@ void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * mode = (BlitMode)data.children[i].mode; pos = _engine->getObjPosition(child); pos += Common::Point(border.leftOffset, border.topOffset); - - if (!_assets.contains(child)) { - _assets[child] = new ImageAsset(child, _graphics); - } + ensureAssetLoaded(child); _assets[child]->blitInto( surface, @@ -710,9 +705,7 @@ void Gui::drawWindowTitle(WindowReference target, Graphics::ManagedSurface * sur void Gui::drawDraggedObject() { if (_draggedObj.id != 0) { - if (!_assets.contains(_draggedObj.id)) - _assets[_draggedObj.id] = new ImageAsset(_draggedObj.id, _graphics); - + ensureAssetLoaded(_draggedObj.id); ImageAsset *asset = _assets[_draggedObj.id]; _draggedSurface.create(asset->getWidth(), asset->getHeight(), _screen.format); @@ -953,21 +946,17 @@ bool Gui::canBeSelected(ObjID obj, const Common::Event &event, const Common::Rec } bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) { - if (_assets.contains(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; + ensureAssetLoaded(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()); + + return _assets[obj]->isRectInside(intersection); } void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point click) { @@ -1142,9 +1131,7 @@ bool Gui::tryCloseWindow(WindowReference winID) { } Common::Point Gui::getObjMeasures(ObjID obj) { - if (!_assets.contains(obj)) { - _assets[obj] = new ImageAsset(obj, _graphics); - } + ensureAssetLoaded(obj); uint w = _assets[obj]->getWidth(); uint h = _assets[obj]->getHeight(); return Common::Point(w, h); @@ -1313,6 +1300,12 @@ void Gui::handleDoubleClick(Common::Point pos) { handleDragRelease(pos, false, true); } +void Gui::ensureAssetLoaded(ObjID obj) { + if (!_assets.contains(obj)) { + _assets[obj] = new ImageAsset(obj, _graphics); + } +} + /* Ugly switches */ BorderBounds Gui::borderBounds(MVWindowType type) { diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index 65f2ec5fdb..a44813511c 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -323,6 +323,8 @@ private: // Methods Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); + void ensureAssetLoaded(ObjID obj); + }; class Cursor { -- cgit v1.2.3