//Ctrl/Shift Pan Animation public ZoomAndPanAnimationHelper(double newOffsetX, double newOffsetY, GraphVisualHost visualHost, GraphControl graphControl) { mousePosition = graphControl.canvasScrollViewer.TranslatePoint(GetMousePosition(), graphControl.CurrentGraphCanvas); this.currentCursor = graphControl.GetCursor(); //System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None; staticGraphControl = graphControl; this.visualHost = visualHost; staticScrollViewer = staticGraphControl.canvasScrollViewer; ZoomAndPanAnimationHelper.newOffsetX = newOffsetX; ZoomAndPanAnimationHelper.newOffsetY = newOffsetY; ZoomAndPanAnimationHelper.newScale = double.MinValue; double offsetX = staticGraphControl.canvasScrollViewer.HorizontalOffset; double offsetY = staticGraphControl.canvasScrollViewer.VerticalOffset; double shiftX = newOffsetX - offsetX; double shiftY = newOffsetY - offsetY; if (Math.Abs(shiftX) < 0.01 && Math.Abs(shiftY) < 0.01) { return; } DoubleAnimation xOffsetAnimation = new DoubleAnimation(); xOffsetAnimation.From = offsetX; xOffsetAnimation.To = newOffsetX; xOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime); Storyboard.SetTarget(xOffsetAnimation, visualHost); Storyboard.SetTargetProperty(xOffsetAnimation, new PropertyPath("XOffset")); DoubleAnimation yOffsetAnimation = new DoubleAnimation(); yOffsetAnimation.From = offsetY; yOffsetAnimation.To = newOffsetY; yOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime); Storyboard.SetTarget(yOffsetAnimation, visualHost); Storyboard.SetTargetProperty(yOffsetAnimation, new PropertyPath("YOffset")); zoomAndPanStoryboard = new Storyboard(); zoomAndPanStoryboard.Children.Add(xOffsetAnimation); zoomAndPanStoryboard.Children.Add(yOffsetAnimation); zoomAndPanStoryboard.Completed += new EventHandler(OnAnimationCompleted); BeginAnimation(); }
//Zoom to Fit Animation public ZoomAndPanAnimationHelper(double newOffsetX, double newOffsetY, double newScale, GraphVisualHost visualHost, GraphControl graphControl, bool captureMouse) { staticGraphControl = graphControl; this.visualHost = visualHost; staticScrollViewer = staticGraphControl.canvasScrollViewer; ZoomAndPanAnimationHelper.newOffsetX = newOffsetX; ZoomAndPanAnimationHelper.newOffsetY = newOffsetY; ZoomAndPanAnimationHelper.newScale = newScale; double offsetX = staticGraphControl.canvasScrollViewer.HorizontalOffset; double offsetY = staticGraphControl.canvasScrollViewer.VerticalOffset; double scale = staticGraphControl.scaleTransform.ScaleX; double shiftX = newOffsetX - offsetX; double shiftY = newOffsetY - offsetY; double scaleChange = newScale - scale; if (captureMouse) { Point mousePositionOnScreen = GetMousePosition(); mousePosition = new Point((mousePositionOnScreen.X + offsetX) / scale, (mousePositionOnScreen.Y + offsetY) / scale); this.currentCursor = staticGraphControl.GetCursor(); //System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None; } if (Math.Abs(shiftX) < 0.05 && Math.Abs(shiftY) < 1 && Math.Abs(scaleChange) < 1) { return; } zoomAndPanStoryboard = new Storyboard(); if (Math.Abs(shiftX) >= 0.05) { DoubleAnimation scaleAnimation = new DoubleAnimation(); scaleAnimation.From = scale; scaleAnimation.To = newScale; scaleAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime); Storyboard.SetTarget(scaleAnimation, visualHost); Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath("Scale")); zoomAndPanStoryboard.Children.Add(scaleAnimation); } if (Math.Abs(shiftX) >= 1) { DoubleAnimation xOffsetAnimation = new DoubleAnimation(); xOffsetAnimation.From = offsetX; xOffsetAnimation.To = newOffsetX; xOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime); Storyboard.SetTarget(xOffsetAnimation, visualHost); Storyboard.SetTargetProperty(xOffsetAnimation, new PropertyPath("XOffset")); zoomAndPanStoryboard.Children.Add(xOffsetAnimation); } if (Math.Abs(shiftY) >= 1) { DoubleAnimation yOffsetAnimation = new DoubleAnimation(); yOffsetAnimation.From = offsetY; yOffsetAnimation.To = newOffsetY; yOffsetAnimation.Duration = TimeSpan.FromMilliseconds(Configurations.ShortAnimationTime); Storyboard.SetTarget(yOffsetAnimation, visualHost); Storyboard.SetTargetProperty(yOffsetAnimation, new PropertyPath("YOffset")); zoomAndPanStoryboard.Children.Add(yOffsetAnimation); } zoomAndPanStoryboard.Completed += new EventHandler(OnAnimationCompleted); BeginAnimation(); }