From 774773b7cd02e3c6932095af4905a25eb1862392 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Wed, 17 Dec 2008 11:15:47 +0000 Subject: Reduced code duplication when manipulating Animations, and cleanup. svn-id: r35408 --- engines/parallaction/objects.cpp | 57 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'engines/parallaction/objects.cpp') diff --git a/engines/parallaction/objects.cpp b/engines/parallaction/objects.cpp index 59e2fb0868..8cbcb293ce 100644 --- a/engines/parallaction/objects.cpp +++ b/engines/parallaction/objects.cpp @@ -57,32 +57,36 @@ Animation::~Animation() { gfxobj->release(); } -uint16 Animation::width() const { - if (!gfxobj) return 0; - Common::Rect r; +void Animation::getFrameRect(Common::Rect &r) const { + r.setWidth(0); r.setHeight(0); + if (!gfxobj) { + return; + } gfxobj->getRect(_frame, r); - return r.width(); + r.translate(_left, _top); } -uint16 Animation::height() const { - if (!gfxobj) return 0; +bool Animation::hitFrameRect(int x, int y) const { + if (!gfxobj) { + return false; + } Common::Rect r; - gfxobj->getRect(_frame, r); - return r.height(); + getFrameRect(r); + return r.contains(x, y); } -int16 Animation::getFrameX() const { - if (!gfxobj) return _left; - Common::Rect r; - gfxobj->getRect(_frame, r); - return r.left + _left; +int16 Animation::getBottom() const { + int bottom = _top; + if (gfxobj) { + Common::Rect r; + getFrameRect(r); + bottom = r.bottom; + } + return bottom; } -int16 Animation::getFrameY() const { - if (!gfxobj) return _top; - Common::Rect r; - gfxobj->getRect(_frame, r); - return r.top + _top; +void Animation::resetZ() { + setZ(getBottom()); } uint16 Animation::getFrameNum() const { @@ -90,9 +94,9 @@ uint16 Animation::getFrameNum() const { return gfxobj->getNum(); } -byte* Animation::getFrameData(uint32 index) const { +byte* Animation::getFrameData() const { if (!gfxobj) return NULL; - return gfxobj->getData(index); + return gfxobj->getData(_frame); } void Animation::validateScriptVars() { @@ -221,12 +225,13 @@ void Zone::translate(int16 x, int16 y) { _bottom += y; } -uint16 Zone::width() const { - return _right - _left; -} - -uint16 Zone::height() const { - return _bottom - _top; +bool Zone::hitRect(int x, int y) const { + // The scripts of Nippon Safes are full of invalid rectangles, used to + // provide 'special' features. + if (_right < _left || _bottom < _top) { + return false; + } + return Common::Rect(_left, _top, _right, _bottom).contains(x, y); } Dialogue::Dialogue() { -- cgit v1.2.3