On Thu, 20 Oct 2022 14:37:04 GMT, Johan Vos <j...@openjdk.org> wrote:

> The root problem is actually broader than stated in the JBS issue. This PR 
> now translates screencoordinates from absolute coordinates into coordinates 
> that take the platformScale into account. 
> The whole process is complicated by the fact that throughout our code, we use 
> e.g. `x` and `y` without clearly stating if those are absolute, logical, 
> screen or rendering coordinates. 
> I believe the most consistent approach is to have the different entry points 
> (e.g. a Glass Window or a JFXPanel) to deal with platformScale before passing 
> screen coordinates. This is already done in the Glass approach, and this PR 
> does the same in JFXPanel. That means some code is duplicated, but since this 
> is only about 12 lines, and said code lives in 2 different modules, I think 
> it's not worth the hassle of moving that into e.g. the base module.

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java line 375:

> 373:         AffineTransform awtScales = 
> graphicsConfiguration.getDefaultTransform();
> 374:         for (Screen screen : Screen.getScreens()) {
> 375:             if ((Math.abs(screen.getPlatformX() - awtBounds.getX() * 
> awtScales.getScaleX()) < 0.001) &&

minor: would it be better to create a standard method?

isNearZero(double)?

although the value of the constant might depend on a situation.

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java line 385:

> 383:     }
> 384: 
> 385:     private Dimension2D getSwingToFxPixel(GraphicsConfiguration g, float 
> wx, float wy) {

minor: convertSwingToFxPixel() ?

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?

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java line 646:

> 644:                 Dimension2D fxcoord = 
> getSwingToFxPixel(getGraphicsConfiguration(), p.x, p.y);
> 645:                 screenX = (int)fxcoord.getWidth();
> 646:                 screenY = (int)fxcoord.getHeight();

same question about negative coordinates.

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

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

Reply via email to