diff options
Diffstat (limited to 'engines/sherlock')
-rw-r--r-- | engines/sherlock/graphics.cpp | 71 | ||||
-rw-r--r-- | engines/sherlock/graphics.h | 2 | ||||
-rw-r--r-- | engines/sherlock/user_interface.cpp | 2 |
3 files changed, 51 insertions, 24 deletions
diff --git a/engines/sherlock/graphics.cpp b/engines/sherlock/graphics.cpp index 1a0144bc4b..306ff23548 100644 --- a/engines/sherlock/graphics.cpp +++ b/engines/sherlock/graphics.cpp @@ -85,9 +85,15 @@ void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt) { */ void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt, const Common::Rect &srcBounds) { - addDirtyRect(Common::Rect(pt.x, pt.y, pt.x + srcBounds.width(), - pt.y + srcBounds.height())); - copyRectToSurface(src, pt.x, pt.y, srcBounds); + Common::Rect destRect(pt.x, pt.y, pt.x + srcBounds.width(), + pt.y + srcBounds.height()); + Common::Rect srcRect = srcBounds; + + if (clip(srcRect, destRect)) { + // Surface is at least partially or completely on-screen + addDirtyRect(destRect); + copyRectToSurface(src, destRect.left, destRect.top, srcRect); + } } /** @@ -104,32 +110,18 @@ void Surface::transBlitFrom(const ImageFrame &src, const Common::Point &pt, void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &pt, bool flipped, int overrideColor) { Common::Rect drawRect(0, 0, src.w, src.h); - Common::Point destPt = pt; - - if (destPt.x < 0) { - drawRect.left += -destPt.x; - destPt.x = 0; - } - if (destPt.y < 0) { - drawRect.top += -destPt.y; - destPt.y = 0; - } - int right = destPt.x + src.w; - if (right > this->w) { - drawRect.right -= (right - this->w); - } - int bottom = destPt.y + src.h; - if (bottom > this->h) { - drawRect.bottom -= (bottom - this->h); - } - - if (!drawRect.isValidRect()) + Common::Rect destRect(pt.x, pt.y, pt.x + src.w, pt.y + src.h); + + // Clip the display area to on-screen + if (!clip(drawRect, destRect)) + // It's completely off-screen return; if (flipped) drawRect = Common::Rect(src.w - drawRect.right, src.h - drawRect.bottom, src.w - drawRect.left, src.h - drawRect.top); + Common::Point destPt(destRect.left, destRect.top); addDirtyRect(Common::Rect(destPt.x, destPt.y, destPt.x + drawRect.width(), destPt.y + drawRect.height())); @@ -169,4 +161,37 @@ Surface Surface::getSubArea(const Common::Rect &r) { return Surface(*this, r); } +/** + * Clips the given source bounds so the passed destBounds will be entirely on-screen + */ +bool Surface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) { + if (destBounds.left >= this->w || destBounds.top >= this->h || + destBounds.right <= 0 || destBounds.bottom <= 0) + return false; + + // Clip the bounds if necessary to fit on-screen + if (destBounds.right > this->w) { + srcBounds.right -= destBounds.right - this->w; + destBounds.right = this->w; + } + + if (destBounds.bottom > this->h) { + srcBounds.bottom -= destBounds.bottom - this->h; + destBounds.bottom = this->h; + } + + if (destBounds.top < 0) { + srcBounds.top += -destBounds.top; + destBounds.top = 0; + } + + if (destBounds.left < 0) { + srcBounds.left += -destBounds.left; + destBounds.left = 0; + } + + return true; +} + + } // End of namespace Sherlock diff --git a/engines/sherlock/graphics.h b/engines/sherlock/graphics.h index c380d805b2..b54dc1ec37 100644 --- a/engines/sherlock/graphics.h +++ b/engines/sherlock/graphics.h @@ -32,6 +32,8 @@ namespace Sherlock { class Surface : public Graphics::Surface { private: bool _freePixels; + + bool clip(Common::Rect &srcBounds, Common::Rect &destBounds); protected: virtual void addDirtyRect(const Common::Rect &r) {} diff --git a/engines/sherlock/user_interface.cpp b/engines/sherlock/user_interface.cpp index 54c1f8e0fc..61933cf9f3 100644 --- a/engines/sherlock/user_interface.cpp +++ b/engines/sherlock/user_interface.cpp @@ -257,7 +257,7 @@ void UserInterface::handleInput() { if (!events._released) lookScreen(pt); } else { - personFound = scene._bgShapes[_bgFound]._aType == PERSON && _bgFound != -1; + personFound = _bgFound != -1 && scene._bgShapes[_bgFound]._aType == PERSON; } if (events._released && personFound) |