From f285e384da6efb992bfc705c32eba44cf3255564 Mon Sep 17 00:00:00 2001 From: Tarek Soliman Date: Fri, 12 Jan 2018 22:43:00 -0600 Subject: [PATCH] GRAPHICS: Fix rounding error when using non-integral scaling When a non-integral scaling was being used, x and/or y cursor position would be one less than what it should be. Fixes Trac#10401 Thanks snover! --- backends/graphics/windowed.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backends/graphics/windowed.h b/backends/graphics/windowed.h index 1d4958c9d68..5f89d2d233e 100644 --- a/backends/graphics/windowed.h +++ b/backends/graphics/windowed.h @@ -94,8 +94,8 @@ protected: error("convertVirtualToWindow called without a valid draw rect"); } - return Common::Point(targetX + x * targetWidth / sourceWidth, - targetY + y * targetHeight / sourceHeight); + return Common::Point(targetX + (x * targetWidth + sourceWidth / 2) / sourceWidth, + targetY + (y * targetHeight + sourceHeight / 2) / sourceHeight); } /** @@ -120,8 +120,8 @@ protected: x = CLIP(x, sourceX, sourceMaxX); y = CLIP(y, sourceY, sourceMaxY); - return Common::Point(((x - sourceX) * targetWidth) / sourceWidth, - ((y - sourceY) * targetHeight) / sourceHeight); + return Common::Point(((x - sourceX) * targetWidth + sourceWidth / 2) / sourceWidth, + ((y - sourceY) * targetHeight + sourceHeight / 2) / sourceHeight); } /**