Pixel scale change notification

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

Pixel scale change notification

Martin
Hi,

I am willing to adapt font size of a chart according to pixel scale (text look tiny when running on Retina or HiDPI).

In the case the user moves the app from an HiDPI main screen to a NON-HiDPI secondary screen, the pixel scale for rendering changes (as soon as one pixel of the app goes to a non HiDPI screen, the entire chart becomes non HiDPI - cooool!).

I wish I could add a listener somewhere to get notified of this change to avoid asking to the GLAutoDrawable its values in a loop/thread.

Is there any way to do it?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Pixel scale change notification

Martin
Hi,

I ended by adding a ScheduledThreadExecutor that watches the GLCanvas surface width / height every second.  

Here is an example of how I did it in Jzy3D where the canvas owner fires a pixel scale change event to its listeners.

This allows updating everything that may be impacted by a change in pixel scale : resize text to keep it the same size visually, change the image used in overlays so that they do not look shrinking or bumping as soon as the application moves from a HiDPI screen to a non HiDPI screen.

This works well at the cost of an additional thread. I am interested by any improvement suggestion!
Reply | Threaded
Open this post in threaded view
|

Re: Pixel scale change notification

farrellf
In reply to this post by Martin
With Java 8 and older, I don't know of a way to detect that. With Java 9 and newer, you can use use "((Graphics2D) getGraphics()).getTransform().getScaleX()" in your resize() method. No need to poll, the resize() method will be called when it changes.
Reply | Threaded
Open this post in threaded view
|

Re: Pixel scale change notification

Martin
Thanks, I used this in EmulGL which is AWT only, but that would not work outside of AWT (e.g. SWT).