Skip to content

Commit

Permalink
fix for coords
Browse files Browse the repository at this point in the history
  • Loading branch information
akoch-yatta committed Sep 11, 2024
1 parent 7f149e0 commit fd0a9d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3031,11 +3031,11 @@ public Point map (Control from, Control to, int x, int y) {
checkDevice ();
Point mappedPointInPoints;
if (from == null) {
Point mappedPointInpixels = mapInPixels(from, to, translateLocationInPixelsInDisplayCoordinateSystem(x, y));
Point mappedPointInpixels = mapInPixels(from, to, getPixelsFromPoint(to.getMonitor(), x, y));
mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
} else if (to == null) {
Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
mappedPointInPoints = translateLocationInPointInDisplayCoordinateSystem(mappedPointInpixels.x, mappedPointInpixels.y);
mappedPointInPoints = getPointFromPixels(from.getMonitor(), mappedPointInpixels.x, mappedPointInpixels.y);
} else {
Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
Expand Down Expand Up @@ -3144,11 +3144,11 @@ public Rectangle map (Control from, Control to, int x, int y, int width, int hei
checkDevice ();
Rectangle mappedRectangleInPoints;
if (from == null) {
Rectangle mappedRectangleInPixels = mapInPixels(from, to, translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height));
Rectangle mappedRectangleInPixels = mapInPixels(from, to, translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, to.getMonitor()));
mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
} else if (to == null) {
Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
mappedRectangleInPoints = translateRectangleInPointsInDisplayCoordinateSystem(mappedRectangleInPixels.x, mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height);
mappedRectangleInPoints = translateRectangleInPointsInDisplayCoordinateSystem(mappedRectangleInPixels.x, mappedRectangleInPixels.y, mappedRectangleInPixels.width, mappedRectangleInPixels.height, from.getMonitor());
} else {
Rectangle mappedRectangleInPixels = mapInPixels(from, to, DPIUtil.scaleUp(new Rectangle(x, y, width, height), from.getZoom()));
mappedRectangleInPoints = DPIUtil.scaleDown(mappedRectangleInPixels, to.getZoom());
Expand Down Expand Up @@ -3181,17 +3181,25 @@ Point translateLocationInPointInDisplayCoordinateSystem(int x, int y) {
return getPointFromPixels(monitor, x, y);
}

Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height) {
Rectangle translateRectangleInPixelsInDisplayCoordinateSystemByContainment(int x, int y, int width, int height) {
Monitor monitor = getContainingMonitor(x, y, width, height);
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor);
}

private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitor) {
Point topLeft = getPixelsFromPoint(monitor, x, y);
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
int widthInPixels = DPIUtil.scaleUp(width, zoom);
int heightInPixels = DPIUtil.scaleUp(height, zoom);
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
}

Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels) {
Rectangle translateRectangleInPointsInDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels) {
Monitor monitor = getContainingMonitorInPixelsCoordiate(x, y, widthInPixels, heightInPixels);
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitor);
}

private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
Point topLeft = getPointFromPixels(monitor, x, y);
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
int width = DPIUtil.scaleDown(widthInPixels, zoom);
Expand Down Expand Up @@ -5355,7 +5363,7 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
return true;
}

Monitor getContainingMonitor(int x, int y) {
private Monitor getContainingMonitor(int x, int y) {
Monitor[] monitors = getMonitors();
for (Monitor currentMonitor : monitors) {
Rectangle clientArea = currentMonitor.getClientArea();
Expand All @@ -5366,7 +5374,7 @@ Monitor getContainingMonitor(int x, int y) {
return getPrimaryMonitor();
}

Monitor getContainingMonitor(int x, int y, int width, int height) {
private Monitor getContainingMonitor(int x, int y, int width, int height) {
Rectangle rectangle = new Rectangle(x, y, width, height);
Monitor[] monitors = getMonitors();
Monitor selectedMonitor = getPrimaryMonitor();
Expand All @@ -5383,7 +5391,7 @@ Monitor getContainingMonitor(int x, int y, int width, int height) {
return selectedMonitor;
}

Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels) {
private Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels) {
Monitor[] monitors = getMonitors();
for (Monitor current : monitors) {
Rectangle clientArea = getMonitorClientAreaInPixels(current);
Expand All @@ -5394,7 +5402,7 @@ Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels) {
return getPrimaryMonitor();
}

Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels, int widthInPixels, int heightInPixels) {
private Monitor getContainingMonitorInPixelsCoordiate(int xInPixels, int yInPixels, int widthInPixels, int heightInPixels) {
Rectangle rectangleInPixels = new Rectangle(xInPixels, yInPixels, widthInPixels, heightInPixels);
Monitor[] monitors = getMonitors();
Monitor selectedMonitor = getPrimaryMonitor();
Expand All @@ -5420,15 +5428,15 @@ private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {

private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
x = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
y = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(x, y);
int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(mappedX, mappedY);
}

private Point getPointFromPixels(Monitor monitor, int x, int y) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
x = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
y = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(x, y);
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(mappedX, mappedY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ public void setAlpha (int alpha) {
@Override
public Rectangle getBounds() {
Rectangle boundsInPixels = getBoundsInPixels();
return display.translateRectangleInPointsInDisplayCoordinateSystem(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
return display.translateRectangleInPointsInDisplayCoordinateSystemByContainment(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
}

@Override
Expand Down Expand Up @@ -1598,7 +1598,7 @@ public void setBounds(Rectangle rect) {

@Override
public void setBounds(int x, int y, int width, int height) {
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height);
Rectangle boundsInPixels = display.translateRectangleInPixelsInDisplayCoordinateSystemByContainment(x, y, width, height);
setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height);
}

Expand Down

0 comments on commit fd0a9d8

Please sign in to comment.