/// <summary> /// 根据当前节点以及插入方式来获取插入的父节点以及插入的位置索引 /// </summary> /// <param name="insertMode"></param> /// <param name="curNode"></param> /// <param name="parent"></param> /// <param name="index"></param> private void GetParentNodeAndInsertIndexByInsertMode(NodeInsertMode insertMode, BaseNode curNode, out BaseNode parent, out int index) { // 选中根节点的时候,只能作为子节点插入 if (curNode.GetNodeType() == NodeType.Root) { parent = _curSelectedNode; index = -1; } else { if (insertMode == NodeInsertMode.InsertAfter) { parent = _curSelectedNode.GetParentNode(); index = parent.GetChildIndex(_curSelectedNode) + 1; } else if (insertMode == NodeInsertMode.InsertBefore) { parent = _curSelectedNode.GetParentNode(); index = parent.GetChildIndex(_curSelectedNode); } else { parent = _curSelectedNode; index = -1; } } }
internal void UpdateHoveredNode() { TreeViewNode oldHoveredNode = HoveredNode; HoveredNode = null; if( mbIsHovered ) { int iNodeY = ( mHoverPoint.Y - ( LayoutRect.Y + 10 ) + (int)Scrollbar.LerpOffset ); int iOffset = iNodeY % ( NodeHeight + NodeSpacing ); if( iOffset < ( NodeHeight + NodeSpacing ) / 4 ) { InsertMode = NodeInsertMode.Before; } else if( iOffset > ( NodeHeight + NodeSpacing ) * 3 / 4 ) { InsertMode = NodeInsertMode.After; } else { InsertMode = NodeInsertMode.Over; } int iNodeIndex = iNodeY / ( NodeHeight + NodeSpacing ); HoveredNode = FindHoveredNode( Nodes, iNodeIndex, 0 ); if( HoveredNode == null ) { InsertMode = iNodeY < ( NodeHeight + NodeSpacing ) / 4 ? NodeInsertMode.Before : NodeInsertMode.After; } else if( HoverHandler != null && oldHoveredNode != HoveredNode ) { HoverHandler( this ); } if( oldHoveredNode != HoveredNode ) { if( mHoveredActionButton != null ) { if( mbIsHoveredActionButtonDown ) { mHoveredActionButton.ResetPressState(); mbIsHoveredActionButtonDown = false; } mHoveredActionButton = null; } } if( ! IsDragging && HoveredNode != null ) { if( mHoveredActionButton != null ) { if( mHoveredActionButton.HitTest( mHoverPoint ) != null ) { mHoveredActionButton.OnMouseMove( mHoverPoint ); } else { mHoveredActionButton.OnMouseOut( mHoverPoint ); if( mbIsHoveredActionButtonDown ) { mHoveredActionButton.ResetPressState(); mbIsHoveredActionButtonDown = false; } mHoveredActionButton = null; } } if( mHoveredActionButton == null ) { mbIsHoveredActionButtonDown = false; foreach( Button button in ActionButtons ) { if( button.HitTest( mHoverPoint ) != null ) { mHoveredActionButton = button; mHoveredActionButton.OnMouseEnter( mHoverPoint ); break; } } } } else { if( mbIsHoveredActionButtonDown ) { mHoveredActionButton.ResetPressState(); mbIsHoveredActionButtonDown = false; } mHoveredActionButton = null; } } else if( mHoveredActionButton != null ) { if( mbIsHoveredActionButtonDown ) { mHoveredActionButton.ResetPressState(); mbIsHoveredActionButtonDown = false; } mHoveredActionButton = null; } }