From 3c11d2fa18e984d6bb024d7e9bd67eb0077cffdf Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Wed, 21 Jun 2006 11:33:04 +0000 Subject: Move moveScreen to common surface functions for graphics svn-id: r23218 --- graphics/surface.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'graphics/surface.cpp') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 6a851ae5e5..e9d52e162e 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -164,4 +164,59 @@ void Surface::frameRect(const Common::Rect &r, uint32 color) { vLine(r.right-1, r.top, r.bottom-1, color); } +void Surface::move(int dx, int dy, int height) { + // Short circuit check - do we have to do anything anyway? + if ((dx == 0 && dy == 0) || height <= 0) + return; + + byte *src, *dst; + int x, y; + + // vertical movement + if (dy > 0) { + // move down - copy from bottom to top + dst = (byte *)pixels + (height - 1) * w; + src = dst - dy * w; + for (y = dy; y < height; y++) { + memcpy(dst, src, w); + src -= w; + dst -= w; + } + } else if (dy < 0) { + // move up - copy from top to bottom + dst = (byte *)pixels; + src = dst - dy * w; + for (y = -dy; y < height; y++) { + memcpy(dst, src, w); + src += w; + dst += w; + } + } + + // horizontal movement + if (dx > 0) { + // move right - copy from right to left + dst = (byte *)pixels + (w - 1); + src = dst - dx; + for (y = 0; y < height; y++) { + for (x = dx; x < w; x++) { + *dst-- = *src--; + } + src += w + (w - dx); + dst += w + (w - dx); + } + } else if (dx < 0) { + // move left - copy from left to right + dst = (byte *)pixels; + src = dst - dx; + for (y = 0; y < height; y++) { + for (x = -dx; x < w; x++) { + *dst++ = *src++; + } + src += w - (w + dx); + dst += w - (w + dx); + } + } +} + } // End of namespace Graphics -- cgit v1.2.3