Windows: drawing artifacts with non-integer scale factors

We found drawing artifacts when moving a Component around when using HiDPI on a system that has a non-integer scale factor (i.e. Display Settings set to 175% or 125%). The problem seems to be that HWNDComponentPeer::repaint() rounds the rectangle to be invalidated rather than expanding to the smallest integer container. The following change fixes it for us:

void repaint (const Rectangle<int>& area) override
{
...
- const RECT r = { roundToInt (area.getX()     * scale), roundToInt (area.getY()      * scale),
- roundToInt (area.getRight() * scale), roundToInt (area.getBottom() * scale) };
+ Rectangle<double> scaledArea = area.toDouble() * scale;
+ const RECT r = RECTFromRectangle(scaledArea.getSmallestIntegerContainer());
    InvalidateRect (hwnd, &r, FALSE);
}

Thanks for taking a look!

1 Like

Thanks! I’ll get this onto develop.

Great, thanks!

Just want to second this. We’ve been having issues with edges of components not being properly cleaned up after a moving them around (leaving a trail of pixels), and this solved our problem.

Please do put this in develop (last time I checked it wasn’t in there yet).

This was added a while ago:

Eeeh, must’ve looked at the wrong branch or something.

Thanks! <3