On Fri, 28 Oct 2022 07:01:02 GMT, Johan Vos <j...@openjdk.org> wrote:

>> modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java line 451:
>> 
>>> 449:         Dimension2D onScreen = 
>>> getSwingToFxPixel(getGraphicsConfiguration(), e.getXOnScreen(), 
>>> e.getYOnScreen());
>>> 450:         int fxXOnScreen = (int) onScreen.getWidth();
>>> 451:         int fxYOnScreen = (int) onScreen.getHeight();
>> 
>> question: should it be (int) or Math.round()?
>> also, coordinates can be negative - will it work then?
>
> I believe these values should be int in the first place. Otherwise, we have 
> issues in JavaFX where we process them as ints.
> About negative coordinates: yes, that works. Is the question about using 
> Dimension2D (width/height) for something that is actually a Point2D? We can 
> use a Point2D here as well, but that class seems to have a bit more overhead 
> than Dimension2D for this goal -- but I'm open to change it to Point2D.

No, what I meant is this:

 System.out.println("(int)-1.9999=" + (int)-1.9999 + " 
(int)Math.round(-1.9999)=" + (int)(Math.round(-1.9999)));
prints
(int)-1.9999=-1 (int)Math.round(-1.9999)=-2


i.e. typecast to int is equivalent to Math.ceil for negative values and 
Math.floor for positive.  We probably should use Math.round().

This code should be better tested on Windows with
a) second monitor positioned to the left of the main one, making its 
coordinates negative
b) using fractional HiDPI scaling which is only available on Windows it seems

And yes, I did not see Dimension2D - we probably should remove confusion and 
use Point2D (why does it have more overhead?)

-------------

PR: https://git.openjdk.org/jfx/pull/924

Reply via email to