Commit 89fa2d72 authored by techird's avatar techird

拖动问题修复

parent 18bc4986
......@@ -21,18 +21,19 @@ var ViewDragger = kity.createClass( "ViewDragger", {
_bind: function () {
var dragger = this,
isRootDrag = false,
startPosition = null,
lastPosition = null;
lastPosition = null,
currentPosition = null;
this._minder.on( 'beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
startPosition = e.getPosition();
lastPosition = e.getPosition();
e.stopPropagation();
}
// 点击未选中的根节点临时开启
else if ( !this.getRoot().isSelected() && e.getTargetNode() == this.getRoot() ) {
startPosition = e.getPosition();
else if ( e.getTargetNode() == this.getRoot() &&
(!this.getRoot().isSelected() || !this.isSingleSelect())) {
lastPosition = e.getPosition();
dragger.setEnabled( true );
isRootDrag = true;
}
......@@ -40,25 +41,20 @@ var ViewDragger = kity.createClass( "ViewDragger", {
} )
.on( 'beforemousemove', function ( e ) {
if ( startPosition ) {
lastPosition = e.getPosition();
if ( lastPosition ) {
currentPosition = e.getPosition();
// 当前偏移加上历史偏移
var offset = kity.Vector.fromPoints( startPosition, lastPosition );
offset = kity.Vector.add( dragger._offset, offset );
var offset = kity.Vector.fromPoints( lastPosition, currentPosition );
this.getRenderContainer().setTransform( new kity.Matrix().translate( offset.x, offset.y ) );
this.getRenderContainer().translate( offset.x, offset.y );
e.stopPropagation();
lastPosition = currentPosition;
}
} )
.on( 'mouseup', function ( e ) {
if ( startPosition && lastPosition ) {
// 合并更改的偏移到历史偏移
dragger._offset.x += lastPosition.x - startPosition.x;
dragger._offset.y += lastPosition.y - startPosition.y;
}
startPosition = null;
lastPosition = null;
// 临时拖动需要还原状态
if ( isRootDrag ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment