Skip to content

Commit

Permalink
GRAPHICS: Fix rounding error when using non-integral scaling
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
tsoliman committed Jan 13, 2018
1 parent 5314675 commit f285e38
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backends/graphics/windowed.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class WindowedGraphicsManager : virtual public GraphicsManager {
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);
}

/**
Expand All @@ -120,8 +120,8 @@ class WindowedGraphicsManager : virtual public GraphicsManager {
x = CLIP<int>(x, sourceX, sourceMaxX);
y = CLIP<int>(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);
}

/**
Expand Down

0 comments on commit f285e38

Please sign in to comment.