protected override void OnLostFocus(RoutedEventArgs e) { base.OnLostFocus(e); if (null == ViewModel) { return; } NodeGraphManager.EndConnection(); NodeGraphManager.EndDragNode(); NodeGraphManager.EndDragSelection(true); if (_IsDraggingCanvas) { _IsDraggingCanvas = false; Mouse.Capture(null); History.NodeGraphHistory history = ViewModel.Model.History; history.EndTransaction(true); } }
private void Timer_Tick(object sender, EventArgs e) { _CurrentTime += _Timer.Interval.Milliseconds; if (null == ViewModel) { return; } if (NodeGraphManager.IsDragging) { MouseArea area = CheckMouseArea(); if (MouseArea.None != area) { Point delta = new Point(0.0, 0.0); if (MouseArea.Left == (area & MouseArea.Left)) { delta.X = -10.0; } if (MouseArea.Right == (area & MouseArea.Right)) { delta.X = 10.0; } if (MouseArea.Top == (area & MouseArea.Top)) { delta.Y = -10.0; } if (MouseArea.Bottom == (area & MouseArea.Bottom)) { delta.Y = 10.0; } Point mousePos = Mouse.GetPosition(this); UpdateDragging( new Point(mousePos.X + delta.X, mousePos.Y + delta.Y), // virtual mouse-position. delta); // virtual delta. _ZoomAndPan.StartX += delta.X; _ZoomAndPan.StartY += delta.Y; } } else if (_IsWheeling) { if (200 < (_CurrentTime - _WheelStartTime)) { _IsWheeling = false; History.NodeGraphHistory history = ViewModel.Model.History; history.AddCommand(new History.ZoomAndPanCommand( "ZoomAndPan", ViewModel.Model, _ZoomAndPanStartMatrix, ZoomAndPan.Matrix)); history.EndTransaction(false); } } else { _CurrentTime = 0.0; } }
protected override void OnMouseRightButtonUp(MouseButtonEventArgs e) { base.OnMouseRightButtonUp(e); if (null == ViewModel) { return; } NodeGraphManager.EndConnection(); NodeGraphManager.EndDragNode(); NodeGraphManager.EndDragSelection(true); Point mousePos = e.GetPosition(this); Point diff = new Point( Math.Abs(_RightButtonDownPos.X - mousePos.X), Math.Abs(_RightButtonDownPos.Y - mousePos.Y)); bool wasDraggingCanvas = (5.0 < diff.X) || (5.0 < diff.Y); if (_IsDraggingCanvas) { _IsDraggingCanvas = false; Mouse.Capture(null); History.NodeGraphHistory history = ViewModel.Model.History; if (wasDraggingCanvas) { history.AddCommand(new History.ZoomAndPanCommand( "ZoomAndPan", ViewModel.Model, _ZoomAndPanStartMatrix, ZoomAndPan.Matrix)); history.EndTransaction(false); } else { history.EndTransaction(true); } } if (!wasDraggingCanvas) { Point viewSpacePos; Point modelSpacePos; ModelType modelType; ModelBase model = FindModelUnderMouse(mousePos, out viewSpacePos, out modelSpacePos, out modelType); if (null != model) { BuildContextMenuArgs args = new BuildContextMenuArgs(); args.ViewSpaceMouseLocation = viewSpacePos; args.ModelSpaceMouseLocation = modelSpacePos; args.ModelType = modelType; ContextMenu = new ContextMenu(); ContextMenu.Closed += ContextMenu_Closed; args.ContextMenu = ContextMenu; if (!NodeGraphManager.InvokeBuildContextMenu(model, args)) { ContextMenu = null; } } } }