aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2014-04-19 19:20:57 -0400
committerPaul Gilbert2014-04-19 19:20:57 -0400
commit58378a0965dd2a0631973786500b0fd171b8f680 (patch)
tree61ca9fce8a0a00f0564cc7547b94c7922d0085a1
parentc4669dd2f2ec850f3a42794dbbc134febed229e2 (diff)
downloadscummvm-rg350-58378a0965dd2a0631973786500b0fd171b8f680.tar.gz
scummvm-rg350-58378a0965dd2a0631973786500b0fd171b8f680.tar.bz2
scummvm-rg350-58378a0965dd2a0631973786500b0fd171b8f680.zip
MADS: Implemented MSurface::mergeFrom method
-rw-r--r--engines/mads/msurface.cpp44
-rw-r--r--engines/mads/msurface.h8
-rw-r--r--engines/mads/user_interface.cpp3
3 files changed, 53 insertions, 2 deletions
diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp
index 2c9d093877..75aad01ee1 100644
--- a/engines/mads/msurface.cpp
+++ b/engines/mads/msurface.cpp
@@ -418,6 +418,50 @@ 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 7cf2bbe15b..f590bac2e5 100644
--- a/engines/mads/msurface.h
+++ b/engines/mads/msurface.h
@@ -188,6 +188,14 @@ 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 7b12ef4941..52b466a0aa 100644
--- a/engines/mads/user_interface.cpp
+++ b/engines/mads/user_interface.cpp
@@ -108,8 +108,7 @@ void UISlots::draw(bool updateFlag, bool delFlag) {
if (slot._flags >= IMG_ERASE) {
// Merge area
- error("TODO: Create a sprite merge method");
- userInterface._surface.copyTo(&userInterface, dirtyArea._bounds,
+ userInterface.mergeFrom(&userInterface._surface, dirtyArea._bounds,
Common::Point(dirtyArea._bounds.left, dirtyArea._bounds.top));
} else {
// Copy area