How to get the mouse position coordinates in a GWindow window (=not the main)

FRVFRV
edited March 2018 in Library Questions

Hello,

Is there any way to retrieve the mouse position in a GWindow window? In other word an equivalent to the mouseMoved() available in the main but for a GWindow window. I tried to pass mouseMove() through a MouseEvent handler which partially works (i.e. I'm entering the mouseMoved() function when moving the mouse over the active GWindow object) but mouseMove() keeps sending the last coordinates when the mouse left the main window, and not the current coordinate in the active GWIndow.

Any hint on the way to implement this = get access to the true mouse coordinates in aGwindow ? any code samples you can share ? I would really appreciate any help you can provide.

Thks

Answers

  • I tried to pass mouseMove() through a MouseEvent handler which partially works

    Can you share your attempt?

    keeps sending the last coordinates when the mouse left the main window, and not the current coordinate in the active GWIndow

    Are you changing the focus of your window for this?

    Kf

  • Hi

    Below a stupid example of the test code. In brief, when I move inside the Map window with the mouse, I get "toto" printed in the console which indicate that the mouseMoved() funtion has been called. But mouseX mouseY return coordinates which are the last coordinates when the mouse left the main window. When I'm back into the main window, mouseX mouseY do behaves as expected. So question = how to get the mouseX, mouseY equivalent for the Map window.

    Thks for helping !

    //////////////////////////////////////////////////////////////// synchronized public void Map_draw(PApplet appc, GWinData data) { //CODE:Map:883061: appc.background(200,200,250); map.draw(); } //CODE:Map:883061:

    synchronized public void Map_Grab(PApplet appc, GWinData data, MouseEvent mevent) { //CODE:Map:845935: println("Map - mouse event " + millis()); mouseMoved(); } //CODE:Map:845935:

    Map = GWindow.getWindow(this, "XTRTrace", 0, 0, 500, 500, P2D); Map.noLoop(); Map.addDrawHandler(this, "Map_draw"); Map.addMouseHandler(this, "Map_Grab");

    GWindow Map;

    void mouseMoved() { println("toto"); println(mouseX); println(mouseY); }

  • FRVFRV
    Answer ✓

    Hi,

    I found my mistake when reading my post - forgot the Map.mouseX Map.mouseY... problem solved.... :-)

Sign In or Register to comment.