Skip to content

Commit 6fa4ee7

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
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 fd40dba commit 6fa4ee7

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
@@ -684,12 +684,16 @@ private void validateMask(ImageData source, ImageData mask) {
684684

685685
@Override
686686
public CursorHandle createHandle(Device device, int zoom) {
687-
float accessibilityFactor = getPointerSizeScaleFactor();
688-
int scaledZoom = (int) (zoom * accessibilityFactor);
689-
ImageData scaledSource = DPIUtil.scaleImageData(device, this.source, scaledZoom, DEFAULT_ZOOM);
690-
ImageData scaledMask = this.mask != null ? DPIUtil.scaleImageData(device, mask, scaledZoom, DEFAULT_ZOOM)
691-
: null;
692-
687+
float scaledZoomFactor = zoom * getPointerSizeScaleFactor() / 100f;
688+
int scaledSourceWidth = Math.round(this.source.width * scaledZoomFactor);
689+
int scaledSourceHeight = Math.round(this.source.height * scaledZoomFactor);
690+
ImageData scaledSource = this.source.scaledTo(scaledSourceWidth, scaledSourceHeight);
691+
ImageData scaledMask = null;
692+
if (this.mask != null) {
693+
int scaledMaskWidth = Math.round(this.mask.width * scaledZoomFactor);
694+
int scaledMaskHeight = Math.round(this.mask.height * scaledZoomFactor);
695+
scaledMask = this.mask.scaledTo(scaledMaskWidth, scaledMaskHeight);
696+
}
693697
return setupCursorFromImageData(device, scaledSource, scaledMask, getHotpotXInPixels(zoom),
694698
getHotpotYInPixels(zoom));
695699
}

0 commit comments

Comments
 (0)