GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

Marc Kurtz
We recently updated to JOGL 2.5.0 to take advantage of the high-dpi improvements. We make sure to size the GL viewport to the value returned by getSurfaceWidth/Height() and everything looks great! But we found that AWT still reports mouse/pointer coordinates in unscaled coordinates so that throws off all of our dragging code (among other things). Is there an easy fix to this? How are others approaching this problem? We see that the NEWT implementation doesn’t do this but unfortunately we are beholden to AWT for the time being. Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

gouessej
Administrator
Hello

I'm not sure that there is a solution in pure Swing/AWT without NEWT.

Have you ever used NewtCanvasAWT?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

Marc Kurtz
Thanks for writing! I have looked at NewtCanvasAWT and it's my understanding that I would first create a Newt window and then wrap that in a NewtCanvasAWT. I think the biggest thing holding us back is that NewtCanvasAWT is not a AWTGLAutoDrawable. This may be an architectural problem on our end, but we expect to be using AWTGLAutoDrawable and I wasn't able to get far.
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

gouessej
Administrator
Why do you need an AWTGLAutoDrawable?

NewtCanvasAWT extends an AWT canvas and the GLEventListener manipulates a GLAutoDrawable, it shouldn't be a big deal.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

Marc Kurtz
I seem to have made some progress with integrating NewtCanvasAWT, and I've been looking at the AWTMouseAdapter to help bridge the gap between the pointers. I see that NewtCanvasAWT does some work setting up an AWTMouseAdapter, but to be sure I am also calling new AWTMouseAdapter(glWindow).addTo(newtCanvasAwt); . However - if I add a mouse listener to the NewtCanvasAWT I don't get any mouse events. Yet if I add a mouse listener to the GLWindow I do get mouse events. So far, I can't figure out why.
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

gouessej
Administrator
Please can you show a small piece of your source code so that I can find the culprit? I assume that you try to add an AWT MouseListener to the NewtCanvasAWT.

I would rather do this:
new AWTMouseAdapter(myAwtMouseListener).addTo(myNewtCanvasAWT);

It attaches an adapter to the NewtCanvasAWT which makes the translation between AWT and NEWT. Look at the examples in the documentation.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

Marc Kurtz
gouessej wrote
I assume that you try to add an AWT MouseListener to the NewtCanvasAWT.
Yes - this is what I am currently doing.

gouessej wrote
I would rather do this:
new AWTMouseAdapter(myAwtMouseListener).addTo(myNewtCanvasAWT);
This sounds like what I want to do - I have an API user that provides an awt.event.MouseListener and I want to forward MouseEvents from NEWT to that AWT listener. However there is no constructor that takes an awt.event.MouseListener, it only takes newt.event.MouseListener. Am I missing something?
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

Marc Kurtz
Just for reference, here is what I see in the documentation:

AWTMouseAdapter()
AWTMouseAdapter​(com.jogamp.newt.event.MouseListener newtListener, NativeSurfaceHolder nsProxy)
AWTMouseAdapter​(com.jogamp.newt.event.MouseListener newtListener, Window newtProxy)
AWTMouseAdapter​(Window downstream)
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel/GLCanvas dpi scaling and AWT pointer coordinates

gouessej
Administrator
Sorry I took the problem in the wrong direction, you're right.

I'm not sure that my solution is suitable for your use case but could you use NEWT mouse listener instead? Actually, the AWTMouseAdapter allows to build an AWT MouseListener,  an AWT MouseMotionListener and an AWT MouseWheelListener from a single NEWT mouse listener but you seem to need to do the opposite. The documentation of isAWTEventPassThrough() indicates that only the NEWT child receives the key and mouse input events, it seems to be consistent with what you observed. I fear that adding an AWTMouseAdapter to the NewtCanvasAWT will lead nowhere. I see two options:
- write a NEWT mouse listener and add it into the NEWT child of the NewtCanvasAWT (you already know that it works)
- write a utility that builds a single NEWT mouse listener from an AWT MouseListener,  an AWT MouseMotionListener and an AWT MouseWheelListener and add it into the NEWT child of the NewtCanvasAWT

Personally, I would choose the first option, it would drive your listener AWT agnostic, you could still use it with NEWT and AWT. The second option is doable but you would introduce AWT event management's limitations into NEWT, you should make a request for enhancement about this subject, maybe I can help you to write the necessary class to do that, it would help the transition from AWT to NEWT because we could use the resulting class in NewtCanvasAWT so that you could simply add an AWT mouse listener to it and it would work but I'm sure that there is a reason why it wasn't designed that way.

Sven, what's your opinion about that?
Julien Gouesse | Personal blog | Website