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!
This commit is contained in:
Tarek Soliman 2018-01-12 22:43:00 -06:00
parent 531467581f
commit f285e384da

View file

@ -94,8 +94,8 @@ protected:
error("convertVirtualToWindow called without a valid draw rect"); error("convertVirtualToWindow called without a valid draw rect");
} }
return Common::Point(targetX + x * targetWidth / sourceWidth, return Common::Point(targetX + (x * targetWidth + sourceWidth / 2) / sourceWidth,
targetY + y * targetHeight / sourceHeight); targetY + (y * targetHeight + sourceHeight / 2) / sourceHeight);
} }
/** /**
@ -120,8 +120,8 @@ protected:
x = CLIP<int>(x, sourceX, sourceMaxX); x = CLIP<int>(x, sourceX, sourceMaxX);
y = CLIP<int>(y, sourceY, sourceMaxY); y = CLIP<int>(y, sourceY, sourceMaxY);
return Common::Point(((x - sourceX) * targetWidth) / sourceWidth, return Common::Point(((x - sourceX) * targetWidth + sourceWidth / 2) / sourceWidth,
((y - sourceY) * targetHeight) / sourceHeight); ((y - sourceY) * targetHeight + sourceHeight / 2) / sourceHeight);
} }
/** /**