protected override void OnMouseWheel(MouseWheelEventArgs e) { base.OnMouseWheel(e); if (null == ViewModel) { return; } if (!_IsWheeling) { History.NodeGraphHistory history = ViewModel.Model.History; history.BeginTransaction("Zooming"); _ZoomAndPanStartMatrix = ZoomAndPan.Matrix; } _WheelStartTime = _CurrentTime; _IsWheeling = true; double newScale = _ZoomAndPan.Scale; newScale += (0.0 > e.Delta) ? -0.05 : 0.05; newScale = Math.Max(0.1, Math.Min(1.0, newScale)); Point vsZoomCenter = e.GetPosition(this); Point zoomCenter = _ZoomAndPan.MatrixInv.Transform(vsZoomCenter); _ZoomAndPan.Scale = newScale; Point vsNextZoomCenter = _ZoomAndPan.Matrix.Transform(zoomCenter); Point vsDelta = new Point(vsZoomCenter.X - vsNextZoomCenter.X, vsZoomCenter.Y - vsNextZoomCenter.Y); _ZoomAndPan.StartX -= vsDelta.X; _ZoomAndPan.StartY -= vsDelta.Y; }
protected override void OnMouseRightButtonDown(MouseButtonEventArgs e) { base.OnMouseRightButtonDown(e); if (null == ViewModel) { return; } Keyboard.Focus(this); _RightButtonDownPos = e.GetPosition(this); _ZoomAndPanStartMatrix = ZoomAndPan.Matrix; if (!NodeGraphManager.IsDragging) { _IsDraggingCanvas = true; Mouse.Capture(this, CaptureMode.SubTree); History.NodeGraphHistory history = ViewModel.Model.History; history.BeginTransaction("Panning"); } }
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); } }
/// <summary> /// Never call this constructor directly. Use GraphManager.CreateFlowChart() method. /// </summary> public FlowChart(NodeGraphManager ngm, Guid guid) : base(guid) { NodeGraphManager = ngm; History = new History.NodeGraphHistory(ngm, this, 100); }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (null == ViewModel) { return; } if (IsFocused) { if (Key.Delete == e.Key) { FlowChart flowChart = ViewModel.Model; flowChart.History.BeginTransaction("Destroy Selected Nodes"); { NodeGraphManager.DestroySelectedNodes(ViewModel.Model); } flowChart.History.EndTransaction(false); } else if (Key.Escape == e.Key) { FlowChart flowChart = ViewModel.Model; flowChart.History.BeginTransaction("Destroy Selected Nodes"); { NodeGraphManager.DeselectAllNodes(ViewModel.Model); } flowChart.History.EndTransaction(false); } else if (Key.A == e.Key) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { NodeGraphManager.SelectAllNodes(ViewModel.Model); } else { FitNodesToView(false); } } else if (Key.F == e.Key) { FitNodesToView(true); } else if (Key.Z == e.Key) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { History.NodeGraphHistory history = ViewModel.Model.History; history.Undo(); } } else if (Key.Y == e.Key) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { History.NodeGraphHistory history = ViewModel.Model.History; history.Redo(); } } } }
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; } } } }
/// <summary> /// Never call this constructor directly. Use GraphManager.CreateFlowChart() method. /// </summary> public FlowChart(Guid guid) : base(guid) { History = new History.NodeGraphHistory(this, 100); }