summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2004-11-13 16:10:25 +0000
committertron <tron@openttd.org>2004-11-13 16:10:25 +0000
commitb5e1240a8a53b99be29492b6f0136f6f4d71d9a0 (patch)
treec601adcb12ff32797b1065f25fa1097289a87e25
parentb8327e0457a8f40d98a8bd5a6889166d4a4afd02 (diff)
downloadopenttd-b5e1240a8a53b99be29492b6f0136f6f4d71d9a0.tar.xz
(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()
-rw-r--r--gfx.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/gfx.c b/gfx.c
index aa208b7fc..449f5aa1a 100644
--- a/gfx.c
+++ b/gfx.c
@@ -44,9 +44,9 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
p = _screen.pitch;
- if (yo > 0 || (yo == 0 && xo > 0)) {
+ if (yo > 0) {
// Calculate pointers
- dst = _screen.dst_ptr + (top+height-1) * p + (left+width-1);
+ dst = _screen.dst_ptr + (top + height - 1) * p + left;
src = dst - yo * p;
// Decrease height and increase top
@@ -56,31 +56,21 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
// Adjust left & width
if (xo >= 0) {
+ dst += xo;
left += xo;
- src -= xo;
width -= xo;
} else {
- dst += xo;
+ src -= xo;
width += xo;
}
- // Offset pointers to fit into the memmove call
- dst += -width + 1;
- src += -width + 1;
- ht = height;
-
- do {
- memmove(dst, src, width);
+ for (ht = height; ht > 0; --ht) {
+ memcpy(dst, src, width);
src -= p;
dst -= p;
- } while (--ht);
-
-
- // This part of the screen is now dirty.
- _video_driver->make_dirty(left, top, width, height);
-
+ }
} else {
- // Calculate pointers to mem.
+ // Calculate pointers
dst = _screen.dst_ptr + top * p + left;
src = dst - yo * p;
@@ -98,17 +88,16 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
width += xo;
}
- ht = height;
-
- do {
- memcpy(dst, src, width);
+ // the y-displacement may be 0 therefore we have to use memmove,
+ // because source and destination may overlap
+ for (ht = height; ht > 0; --ht) {
+ memmove(dst, src, width);
src += p;
dst += p;
- } while (--ht);
-
- // This part of the screen is now dirty.
- _video_driver->make_dirty(left, top, width, height);
+ }
}
+ // This part of the screen is now dirty.
+ _video_driver->make_dirty(left, top, width, height);
}