Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper() {
void translatePointInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Point pt = createExpectedPoint(mapper, 5000, -400, monitors[0]);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
assertEquals(pt, mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom()));
Point px = mapper.translateToDisplayCoordinates(pt);
assertEquals(pt, mapper.translateFromDisplayCoordinates(px));
}

@Test
void translatePointInGapBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Point pt = new Point(1900, 400);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
assertEquals(pt, mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom()));
Point px = mapper.translateToDisplayCoordinates(pt);
assertEquals(pt, mapper.translateFromDisplayCoordinates(px));
}

@Test
void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Point pt = new Point(1900, 400);
Point px = mapper.translateToDisplayCoordinates(pt, monitors[0].getZoom());
Point translatedPt = mapper.translateFromDisplayCoordinates(px, monitors[0].getZoom());
Point translatedPx = mapper.translateToDisplayCoordinates(translatedPt, monitors[0].getZoom());
Point px = mapper.translateToDisplayCoordinates(pt);
Point translatedPt = mapper.translateFromDisplayCoordinates(px);
Point translatedPx = mapper.translateToDisplayCoordinates(translatedPt);
assertEquals(new Point(translatedPt.x, translatedPt.y), translatedPx);
assertEquals(translatedPx, px);
}
Expand All @@ -94,26 +94,26 @@ void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor() {
void translateRectangleInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPts = createExpectedRectangle(mapper, 5000, -400, 200, 200, monitors[0]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@Test
void translateRectangleInGapBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1800, 400, 100, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@Test
void translateRectangleInGapBackAndForthInMultiZoomShouldBeInMonitorBounds() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1800, 400, 100, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs);
boolean isInsideMonitor = false;
for (Monitor monitor : monitors) {
if (monitor.getClientArea().intersects(rectInPtsTranslated)) {
Expand All @@ -129,46 +129,45 @@ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheS
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(1950, 400, 150, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@Test
void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle.WithMonitor(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPts = createExpectedRectangle(mapper, 750, 400, 100, 100, monitors[0]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@Test
void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInSingleZoomShouldBeTheSame() {
SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(950, 400, 1500, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@Test
void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInMultiZoomShouldNotEndUpInGap() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new Rectangle(950, 400, 1500, 100);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPxsTranslated = mapper.translateToDisplayCoordinates(rectInPtsTranslated,
monitors[0].getZoom());
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
Rectangle rectInPtsTranslated = mapper.translateFromDisplayCoordinates(rectInPxs);
Rectangle rectInPxsTranslated = mapper.translateToDisplayCoordinates(rectInPtsTranslated);
assertEquals(rectInPxs, rectInPxsTranslated);
}

Expand All @@ -182,13 +181,13 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
expectedSmallRectInPxs.y = rectInPxs.y + (rectInPxs.height / 2) - 200;
expectedSmallRectInPxs.width = 400;
expectedSmallRectInPxs.height = 400;
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs);
Rectangle smallRectInPts = new Rectangle(0, 0, 0, monitors[0].getZoom());
smallRectInPts.x = rectInPts.x + (rectInPts.width / 2) - 200;
smallRectInPts.y = rectInPts.y + (rectInPts.height / 2) - 200;
smallRectInPts.width = 400;
smallRectInPts.height = 400;
Rectangle smallRectInPxs = mapper.translateToDisplayCoordinates(smallRectInPts, monitors[0].getZoom());
Rectangle smallRectInPxs = mapper.translateToDisplayCoordinates(smallRectInPts);
assertEquals(expectedSmallRectInPxs, smallRectInPxs);
}

Expand All @@ -197,26 +196,26 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
void translateRectangleInPixelsOutisdeMonitorsBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPxs = new Rectangle(400, 2400, 1000, 1000);
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom()));
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs);
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInPixelsInBothMonitorsBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPxs = new Rectangle(1500, 400, 502, 500);
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom());
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom()));
Rectangle rectInPts = mapper.translateFromDisplayCoordinates(rectInPxs);
assertEquals(rectInPxs, mapper.translateToDisplayCoordinates(rectInPts));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateRectangleInPixelsForZeroSize(CoordinateSystemMapper mapper) {
setupMonitors(mapper);
Rectangle rectInPts = createExpectedRectangle(mapper, 0, 0, 0, 0, monitors[0]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts);
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, Monitor monitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4028,10 +4028,9 @@ void subclass () {
*/
public Point toControl (int x, int y) {
checkWidget ();
int zoom = getZoom();
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point(x, y), zoom);
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point(x, y));
final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y);
return Win32DPIUtils.pixelToPoint(controlPointInPixels, zoom);
return Win32DPIUtils.pixelToPoint(controlPointInPixels, getZoom());
}

Point toControlInPixels (int x, int y) {
Expand Down Expand Up @@ -4091,7 +4090,7 @@ public Point toDisplay (int x, int y) {
checkWidget ();
int zoom = getZoom();
Point displayPointInPixels = toDisplayInPixels(Win32DPIUtils.pointToPixel(x, zoom), Win32DPIUtils.pointToPixel(y, zoom));
return getDisplay().translateFromDisplayCoordinates(displayPointInPixels, zoom);
return getDisplay().translateFromDisplayCoordinates(displayPointInPixels);
}

Point toDisplayInPixels (int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ interface CoordinateSystemMapper {

Rectangle mapMonitorBounds(Rectangle rectangle, int zoom);

Point translateFromDisplayCoordinates(Point point, int zoom);
Point translateFromDisplayCoordinates(Point point);

Point translateToDisplayCoordinates(Point point, int zoom);
Point translateToDisplayCoordinates(Point point);

Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom);
Rectangle translateFromDisplayCoordinates(Rectangle rect);

Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom);
Rectangle translateToDisplayCoordinates(Rectangle rect);

Rectangle getContainingMonitorBoundsInPixels(Point point);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3166,20 +3166,20 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he
return new Rectangle (rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}

Point translateFromDisplayCoordinates(Point point, int zoom) {
return coordinateSystemMapper.translateFromDisplayCoordinates(point, zoom);
Point translateFromDisplayCoordinates(Point point) {
return coordinateSystemMapper.translateFromDisplayCoordinates(point);
}

Point translateToDisplayCoordinates(Point point, int zoom) {
return coordinateSystemMapper.translateToDisplayCoordinates(point, zoom);
Point translateToDisplayCoordinates(Point point) {
return coordinateSystemMapper.translateToDisplayCoordinates(point);
}

Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
return coordinateSystemMapper.translateFromDisplayCoordinates(rect, zoom);
Rectangle translateFromDisplayCoordinates(Rectangle rect) {
return coordinateSystemMapper.translateFromDisplayCoordinates(rect);
}

Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
return coordinateSystemMapper.translateToDisplayCoordinates(rect, zoom);
Rectangle translateToDisplayCoordinates(Rectangle rect) {
return coordinateSystemMapper.translateToDisplayCoordinates(rect);
}

long messageProc (long hwnd, long msg, long wParam, long lParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ void setLocationInPixels (int x, int y) {
public void setLocation (Point location) {
checkWidget ();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
Point locationInPixels = getDisplay().translateToDisplayCoordinates(location, getZoom());
Point locationInPixels = getDisplay().translateToDisplayCoordinates(location);
setLocationInPixels(locationInPixels.x, locationInPixels.y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
}

@Override
public Point translateFromDisplayCoordinates(Point point, int zoom) {
public Point translateFromDisplayCoordinates(Point point) {
return translateLocationInPixelsToPoints(point.x, point.y);
}

@Override
public Point translateToDisplayCoordinates(Point point, int zoom) {
public Point translateToDisplayCoordinates(Point point) {
Monitor monitor = point instanceof Point.WithMonitor pointWithMonitor ? pointWithMonitor.getMonitor() : null;
return translateLocationInPointsToPixels(point.x, point.y, monitor);
}

@Override
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
public Rectangle translateFromDisplayCoordinates(Rectangle rect) {
Monitor monitor = rect instanceof Rectangle.WithMonitor rectWithMonitor ? rectWithMonitor.getMonitor() : null;
return translateRectangleInPixelsToPoints(rect.x, rect.y, rect.width, rect.height, monitor);
}

@Override
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
public Rectangle translateToDisplayCoordinates(Rectangle rect) {
Monitor monitor = rect instanceof Rectangle.WithMonitor rectWithMonitor ? rectWithMonitor.getMonitor() : null;
return translateRectangleInPointsToPixels(rect.x, rect.y, rect.width, rect.height, monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1561,20 +1561,20 @@ public void setAlpha (int alpha) {
@Override
public Rectangle getBounds() {
checkWidget ();
return getDisplay().translateFromDisplayCoordinates(getBoundsInPixels(), getZoom());
return getDisplay().translateFromDisplayCoordinates(getBoundsInPixels());
}

@Override
public Point getLocation() {
checkWidget ();
return getDisplay().translateFromDisplayCoordinates(getLocationInPixels(), getZoom());
return getDisplay().translateFromDisplayCoordinates(getLocationInPixels());
}

@Override
public void setLocation(Point location) {
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
checkWidget ();
Point locationInPixels = getDisplay().translateToDisplayCoordinates(location, getZoom());
Point locationInPixels = getDisplay().translateToDisplayCoordinates(location);
setLocationInPixels(locationInPixels.x, locationInPixels.y);
}

Expand All @@ -1587,7 +1587,7 @@ public void setLocation(int x, int y) {
public void setBounds(Rectangle rect) {
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
checkWidget ();
Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(rect, getZoom());
Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(rect);
// The scaling of the width and height in case of a monitor change is handled by
// the WM_DPICHANGED event processing. So to avoid duplicate scaling, we always
// have to scale width and height with the zoom of the original monitor (still
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
}

@Override
public Point translateFromDisplayCoordinates(Point point, int zoom) {
public Point translateFromDisplayCoordinates(Point point) {
return Win32DPIUtils.pixelToPoint(point, DPIUtil.getDeviceZoom());
}

@Override
public Point translateToDisplayCoordinates(Point point, int zoom) {
public Point translateToDisplayCoordinates(Point point) {
return Win32DPIUtils.pointToPixel(point, DPIUtil.getDeviceZoom());
}

@Override
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
public Rectangle translateFromDisplayCoordinates(Rectangle rect) {
return Win32DPIUtils.pixelToPoint(rect, DPIUtil.getDeviceZoom());
}

@Override
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
public Rectangle translateToDisplayCoordinates(Rectangle rect) {
return Win32DPIUtils.pointToPixel(rect, DPIUtil.getDeviceZoom());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ boolean showMenu (int x, int y) {

boolean showMenu (int x, int y, int detail) {
Event event = new Event ();
Point mappedLocation = getDisplay().translateFromDisplayCoordinates(new Point(x, y), getZoom());
Point mappedLocation = getDisplay().translateFromDisplayCoordinates(new Point(x, y));
event.setLocation(mappedLocation.x, mappedLocation.y);
event.detail = detail;
if (event.detail == SWT.MENU_KEYBOARD) {
Expand Down
Loading