src/render/SDL_render.c
changeset 7141 e276777b4247
parent 7109 003d40e446f5
child 7143 fa117b9cc89b
     1.1 --- a/src/render/SDL_render.c	Fri May 03 14:11:41 2013 +0930
     1.2 +++ b/src/render/SDL_render.c	Sat May 04 04:46:00 2013 -0700
     1.3 @@ -932,6 +932,7 @@
     1.4      if (texture && !renderer->target) {
     1.5          /* Make a backup of the viewport */
     1.6          renderer->viewport_backup = renderer->viewport;
     1.7 +        renderer->clip_rect_backup = renderer->clip_rect;
     1.8          renderer->scale_backup = renderer->scale;
     1.9          renderer->logical_w_backup = renderer->logical_w;
    1.10          renderer->logical_h_backup = renderer->logical_h;
    1.11 @@ -953,6 +954,7 @@
    1.12          renderer->logical_h = 0;
    1.13      } else {
    1.14          renderer->viewport = renderer->viewport_backup;
    1.15 +        renderer->clip_rect = renderer->clip_rect_backup;
    1.16          renderer->scale = renderer->scale_backup;
    1.17          renderer->logical_w = renderer->logical_w_backup;
    1.18          renderer->logical_h = renderer->logical_h_backup;
    1.19 @@ -960,6 +962,9 @@
    1.20      if (renderer->UpdateViewport(renderer) < 0) {
    1.21          return -1;
    1.22      }
    1.23 +    if (renderer->UpdateClipRect(renderer) < 0) {
    1.24 +        return -1;
    1.25 +    }
    1.26  
    1.27      /* All set! */
    1.28      return 0;
    1.29 @@ -1098,6 +1103,35 @@
    1.30  }
    1.31  
    1.32  int
    1.33 +SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
    1.34 +{
    1.35 +    CHECK_RENDERER_MAGIC(renderer, )
    1.36 +
    1.37 +    if (rect) {
    1.38 +        renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
    1.39 +        renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
    1.40 +        renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
    1.41 +        renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
    1.42 +    } else {
    1.43 +        SDL_zero(renderer->clip_rect);
    1.44 +    }
    1.45 +    return renderer->UpdateClipRect(renderer);
    1.46 +}
    1.47 +
    1.48 +void
    1.49 +SDL_RenderGetClipRect(SDL_Renderer * renderer, SDL_Rect * rect)
    1.50 +{
    1.51 +    CHECK_RENDERER_MAGIC(renderer, )
    1.52 +
    1.53 +    if (rect) {
    1.54 +        rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
    1.55 +        rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
    1.56 +        rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
    1.57 +        rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +int
    1.62  SDL_RenderSetScale(SDL_Renderer * renderer, float scaleX, float scaleY)
    1.63  {
    1.64      CHECK_RENDERER_MAGIC(renderer, -1);