Loading...
Logo
Processing Forum
i need the upper-left corner of my sketch in screen (OS) coordinates. i've tried using frame.getInsets() but i found that PApplet's frame is a local variable inside main(), and the public Frame frame in PApplet is never used (weird...).

any clues?

Replies(2)

The upper left hand corner of the frame can be achieved with frame.getLocation().x and frame.getLocation().y... but you want to account for the insets? Can't you just use frame.getInsets()? I guess I don't understand your problem.

The following sketch works for me:

Copy code
  1. void setup() {
  2.   size(400, 400);
  3.  
  4.   strokeWeight(10);
  5.   smooth();
  6. }

  7. void draw() {
  8.   PVector screenLoc = new PVector(frame.getLocation().x + frame.getInsets().left, frame.getLocation().y + frame.getInsets().top;
  9.   println(screenLoc);
  10.  
  11.   //Center the sketch window in the screen to see the point
  12.  
  13.   background(255);
  14.   point(screenWidth / 2 - screenLoc.x, screenHeight / 2 - screenLoc.y);
  15. }
getLocation is better than getInsets, thanks.

strange, using frame in either setup() or draw() gives me a null pointer exception in my application, which is running from eclipse.  pasting your code into the processing IDE works tho...

let me look around some more...