Skip to content

Commit f275dba

Browse files
HeikoKlareakoch-yatta
authored andcommitted
[Win32] Properly convert event coordinates in Tracker
The coordinates for mouse move events in Tracker are currently just scaled via pixel/point conversion methods. However, those are display coordinates which need to take the coordinate system specifics into account and thus have to be converted via the display methods for translating coordinates. This change adapts the implementation accordingly.
1 parent 77f9654 commit f275dba

File tree

1 file changed

+9
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+9
-4
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tracker.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,11 @@ public void setRectangles (Rectangle [] rectangles) {
846846
if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT);
847847
Rectangle [] rectanglesInPixels = new Rectangle [rectangles.length];
848848
for (int i = 0; i < rectangles.length; i++) {
849-
rectanglesInPixels [i] = Win32DPIUtils.pointToPixel (rectangles [i], getZoom());
849+
if (parent != null) {
850+
rectanglesInPixels [i] = Win32DPIUtils.pointToPixel (rectangles [i], getZoom());
851+
} else {
852+
rectanglesInPixels [i] = display.translateToDisplayCoordinates(rectangles[i]);
853+
}
850854
}
851855
setRectanglesInPixels (rectanglesInPixels);
852856
}
@@ -999,7 +1003,8 @@ LRESULT wmKeyDown (long hwnd, long wParam, long lParam) {
9991003
rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
10001004
}
10011005
Event event = new Event ();
1002-
event.setLocation(DPIUtil.pixelToPoint(oldX + xChange, getZoom()), DPIUtil.pixelToPoint(oldY + yChange, getZoom()));
1006+
Point newLocationInPoints = display.translateFromDisplayCoordinates(new Point(oldX + xChange, oldY + yChange));
1007+
event.setLocation(newLocationInPoints.x, newLocationInPoints.y);
10031008
Point cursorPos;
10041009
if ((style & SWT.RESIZE) != 0) {
10051010
resizeRectangles (xChange, yChange);
@@ -1119,8 +1124,8 @@ LRESULT wmMouse (int message, long wParam, long lParam) {
11191124
rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height);
11201125
}
11211126
Event event = new Event ();
1122-
int zoom = getZoom();
1123-
event.setLocation(DPIUtil.pixelToPoint(newX, zoom), DPIUtil.pixelToPoint(newY, zoom));
1127+
Point newLocationInPoints = display.translateFromDisplayCoordinates(new Point(newX, newY));
1128+
event.setLocation(newLocationInPoints.x, newLocationInPoints.y);
11241129
if ((style & SWT.RESIZE) != 0) {
11251130
if (isMirrored) {
11261131
resizeRectangles (oldX - newX, newY - oldY);

0 commit comments

Comments
 (0)