Skip to content

Commit c1ee9dd

Browse files
Fixing transparency on scaled variant of cursor with source and mask
When creating a custom cursor using source and mask ImageData, the transparency mask does not scale correctly when applying DPIUtil.autoScaleImageData() in a multi-monitor setup with different DPI settings. With this change we use scaleTo method to scale the data.
1 parent ce98326 commit c1ee9dd

File tree

1 file changed

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

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,16 @@ private void validateMask(ImageData source, ImageData mask) {
681681

682682
@Override
683683
public CursorHandle createHandle(Device device, int 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)
688-
: null;
689-
684+
float scaledZoomFactor = zoom * getPointerSizeScaleFactor() / 100f;
685+
int scaledSourceWidth = Math.round(this.source.width * scaledZoomFactor);
686+
int scaledSourceHeight = Math.round(this.source.height * scaledZoomFactor);
687+
ImageData scaledSource = this.source.scaledTo(scaledSourceWidth, scaledSourceHeight);
688+
ImageData scaledMask = null;
689+
if (this.mask != null) {
690+
int scaledMaskWidth = Math.round(this.mask.width * scaledZoomFactor);
691+
int scaledMaskHeight = Math.round(this.mask.height * scaledZoomFactor);
692+
scaledMask = this.mask.scaledTo(scaledMaskWidth, scaledMaskHeight);
693+
}
690694
return setupCursorFromImageData(device, scaledSource, scaledMask, getHotpotXInPixels(zoom),
691695
getHotpotYInPixels(zoom));
692696
}

0 commit comments

Comments
 (0)