aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mohawk/graphics.cpp')
-rw-r--r--engines/mohawk/graphics.cpp47
1 files changed, 34 insertions, 13 deletions
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp
index bcb3e44148..8ffbe2f81b 100644
--- a/engines/mohawk/graphics.cpp
+++ b/engines/mohawk/graphics.cpp
@@ -790,29 +790,41 @@ void LBGraphics::preloadImage(uint16 image) {
void LBGraphics::copyImageToScreen(uint16 image, bool useOffsets, int left, int top) {
MohawkSurface *mhkSurface = findImage(image);
+ Graphics::Surface *surface = mhkSurface->getSurface();
if (useOffsets) {
left -= mhkSurface->getOffsetX();
top -= mhkSurface->getOffsetY();
}
+ Common::Rect srcRect(0, 0, surface->w, surface->h);
+ Common::Rect dstRect(left, top, left + surface->w, top + surface->h);
+ copyImageSectionToScreen(image, srcRect, dstRect);
+}
+
+void LBGraphics::copyImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
+ MohawkSurface *mhkSurface = findImage(image);
+
uint16 startX = 0;
uint16 startY = 0;
+ assert(srcRect.isValidRect() && dstRect.isValidRect());
+ assert(srcRect.left >= 0 && srcRect.top >= 0);
+
// TODO: clip rect
- if (left < 0) {
- startX -= left;
- left = 0;
+ if (dstRect.left < 0) {
+ startX -= dstRect.left;
+ dstRect.left = 0;
}
- if (top < 0) {
- startY -= top;
- top = 0;
+ if (dstRect.top < 0) {
+ startY -= dstRect.top;
+ dstRect.top = 0;
}
- if (left >= _vm->_system->getWidth())
+ if (dstRect.left >= _vm->_system->getWidth())
return;
- if (top >= _vm->_system->getHeight())
+ if (dstRect.top >= _vm->_system->getHeight())
return;
Graphics::Surface *surface = mhkSurface->getSurface();
@@ -821,16 +833,25 @@ void LBGraphics::copyImageToScreen(uint16 image, bool useOffsets, int left, int
if (startY >= surface->h)
return;
- uint16 width = MIN<int>(surface->w - startX, _vm->_system->getWidth() - left);
- uint16 height = MIN<int>(surface->h - startY, _vm->_system->getHeight() - top);
+ if (srcRect.left > surface->w)
+ return;
+ if (srcRect.top > surface->h)
+ return;
+ if (srcRect.right > surface->w)
+ srcRect.right = surface->w;
+ if (srcRect.bottom > surface->h)
+ srcRect.bottom = surface->h;
+
+ uint16 width = MIN<int>(srcRect.right - srcRect.left - startX, _vm->_system->getWidth() - dstRect.left);
+ uint16 height = MIN<int>(srcRect.bottom - srcRect.top - startY, _vm->_system->getHeight() - dstRect.top);
- byte *surf = (byte *)surface->getBasePtr(0, startY);
+ byte *surf = (byte *)surface->getBasePtr(0, srcRect.top + startY);
Graphics::Surface *screen = _vm->_system->lockScreen();
// image and screen are always 8bpp for LB
for (uint16 y = 0; y < height; y++) {
- byte *dest = (byte *)screen->getBasePtr(left, top + y);
- byte *src = surf + startX;
+ byte *dest = (byte *)screen->getBasePtr(dstRect.left, dstRect.top + y);
+ byte *src = surf + srcRect.left + startX;
// blit, with 0 being transparent
for (uint16 x = 0; x < width; x++) {
if (*src)