Skip to content

Commit c3cebe8

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
[win32] Fix pointer size scaling precision for custom cursors
The value in the registry for CursorBaseSize is not always divisible by 32, so integer division was causing loss of precision in pointer scaling. This commit changes getPointerSizeScaleFactor() to return a float using floating-point division, and ensures all usages of this method in Cursor.java handle the scale as a float. The float is then cast to int only when calling DPIUtil.scaleImageData, which only accepts integer zoom values. This preserves as much precision as possible and avoids rounding errors in pointer scaling for accessibility settings.
1 parent 87fa834 commit c3cebe8

File tree

1 file changed

+10
-7
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+10
-7
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,14 @@ private void setHandleForZoomLevel(CursorHandle handle, Integer zoom) {
352352
* size, etc.)
353353
*/
354354

355-
private static int getPointerSizeScaleFactor() {
355+
private static float getPointerSizeScaleFactor() {
356356
if (OsVersion.IS_WIN10_1809) {
357357
int[] cursorBaseSize = OS.readRegistryDwords(OS.HKEY_CURRENT_USER, "Control Panel\\Cursors", "CursorBaseSize");
358358
if (cursorBaseSize != null && cursorBaseSize.length > 0 && cursorBaseSize[0] > 0) {
359-
return cursorBaseSize[0] / 32;
359+
return cursorBaseSize[0] / 32.0f;
360360
}
361361
}
362-
return 1;
362+
return 1.0f;
363363
}
364364

365365
@Override
@@ -648,8 +648,9 @@ public ImageDataCursorHandleProvider(ImageData source, int hotspotX, int hotspot
648648

649649
@Override
650650
public CursorHandle createHandle(Device device, int zoom) {
651-
int accessibilityFactor = getPointerSizeScaleFactor();
652-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, zoom * accessibilityFactor, DEFAULT_ZOOM);
651+
float accessibilityFactor = getPointerSizeScaleFactor();
652+
int scaledZoom = (int) (zoom * accessibilityFactor);
653+
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, scaledZoom, DEFAULT_ZOOM);
653654
return setupCursorFromImageData(device, scaledSource, null, getHotpotXInPixels(zoom),
654655
getHotpotYInPixels(zoom));
655656
}
@@ -680,8 +681,10 @@ private void validateMask(ImageData source, ImageData mask) {
680681

681682
@Override
682683
public CursorHandle createHandle(Device device, int zoom) {
683-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, getPointerSizeScaleFactor() * zoom, DEFAULT_ZOOM);
684-
ImageData scaledMask = this.mask != null ? DPIUtil.scaleImageData(device, mask, getPointerSizeScaleFactor() * zoom, DEFAULT_ZOOM)
684+
float accessibilityFactor = getPointerSizeScaleFactor();
685+
int scaledZoom = (int) (zoom * accessibilityFactor);
686+
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, scaledZoom, DEFAULT_ZOOM);
687+
ImageData scaledMask = this.mask != null ? DPIUtil.scaleImageData(device, mask, scaledZoom, DEFAULT_ZOOM)
685688
: null;
686689

687690
return setupCursorFromImageData(device, scaledSource, scaledMask, getHotpotXInPixels(zoom),

0 commit comments

Comments
 (0)