Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed clipping source rect to match destination rect clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 23, 2008
1 parent eafc931 commit 4c57aa0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -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,
Expand Down

0 comments on commit 4c57aa0

Please sign in to comment.