/// <summary> /// Handles when the mouse is moved. /// </summary> protected override void OnMouseMove(MouseEventArgs e) { if (_lostFocus) { _lostFocus = false; // update the last ouse position _lastMousePosition = e.Location; base.OnMouseMove(e); return; } // returns the mouse under the mouse cursor NodeViewData nodeFound = _rootNodeView.GetInsideNode(e.Location); NodeViewData.SubItem subItemFound = null; if (nodeFound != null) { subItemFound = nodeFound.GetSubItem(nodeFound, _nodeLayoutManager.ViewToGraph(e.Location)); } else { this.toolTip.Hide(this); } // clear previously stored node which can cause problems when dragging to another view //_dragTargetNode = null; if (nodeFound != null || _currentExpandNode != null || subItemFound != null) { if (_dragAttachment == null) { _currentNode = nodeFound; } if (Settings.Default.ShowNodeToolTips) { if (nodeFound != null) { _nodeToolTip = (subItemFound != null) ? subItemFound.ToolTip : nodeFound.ToolTip; } if (!string.IsNullOrEmpty(_nodeToolTip)) { this.toolTipTimer.Start(); } } Invalidate(); } // check if we are currently dragging the graph if ((e.Button == MouseButtons.Middle || (e.Button == MouseButtons.Left && _objectDragType == ObjectDragTypes.kGraph)) && _lastMousePosition != e.Location && !this.contextMenu.Visible) { Cursor = Cursors.SizeAll; // move the graph according to the last mouse position _nodeLayoutManager.Offset = new PointF(_nodeLayoutManager.Offset.X - (_lastMousePosition.X - e.X), _nodeLayoutManager.Offset.Y - (_lastMousePosition.Y - e.Y)); Invalidate(); } // check if we start duplicating an existing node step 1 else if (e.Button == MouseButtons.Left && KeyCtrlIsDown && _lastMousePosition != e.Location && _dragNodeDefaults == null && _copiedNode == null && _currentNode != null && !(_currentNode.Node is BehaviorNode)) { if (_objectDragType == ObjectDragTypes.kNode) { // node _movedNode = null; _copiedNode = _currentNode.Node; // create the layout manager used to draw the graph _movedNodeGraph = new NodeLayoutManager(_copiedNode.CloneBranch().CreateNodeViewData(null, _rootNodeView.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenSelected, _nodeLayoutManager.EdgePenHighlighted, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); _movedNodeGraph.Scale = 0.3f; _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; // use the existing node as the node defaults _dragNodeDefaults = _copiedNode; } else if (_objectDragType == ObjectDragTypes.kAttachment) { // attachment if (_dragAttachment == null) { NodeViewData.SubItem subItem = _currentNode.GetSubItem(_currentNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragAttachment = subItem as NodeViewData.SubItemAttachment; } } Invalidate(); } // check if we are duplicating an existing node step 2 else if (e.Button == MouseButtons.Left && KeyCtrlIsDown && (_copiedNode != null || _dragAttachment != null)) { if (_objectDragType == ObjectDragTypes.kNode) { // node _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; //Point movedGraphGraphPos= new Point(e.Location.X + _movedNodeGraph.Offset.X, e.Location.Y + _movedNodeGraph.Offset.Y /-2); //_movedNodeGraph.Location= movedGraphGraphPos; } else if (_objectDragType == ObjectDragTypes.kAttachment) { // attachment _dragTargetNode = nodeFound; if (_dragTargetNode != null) { NodeViewData.SubItem subItem = _dragTargetNode.GetSubItem(_dragTargetNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragTargetAttachment = subItem as NodeViewData.SubItemAttachment; } } Invalidate(); } // check if we start dragging an existing node step 1 else if (e.Button == MouseButtons.Left && _lastMousePosition != e.Location && !KeyCtrlIsDown && _movedNode == null && _currentNode != null) { if (_objectDragType == ObjectDragTypes.kNode) { // node if (_currentNode.CanBeDragged()) { if (_currentNode.IsFSM) { PointF currentGraphMousePos = _nodeLayoutManager.ViewToGraph(e.Location); PointF lastGraphMousePos = _nodeLayoutManager.ViewToGraph(_lastMousePosition); _currentNode.ScreenLocation = new PointF(_currentNode.ScreenLocation.X + currentGraphMousePos.X - lastGraphMousePos.X, _currentNode.ScreenLocation.Y + currentGraphMousePos.Y - lastGraphMousePos.Y); LayoutChanged(); } else if ((KeyShiftIsDown || _currentNode.Node.ParentCanAdoptChildren)) { _movedNode = _currentNode.Node; // create the layout manager used to draw the graph if (_movedNodeGraph == null) { _movedNodeGraph = new NodeLayoutManager(_movedNode.CloneBranch().CreateNodeViewData(null, _rootNodeView.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenSelected, _nodeLayoutManager.EdgePenHighlighted, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); } _movedNodeGraph.Scale = 0.3f; //_movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _movedNodeGraph.RenderDepth = int.MaxValue; } } } else if (_objectDragType == ObjectDragTypes.kAttachment) { // attachment if (_fsmDragMode == FSMDragModes.kNone && Plugin.EditMode == EditModes.Design) { _movedNodeGraph = null; _dragTargetNode = nodeFound; if (_dragAttachment == null) { NodeViewData.SubItem subItem = _currentNode.GetSubItem(_currentNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragAttachment = subItem as NodeViewData.SubItemAttachment; if (_dragAttachment != null) { _movedSubItem = _dragAttachment.Clone(_currentNode.Node); } } else if (_dragTargetNode != null) { NodeViewData.SubItem subItem = _dragTargetNode.GetSubItem(_dragTargetNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragTargetAttachment = subItem as NodeViewData.SubItemAttachment; } } } Invalidate(); } // check if we start dragging an existing node step 2 else if (e.Button == MouseButtons.Left && _movedNode != null && !_clipboardPasteMode) { // create the layout manager used to draw the graph if (_movedNodeGraph == null) { _movedNodeGraph = new NodeLayoutManager(_movedNode.CloneBranch().CreateNodeViewData(null, _rootNodeView.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenSelected, _nodeLayoutManager.EdgePenHighlighted, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); } _movedNodeGraph.Scale = 0.3f; _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _dragNodeDefaults = _movedNode; _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; Invalidate(); } else if (_clipboardPasteMode) { if (_movedNodeGraph != null) { //_movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _movedNodeGraph.RenderDepth = int.MaxValue; } _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; Invalidate(); } else if (_currentNode != null && _dragAttachment == null) { // Highlight the expand/collapse flag PointF graphMousePos = _nodeLayoutManager.ViewToGraph(e.Location); bool isInExandRange = _currentNode.IsInExpandRange(graphMousePos); bool isInExandConnectorRange = _currentNode.IsInExpandConnectorRange(graphMousePos); if (isInExandRange || isInExandConnectorRange) { _currentExpandNode = _currentNode; _nodeToolTip = isInExandRange ? Resources.ExpandAllInfo : Resources.ExpandConnectorInfo; Invalidate(); } else if (_currentExpandNode != null) { _currentExpandNode = null; Invalidate(); } } // update the last ouse position _lastMousePosition = e.Location; base.OnMouseMove(e); }
/// <summary> /// Handles when the mouse is moved. /// </summary> protected override void OnMouseMove(MouseEventArgs e) { if (_lostFocus) { _lostFocus = false; // update the last ouse position _lastMousePosition = e.Location; base.OnMouseMove(e); return; } // returns the mouse under the mouse cursor NodeViewData nodeFound = _rootNode.IsInside(e.Location); // clear previously stored node which can cause problems when dragging to another view //_dragTargetNode = null; // if a different node is the current one, update it if (nodeFound != _currentNode || _currentExpandNode != null) { if (_dragAttachment == null) { _currentNode = nodeFound; } if (nodeFound == null) { this.toolTip.Hide(this); } else if (Settings.Default.ShowNodeToolTips) { if (!string.IsNullOrEmpty(nodeFound.ToolTip)) this.toolTipTimer.Start(); } Invalidate(); } // check if we are currently dragging the graph if ((e.Button == MouseButtons.Middle || e.Button == MouseButtons.Left && IsPanMode) && _lastMousePosition != e.Location && !this.contextMenu.Visible) { _isGraphDragged = true; // move the graph according to the last mouse position _nodeLayoutManager.Offset = new PointF(_nodeLayoutManager.Offset.X - (_lastMousePosition.X - e.X), _nodeLayoutManager.Offset.Y - (_lastMousePosition.Y - e.Y)); Invalidate(); } // check if we start duplicating an existing node step 1 else if (e.Button == MouseButtons.Left && KeyCtrlIsDown && _lastMousePosition != e.Location && _dragNodeDefaults == null && _copiedNode == null && _currentNode != null && !(_currentNode.Node is BehaviorNode)) { _movedNode = null; _copiedNode = _currentNode.Node; // create the layout manager used to draw the graph _movedNodeGraph = new NodeLayoutManager(_copiedNode.CloneBranch().CreateNodeViewData(null, _rootNode.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenHighlight, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); _movedNodeGraph.Scale = 0.3f; _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; // use the existing node as the node defaults _dragNodeDefaults = _copiedNode; Invalidate(); } // check if we are duplicating an existing node step 2 else if (e.Button == MouseButtons.Left && KeyCtrlIsDown && _copiedNode != null) { _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; //Point movedGraphGraphPos= new Point(e.Location.X + _movedNodeGraph.Offset.X, e.Location.Y + _movedNodeGraph.Offset.Y /-2); //_movedNodeGraph.Location= movedGraphGraphPos; Invalidate(); } // check if we start dragging an existing node step 1 else if (e.Button == MouseButtons.Left && _lastMousePosition != e.Location && !KeyCtrlIsDown && _movedNode == null && _currentNode != null && !(_currentNode.Node is BehaviorNode)) { if (_isNodeDragged) // node { if (KeyShiftIsDown || _currentNode.Node.ParentCanAdoptChildren) { _movedNode = _currentNode.Node; // create the layout manager used to draw the graph if (_movedNodeGraph == null) _movedNodeGraph = new NodeLayoutManager(_movedNode.CloneBranch().CreateNodeViewData(null, _rootNode.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenHighlight, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); _movedNodeGraph.Scale = 0.3f; _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; } } else // attachment { _movedNodeGraph = null; if (_dragAttachment == null) { NodeViewData.SubItem subItem = _currentNode.GetSubItem(_currentNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragAttachment = subItem as NodeViewData.SubItemAttachment; } else { NodeViewData.SubItem subItem = _currentNode.GetSubItem(_currentNode, _nodeLayoutManager.ViewToGraph(e.Location)); _dragTargetAttachment = subItem as NodeViewData.SubItemAttachment; Invalidate(); } } } // check if we start dragging an existing node step 2 else if (e.Button == MouseButtons.Left && _movedNode != null && !_clipboardPasteMode) { // create the layout manager used to draw the graph if (_movedNodeGraph == null) _movedNodeGraph = new NodeLayoutManager(_movedNode.CloneBranch().CreateNodeViewData(null, _rootNode.RootBehavior), _nodeLayoutManager.EdgePen, _nodeLayoutManager.EdgePenHighlight, _nodeLayoutManager.EdgePenUpdate, _nodeLayoutManager.EdgePenReadOnly, true); _movedNodeGraph.Scale = 0.3f; _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _dragNodeDefaults = _movedNode; _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; Invalidate(); } else if (e.Button == MouseButtons.Right && IsPanMode && _panStartMousePosition != e.Location) { int delta = e.X - (int)_panStartMousePosition.X + (int)_panStartMousePosition.Y - e.Y; scaleGraph(delta / 16, false); } else if (_clipboardPasteMode) { if (_movedNodeGraph != null) _movedNodeGraph.RenderDepth = KeyShiftIsDown ? int.MaxValue : 0; _dragTargetNode = _currentNode; Cursor = _currentNode == null ? Cursors.No : Cursors.Default; Invalidate(); } else if (_currentNode != null && _dragAttachment == null) { // Highlight the expand/collapse flag PointF graphMousePos = _nodeLayoutManager.ViewToGraph(e.Location); if (_currentNode.IsInExpandRange(graphMousePos)) { _currentExpandNode = _currentNode; Invalidate(); } else if (_currentExpandNode != null) { _currentExpandNode = null; Invalidate(); } } // update the last ouse position _lastMousePosition = e.Location; base.OnMouseMove(e); }