1
0
Fork 0

(svn r564) Simplify scroll logic and correct one erroneous use of memcpy()

release/0.4.5
tron 2004-11-13 16:10:25 +00:00
parent b8327e0457
commit b5e1240a8a
1 changed files with 15 additions and 26 deletions

39
gfx.c
View File

@ -44,9 +44,9 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
p = _screen.pitch; p = _screen.pitch;
if (yo > 0 || (yo == 0 && xo > 0)) { if (yo > 0) {
// Calculate pointers // 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; src = dst - yo * p;
// Decrease height and increase top // 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 // Adjust left & width
if (xo >= 0) { if (xo >= 0) {
dst += xo;
left += xo; left += xo;
src -= xo;
width -= xo; width -= xo;
} else { } else {
dst += xo; src -= xo;
width += xo; width += xo;
} }
// Offset pointers to fit into the memmove call for (ht = height; ht > 0; --ht) {
dst += -width + 1; memcpy(dst, src, width);
src += -width + 1;
ht = height;
do {
memmove(dst, src, width);
src -= p; src -= p;
dst -= p; dst -= p;
} while (--ht); }
// This part of the screen is now dirty.
_video_driver->make_dirty(left, top, width, height);
} else { } else {
// Calculate pointers to mem. // Calculate pointers
dst = _screen.dst_ptr + top * p + left; dst = _screen.dst_ptr + top * p + left;
src = dst - yo * p; src = dst - yo * p;
@ -98,18 +88,17 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo) {
width += xo; width += xo;
} }
ht = height; // the y-displacement may be 0 therefore we have to use memmove,
// because source and destination may overlap
do { for (ht = height; ht > 0; --ht) {
memcpy(dst, src, width); memmove(dst, src, width);
src += p; src += p;
dst += p; dst += p;
} while (--ht); }
}
// This part of the screen is now dirty. // This part of the screen is now dirty.
_video_driver->make_dirty(left, top, width, height); _video_driver->make_dirty(left, top, width, height);
} }
}
void GfxFillRect(int left, int top, int right, int bottom, int color) { void GfxFillRect(int left, int top, int right, int bottom, int color) {