Skip to content

Commit 3d93396

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
Refactor: Move Cocoa-specific DPI methods to CocoaDPIUtil
The `autoScale` methods no longer have relevance in the Win32 implementation, so this commit extracts the macOS-specific DPI scaling logic into a dedicated `CocoaDPIUtil` class. This improves platform separation and maintains cleaner, OS-specific code boundaries.
1 parent 51fed8e commit 3d93396

File tree

1 file changed

+19
-2
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics

1 file changed

+19
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,11 +1822,28 @@ public String toString () {
18221822
* @noreference This method is not intended to be referenced by clients.
18231823
*/
18241824
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1825-
gc.drawImage (original, 0, 0, DPIUtil.autoScaleDown (width), DPIUtil.autoScaleDown (height),
1825+
gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height),
18261826
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
18271827
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
18281828
*/
1829-
0, 0, Math.round (DPIUtil.autoScaleDown (width * scaleFactor)), Math.round (DPIUtil.autoScaleDown (height * scaleFactor)));
1829+
0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor)));
1830+
}
1831+
1832+
private final class CocoaDPIUtil {
1833+
1834+
/**
1835+
* Auto-scale down int dimensions.
1836+
*/
1837+
public static int autoScaleDown(int size) {
1838+
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1839+
}
1840+
1841+
/**
1842+
* Auto-scale down float dimensions.
1843+
*/
1844+
public static float autoScaleDown(float size) {
1845+
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1846+
}
18301847
}
18311848

18321849
}

0 commit comments

Comments
 (0)