2010-04-16 2 views
0

매우 가까워도 an acceptable solution에 가깝지만 작동하지 않습니다. Dock을 단지 사각형이면 드래그 할 수 있습니다. 그러나 노드 (예 : 이미지)를이 독에 추가하면 작동하는 솔루션을 얻을 수 없습니다. 다른 노드에서 사실 등의 mouseReleased와 그것을 시도하지만 제대로 작동 솔루션을 얻을 수 coudn't : JavaFX에서 사용자 노드 드래그

public class Dock extends CustomNode { 

    // initialize this with an 64x64 image of your choice 
    // via ImageView { image: Image {..}} 
    public var content: Node[]; 
    public var width = 64; 
    public var height = 64; 
    public var xOffset: Number = 0; 
    public var yOffset: Number = 0; 
    var imgX: Number = 0; 
    var imgY: Number = 0; 
    var distX: Number; 
    var distY: Number; 
    public var rasterX = function (n: Number): Number { 
       var MAX = 4 * 64; 
       if (n < 0) { 
        return 0 
       } else if (n > MAX) { 
        return MAX 
       } else 
        return n 
      } 
    public var rasterY = rasterX; 

    override protected function create(): Node { 
     Group { 
      // if we place the translate here then the whole dock will flicker 
      //translateX: bind imgX; 
      //translateY: bind imgY; 
      content: [ 
       Rectangle { 
        // ... and here 'content' logically won't be dragged 
        translateX: bind imgX; 
        translateY: bind imgY; 
        height: bind height 
        width: bind width 
        fill: Color.LIGHTGRAY 
        strokeWidth: 4 
        stroke: Color.BLACK 
       }, content] 

      onMousePressed: function (e: MouseEvent): Void { 
        xOffset = e.x; 
        yOffset = e.y; 

        // Calculate the distance of the mouse point from the image 
        // top-left corner which will always come out as positive value 
        distX = e.x - imgX; 
        distY = e.y - imgY;      
      } 
      onMouseDragged: function (e: MouseEvent): Void { 
        // Find out the new image postion by subtracting the distance 
        // part from the mouse point. 
        imgX = rasterX(e.x - distX); 
        imgY = rasterY(e.y - distY);      
      } 
     } 
    } 

내가 blocksMouse을 시도 :

여기 내 코드입니다. 어떻게 올바르게했는지에 대한 조언이나 조언이 있습니까?

답변

0

마지막 this example에서 그것을 밖으로 분류되어 있지만 (나는 예외를!?있어) 자습서를 수행 할 필요가 없습니다 - 단순히 sources 또는 사용 다운로드 : 나는 드래그를 해결하기 위해 노력하고

public class Dock extends CustomNode { 

public var content: Node[]; 
public var width = 64; 
public var height = 64; 
public var xOffset: Number = 0; 
public var yOffset: Number = 0;  
public var rasterX = function (n: Number): Number { 
      // the following code is for the 'grid' which can be avoided of course 
      var n2 = n - n mod 64; 
      var MAX = 4 * 64; 
      if (n2 < 0) { 
       return 0 
      } else if (n2 > MAX) { 
       return MAX 
      } else 
       return n2 
     } 
public var rasterY = rasterX;  

override protected function create(): Node { 
    var node: Group; 
    node = Group { 
     content: [ 
      Rectangle { 
       height: bind height 
       width: bind width 
       arcHeight: 10 
       arcWidth: 10 
       fill: Color.LIGHTGRAY 
       strokeWidth: 4 
       stroke: Color.BLACK 
       effect: DropShadow { 
        offsetX: 5 
        offsetY: 5 
        color: Color.DARKGRAY 
        radius: 10 
       } 
      }, content] 
     onMousePressed: function (e: MouseEvent): Void { 
      xOffset = e.sceneX - node.translateX; 
      yOffset = e.sceneY - node.translateY; 
     } 
     onMouseDragged: function (e: MouseEvent): Void { 
      node.translateX = rasterX(e.sceneX - yOffset); 
      node.translateY = rasterY(e.sceneY - yOffset); 
     } 
    } 
} 
} 
+0

을 드롭 문제는 내가 가지고 있고이 질문을 발견했다. 구식이 구식입니까? 나 또는 내 IDE가이 구문을 인식하지 못합니다. – Giannis

+0

네, 생각합니다 ... – Karussell