so Processing used to have a "frame" class which allowed for some versatile functionality. I'm trying to get the location of the PApplet window onscreen but without the "frame" class, I can't seem to to do it.
The old way:
int fX = frame.getX();
or
int fX = frame.getLocationOnScreen().x;
The whole thing is supposed to be dynamic, so setting the window location in Processings setup() is not an option.
Hope somebody can help,
Greetings! B
You're probably best off just using the old frame
variable.
For most things like this, you should use the new surface
variable, which is of type PSurface
. You can view the source for PSurface
here. Reading that, we see that unfortunately, the surface
variable doesn't give us access to the frame's position.
Since you can't get to the location from the surface
variable, you have to go a level deeper and get the native component (in the default case, a SmoothCanvas
which extends an awt Canvas
). I figured this out by looking at the source for PSurfaceAWT
available here.
The code for that looks a little gross, since you have to do some casting:
import processing.awt.PSurfaceAWT;
import processing.awt.PSurfaceAWT.SmoothCanvas;
void setup(){
size(200, 200);
}
void draw(){
background(0);
int x = ( (SmoothCanvas) ((PSurfaceAWT)surface).getNative()).getFrame().getX();
text("x: " + x , 20, 20);
}