comparison src/video/SDL_video.c @ 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 27d8b12e0e8e
children bd518fc76f28
comparison
equal deleted inserted replaced
2911:45664f0e5f68 2912:1d50666ed3d5
2203 real_dstrect.h = window->h; 2203 real_dstrect.h = window->h;
2204 if (dstrect) { 2204 if (dstrect) {
2205 if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) { 2205 if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
2206 return 0; 2206 return 0;
2207 } 2207 }
2208 /* Clip srcrect by the same amount as dstrect was clipped */
2209 if (dstrect->w != real_dstrect.w) {
2210 int deltax = (real_dstrect.x - dstrect->x);
2211 int deltaw = (real_dstrect.w - dstrect->w);
2212 real_srcrect.x += (deltax * dstrect->w) / real_srcrect.w;
2213 real_srcrect.w += (deltaw * dstrect->w) / real_srcrect.w;
2214 }
2215 if (dstrect->h != real_dstrect.h) {
2216 int deltay = (real_dstrect.y - dstrect->y);
2217 int deltah = (real_dstrect.h - dstrect->h);
2218 real_srcrect.y += (deltay * dstrect->h) / real_srcrect.h;
2219 real_srcrect.h += (deltah * dstrect->h) / real_srcrect.h;
2220 }
2208 } 2221 }
2209 2222
2210 return renderer->RenderCopy(renderer, texture, &real_srcrect, 2223 return renderer->RenderCopy(renderer, texture, &real_srcrect,
2211 &real_dstrect); 2224 &real_dstrect);
2212 } 2225 }