Finding the location of surface

edited January 2017 in Programming Questions

I would like to get the location of surface, but I don't know how to get that parameter. Also, is there a reference somewhere for surface? I cannot find a general reference for it anywhere.

Answers

  • What is surface? A library?

  • Answer ✓

    This link to show search results of interest:

    https://forum.processing.org/two/search?Search=getsurface

    Specifically,

    https://forum.processing.org/two/discussion/comment/73009/#Comment_73009

    Kf

    Title: How to get surface / window x and y coordinates? Keywords: surface.getNative processing.awt.PSurfaceAWT.SmoothCanvas https://forum.processing.org/two/discussion/comment/73029/#Comment_73029

  • edited January 2017

    Surface replaced frame in 3.0. Surface is the main window for a sketch. You can call surface.setVisible(false) and it will hide the window. With Frame you can get the position of X or Y with frame.getX() or frame.getY()

    I have done some searches with no answers to this. I would really like a reference for surface. Code autocomplete doesn't show available functions/methods/variables as it does with frame in the Processing IDE.

  • Okay, I am starting to understand now. I can make the window translucent and draw on it with the mouse. But I need a better way to move the window around. The issue appears to be that I need the mouse location on the screen and not the window. But should be a different thread. Thank you.

  • edited January 2017 Answer ✓

    @Bird -- just so I understand -- is the idea behind working with surface that you using the sketch OS window (e.g., the window frame, in Windows / macOS etc.) and you want dragging the OS-level sketch window frame around on the desktop to show different contents in the window -- like a kind of magnifying glass showing an image that covers the entire OS desktop space?

    Edit: corrected/expanded

    In that case, even if you could access desktop-offset coordinates of mouseX and mouseY, they might not give you a smooth visual experience. In the case of these variables, when you drag a window Processing does not update the mouse coordinate values until the mouse re-enters the sketch drawing area, so sketch contents would stay frozen while the sketch was being dragged.

    void draw() {
        if (mouseX!=pmouseX){
          line(mouseX, mouseY, pmouseX, pmouseY);
        }
    }
    

    Based on testing with @GoToLoop 's example sketch, getJFrame(getSurface()).getX() does update even when the mouse is out of focus or in the midst of a sketch window header click -- but it only updates its value when active dragging stops for more than a fraction of a second. The mouse click can still be down on the sketch title bar, but the value won't update until the sketch pauses moving. If you drag actively around the screen in loops then getX() continues to return the old position when the dragging started.

    Here is a modified version of that sketch for testing:

    void setup() {
      frameRate(4);
    }
    void draw(){
      println(getJFrame(getSurface()).getX());
    }
    static final javax.swing.JFrame getJFrame(final PSurface surf) {
      return
        (javax.swing.JFrame)
        ((processing.awt.PSurfaceAWT.SmoothCanvas)
        surf.getNative()).getFrame();
    }
    
Sign In or Register to comment.