Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210294

Wrong positioning calculation at the edge of the Stage

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: openjfx11
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:

      Description

      When a node is positioned on the edge of the stage there are 2 calculations that are wrong, demonstrated by the following example:

      import javafx.application.Application;
      import javafx.geometry.Bounds;
      import javafx.geometry.Point3D;
      import javafx.scene.Group;
      import javafx.scene.PerspectiveCamera;
      import javafx.scene.Scene;
      import javafx.scene.SceneAntialiasing;
      import javafx.scene.SubScene;
      import javafx.scene.control.Slider;
      import javafx.scene.layout.AnchorPane;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.paint.PhongMaterial;
      import javafx.scene.shape.Box;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.transform.Rotate;
      import javafx.stage.Stage;

      public class BoundsTest2 extends Application {

      @Override
      public void start(Stage primaryStage) {
      Box shape = new Box(10, 10, 10);
      shape.setMaterial(new PhongMaterial(Color.RED));
      Group group = new Group(shape);
      SubScene subScene = new SubScene(group, 500, 500, true, SceneAntialiasing.BALANCED);

      AnchorPane anchorPane = new AnchorPane();

      Slider slider = new Slider(0, 20, 20);
      slider.setShowTickMarks(true);
      slider.setShowTickLabels(true);
      slider.valueProperty().addListener((obs, ov, nv) -> drawBounds(shape, anchorPane));

      PerspectiveCamera camera = new PerspectiveCamera(true);
      camera.translateXProperty().bind(slider.valueProperty().negate());
      camera.setTranslateZ(-60);
      camera.getTransforms().add(new Rotate(45, 0, 0, 60, new Point3D(1, 1, 1)));
      subScene.setCamera(camera);

      drawBounds(shape, anchorPane);

      Scene scene = new Scene(new VBox(slider, new StackPane(subScene, anchorPane)), 500, 500);

      primaryStage.setScene(scene);
      primaryStage.show();
      }

      private void drawBounds(Box shape, AnchorPane anchorPane) {
      Bounds boundsInParent = shape.getBoundsInParent();
      Bounds sceneBounds = shape.getParent().localToScene(boundsInParent, true);
      Bounds anchorBounds = anchorPane.sceneToLocal(sceneBounds, true);
      Rectangle rect = new Rectangle(anchorBounds.getMinX(), anchorBounds.getMinY(), anchorBounds.getWidth(), anchorBounds.getHeight());
      rect.setFill(Color.rgb(50, 150, 150, 0.3));
      anchorPane.getChildren().setAll(rect);
      }

      public static void main(String[] args) {
      launch(args);
      }
      }

      1. The bounds of the box are converted to an overlay pane. On running, if the box is on the edge of the stage, the bounds are misaligned. After running, moving the slider will re-align the bounds gradually. Eventually, the bounds will stick to the correct position.

      2. The direction of the box (the camera is actually translated) is inconsistent. On running, sliding to the left will first move the box to the right, then back to the left. After the box fully entered the stage, sliding to the right will cause a small change in trajectory when the box hits the edge of the stage.

        Attachments

        1. BoundsTest2.java
          2 kB
          Ambarish Rapte
        2. with_latest_fx.png
          14 kB
          Ambarish Rapte

          Activity

            People

            • Assignee:
              arapte Ambarish Rapte
              Reporter:
              nlisker Nir Lisker
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: