Experiment to try to account for source clipping
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 23:16:58 -0800
changeset 5368f0ee2c086931
parent 5367 71fe70373e58
child 5369 e049a7b85fd1
Experiment to try to account for source clipping
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Sun Feb 20 20:49:31 2011 -0800
     1.2 +++ b/src/render/SDL_render.c	Sun Feb 20 23:16:58 2011 -0800
     1.3 @@ -999,6 +999,7 @@
     1.4  {
     1.5      SDL_Window *window;
     1.6      SDL_Rect real_srcrect;
     1.7 +    SDL_Rect clip_dstrect;
     1.8      SDL_Rect real_dstrect;
     1.9  
    1.10      CHECK_RENDERER_MAGIC(renderer, -1);
    1.11 @@ -1010,6 +1011,16 @@
    1.12      }
    1.13      window = renderer->window;
    1.14  
    1.15 +    if (dstrect) {
    1.16 +        clip_dstrect = *dstrect;
    1.17 +    } else {
    1.18 +        clip_dstrect.x = 0;
    1.19 +        clip_dstrect.y = 0;
    1.20 +        clip_dstrect.w = renderer->viewport.w;
    1.21 +        clip_dstrect.h = renderer->viewport.h;
    1.22 +    }
    1.23 +    dstrect = &clip_dstrect;
    1.24 +
    1.25      real_srcrect.x = 0;
    1.26      real_srcrect.y = 0;
    1.27      real_srcrect.w = texture->w;
    1.28 @@ -1018,29 +1029,40 @@
    1.29          if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
    1.30              return 0;
    1.31          }
    1.32 +        /* Clip dstrect by the same amount as srcrect was clipped */
    1.33 +        if (srcrect->w != real_srcrect.w) {
    1.34 +            int deltax = (real_srcrect.x - srcrect->x);
    1.35 +            int deltaw = (real_srcrect.w - srcrect->w);
    1.36 +            clip_dstrect.x += (deltax * clip_dstrect.w) / srcrect->w;
    1.37 +            clip_dstrect.w += (deltaw * clip_dstrect.w) / srcrect->w;
    1.38 +        }
    1.39 +        if (srcrect->h != real_srcrect.h) {
    1.40 +            int deltay = (real_srcrect.y - srcrect->y);
    1.41 +            int deltah = (real_srcrect.h - srcrect->h);
    1.42 +            clip_dstrect.y += (deltay * clip_dstrect.h) / srcrect->h;
    1.43 +            clip_dstrect.h += (deltah * clip_dstrect.h) / srcrect->h;
    1.44 +        }
    1.45      }
    1.46  
    1.47      real_dstrect.x = 0;
    1.48      real_dstrect.y = 0;
    1.49      real_dstrect.w = renderer->viewport.w;
    1.50      real_dstrect.h = renderer->viewport.h;
    1.51 -    if (dstrect) {
    1.52 -        if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
    1.53 -            return 0;
    1.54 -        }
    1.55 -        /* Clip srcrect by the same amount as dstrect was clipped */
    1.56 -        if (dstrect->w != real_dstrect.w) {
    1.57 -            int deltax = (real_dstrect.x - dstrect->x);
    1.58 -            int deltaw = (real_dstrect.w - dstrect->w);
    1.59 -            real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
    1.60 -            real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
    1.61 -        }
    1.62 -        if (dstrect->h != real_dstrect.h) {
    1.63 -            int deltay = (real_dstrect.y - dstrect->y);
    1.64 -            int deltah = (real_dstrect.h - dstrect->h);
    1.65 -            real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
    1.66 -            real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
    1.67 -        }
    1.68 +    if (!SDL_IntersectRect(&clip_dstrect, &real_dstrect, &real_dstrect)) {
    1.69 +        return 0;
    1.70 +    }
    1.71 +    /* Clip srcrect by the same amount as dstrect was clipped */
    1.72 +    if (dstrect->w != real_dstrect.w) {
    1.73 +        int deltax = (real_dstrect.x - dstrect->x);
    1.74 +        int deltaw = (real_dstrect.w - dstrect->w);
    1.75 +        real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
    1.76 +        real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
    1.77 +    }
    1.78 +    if (dstrect->h != real_dstrect.h) {
    1.79 +        int deltay = (real_dstrect.y - dstrect->y);
    1.80 +        int deltah = (real_dstrect.h - dstrect->h);
    1.81 +        real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
    1.82 +        real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
    1.83      }
    1.84  
    1.85      if (texture->native) {