src/render/SDL_render.c
changeset 8728 c7174f961388
parent 8654 275c4c82803b
child 9078 230e7558f76a
equal deleted inserted replaced
8726:9a5a5808aa14 8728:c7174f961388
  1069 
  1069 
  1070     if (texture && !renderer->target) {
  1070     if (texture && !renderer->target) {
  1071         /* Make a backup of the viewport */
  1071         /* Make a backup of the viewport */
  1072         renderer->viewport_backup = renderer->viewport;
  1072         renderer->viewport_backup = renderer->viewport;
  1073         renderer->clip_rect_backup = renderer->clip_rect;
  1073         renderer->clip_rect_backup = renderer->clip_rect;
       
  1074         renderer->clipping_enabled_backup = renderer->clipping_enabled;
  1074         renderer->scale_backup = renderer->scale;
  1075         renderer->scale_backup = renderer->scale;
  1075         renderer->logical_w_backup = renderer->logical_w;
  1076         renderer->logical_w_backup = renderer->logical_w;
  1076         renderer->logical_h_backup = renderer->logical_h;
  1077         renderer->logical_h_backup = renderer->logical_h;
  1077     }
  1078     }
  1078     renderer->target = texture;
  1079     renderer->target = texture;
  1091         renderer->logical_w = texture->w;
  1092         renderer->logical_w = texture->w;
  1092         renderer->logical_h = texture->h;
  1093         renderer->logical_h = texture->h;
  1093     } else {
  1094     } else {
  1094         renderer->viewport = renderer->viewport_backup;
  1095         renderer->viewport = renderer->viewport_backup;
  1095         renderer->clip_rect = renderer->clip_rect_backup;
  1096         renderer->clip_rect = renderer->clip_rect_backup;
       
  1097         renderer->clipping_enabled = renderer->clipping_enabled_backup;
  1096         renderer->scale = renderer->scale_backup;
  1098         renderer->scale = renderer->scale_backup;
  1097         renderer->logical_w = renderer->logical_w_backup;
  1099         renderer->logical_w = renderer->logical_w_backup;
  1098         renderer->logical_h = renderer->logical_h_backup;
  1100         renderer->logical_h = renderer->logical_h_backup;
  1099     }
  1101     }
  1100     if (renderer->UpdateViewport(renderer) < 0) {
  1102     if (renderer->UpdateViewport(renderer) < 0) {
  1231 SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
  1233 SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
  1232 {
  1234 {
  1233     CHECK_RENDERER_MAGIC(renderer, -1)
  1235     CHECK_RENDERER_MAGIC(renderer, -1)
  1234 
  1236 
  1235     if (rect) {
  1237     if (rect) {
       
  1238         renderer->clipping_enabled = SDL_TRUE;
  1236         renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
  1239         renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
  1237         renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
  1240         renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
  1238         renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
  1241         renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x);
  1239         renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
  1242         renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y);
  1240     } else {
  1243     } else {
       
  1244         renderer->clipping_enabled = SDL_FALSE;
  1241         SDL_zero(renderer->clip_rect);
  1245         SDL_zero(renderer->clip_rect);
  1242     }
  1246     }
  1243     return renderer->UpdateClipRect(renderer);
  1247     return renderer->UpdateClipRect(renderer);
  1244 }
  1248 }
  1245 
  1249 
  1252         rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
  1256         rect->x = (int)(renderer->clip_rect.x / renderer->scale.x);
  1253         rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
  1257         rect->y = (int)(renderer->clip_rect.y / renderer->scale.y);
  1254         rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
  1258         rect->w = (int)(renderer->clip_rect.w / renderer->scale.x);
  1255         rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
  1259         rect->h = (int)(renderer->clip_rect.h / renderer->scale.y);
  1256     }
  1260     }
       
  1261 }
       
  1262 
       
  1263 SDL_bool
       
  1264 SDL_RenderIsClipEnabled(SDL_Renderer * renderer)
       
  1265 {
       
  1266     CHECK_RENDERER_MAGIC(renderer, SDL_FALSE)
       
  1267     return renderer->clipping_enabled;
  1257 }
  1268 }
  1258 
  1269 
  1259 int
  1270 int
  1260 SDL_RenderSetScale(SDL_Renderer * renderer, float scaleX, float scaleY)
  1271 SDL_RenderSetScale(SDL_Renderer * renderer, float scaleX, float scaleY)
  1261 {
  1272 {