From ddd691e2d3c02f9b1dfcaafd2239a4a04a7996a3 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Wed, 1 Dec 2010 18:21:17 +0000 Subject: MOHAWK: add LBGraphics::copyImageSectionToScreen svn-id: r54707 --- engines/mohawk/graphics.cpp | 47 ++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'engines/mohawk/graphics.cpp') 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(surface->w - startX, _vm->_system->getWidth() - left); - uint16 height = MIN(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(srcRect.right - srcRect.left - startX, _vm->_system->getWidth() - dstRect.left); + uint16 height = MIN(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) -- cgit v1.2.3