diff options
author | Paul Gilbert | 2014-04-21 19:12:28 -0400 |
---|---|---|
committer | Paul Gilbert | 2014-04-21 19:12:28 -0400 |
commit | ff70186855bec22fe77043d89917b189218ff856 (patch) | |
tree | 66825eebb4ced6fa945596387717672a676ebd81 /engines/mads | |
parent | 0e6c4abd13e7bea64ce36537cc8c4ebb03ccfbfc (diff) | |
download | scummvm-rg350-ff70186855bec22fe77043d89917b189218ff856.tar.gz scummvm-rg350-ff70186855bec22fe77043d89917b189218ff856.tar.bz2 scummvm-rg350-ff70186855bec22fe77043d89917b189218ff856.zip |
MADS: Improve background user interface sprite animations
Diffstat (limited to 'engines/mads')
-rw-r--r-- | engines/mads/msurface.cpp | 44 | ||||
-rw-r--r-- | engines/mads/msurface.h | 8 | ||||
-rw-r--r-- | engines/mads/user_interface.cpp | 49 | ||||
-rw-r--r-- | engines/mads/user_interface.h | 11 |
4 files changed, 58 insertions, 54 deletions
diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp index 75aad01ee1..2c9d093877 100644 --- a/engines/mads/msurface.cpp +++ b/engines/mads/msurface.cpp @@ -418,50 +418,6 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth, } } -void MSurface::mergeFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos) { - // Validation of the rectangle and position - int destX = destPos.x, destY = destPos.y; - if ((destX >= w) || (destY >= h)) - return; - - Common::Rect copyRect = srcBounds; - if (destX < 0) { - copyRect.left += -destX; - destX = 0; - } - else if (destX + copyRect.width() > w) { - copyRect.right -= destX + copyRect.width() - w; - } - if (destY < 0) { - copyRect.top += -destY; - destY = 0; - } - else if (destY + copyRect.height() > h) { - copyRect.bottom -= destY + copyRect.height() - h; - } - - if (!copyRect.isValidRect()) - return; - - // Copy the specified area - - byte *data = src->getData(); - byte *srcPtr = data + (src->getWidth() * copyRect.top + copyRect.left); - byte *destPtr = (byte *)pixels + (destY * getWidth()) + destX; - - for (int rowCtr = 0; rowCtr < copyRect.height(); ++rowCtr) { - // Process each line of the area - for (int xCtr = 0; xCtr < copyRect.width(); ++xCtr) { - // Check for the range used for on-screen text, which should be kept intact - if (srcPtr[xCtr] < 8 || srcPtr[xCtr] > 15) - destPtr[xCtr] = srcPtr[xCtr]; - } - - srcPtr += src->getWidth(); - destPtr += getWidth(); - } -} - void MSurface::scrollX(int xAmount) { if (xAmount == 0) return; diff --git a/engines/mads/msurface.h b/engines/mads/msurface.h index f590bac2e5..7cf2bbe15b 100644 --- a/engines/mads/msurface.h +++ b/engines/mads/msurface.h @@ -188,14 +188,6 @@ public: } /** - * Merges a sub-section of another surface into the current one. - * @param src Source surface - * @param srcBounds Area to copy/merge from - * @param destPos Destination position to draw in current surface - */ - void mergeFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos); - - /** * Scroll the screen horizontally by a given amount * @param xAmount Horizontal amount */ diff --git a/engines/mads/user_interface.cpp b/engines/mads/user_interface.cpp index a5e8a844f9..f775e459b5 100644 --- a/engines/mads/user_interface.cpp +++ b/engines/mads/user_interface.cpp @@ -162,10 +162,12 @@ void UISlots::draw(bool updateFlag, bool delFlag) { if (flipped) { MSurface *spr = sprite->flipHorizontal(); - spr->copyTo(&userInterface, slot._position, sprite->getTransparencyIndex()); + userInterface.mergeFrom(spr, spr->getBounds(), slot._position, + sprite->getTransparencyIndex()); delete spr; } else { - sprite->copyTo(&userInterface, slot._position, sprite->getTransparencyIndex()); + userInterface.mergeFrom(sprite, sprite->getBounds(), slot._position, + sprite->getTransparencyIndex()); } } } @@ -407,6 +409,49 @@ void UserInterface::drawTextElements() { } } +void UserInterface::mergeFrom(MSurface *src, const Common::Rect &srcBounds, + const Common::Point &destPos, int transparencyIndex) { + // Validation of the rectangle and position + int destX = destPos.x, destY = destPos.y; + if ((destX >= w) || (destY >= h)) + return; + + Common::Rect copyRect = srcBounds; + if (destX < 0) { + copyRect.left += -destX; + destX = 0; + } else if (destX + copyRect.width() > w) { + copyRect.right -= destX + copyRect.width() - w; + } + if (destY < 0) { + copyRect.top += -destY; + destY = 0; + } else if (destY + copyRect.height() > h) { + copyRect.bottom -= destY + copyRect.height() - h; + } + + if (!copyRect.isValidRect()) + return; + + // Copy the specified area + + byte *data = src->getData(); + byte *srcPtr = data + (src->getWidth() * copyRect.top + copyRect.left); + byte *destPtr = (byte *)this->pixels + (destY * getWidth()) + destX; + + for (int rowCtr = 0; rowCtr < copyRect.height(); ++rowCtr) { + // Process each line of the area + for (int xCtr = 0; xCtr < copyRect.width(); ++xCtr) { + // Check for the range used for on-screen text, which should be kept intact + if ((destPtr[xCtr] >= 8 && destPtr[xCtr] <= 15) && (int)srcPtr[xCtr] != transparencyIndex) + destPtr[xCtr] = srcPtr[xCtr]; + } + + srcPtr += src->getWidth(); + destPtr += getWidth(); + } +} + void UserInterface::drawActions() { for (int idx = 0; idx < 10; ++idx) { writeVocab(CAT_COMMAND, idx); diff --git a/engines/mads/user_interface.h b/engines/mads/user_interface.h index 7541bb8661..a29a0e6de0 100644 --- a/engines/mads/user_interface.h +++ b/engines/mads/user_interface.h @@ -229,6 +229,17 @@ public: void drawTextElements(); /** + * Merges a sub-section of another surface into the user interface without + * destroying any on-screen text + * @param src Source surface + * @param srcBounds Area to copy/merge from + * @param destPos Destination position to draw in current surface + * @param transparencyIndex Transparency color + */ + void mergeFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos, + int transparencyIndex = -1); + + /** * Loads the animation sprite data for a given inventory object */ void loadInventoryAnim(int objectId); |