Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ public static Rectangle pixelToPoint(Rectangle rect, int zoom) {
}

public static Rectangle pixelToPointWithSufficientlyLargeSize(Rectangle rect, int zoom) {
return pixelToPoint(rect, zoom, RoundingMode.UP);
if (zoom == 100 || rect == null) return rect;

Point scaledTopLeft = pixelToPoint(new Point(rect.x, rect.y), zoom, RoundingMode.DOWN);
Point scaledBottomRight = pixelToPoint(new Point(rect.x + rect.width, rect.y + rect.height), zoom, RoundingMode.UP);
Comment on lines +183 to +184
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation can lead to an unintended overcalculation. In addition, it does not consider input rectangles already being at floating-point precision, for which an exact conversion was done before this change.
Can't we solve the issue at the root (inside the pixelToPoint method), which already seems to yield unexpected results when using rounding mode "up". E.g., the scaledBottomRight calculation may incorporate the rounding mode with something like Point.OfFloat.from(pixelToPoint(floatRect.getBottomRight(), zoom, sizeRounding)).
Also note that the pixelToPoint calculation does some internal rounding (calculating based on rounded values instead of the float-based values and rounding afterwards) because everything else broke one case or another.

It would also be good to isolate this change from further changes, such as consumers of this method.

return new Rectangle(scaledTopLeft.x, scaledTopLeft.y,
scaledBottomRight.x - scaledTopLeft.x,
scaledBottomRight.y - scaledTopLeft.y);
}

private static Rectangle pixelToPoint(Rectangle rect, int zoom, RoundingMode sizeRounding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {

Event event = new Event ();
event.gc = gc;
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(ps.left, ps.top, width, height), getAutoscalingZoom()));
event.setBounds(Win32DPIUtils.pixelToPointWithSufficientlyLargeSize(new Rectangle.OfFloat(ps.left, ps.top, width, height), getAutoscalingZoom()));
sendEvent (SWT.Paint, event);
if (data.focusDrawn && !isDisposed ()) updateUIState ();
gc.dispose ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void destroyScrollBar (int type) {
*/
public Rectangle getClientArea () {
checkWidget ();
return Win32DPIUtils.pixelToPoint(getClientAreaInPixels(), getAutoscalingZoom());
return Win32DPIUtils.pixelToPointWithSufficientlyLargeSize(getClientAreaInPixels(), getAutoscalingZoom());
}

Rectangle getClientAreaInPixels () {
Expand Down
Loading