mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
use absolute distance to choose correct screen for offscreen clamping
This commit is contained in:
parent
5cd1e6a7c5
commit
82044442ee
1 changed files with 15 additions and 21 deletions
|
@ -218,12 +218,9 @@ public class Robot {
|
||||||
* @param y Y position
|
* @param y Y position
|
||||||
*/
|
*/
|
||||||
public synchronized void mouseMove(int x, int y) {
|
public synchronized void mouseMove(int x, int y) {
|
||||||
int leastXDiff = Integer.MAX_VALUE;
|
int leastDiff = Integer.MAX_VALUE;
|
||||||
int leastYDiff = Integer.MAX_VALUE;
|
int finX = x;
|
||||||
int finX1 = x;
|
int finY = y;
|
||||||
int finY1 = y;
|
|
||||||
int finX2 = x;
|
|
||||||
int finY2 = y;
|
|
||||||
|
|
||||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||||
|
@ -238,32 +235,29 @@ public class Robot {
|
||||||
|
|
||||||
int currXDiff = Math.abs(x - cP.x);
|
int currXDiff = Math.abs(x - cP.x);
|
||||||
int currYDiff = Math.abs(y - cP.y);
|
int currYDiff = Math.abs(y - cP.y);
|
||||||
|
int currDiff = (int) Math.round(Math.hypot(currXDiff, currYDiff));
|
||||||
|
|
||||||
if ((currXDiff == 0) && (currYDiff == 0)) {
|
if (currDiff == 0) {
|
||||||
peer.mouseMove(x,y);
|
peer.mouseMove(x,y);
|
||||||
afterEvent();
|
afterEvent();
|
||||||
return;
|
return;
|
||||||
} if (currXDiff < leastXDiff) {
|
} if (currDiff < leastDiff) {
|
||||||
finX1 = cP.x;
|
finX = cP.x;
|
||||||
finY1 = cP.y;
|
finY = cP.y;
|
||||||
leastXDiff = currXDiff;
|
leastDiff = currDiff;
|
||||||
} if (currYDiff < leastYDiff) {
|
|
||||||
finX2 = cP.x;
|
|
||||||
finY2 = cP.y;
|
|
||||||
leastYDiff = currYDiff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leastXDiff > leastYDiff) {
|
peer.mouseMove(finX, finY);
|
||||||
peer.mouseMove(finX2, finY2);
|
|
||||||
} else {
|
|
||||||
peer.mouseMove(finX1, finY1);
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEvent();
|
afterEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point calcClosestPoint(int x, int y, Rectangle screenBounds) {
|
private Point calcClosestPoint(int x, int y, Rectangle screenBounds) {
|
||||||
|
Point p = new Point(Math.min(Math.max(x, screenBounds.x), screenBounds.x + screenBounds.width-1),
|
||||||
|
Math.min(Math.max(y, screenBounds.y), screenBounds.y + screenBounds.height-1));
|
||||||
|
System.out.println("bounds " + screenBounds);
|
||||||
|
System.out.println("tpt " + new Point(x,y));
|
||||||
|
System.out.println("cpt " + p + "\n");
|
||||||
return new Point(Math.min(Math.max(x, screenBounds.x), screenBounds.x + screenBounds.width-1),
|
return new Point(Math.min(Math.max(x, screenBounds.x), screenBounds.x + screenBounds.width-1),
|
||||||
Math.min(Math.max(y, screenBounds.y), screenBounds.y + screenBounds.height-1));
|
Math.min(Math.max(y, screenBounds.y), screenBounds.y + screenBounds.height-1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue