private static void AnimationFunction_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { RectAnimation a = (RectAnimation)d; a._isAnimationFunctionValid = false; a.PropertyChanged(e.Property); }
public DLRectAnimation(Rect fromValue, Rect toValue, Duration duration, Action<object> frameCallback, IEasingFunction easingFunction = null) { FrameCallback = frameCallback; _areaRect = new AreaRect(); _rectAnimation = new System.Windows.Media.Animation.RectAnimation(fromValue, toValue, duration); if(easingFunction != null) { _rectAnimation.EasingFunction = easingFunction; } _rectAnimation.Completed += (sender, args) => { FrameCallback(_rectAnimation.To); _areaRect.BeginAnimation(AreaRect.AreaRectProperty, null); }; }
private RectAnimation createDetonateViewportAni(WalkDirection dir,int power) { RectAnimation retVal = new RectAnimation(); retVal.From = new Rect(0, 0, scene.tileWidth, scene.tileHeight); switch (dir) { case WalkDirection.DOWN: retVal.To = new Rect(0, power * scene.tileHeight, scene.tileWidth, scene.tileHeight); break; case WalkDirection.LEFT: retVal.To = new Rect(power * -scene.tileWidth, 0, scene.tileWidth, scene.tileHeight); break; case WalkDirection.RIGHT: retVal.To = new Rect(power * scene.tileWidth, 0, scene.tileWidth, scene.tileHeight); break; case WalkDirection.UP: retVal.To = new Rect(0, power * -scene.tileHeight, scene.tileWidth, scene.tileHeight); break; } retVal.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed); retVal.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut }; Storyboard.SetTarget(retVal, detonateRects[dir]); //detonateBrushes[dir].Viewport Storyboard.SetTargetProperty(retVal, new PropertyPath("Fill.(ImageBrush.Viewport)")); return retVal; }
private void Animate(List<Rect> fromRects, List<Rect> toRects) { TargetRects = toRects; AnimationStoryboard.Stop(); AnimationStoryboard.Children.Clear(); var duration = new Duration(TimeSpan.FromMilliseconds(300)); var easingFunction = new CubicEase(); easingFunction.EasingMode = EasingMode.EaseInOut; var targetOpacity = (AnimationState == AnimationStates.Hiding) ? 0.0 : 0.6; DoubleAnimation backdropOpacityAnimation = new DoubleAnimation(BackdropCanvas.Opacity, targetOpacity, duration); backdropOpacityAnimation.EasingFunction = easingFunction; AnimationStoryboard.Children.Add(backdropOpacityAnimation); Storyboard.SetTarget(backdropOpacityAnimation, BackdropCanvas); Storyboard.SetTargetProperty(backdropOpacityAnimation, new PropertyPath(OpacityProperty)); var thumbs = ThumbnailCanvas.Children; var count = thumbs.Count; for (var i=0; i< count; i++) { var thumb = (ThumbnailBorder)thumbs[i]; thumb.HideDecorations(); thumb.Layout(); var animation = new RectAnimation(fromRects[i], toRects[i], duration); animation.EasingFunction = easingFunction; Storyboard.SetTarget(animation, thumb); Storyboard.SetTargetProperty(animation, new PropertyPath(ThumbnailBorder.RectProperty)); //Timeline.SetDesiredFrameRate(animation, 120); AnimationStoryboard.Children.Add(animation); if (thumb.Thumb.Minimized) { var toOpacity = 1; var fromOpacity = 0; if (AnimationState == AnimationStates.Hiding) { toOpacity = 0; fromOpacity = 1; } var opacityAnimation = new DoubleAnimation(fromOpacity, toOpacity, duration); opacityAnimation.EasingFunction = easingFunction; Storyboard.SetTarget(opacityAnimation, thumb); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); AnimationStoryboard.Children.Add(opacityAnimation); } } AnimationStoryboard.Begin(); }
public void UpdateOverlay() { if (TutorialManager.CurrentTutorial != null && TutorialManager.CurrentTutorial.CurrentStep != null) { RectangleGeometry hole = this.Resources["Hole"] as RectangleGeometry; //FrameworkElement target = HelpOverlyHelper.FindChild(Application.Current.MainWindow, TutorialManager.CurrentTutorial.CurrentStep.TargetElementName); FrameworkElement target = GetElement(null, Application.Current.MainWindow, TutorialManager.CurrentTutorial.CurrentStep.Path, 0); if (target != null) { target.PreviewMouseDown -= previewMouseDown; target.PreviewMouseDown += previewMouseDown; } if (hole != null && target != null) { Point targetTopLeft = target.TranslatePoint(new Point(0, 0), Application.Current.MainWindow); Rect newRect = new Rect(targetTopLeft.X - CUTOUT_MARGIN, targetTopLeft.Y - CUTOUT_MARGIN, target.ActualWidth + CUTOUT_MARGIN * 2, target.ActualHeight + CUTOUT_MARGIN * 2); double topDistance = newRect.Top; double bottomDistance = Application.Current.MainWindow.ActualHeight - newRect.Bottom; double leftDistance = newRect.Left; double rightDistance = Application.Current.MainWindow.ActualWidth - newRect.Right; if (topDistance > bottomDistance && topDistance > leftDistance && topDistance > rightDistance) TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement = Placement.Above; if (bottomDistance > topDistance && bottomDistance > leftDistance && bottomDistance > rightDistance) TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement = Placement.Below; if (leftDistance > bottomDistance && leftDistance > topDistance && leftDistance > rightDistance) TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement = Placement.Left; if (rightDistance > bottomDistance && rightDistance > leftDistance && rightDistance > topDistance) TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement = Placement.Right; if (hole.Rect != Rect.Empty || TutorialManager.CurrentTutorial.CurrentStep.ToString() == lastTarget) { RectAnimation rectAnimation = new RectAnimation(newRect, duration); rectAnimation.EasingFunction = new CubicEase() { EasingMode = System.Windows.Media.Animation.EasingMode.EaseInOut }; DoubleAnimation fadeInWaitAnimation = new DoubleAnimation(0, 0, duration); fadeInWaitAnimation.Completed += new EventHandler((o, e) => { DoubleAnimation fadeInFinalAnimation = new DoubleAnimation(0, 1, duration); Message.BeginAnimation(Border.OpacityProperty, fadeInFinalAnimation); Arrow.BeginAnimation(Arrow.OpacityProperty, fadeInFinalAnimation); }); //fadeInAnimation.BeginTime = halfDuration.TimeSpan; hole.BeginAnimation(RectangleGeometry.RectProperty, rectAnimation); Arrow.BeginAnimation(Arrow.OpacityProperty, fadeInWaitAnimation); Message.BeginAnimation(Border.OpacityProperty, fadeInWaitAnimation); } else { hole.Rect = newRect; } MessageTextBox.Text = TutorialManager.CurrentTutorial.CurrentStep.Message; if (TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement == Placement.Right) { double leftPlacement = targetTopLeft.X + target.ActualWidth + CUTOUT_MARGIN; Canvas.SetLeft(MessageContainer, leftPlacement); Canvas.SetRight(MessageContainer, 0); Canvas.SetTop(MessageContainer, 0); Canvas.SetBottom(MessageContainer, 0); var size = Application.Current.MainWindow.ActualWidth - leftPlacement; if (size < 0) { size *= -1; } MessageContainer.Width = size; MessageContainer.Height = Application.Current.MainWindow.ActualHeight; } else if (TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement == Placement.Left) { double rightPlacement = targetTopLeft.X - CUTOUT_MARGIN; Canvas.SetRight(MessageContainer, rightPlacement); Canvas.SetLeft(MessageContainer, 0); Canvas.SetTop(MessageContainer, 0); Canvas.SetBottom(MessageContainer, 0); var size = rightPlacement; if (size < 0) { size *= -1; } MessageContainer.Width = size; MessageContainer.Height = Application.Current.MainWindow.ActualHeight; } else if (TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement == Placement.Above) { double bottomPlacement = targetTopLeft.Y - CUTOUT_MARGIN; Canvas.SetBottom(MessageContainer, bottomPlacement); Canvas.SetLeft(MessageContainer, 0); Canvas.SetRight(MessageContainer, 0); Canvas.SetTop(MessageContainer, 0); var size = bottomPlacement; if (size < 0) { size *= -1; } MessageContainer.Width = Application.Current.MainWindow.ActualWidth; MessageContainer.Height = size; } else if (TutorialManager.CurrentTutorial.CurrentStep.MessagePlacement == Placement.Below) { double topPlacement = targetTopLeft.Y + target.ActualHeight + CUTOUT_MARGIN; Canvas.SetTop(MessageContainer, topPlacement); Canvas.SetLeft(MessageContainer, 0); Canvas.SetRight(MessageContainer, 0); Canvas.SetBottom(MessageContainer, 0); var size = Application.Current.MainWindow.ActualHeight - topPlacement; if (size < 0) { size *= -1; } MessageContainer.Width = Application.Current.MainWindow.ActualWidth; MessageContainer.Height = size; } lastTarget = TutorialManager.CurrentTutorial.CurrentStep.ToString(); } } }
private void OnMouseUp(object sender, MouseButtonEventArgs e) { if (isDragging && e.ChangedButton == MouseButton.Left) { isDragging = false; ReleaseMouseCapture(); Point endPointInOutput = e.GetPosition(this); Point endPointInVisible = endPointInOutput.Transform(Viewport.Output, Viewport.Visible); Vector mouseShift = -(endPointInVisible - dragStartPointInVisible); Vector outputShift = endPointInOutput - dragStartPointInOutput; int time = e.Timestamp; int deltaTime = time - dragStartTimestamp; double seconds = deltaTime / 1000.0; // mouse moved short enough and for rather long distance. bool shouldStartAnimation = seconds < 1 && outputShift.Length > 20; if (shouldStartAnimation) { Rect moveTo = Viewport.Visible; moveTo.Offset(mouseShift * 2); //if (dragAnimation == null) { dragAnimation = new RectAnimation(moveTo, TimeSpan.FromSeconds(1)); dragAnimation.DecelerationRatio = 0.2; //} //else { // dragAnimation.To = moveTo; // dragAnimation.Duration = TimeSpan.FromSeconds(1); // AnimationClock clock = dragAnimation.CreateClock(); // clock.Controller.Begin(); //} BeginAnimation(VisibleRectProperty, dragAnimation); shouldApplyAnimation = true; Debug.WriteLine("Starting animation"); } else if (dragAnimation != null) { StopDragAnimation(); } // focusing on LMB click if (endPointInVisible == dragStartPointInVisible) { //Keyboard.Focus(Parent as IInputElement); } } else if (isZooming && e.ChangedButton == MouseButton.Left) { isZooming = false; if (zoomRect.HasValue) { Rect output = Viewport.Output; Point p1 = zoomRect.Value.TopLeft.Transform(output, Viewport.Visible); Point p2 = zoomRect.Value.BottomRight.Transform(output, Viewport.Visible); Rect newVisible = new Rect(p1, p2); Viewport.Visible = newVisible; zoomRect = null; ReleaseMouseCapture(); RemoveSelectionAdorner(); } } }