From 9b4e9ba58cef9032e7761d83e95e6b44fa12f2fe Mon Sep 17 00:00:00 2001 From: Andreas Koch Date: Mon, 27 Jan 2025 17:41:42 +0100 Subject: [PATCH] [win32] Unify up-scaling bounds using Rectangle This commit unifies scale up results in different places. With zoom values not dividable by 100 scaling up via rectangle or scaling up all values separately can give different result. Scaling always as rectangle solves this limitation. --- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java | 7 ++----- .../win32/org/eclipse/swt/widgets/Composite.java | 7 ++----- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java | 7 ++----- .../win32/org/eclipse/swt/widgets/Scrollable.java | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java index b3b285151d0..068fa7671ce 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Canvas.java @@ -200,11 +200,8 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b int zoom = getZoom(); destX = DPIUtil.scaleUp(destX, zoom); destY = DPIUtil.scaleUp(destY, zoom); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - width = DPIUtil.scaleUp(width, zoom); - height = DPIUtil.scaleUp(height, zoom); - scrollInPixels(destX, destY, x, y, width, height, all); + Rectangle rectangle = DPIUtil.scaleUp(new Rectangle(x, y, width, height), zoom); + scrollInPixels(destX, destY, rectangle.x, rectangle.y, rectangle.width, rectangle.height, all); } void scrollInPixels (int destX, int destY, int x, int y, int width, int height, boolean all) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java index c8e4303002c..f360f696dd5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java @@ -356,13 +356,10 @@ int applyThemeBackground () { public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) { checkWidget (); int zoom = getZoom(); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - width = DPIUtil.scaleUp(width, zoom); - height = DPIUtil.scaleUp(height, zoom); + Rectangle rectangle = DPIUtil.scaleUp(new Rectangle(x, y, width, height), zoom); offsetX = DPIUtil.scaleUp(offsetX, zoom); offsetY = DPIUtil.scaleUp(offsetY, zoom); - drawBackgroundInPixels(gc, x, y, width, height, offsetX, offsetY); + drawBackgroundInPixels(gc, rectangle.x, rectangle.y, rectangle.width, rectangle.height, offsetX, offsetY); } void drawBackgroundInPixels(GC gc, int x, int y, int width, int height, int offsetX, int offsetY) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java index c8c9a979ab6..7020bf7e28b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java @@ -2434,14 +2434,11 @@ public void redraw () { public void redraw (int x, int y, int width, int height, boolean all) { checkWidget (); int zoom = getZoom(); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - width = DPIUtil.scaleUp(width, zoom); - height = DPIUtil.scaleUp(height, zoom); if (width <= 0 || height <= 0) return; + Rectangle rectangle = DPIUtil.scaleUp(new Rectangle(x, y, width, height), zoom); RECT rect = new RECT (); - OS.SetRect (rect, x, y, x + width, y + height); + OS.SetRect (rect, rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height); redrawInPixels(rect, all); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java index bcf9111e1c1..001e93bc454 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Scrollable.java @@ -121,11 +121,8 @@ long callWindowProc (long hwnd, int msg, long wParam, long lParam) { public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget (); int zoom = getZoom(); - x = DPIUtil.scaleUp(x, zoom); - y = DPIUtil.scaleUp(y, zoom); - width = DPIUtil.scaleUp(width, zoom); - height = DPIUtil.scaleUp(height, zoom); - return DPIUtil.scaleDown(computeTrimInPixels(x, y, width, height), zoom); + Rectangle rectangle = DPIUtil.scaleUp(new Rectangle(x, y, width, height), zoom); + return DPIUtil.scaleDown(computeTrimInPixels(rectangle.x, rectangle.y, rectangle.width, rectangle.height), zoom); } Rectangle computeTrimInPixels (int x, int y, int width, int height) {