diff --git a/Source/utils/sdl2_to_1_2_backports.cpp b/Source/utils/sdl2_to_1_2_backports.cpp index a38384d4f..1ce9ebcee 100644 --- a/Source/utils/sdl2_to_1_2_backports.cpp +++ b/Source/utils/sdl2_to_1_2_backports.cpp @@ -1,6 +1,7 @@ #include "./sdl2_to_1_2_backports.h" #include +#include #include "./console.h" @@ -447,26 +448,18 @@ int SDL_BlitScaled(SDL_Surface *src, SDL_Rect *srcrect, dst_y0 += dst->clip_rect.y; dst_y1 += dst->clip_rect.y; - final_src.x = (Sint16)SDL_floor(src_x0 + 0.5); - final_src.y = (Sint16)SDL_floor(src_y0 + 0.5); - src_w = (int)SDL_floor(src_x1 + 1 + 0.5) - (int)SDL_floor(src_x0 + 0.5); - src_h = (int)SDL_floor(src_y1 + 1 + 0.5) - (int)SDL_floor(src_y0 + 0.5); - if (src_w < 0) - src_w = 0; - if (src_h < 0) - src_h = 0; + final_src.x = static_cast(SDL_floor(src_x0 + 0.5)); + final_src.y = static_cast(SDL_floor(src_y0 + 0.5)); + src_w = std::max(static_cast(SDL_floor(src_x1 + 1 + 0.5)) - static_cast(SDL_floor(src_x0 + 0.5)), 0); + src_h = std::max(static_cast(SDL_floor(src_y1 + 1 + 0.5)) - static_cast(SDL_floor(src_y0 + 0.5)), 0); final_src.w = static_cast(src_w); final_src.h = static_cast(src_h); - final_dst.x = (Sint16)SDL_floor(dst_x0 + 0.5); - final_dst.y = (Sint16)SDL_floor(dst_y0 + 0.5); - dst_w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5); - dst_h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5); - if (dst_w < 0) - dst_w = 0; - if (dst_h < 0) - dst_h = 0; + final_dst.x = static_cast(SDL_floor(dst_x0 + 0.5)); + final_dst.y = static_cast(SDL_floor(dst_y0 + 0.5)); + dst_w = std::max(static_cast(SDL_floor(dst_x1 - dst_x0 + 1.5)), 0); + dst_h = std::max(static_cast(SDL_floor(dst_y1 - dst_y0 + 1.5)), 0); final_dst.w = static_cast(dst_w); final_dst.h = static_cast(dst_h);