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

Transformed node receives mouse coordinates in MouseEvent incorrectly

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P3
    • None
    • fx1.0
    • javafx
    • Windows XP Pro, NetBeans 6.5, JavaFX 1.0

    Description

      It would be logical if a node that receives mouse events was getting mouse coordinates in its own coordinate space, before transformations are applied. Consider an example: A node that shows a line when the mouse is clicked and dragged over it -- class LineDragger. This class works fine until a transformation is applied to the group that contains it (see code below). The example demonstrates that mouse coordinates are useless for a node that has transformations applied to it or to any of its parents. A more practical example is a control (e.g. scrollbar, tabbed pane) that is created in horizontal mode and then rotated to work in vertical mode.

      This issue is related to RT-659, which talks about effects.

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

      import javafx.scene.CustomNode;
      import javafx.scene.Group;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.Node;
      import javafx.scene.paint.Color;
      import javafx.scene.Scene;
      import javafx.scene.shape.Line;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.transform.Rotate;
      import javafx.stage.Stage;

      class LineDragger extends CustomNode {


          override function create (): Node {
              var l: Line;
              var r: Rectangle;
              def g: Group = Group {
                  content: [
                      r = Rectangle {
                          fill: Color.BLUE
                          width: 100
                          height: 100
                      }
                      l = Line {
                          stroke: Color.WHITE;
                          visible: false
                      }
                  ]

                  onMouseDragged: function(e: MouseEvent) {
                      l.startX = e.dragAnchorX - g.boundsInScene.minX;
                      l.startY = e.dragAnchorY - g.boundsInScene.minY;
                      l.endX = e.dragAnchorX + e.dragX - g.boundsInScene.minX;
                      l.endY = e.dragAnchorY + e.dragY - g.boundsInScene.minY;
                      l.visible = true;
                  }

                  onMouseReleased: function(e: MouseEvent) {
                      l.visible = false;
                  }
              };
              return g
          }
      }



      Stage {
          width: 200
          height: 200
          scene: Scene {
              var g: Group;
              content: g = Group {
                      translateX: 20
                      translateY: 20
                      content: [LineDragger {}]
                      transforms: Rotate {
                          angle: 45
                          pivotX: bind g.boundsInLocal.width / 2
                          pivotY: bind g.boundsInLocal.height / 2
                      }
                  }
          }
      }

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

      Change the angle from 45 to 0 to make this code work just fine.

      Attachments

        Activity

          People

            kcr Kevin Rushforth
            aryzhovjfx Alex Ryzhov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: