@@ -120,7 +120,7 @@ public final class Cursor extends Resource {
120
120
public Cursor (Device device , int style ) {
121
121
super (device );
122
122
this .cursorHandleProvider = new StyleCursorHandleProvider (style );
123
- this .handle = this .cursorHandleProvider .createHandle (this , DEFAULT_ZOOM );
123
+ this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM );
124
124
init ();
125
125
this .device .registerResourceWithZoomSupport (this );
126
126
}
@@ -160,8 +160,8 @@ public Cursor(Device device, int style) {
160
160
*/
161
161
public Cursor (Device device , ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
162
162
super (device );
163
- this .cursorHandleProvider = new ImageDataCursorHandleProvider (source , mask , hotspotX , hotspotY );
164
- this .handle = this .cursorHandleProvider .createHandle (this , DEFAULT_ZOOM );
163
+ this .cursorHandleProvider = new ImageDataWithMaskCursorHandleProvider (source , mask , hotspotX , hotspotY );
164
+ this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM );
165
165
init ();
166
166
this .device .registerResourceWithZoomSupport (this );
167
167
}
@@ -229,9 +229,9 @@ private static long setupCursorFromImageData(ImageData source, ImageData mask, i
229
229
*/
230
230
public Cursor (Device device , ImageData source , int hotspotX , int hotspotY ) {
231
231
super (device );
232
- this .cursorHandleProvider = new ImageDataCursorHandleProvider (source , null , hotspotX , hotspotY );
232
+ this .cursorHandleProvider = new ImageDataCursorHandleProvider (source , hotspotX , hotspotY );
233
233
isIcon = true ;
234
- this .handle = this .cursorHandleProvider .createHandle (this , DEFAULT_ZOOM );
234
+ this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM );
235
235
init ();
236
236
this .device .registerResourceWithZoomSupport (this );
237
237
}
@@ -344,7 +344,7 @@ public Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX,
344
344
if (imageDataProvider == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
345
345
this .cursorHandleProvider = new ImageDataProviderCursorHandleProvider (imageDataProvider , hotspotX , hotspotY );
346
346
isIcon = true ;
347
- this .handle = this .cursorHandleProvider .createHandle (this , DEFAULT_ZOOM );
347
+ this .handle = this .cursorHandleProvider .createHandle (device , DEFAULT_ZOOM );
348
348
init ();
349
349
this .device .registerResourceWithZoomSupport (this );
350
350
}
@@ -372,7 +372,7 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
372
372
return cursor .zoomLevelToHandle .get (zoom );
373
373
}
374
374
375
- long handle = cursor .cursorHandleProvider .createHandle (cursor , zoom );
375
+ long handle = cursor .cursorHandleProvider .createHandle (cursor . device , zoom );
376
376
cursor .setHandleForZoomLevel (handle , zoom );
377
377
378
378
return cursor .zoomLevelToHandle .get (zoom );
@@ -502,7 +502,7 @@ void destroyHandlesExcept(Set<Integer> zoomLevels) {
502
502
}
503
503
504
504
private static interface CursorHandleProvider {
505
- long createHandle (Cursor cursor , int zoom );
505
+ long createHandle (Device device , int zoom );
506
506
}
507
507
508
508
private static class StyleCursorHandleProvider implements CursorHandleProvider {
@@ -513,7 +513,7 @@ public StyleCursorHandleProvider(int style) {
513
513
}
514
514
515
515
@ Override
516
- public long createHandle (Cursor cursor , int zoom ) {
516
+ public long createHandle (Device device , int zoom ) {
517
517
// zoom ignored, LoadCursor handles scaling internally
518
518
return setupCursorFromStyle (this .style );
519
519
}
@@ -625,41 +625,49 @@ public ImageDataProviderCursorHandleProvider(ImageDataProvider provider, int hot
625
625
}
626
626
627
627
@ Override
628
- public long createHandle (Cursor cursor , int zoom ) {
628
+ public long createHandle (Device device , int zoom ) {
629
629
ImageData source ;
630
630
if (zoom == DEFAULT_ZOOM ) {
631
631
source = this .provider .getImageData (DEFAULT_ZOOM );
632
632
} else {
633
- Image tempImage = new Image (cursor . device , this .provider );
633
+ Image tempImage = new Image (device , this .provider );
634
634
source = tempImage .getImageData (zoom );
635
635
tempImage .dispose ();
636
636
}
637
- return setupCursorFromImageData (cursor . device , source , getHotpotXInPixels (zoom ), getHotpotYInPixels (zoom ));
637
+ return setupCursorFromImageData (device , source , getHotpotXInPixels (zoom ), getHotpotYInPixels (zoom ));
638
638
}
639
639
}
640
640
641
641
private static class ImageDataCursorHandleProvider extends HotspotAwareCursorHandleProvider {
642
- private final ImageData source ;
643
- private final ImageData mask ;
642
+ protected final ImageData source ;
644
643
645
- public ImageDataCursorHandleProvider (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
644
+ public ImageDataCursorHandleProvider (ImageData source , int hotspotX , int hotspotY ) {
646
645
super (hotspotX , hotspotY );
647
646
this .source = source ;
647
+ }
648
+
649
+ @ Override
650
+ public long createHandle (Device device , int zoom ) {
651
+ ImageData scaledSource = DPIUtil .scaleImageData (device , this .source , zoom , DEFAULT_ZOOM );
652
+ return setupCursorFromImageData (device , scaledSource , getHotpotXInPixels (zoom ),
653
+ getHotpotYInPixels (zoom ));
654
+ }
655
+ }
656
+
657
+ private static class ImageDataWithMaskCursorHandleProvider extends ImageDataCursorHandleProvider {
658
+ private final ImageData mask ;
659
+
660
+ public ImageDataWithMaskCursorHandleProvider (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
661
+ super (source , hotspotX , hotspotY );
648
662
this .mask = mask ;
649
663
}
650
664
651
665
@ Override
652
- public long createHandle (Cursor cursor , int zoom ) {
653
- ImageData scaledSource = DPIUtil .scaleImageData (cursor .device , this .source , zoom , DEFAULT_ZOOM );
654
- if (cursor .isIcon ) {
655
- return setupCursorFromImageData (cursor .device , scaledSource , getHotpotXInPixels (zoom ),
656
- getHotpotYInPixels (zoom ));
657
- } else {
658
- ImageData scaledMask = this .mask != null ? DPIUtil .scaleImageData (cursor .device , mask , zoom , DEFAULT_ZOOM )
659
- : null ;
660
- return setupCursorFromImageData (scaledSource , scaledMask , getHotpotXInPixels (zoom ),
661
- getHotpotYInPixels (zoom ));
662
- }
666
+ public long createHandle (Device device , int zoom ) {
667
+ ImageData scaledSource = DPIUtil .scaleImageData (device , this .source , zoom , DEFAULT_ZOOM );
668
+ ImageData scaledMask = this .mask != null ? DPIUtil .scaleImageData (device , mask , zoom , DEFAULT_ZOOM )
669
+ : null ;
670
+ return setupCursorFromImageData (scaledSource , scaledMask , getHotpotXInPixels (zoom ), getHotpotYInPixels (zoom ));
663
671
}
664
672
}
665
673
0 commit comments