@@ -598,17 +598,32 @@ private static final long setupCursorFromStyle(int style) {
598598 }
599599}
600600
601- private static class ImageDataProviderCursorHandleProvider implements CursorHandleProvider {
602- private final ImageDataProvider provider ;
601+ private static abstract class HotspotAwareCursorHandleProvider implements CursorHandleProvider {
603602 private final int hotspotX ;
604603 private final int hotspotY ;
605604
606- public ImageDataProviderCursorHandleProvider (ImageDataProvider provider , int hotspotX , int hotspotY ) {
607- this .provider = provider ;
605+ public HotspotAwareCursorHandleProvider (int hotspotX , int hotspotY ) {
608606 this .hotspotX = hotspotX ;
609607 this .hotspotY = hotspotY ;
610608 }
611609
610+ protected final int getHotpotXInPixels (int zoom ) {
611+ return Win32DPIUtils .pointToPixel (hotspotX , zoom );
612+ }
613+
614+ protected final int getHotpotYInPixels (int zoom ) {
615+ return Win32DPIUtils .pointToPixel (hotspotY , zoom );
616+ }
617+ }
618+
619+ private static class ImageDataProviderCursorHandleProvider extends HotspotAwareCursorHandleProvider {
620+ private final ImageDataProvider provider ;
621+
622+ public ImageDataProviderCursorHandleProvider (ImageDataProvider provider , int hotspotX , int hotspotY ) {
623+ super (hotspotX , hotspotY );
624+ this .provider = provider ;
625+ }
626+
612627 @ Override
613628 public long createHandle (Cursor cursor , int zoom ) {
614629 ImageData source ;
@@ -619,36 +634,31 @@ public long createHandle(Cursor cursor, int zoom) {
619634 source = tempImage .getImageData (zoom );
620635 tempImage .dispose ();
621636 }
622- int hotspotXInPixels = Win32DPIUtils .pointToPixel (hotspotX , zoom );
623- int hotspotYInPixels = Win32DPIUtils .pointToPixel (hotspotY , zoom );
624- return setupCursorFromImageData (cursor .device , source , hotspotXInPixels , hotspotYInPixels );
637+ return setupCursorFromImageData (cursor .device , source , getHotpotXInPixels (zoom ), getHotpotYInPixels (zoom ));
625638 }
626639}
627640
628- private static class ImageDataCursorHandleProvider implements CursorHandleProvider {
641+ private static class ImageDataCursorHandleProvider extends HotspotAwareCursorHandleProvider {
629642 private final ImageData source ;
630643 private final ImageData mask ;
631- private final int hotspotX ;
632- private final int hotspotY ;
633644
634645 public ImageDataCursorHandleProvider (ImageData source , ImageData mask , int hotspotX , int hotspotY ) {
646+ super (hotspotX , hotspotY );
635647 this .source = source ;
636648 this .mask = mask ;
637- this .hotspotX = hotspotX ;
638- this .hotspotY = hotspotY ;
639649 }
640650
641651 @ Override
642652 public long createHandle (Cursor cursor , int zoom ) {
643653 ImageData scaledSource = DPIUtil .scaleImageData (cursor .device , this .source , zoom , DEFAULT_ZOOM );
644- int hotspotXInPixels = Win32DPIUtils .pointToPixel (hotspotX , zoom );
645- int hotspotYInPixels = Win32DPIUtils .pointToPixel (hotspotY , zoom );
646654 if (cursor .isIcon ) {
647- return setupCursorFromImageData (cursor .device , scaledSource , hotspotXInPixels , hotspotYInPixels );
655+ return setupCursorFromImageData (cursor .device , scaledSource , getHotpotXInPixels (zoom ),
656+ getHotpotYInPixels (zoom ));
648657 } else {
649658 ImageData scaledMask = this .mask != null ? DPIUtil .scaleImageData (cursor .device , mask , zoom , DEFAULT_ZOOM )
650659 : null ;
651- return setupCursorFromImageData (scaledSource , scaledMask , hotspotXInPixels , hotspotYInPixels );
660+ return setupCursorFromImageData (scaledSource , scaledMask , getHotpotXInPixels (zoom ),
661+ getHotpotYInPixels (zoom ));
652662 }
653663 }
654664}
0 commit comments