changeset 2912:1d50666ed3d5

Fixed clipping source rect to match destination rect clipping
author Sam Lantinga <slouken@libsdl.org>
date Tue, 23 Dec 2008 04:51:36 +0000
parents 45664f0e5f68
children ffae53de58f4
files src/video/SDL_video.c
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_video.c	Tue Dec 23 02:39:03 2008 +0000
+++ b/src/video/SDL_video.c	Tue Dec 23 04:51:36 2008 +0000
@@ -2205,6 +2205,19 @@
         if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
             return 0;
         }
+        /* Clip srcrect by the same amount as dstrect was clipped */
+        if (dstrect->w != real_dstrect.w) {
+            int deltax = (real_dstrect.x - dstrect->x);
+            int deltaw = (real_dstrect.w - dstrect->w);
+            real_srcrect.x += (deltax * dstrect->w) / real_srcrect.w;
+            real_srcrect.w += (deltaw * dstrect->w) / real_srcrect.w;
+        }
+        if (dstrect->h != real_dstrect.h) {
+            int deltay = (real_dstrect.y - dstrect->y);
+            int deltah = (real_dstrect.h - dstrect->h);
+            real_srcrect.y += (deltay * dstrect->h) / real_srcrect.h;
+            real_srcrect.h += (deltah * dstrect->h) / real_srcrect.h;
+        }
     }
 
     return renderer->RenderCopy(renderer, texture, &real_srcrect,