You can get the window's top-left location with this renderer-independent method and use that to location the coordinate of the center of the sketch. Note you might have to account for the height of the titlebar.
PVector getWindowLocation() {
PVector windowLocation = new PVector();
switch (sketchRenderer()) {
case P2D:
case P3D:
com.jogamp.nativewindow.util.Point p = new com.jogamp.nativewindow.util.Point();
((com.jogamp.newt.opengl.GLWindow) surface.getNative()).getLocationOnScreen(p);
windowLocation.x = p.getX();
windowLocation.y = p.getY();
break;
case FX2D:
final processing.javafx.PSurfaceFX FXSurface = (processing.javafx.PSurfaceFX) surface;
final javafx.scene.canvas.Canvas canvas = (javafx.scene.canvas.Canvas) FXSurface.getNative();
final javafx.stage.Stage stage = (javafx.stage.Stage) canvas.getScene().getWindow();
windowLocation.x = (float) stage.getX();
windowLocation.y = (float) stage.getY();
break;
case JAVA2D:
java.awt.Frame f = (java.awt.Frame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative())
.getFrame();
windowLocation.x = f.getX();
windowLocation.y = f.getY();
break;
}
return windowLocation;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…