@@ -1704,8 +1704,7 @@ public Control getCursorControl () {
1704
1704
*/
1705
1705
public Point getCursorLocation () {
1706
1706
checkDevice ();
1707
- Point cursorLocationInPixels = getCursorLocationInPixels ();
1708
- return translateLocationInPointInDisplayCoordinateSystem (cursorLocationInPixels .x , cursorLocationInPixels .y );
1707
+ return DPIUtil .autoScaleDown (getCursorLocationInPixels ());
1709
1708
}
1710
1709
1711
1710
Point getCursorLocationInPixels () {
@@ -2184,25 +2183,18 @@ Monitor getMonitor (long hmonitor) {
2184
2183
OS .GetMonitorInfo (hmonitor , lpmi );
2185
2184
Monitor monitor = new Monitor ();
2186
2185
monitor .handle = hmonitor ;
2187
- Rectangle boundsInPixels = new Rectangle (lpmi .rcMonitor_left , lpmi .rcMonitor_top , lpmi .rcMonitor_right - lpmi .rcMonitor_left ,lpmi .rcMonitor_bottom - lpmi .rcMonitor_top );
2188
- Rectangle clientAreaInPixels = new Rectangle (lpmi .rcWork_left , lpmi .rcWork_top , lpmi .rcWork_right - lpmi .rcWork_left , lpmi .rcWork_bottom - lpmi .rcWork_top );
2186
+ Rectangle boundsInPixels = new Rectangle (lpmi .rcMonitor_left , lpmi .rcMonitor_top , lpmi .rcMonitor_right - lpmi .rcMonitor_left ,lpmi .rcMonitor_bottom - lpmi .rcMonitor_top );
2187
+ monitor .setBounds (DPIUtil .autoScaleDown (boundsInPixels ));
2188
+ Rectangle clientAreaInPixels = new Rectangle (lpmi .rcWork_left , lpmi .rcWork_top , lpmi .rcWork_right - lpmi .rcWork_left , lpmi .rcWork_bottom - lpmi .rcWork_top );
2189
+ monitor .setClientArea (DPIUtil .autoScaleDown (clientAreaInPixels ));
2189
2190
int [] dpiX = new int [1 ];
2190
2191
int [] dpiY = new int [1 ];
2191
2192
int result = OS .GetDpiForMonitor (monitor .handle , OS .MDT_EFFECTIVE_DPI , dpiX , dpiY );
2192
2193
result = (result == OS .S_OK ) ? DPIUtil .mapDPIToZoom (dpiX [0 ]) : 100 ;
2193
-
2194
- int autoscaleZoom ;
2195
- if (DPIUtil .isAutoScaleOnRuntimeActive ()) {
2196
- autoscaleZoom = DPIUtil .getZoomForAutoscaleProperty (result );
2197
- } else {
2198
- autoscaleZoom = DPIUtil .getDeviceZoom ();
2199
- }
2200
2194
if (result == 0 ) {
2201
2195
System .err .println ("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor." );
2202
2196
result = 100 ;
2203
2197
}
2204
- monitor .setBounds (getMonitorBoundsInPointsInDisplayCoordinateSystem (boundsInPixels , autoscaleZoom ));
2205
- monitor .setClientArea (getMonitorBoundsInPointsInDisplayCoordinateSystem (clientAreaInPixels , autoscaleZoom ));
2206
2198
/*
2207
2199
* Always return true monitor zoom value as fetched from native, else will lead
2208
2200
* to scaling issue on OS Win8.1 and above, for more details refer bug 537614.
@@ -2211,13 +2203,6 @@ Monitor getMonitor (long hmonitor) {
2211
2203
return monitor ;
2212
2204
}
2213
2205
2214
- private Rectangle getMonitorBoundsInPointsInDisplayCoordinateSystem (Rectangle boundsInPixels , int zoom ) {
2215
- Rectangle bounds = DPIUtil .scaleDown (boundsInPixels , zoom );
2216
- bounds .x = boundsInPixels .x ;
2217
- bounds .y = boundsInPixels .y ;
2218
- return bounds ;
2219
- }
2220
-
2221
2206
/**
2222
2207
* Returns an array of monitors attached to the device.
2223
2208
*
@@ -2959,7 +2944,9 @@ boolean isValidThread () {
2959
2944
public Point map (Control from , Control to , Point point ) {
2960
2945
checkDevice ();
2961
2946
if (point == null ) error (SWT .ERROR_NULL_ARGUMENT );
2962
- return map (from , to , point .x , point .y );
2947
+ int zoom = getZoomLevelForMapping (from , to );
2948
+ point = DPIUtil .scaleUp (point , zoom );
2949
+ return DPIUtil .scaleDown (mapInPixels (from , to , point ), zoom );
2963
2950
}
2964
2951
2965
2952
Point mapInPixels (Control from , Control to , Point point ) {
@@ -3004,18 +2991,10 @@ Point mapInPixels (Control from, Control to, Point point) {
3004
2991
*/
3005
2992
public Point map (Control from , Control to , int x , int y ) {
3006
2993
checkDevice ();
3007
- Point mappedPointInPoints ;
3008
- if (from == null ) {
3009
- Point mappedPointInpixels = mapInPixels (from , to , getPixelsFromPoint (to .getShell ().getMonitor (), x , y ));
3010
- mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
3011
- } else if (to == null ) {
3012
- Point mappedPointInpixels = mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
3013
- mappedPointInPoints = getPointFromPixels (from .getShell ().getMonitor (), mappedPointInpixels .x , mappedPointInpixels .y );
3014
- } else {
3015
- Point mappedPointInpixels = mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
3016
- mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
3017
- }
3018
- return mappedPointInPoints ;
2994
+ int zoom = getZoomLevelForMapping (from , to );
2995
+ x = DPIUtil .scaleUp (x , zoom );
2996
+ y = DPIUtil .scaleUp (y , zoom );
2997
+ return DPIUtil .scaleDown (mapInPixels (from , to , x , y ), zoom );
3019
2998
}
3020
2999
3021
3000
Point mapInPixels (Control from , Control to , int x , int y ) {
@@ -3031,6 +3010,15 @@ Point mapInPixels (Control from, Control to, int x, int y) {
3031
3010
return new Point (point .x , point .y );
3032
3011
}
3033
3012
3013
+ private int getZoomLevelForMapping (Control from , Control to ) {
3014
+ if (from != null && from .isDisposed ()) error (SWT .ERROR_INVALID_ARGUMENT );
3015
+ if (to != null && to .isDisposed ()) error (SWT .ERROR_INVALID_ARGUMENT );
3016
+ if (to != null ) {
3017
+ return to .getZoom ();
3018
+ }
3019
+ return from .getZoom ();
3020
+ }
3021
+
3034
3022
/**
3035
3023
* Maps a point from one coordinate system to another.
3036
3024
* When the control is null, coordinates are mapped to
@@ -3070,7 +3058,9 @@ Point mapInPixels (Control from, Control to, int x, int y) {
3070
3058
public Rectangle map (Control from , Control to , Rectangle rectangle ) {
3071
3059
checkDevice ();
3072
3060
if (rectangle == null ) error (SWT .ERROR_NULL_ARGUMENT );
3073
- return map (from , to , rectangle .x , rectangle .y , rectangle .width , rectangle .height );
3061
+ int zoom = getZoomLevelForMapping (from , to );
3062
+ rectangle = DPIUtil .scaleUp (rectangle , zoom );
3063
+ return DPIUtil .scaleDown (mapInPixels (from , to , rectangle ), zoom );
3074
3064
}
3075
3065
3076
3066
Rectangle mapInPixels (Control from , Control to , Rectangle rectangle ) {
@@ -3117,18 +3107,12 @@ Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) {
3117
3107
*/
3118
3108
public Rectangle map (Control from , Control to , int x , int y , int width , int height ) {
3119
3109
checkDevice ();
3120
- Rectangle mappedRectangleInPoints ;
3121
- if (from == null ) {
3122
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , to .getShell ().getMonitor ()));
3123
- mappedRectangleInPoints = DPIUtil .scaleDown (mappedRectangleInPixels , to .getZoom ());
3124
- } else if (to == null ) {
3125
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , DPIUtil .scaleUp (new Rectangle (x , y , width , height ), from .getZoom ()));
3126
- mappedRectangleInPoints = translateRectangleInPointsInDisplayCoordinateSystem (mappedRectangleInPixels .x , mappedRectangleInPixels .y , mappedRectangleInPixels .width , mappedRectangleInPixels .height , from .getShell ().getMonitor ());
3127
- } else {
3128
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , DPIUtil .scaleUp (new Rectangle (x , y , width , height ), from .getZoom ()));
3129
- mappedRectangleInPoints = DPIUtil .scaleDown (mappedRectangleInPixels , to .getZoom ());
3130
- }
3131
- return mappedRectangleInPoints ;
3110
+ int zoom = getZoomLevelForMapping (from , to );
3111
+ x = DPIUtil .scaleUp (x , zoom );
3112
+ y = DPIUtil .scaleUp (y , zoom );
3113
+ width = DPIUtil .scaleUp (width , zoom );
3114
+ height = DPIUtil .scaleUp (height , zoom );
3115
+ return DPIUtil .scaleDown (mapInPixels (from , to , x , y , width , height ), zoom );
3132
3116
}
3133
3117
3134
3118
Rectangle mapInPixels (Control from , Control to , int x , int y , int width , int height ) {
@@ -3146,57 +3130,6 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he
3146
3130
return new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom - rect .top );
3147
3131
}
3148
3132
3149
- Point translateLocationInPixelsInDisplayCoordinateSystem (int x , int y ) {
3150
- Monitor monitor = getContainingMonitor (x , y );
3151
- return getPixelsFromPoint (monitor , x , y );
3152
- }
3153
-
3154
- Point translateLocationInPointInDisplayCoordinateSystem (int x , int y ) {
3155
- Monitor monitor = getContainingMonitorInPixelsCoordinate (x , y );
3156
- return getPointFromPixels (monitor , x , y );
3157
- }
3158
-
3159
- Rectangle translateRectangleInPixelsInDisplayCoordinateSystemByContainment (int x , int y , int width , int height ) {
3160
- Monitor monitorByLocation = getContainingMonitor (x , y );
3161
- Monitor monitorByContainment = getContainingMonitor (x , y , width , height );
3162
- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitorByLocation , monitorByContainment );
3163
- }
3164
-
3165
- private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitor ) {
3166
- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitor , monitor );
3167
- }
3168
-
3169
- private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitorOfLocation , Monitor monitorOfArea ) {
3170
- Point topLeft = getPixelsFromPoint (monitorOfLocation , x , y );
3171
- int zoom = getApplicableMonitorZoom (monitorOfArea );
3172
- int widthInPixels = DPIUtil .scaleUp (width , zoom );
3173
- int heightInPixels = DPIUtil .scaleUp (height , zoom );
3174
- return new Rectangle (topLeft .x , topLeft .y , widthInPixels , heightInPixels );
3175
- }
3176
-
3177
- Rectangle translateRectangleInPointsInDisplayCoordinateSystemByContainment (int x , int y , int widthInPixels , int heightInPixels ) {
3178
- Monitor monitorByLocation = getContainingMonitor (x , y );
3179
- Monitor monitorByContainment = getContainingMonitor (x , y , widthInPixels , heightInPixels );
3180
- return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels , monitorByLocation , monitorByContainment );
3181
- }
3182
-
3183
- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitor ) {
3184
- return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels , monitor , monitor );
3185
- }
3186
-
3187
-
3188
- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitorOfLocation , Monitor monitorOfArea ) {
3189
- Point topLeft = getPointFromPixels (monitorOfLocation , x , y );
3190
- int zoom = getApplicableMonitorZoom (monitorOfArea );
3191
- int width = DPIUtil .scaleDown (widthInPixels , zoom );
3192
- int height = DPIUtil .scaleDown (heightInPixels , zoom );
3193
- return new Rectangle (topLeft .x , topLeft .y , width , height );
3194
- }
3195
-
3196
- private int getApplicableMonitorZoom (Monitor monitor ) {
3197
- return DPIUtil .getZoomForAutoscaleProperty (isRescalingAtRuntime () ? monitor .zoom : getDeviceZoom ());
3198
- }
3199
-
3200
3133
long messageProc (long hwnd , long msg , long wParam , long lParam ) {
3201
3134
switch ((int )msg ) {
3202
3135
case SWT_RUNASYNC : {
@@ -4422,8 +4355,7 @@ public void sendPostExternalEventDispatchEvent () {
4422
4355
*/
4423
4356
public void setCursorLocation (int x , int y ) {
4424
4357
checkDevice ();
4425
- Point cursorLocationInPixels = translateLocationInPixelsInDisplayCoordinateSystem (x , y );
4426
- setCursorLocationInPixels (cursorLocationInPixels .x , cursorLocationInPixels .y );
4358
+ setCursorLocationInPixels (DPIUtil .autoScaleUp (x ), DPIUtil .autoScaleUp (y ));
4427
4359
}
4428
4360
4429
4361
void setCursorLocationInPixels (int x , int y ) {
@@ -5458,63 +5390,4 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
5458
5390
return true ;
5459
5391
}
5460
5392
5461
- private Monitor getContainingMonitor (int x , int y ) {
5462
- Monitor [] monitors = getMonitors ();
5463
- for (Monitor currentMonitor : monitors ) {
5464
- Rectangle clientArea = currentMonitor .getClientArea ();
5465
- if (clientArea .contains (x , y )) {
5466
- return currentMonitor ;
5467
- }
5468
- }
5469
- return getPrimaryMonitor ();
5470
- }
5471
-
5472
- private Monitor getContainingMonitor (int x , int y , int width , int height ) {
5473
- Rectangle rectangle = new Rectangle (x , y , width , height );
5474
- Monitor [] monitors = getMonitors ();
5475
- Monitor selectedMonitor = getPrimaryMonitor ();
5476
- int highestArea = 0 ;
5477
- for (Monitor currentMonitor : monitors ) {
5478
- Rectangle clientArea = currentMonitor .getClientArea ();
5479
- Rectangle intersection = clientArea .intersection (rectangle );
5480
- int area = intersection .width * intersection .height ;
5481
- if (area > highestArea ) {
5482
- selectedMonitor = currentMonitor ;
5483
- highestArea = area ;
5484
- }
5485
- }
5486
- return selectedMonitor ;
5487
- }
5488
-
5489
- private Monitor getContainingMonitorInPixelsCoordinate (int xInPixels , int yInPixels ) {
5490
- Monitor [] monitors = getMonitors ();
5491
- for (Monitor current : monitors ) {
5492
- Rectangle clientArea = getMonitorClientAreaInPixels (current );
5493
- if (clientArea .contains (xInPixels , yInPixels )) {
5494
- return current ;
5495
- }
5496
- }
5497
- return getPrimaryMonitor ();
5498
- }
5499
-
5500
- private Rectangle getMonitorClientAreaInPixels (Monitor monitor ) {
5501
- int zoom = getApplicableMonitorZoom (monitor );
5502
- int widthInPixels = DPIUtil .scaleUp (monitor .clientWidth , zoom );
5503
- int heightInPixels = DPIUtil .scaleUp (monitor .clientHeight , zoom );
5504
- return new Rectangle (monitor .clientX , monitor .clientY , widthInPixels , heightInPixels );
5505
- }
5506
-
5507
- private Point getPixelsFromPoint (Monitor monitor , int x , int y ) {
5508
- int zoom = getApplicableMonitorZoom (monitor );
5509
- int mappedX = DPIUtil .scaleUp (x - monitor .clientX , zoom ) + monitor .clientX ;
5510
- int mappedY = DPIUtil .scaleUp (y - monitor .clientY , zoom ) + monitor .clientY ;
5511
- return new Point (mappedX , mappedY );
5512
- }
5513
-
5514
- private Point getPointFromPixels (Monitor monitor , int x , int y ) {
5515
- int zoom = getApplicableMonitorZoom (monitor );
5516
- int mappedX = DPIUtil .scaleDown (x - monitor .clientX , zoom ) + monitor .clientX ;
5517
- int mappedY = DPIUtil .scaleDown (y - monitor .clientY , zoom ) + monitor .clientY ;
5518
- return new Point (mappedX , mappedY );
5519
- }
5520
5393
}
0 commit comments