Fixed clipping source rect to match destination rect clipping
authorSam Lantinga <slouken@libsdl.org>
Tue, 23 Dec 2008 04:51:36 +0000
changeset 29121d50666ed3d5
parent 2911 45664f0e5f68
child 2913 ffae53de58f4
Fixed clipping source rect to match destination rect clipping
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Tue Dec 23 02:39:03 2008 +0000
     1.2 +++ b/src/video/SDL_video.c	Tue Dec 23 04:51:36 2008 +0000
     1.3 @@ -2205,6 +2205,19 @@
     1.4          if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
     1.5              return 0;
     1.6          }
     1.7 +        /* Clip srcrect by the same amount as dstrect was clipped */
     1.8 +        if (dstrect->w != real_dstrect.w) {
     1.9 +            int deltax = (real_dstrect.x - dstrect->x);
    1.10 +            int deltaw = (real_dstrect.w - dstrect->w);
    1.11 +            real_srcrect.x += (deltax * dstrect->w) / real_srcrect.w;
    1.12 +            real_srcrect.w += (deltaw * dstrect->w) / real_srcrect.w;
    1.13 +        }
    1.14 +        if (dstrect->h != real_dstrect.h) {
    1.15 +            int deltay = (real_dstrect.y - dstrect->y);
    1.16 +            int deltah = (real_dstrect.h - dstrect->h);
    1.17 +            real_srcrect.y += (deltay * dstrect->h) / real_srcrect.h;
    1.18 +            real_srcrect.h += (deltah * dstrect->h) / real_srcrect.h;
    1.19 +        }
    1.20      }
    1.21  
    1.22      return renderer->RenderCopy(renderer, texture, &real_srcrect,