From 4c57aa04c28e76372464f45fc2c722c7c568b08f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 23 Dec 2008 04:51:36 +0000 Subject: [PATCH] Fixed clipping source rect to match destination rect clipping --- src/video/SDL_video.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8a76e9ee4..ebec773b0 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2205,6 +2205,19 @@ SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, 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,