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 @@ -218,6 +218,31 @@ void translateRectangleInPixelsForZeroSize(CoordinateSystemMapper mapper) {
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translateBoundsToSecondMonitor(CoordinateSystemMapper mapper) {
final int OFFSET = 30;
final int SIZE = OFFSET * 3;
setupMonitors(mapper);
Rectangle currentPosition = new Rectangle.WithMonitor(monitors[1].getClientArea().x - OFFSET, 0, SIZE, SIZE,
monitors[1]);
Rectangle result = mapper.translateFromDisplayCoordinates(currentPosition);
assertTrue(monitors[1].getClientArea().intersects(result));
}

@ParameterizedTest
@MethodSource("provideCoordinateSystemMappers")
void translatePointsToSecondMonitor(CoordinateSystemMapper mapper) {
final int OFFSET = 30;
final int SIZE = OFFSET * 3;
setupMonitors(mapper);
Point currentPosition = new Point.WithMonitor(monitors[1].getClientArea().x - OFFSET, 0, monitors[1]);
Point size = new Point(SIZE, SIZE);
Point result = mapper.translateFromDisplayCoordinates(currentPosition);
Rectangle resultRect = new Rectangle(result.x, result.y, size.x, size.y);
assertTrue(monitors[1].getClientArea().intersects(resultRect));
}

private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, Monitor monitor) {
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Point(x, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {

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

@Override
Expand All @@ -117,7 +118,7 @@ public Rectangle translateToDisplayCoordinates(Rectangle rect) {
@Override
public Point getCursorLocation() {
Point cursorLocationInPixels = display.getCursorLocationInPixels();
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y);
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y, null);
}

@Override
Expand All @@ -131,8 +132,10 @@ private Point translateLocationInPointsToPixels(int x, int y, Monitor monitor) {
return getPixelsFromPoint(monitor, x, y);
}

private Point translateLocationInPixelsToPoints(int x, int y) {
Monitor monitor = getContainingMonitorForPixels(x, y);
private Point translateLocationInPixelsToPoints(int x, int y, Monitor monitor) {
if (monitor == null) {
monitor = getContainingMonitorForPixels(x, y);
}
return getPointFromPixels(monitor, x, y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public int getAlpha () {
OS.GetWindowRect (handle, rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
return new Rectangle (rect.left, rect.top, width, height);
return new Rectangle.WithMonitor (rect.left, rect.top, width, height, getMonitor());
}

ToolTip getCurrentToolTip () {
Expand Down Expand Up @@ -1017,7 +1017,7 @@ public int getImeInputMode () {
if (OS.IsIconic (handle)) return super.getLocationInPixels ();
RECT rect = new RECT ();
OS.GetWindowRect (handle, rect);
return new Point (rect.left, rect.top);
return new Point.WithMonitor (rect.left, rect.top, getMonitor());
}

@Override
Expand Down
Loading