Commit 18bc4986 authored by techird's avatar techird

补注释

parent 17d20b9c
...@@ -25,30 +25,42 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -25,30 +25,42 @@ var ViewDragger = kity.createClass( "ViewDragger", {
lastPosition = null; lastPosition = null;
this._minder.on( 'beforemousedown', function ( e ) { this._minder.on( 'beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) { if ( dragger.isEnabled() ) {
startPosition = e.getPosition(); startPosition = e.getPosition();
e.stopPropagation(); e.stopPropagation();
} else if ( !this.getRoot().isSelected() && e.getTargetNode() == this.getRoot() ) { }
// 点击未选中的根节点临时开启
else if ( !this.getRoot().isSelected() && e.getTargetNode() == this.getRoot() ) {
startPosition = e.getPosition(); startPosition = e.getPosition();
dragger.setEnabled( true ); dragger.setEnabled( true );
isRootDrag = true; isRootDrag = true;
} }
} ).on( 'beforemousemove', function ( e ) { } )
.on( 'beforemousemove', function ( e ) {
if ( startPosition ) { if ( startPosition ) {
lastPosition = e.getPosition(); lastPosition = e.getPosition();
// 当前偏移加上历史偏移
var offset = kity.Vector.fromPoints( startPosition, lastPosition ); var offset = kity.Vector.fromPoints( startPosition, lastPosition );
offset = kity.Vector.add( dragger._offset, offset ); offset = kity.Vector.add( dragger._offset, offset );
this.getRenderContainer().setTransform( new kity.Matrix().translate( offset.x, offset.y ) ); this.getRenderContainer().setTransform( new kity.Matrix().translate( offset.x, offset.y ) );
e.stopPropagation(); e.stopPropagation();
} }
} ).on( 'mouseup', function ( e ) { } )
.on( 'mouseup', function ( e ) {
if ( startPosition && lastPosition ) { if ( startPosition && lastPosition ) {
// 合并更改的偏移到历史偏移
dragger._offset.x += lastPosition.x - startPosition.x; dragger._offset.x += lastPosition.x - startPosition.x;
dragger._offset.y += lastPosition.y - startPosition.y; dragger._offset.y += lastPosition.y - startPosition.y;
} }
startPosition = null; startPosition = null;
// 临时拖动需要还原状态
if ( isRootDrag ) { if ( isRootDrag ) {
dragger.setEnabled( false ); dragger.setEnabled( false );
isRootDrag = false; isRootDrag = false;
......
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