/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> public static void StartAnimation(UIElement animatableElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { double fromValue = (double)animatableElement.GetValue(dependencyProperty); DoubleAnimation animation = new DoubleAnimation(); animation.From = fromValue; animation.To = toValue; animation.Duration = TimeSpan.FromSeconds(animationDurationSeconds); animation.Completed += delegate(object sender, EventArgs e) { // // When the animation has completed bake final value of the animation // into the property. // animatableElement.SetValue(dependencyProperty, animatableElement.GetValue(dependencyProperty)); CancelAnimation(animatableElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation); }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> public static void StartAnimation(UIElement animationElement, DependencyProperty dependencyProperty, double toValue, double animationDurationSeconds, EventHandler completedEvent) { if (animationElement == null) { throw new ArgumentNullResourceException("animationElement", Resources.General_Given_Parameter_Cannot_Be_Null); } var fromValue = (double)animationElement.GetValue(dependencyProperty); var animation = new DoubleAnimation { From = fromValue, To = toValue, Duration = TimeSpan.FromSeconds(animationDurationSeconds) }; animation.Completed += (sender, e) => { // When the animation has completed bake final value of the animation // into the property. animationElement.SetValue(dependencyProperty, animationElement.GetValue(dependencyProperty)); CancelAnimation(animationElement, dependencyProperty); if (completedEvent != null) { completedEvent(sender, e); } }; animation.Freeze(); animationElement.BeginAnimation(dependencyProperty, animation); }
/// <summary> /// Starts an animation to a particular value on the specified dependency property. /// You can pass in an event handler to call when the animation has completed. /// </summary> /// <param name="pAnimatableElement">The gui element to animate.</param> /// <param name="pDependencyProperty">The dependency property to animate.</param> /// <param name="pToValue">The final value of the dependency property.</param> /// <param name="pAnimationDurationSeconds">The animation duration.</param> /// <param name="pCompletedEvent">The callback executed when the animation ended.</param> public static void StartAnimation(UIElement pAnimatableElement, DependencyProperty pDependencyProperty, double pToValue, double pAnimationDurationSeconds, EventHandler pCompletedEvent) { double lFromValue = (double)pAnimatableElement.GetValue(pDependencyProperty); DoubleAnimation lAnimation = new DoubleAnimation(); lAnimation.From = lFromValue; lAnimation.To = pToValue; lAnimation.Duration = TimeSpan.FromSeconds(pAnimationDurationSeconds); lAnimation.Completed += delegate(object pSender, EventArgs pEventArgs) { // // When the animation has completed bake final value of the animation // into the property. // pAnimatableElement.SetValue(pDependencyProperty, pAnimatableElement.GetValue(pDependencyProperty)); CancelAnimation(pAnimatableElement, pDependencyProperty); if (pCompletedEvent != null) { pCompletedEvent(pSender, pEventArgs); } }; lAnimation.Freeze(); pAnimatableElement.BeginAnimation(pDependencyProperty, lAnimation); }
public static DoubleAnimation CreateAnimation(double from, double to, double beginTime, double time, IEasingFunction ease = null, EventHandler completed = null) { DoubleAnimation animation = new DoubleAnimation(from, to, new Duration(TimeSpan.FromSeconds(time))); animation.BeginTime = TimeSpan.FromSeconds(beginTime); if (ease != null) animation.EasingFunction = ease; if (completed != null) animation.Completed += completed; animation.Freeze(); return animation; }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="whenDone">(optional) A callback that will be called when the animation has completed.</param> private AnimationTimeline CreateAnimation(double from, double to, EventHandler whenDone = null) { IEasingFunction ease = new BackEase { Amplitude = 0.5, EasingMode = EasingMode.EaseOut }; var duration = new Duration(TimeSpan.FromSeconds(0.5)); var anim = new DoubleAnimation(from, to, duration) { EasingFunction = ease }; if (whenDone != null) anim.Completed += whenDone; anim.Freeze(); return anim; }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="whenDone">(optional) A callback that will be called when the animation has completed.</param> private static AnimationTimeline CreateAnimation(double from, double to, TimeSpan timeDuration, EventHandler whenDone = null) { var duration = new Duration(timeDuration); var anim = new DoubleAnimation(from, to, duration);// { EasingFunction = ease }; if (whenDone != null) anim.Completed += whenDone; anim.Freeze(); return anim; }
private static DoubleAnimation GetMoveCharacterPanAnimation(Double toValue) { //we add a slight delay onto the animation, so that if we have back-to-back animations, the handoff between them is smooth var animation = new DoubleAnimation(toValue, TimerUtility.GetTickDelay(Constants.MAP_MOVE_CHARACTER_TICKS).Add(TimeSpan.FromMilliseconds(10))) { AccelerationRatio = 0, //keep the ratios at 0 so you're moving at a constant speed DecelerationRatio = 0, FillBehavior = FillBehavior.HoldEnd }; animation.Freeze(); return animation; }
public static void StartAnimation (Transform animatableElement, DependencyProperty dependencyProperty, double toValue, double durationMilliseconds, double accelerationRatio, double decelerationRatio) { DoubleAnimation animation = new DoubleAnimation(); animation.To = toValue; animation.AccelerationRatio = accelerationRatio; animation.DecelerationRatio = decelerationRatio; animation.FillBehavior = FillBehavior.HoldEnd; animation.Duration = TimeSpan.FromMilliseconds(durationMilliseconds); animation.Freeze(); animatableElement.BeginAnimation(dependencyProperty, animation, HandoffBehavior.Compose); }
/// <summary> /// Create the animation and add it to the master timeline /// </summary> protected override void CreateAnimation() { var animationDuration = new Duration(this.AnimationConfiguration.Duration); this.MasterStoryboard.Duration = animationDuration; var animationX = new DoubleAnimation(this.StartX, this.EndX, animationDuration); var animationY = new DoubleAnimation(this.StartY, this.EndY, animationDuration); Storyboard.SetTargetProperty(animationX, new PropertyPath(Canvas.LeftProperty)); Storyboard.SetTargetProperty(animationY, new PropertyPath(Canvas.TopProperty)); animationX.Freeze(); animationY.Freeze(); this.MasterStoryboard.Children.Add(animationX); this.MasterStoryboard.Children.Add(animationY); }
public DragAdorner(UIElement adorned) : base(adorned) { var brush = new VisualBrush(adorned) {Stretch = Stretch.None, AlignmentX = AlignmentX.Left}; // HACK: this makes the markers work properly, // even after adding 4+ markers and then removing to 3-, // and then shift-dragging (in which case the size of the adorner is correct, // but the VisualBrush tries to render the now invisible number. _child = new Rectangle(); _child.BeginInit(); _child.Width = adorned.RenderSize.Width; _child.Height = adorned.RenderSize.Height; _child.Fill = brush; _child.IsHitTestVisible = false; _child.EndInit(); var animation = new DoubleAnimation(0.6, 0.85, new Duration(TimeSpan.FromMilliseconds(500))) {AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever}; animation.Freeze(); brush.BeginAnimation(Brush.OpacityProperty, animation); }
DoubleAnimation CreateZoomAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(555))); da.AccelerationRatio = 0.1; da.DecelerationRatio = 0.9; da.FillBehavior = FillBehavior.HoldEnd; da.Freeze(); return da; }
void Animate(double to, DependencyProperty dp) { var animation = new DoubleAnimation(); animation.From = (double)GetValue(dp); if (!double.IsNaN(to)) animation.To = Math.Max(0, to); else animation.To = 0; animation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); animation.Freeze(); BeginAnimation(dp, animation); }
/// <summary> /// Fade the adorner out and make it visible. /// </summary> public void FadeOutAdorner() { if (adornerShowState == AdornerShowState.FadingOut) { // // Already fading out. // return; } if (adornerShowState == AdornerShowState.Hidden) { // // Adorner has already been hidden. // return; } DoubleAnimation fadeOutAnimation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(FadeOutTime))); fadeOutAnimation.Completed += new EventHandler(fadeOutAnimation_Completed); fadeOutAnimation.Freeze(); adorner.BeginAnimation(FrameworkElement.OpacityProperty, fadeOutAnimation); adornerShowState = AdornerShowState.FadingOut; }
/// <summary> /// Fade the adorner in and make it visible. /// </summary> public void FadeInAdorner() { if (adornerShowState == AdornerShowState.Visible || adornerShowState == AdornerShowState.FadingIn) { // Already visible or fading in. return; } this.ShowAdorner(); if (adornerShowState != AdornerShowState.FadingOut) { adorner.Opacity = 0.0; } DoubleAnimation doubleAnimation = new DoubleAnimation(1.0, new Duration(TimeSpan.FromSeconds(FadeInTime))); doubleAnimation.Completed += new EventHandler(fadeInAnimation_Completed); doubleAnimation.Freeze(); adorner.BeginAnimation(FrameworkElement.OpacityProperty, doubleAnimation); adornerShowState = AdornerShowState.FadingIn; }
protected override Point ProcessNewChild(UIElement child, Rect providedBounds) { var startLocation = providedBounds.Location; if (m_arrangedOnce) { if (m_itemOpacityAnimation == null) { m_itemOpacityAnimation = new DoubleAnimation() { From = 0, Duration = new Duration(TimeSpan.FromSeconds(.5)) }; m_itemOpacityAnimation.Freeze(); } child.BeginAnimation(UIElement.OpacityProperty, m_itemOpacityAnimation); startLocation -= new Vector(providedBounds.Width, 0); } return startLocation; }
/// <summary> /// Sets the translation animation for the move. /// </summary> /// <param name="moveStoryboard"></param> /// <param name="move"></param> /// <param name="duration"></param> private void SetTranslationAnimation(Storyboard moveStoryboard, Rectangle element, int duration) { // animate the piece from the current position to the ending square // the animations will not be modified so they will be freezed // set the animation along the X axis DoubleAnimation xAnimation = new DoubleAnimation(); xAnimation.To = 100; xAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); xAnimation.BeginTime = TimeSpan.FromMilliseconds(500); Storyboard.SetTargetName(xAnimation, element.Name); Storyboard.SetTargetProperty(xAnimation, new PropertyPath("(0).(1)", RenderTransformProperty, TranslateTransform.XProperty)); xAnimation.Freeze(); // set the animation along the Y axis DoubleAnimation yAnimation = new DoubleAnimation(); yAnimation.To = 100; yAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); yAnimation.BeginTime = TimeSpan.FromMilliseconds(500); Storyboard.SetTargetName(yAnimation, element.Name); Storyboard.SetTargetProperty(yAnimation, new PropertyPath("(0).(1)", RenderTransformProperty, TranslateTransform.YProperty)); yAnimation.Freeze(); // add the animations to the storyboard moveStoryboard.Children.Add(xAnimation); moveStoryboard.Children.Add(yAnimation); }
private static DoubleAnimation GetNewHideAnimation(GraphContentPresenter element, Graph owner, int key) { DoubleAnimation da = new DoubleAnimation(0, HideDuration); da.FillBehavior = FillBehavior.Stop; //da.SetValue(Timeline.DesiredFrameRateProperty, HideDesiredFrameRate); HideAnimationManager ham = new HideAnimationManager(owner, key); da.Completed += new EventHandler(ham.CompletedHandler); da.Freeze(); return da; }
protected override Point ProcessNewChild(UIElement child, Rect providedBounds) { Point startLocation = providedBounds.Location; if (_m_item_opacity_animation == null) { _m_item_opacity_animation = new DoubleAnimation { From = 0, Duration = new Duration(TimeSpan.FromSeconds(.2)) }; _m_item_opacity_animation.Freeze(); } child.BeginAnimation(OpacityProperty, _m_item_opacity_animation); //startLocation -= new Vector(providedBounds.Width, 0); return startLocation; }
/// <summary>Helper to create the zoom double animation for scaling.</summary> /// <param name="toValue">Value to animate to.</param> /// <returns>Double animation.</returns> private static DoubleAnimation CreateZoomAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(500))) { AccelerationRatio = 0.1, DecelerationRatio = 0.9, FillBehavior = FillBehavior.HoldEnd }; da.Freeze(); return da; }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="time">The animation duration</param> /// <param name="easingFunction">The easing function.</param> /// <param name="whenDoubleAnimationDone">The when double animation done.</param> /// <param name="whenParentAnimationDone">The when parent animation done.</param> /// <returns>The animation object</returns> /// TODO: refactor this to a private method that's being used by a specific public animation method (fade,slide etc) private static AnimationTimeline CreateDoubleAnimationWithEasing(double from, double to, double time, IEasingFunction easingFunction, EventHandler whenDoubleAnimationDone = null, EventHandler whenParentAnimationDone = null) { var duration = new Duration(TimeSpan.FromSeconds(time)); var animation = new DoubleAnimation(from, to, duration); if (easingFunction != null) { animation.EasingFunction = easingFunction; } if (whenDoubleAnimationDone != null) { animation.Completed += whenDoubleAnimationDone; } if (whenParentAnimationDone != null) { animation.Completed += whenParentAnimationDone; } animation.Freeze(); return animation; }
/// <summary> /// Creates the animation that moves content in or out of view. /// </summary> /// <param name="from">The starting value of the animation.</param> /// <param name="to">The end value of the animation.</param> /// <param name="time">The animation duration</param> /// <param name="whenDoubleAnimationDone">The when double animation done.</param> /// <returns>The animation object</returns> /// TODO: refactor this to a private method that's being used by a specific public animation method (fade,slide etc) public static AnimationTimeline CreateDoubleAnimation(double from, double to, double time, EventHandler whenDoubleAnimationDone = null) { var duration = new Duration(TimeSpan.FromSeconds(time)); var animation = new DoubleAnimation(from, to, duration); if (whenDoubleAnimationDone != null) { animation.Completed += whenDoubleAnimationDone; } animation.Freeze(); return animation; }
/// <summary>Helper to create the zoom double animation for scaling.</summary> /// <param name="toValue">Value to animate to.</param> /// <returns>Double animation.</returns> private DoubleAnimation CreateZoomAnimation(double toValue) { var da = new DoubleAnimation(toValue, new Duration(TimeSpan.FromMilliseconds(/*checkBox1.IsChecked.Value*/true ? 300 : 0))); da.AccelerationRatio = 0.1; da.DecelerationRatio = 0.9; da.FillBehavior = FillBehavior.HoldEnd; da.Freeze(); return da; }
private static DoubleAnimation GetRandomRotateAnimation() { double angle = (.5 - Util.Rnd.NextDouble()) * 20; DoubleAnimation animation = new DoubleAnimation(); animation.To = angle; animation.DecelerationRatio = .5; animation.Duration = s_defaultDuration; animation.Freeze(); return animation; }
//fix MAINWINDOW bug public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint) : base(Program.PlayWindow.Content as UIElement) { SourceCard = sourceCard; bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted); Point cardOrigin; if (isCardInverted) { CardDef cardDef = Program.Game.Definition.CardDefinition; cardOrigin = new Point(cardDef.Width, cardDef.Height); _mouseOffset = new Vector(cardDef.Width - mousePoint.X, cardDef.Height - mousePoint.Y); } else { cardOrigin = new Point(); _mouseOffset = mousePoint; } //fix MAINWINDOW bug _basePt = anchor.TranslatePoint(cardOrigin, Program.PlayWindow.Content as UIElement); _faceUp = sourceCard.IsAlwaysUp || sourceCard.Card.FaceUp; _lightRedBrush = Brushes.Red.Clone(); _faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false)); _faceUpBrush = _faceUp ? new VisualBrush(sourceCard.GetCardVisual()) { Viewbox = new Rect(0, 0, sourceCard.ActualWidth, sourceCard.ActualHeight), ViewboxUnits = BrushMappingMode.Absolute } : (Brush) new ImageBrush(new BitmapImage(new Uri(Program.Game.Definition.CardDefinition.Front))); _invertTransform = new ScaleTransform {CenterX = 0.5, CenterY = 0.5}; _faceUpBrush.RelativeTransform = _invertTransform; if (_faceUpBrush is VisualBrush) RenderOptions.SetCachingHint(_faceUpBrush, CachingHint.Cache); _child.BeginInit(); _child.Width = anchor.ActualWidth*CardControl.ScaleFactor.Width; _child.Height = anchor.ActualHeight*CardControl.ScaleFactor.Height; _child.Fill = _faceUp ? _faceUpBrush : _faceDownBrush; _child.StrokeThickness = 3; var transforms = new TransformGroup(); _child.RenderTransform = transforms; _rot = sourceCard.Card.Orientation; if ((_rot & CardOrientation.Rot180) != 0) { _rot180Transform = new RotateTransform(180, _child.Width/2, _child.Height/2); transforms.Children.Add(_rot180Transform); } if ((_rot & CardOrientation.Rot90) != 0) { _rot90Transform = isCardInverted ? new RotateTransform(90, _child.Width/2, _child.Width/2) : new RotateTransform(90, _child.Width/2, _child.Height - _child.Width/2); transforms.Children.Add(_rot90Transform); } _translate = new TranslateTransform(); transforms.Children.Add(_translate); _child.IsHitTestVisible = false; _child.EndInit(); AddVisualChild(_child); var animation = new DoubleAnimation(0.55, 0.75, new Duration(TimeSpan.FromMilliseconds(500))) {AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever}; animation.Freeze(); _faceUpBrush.BeginAnimation(Brush.OpacityProperty, animation); _faceDownBrush.BeginAnimation(Brush.OpacityProperty, animation); _lightRedBrush.BeginAnimation(Brush.OpacityProperty, animation); }
private static DoubleAnimation GetShrinkAnimation() { DoubleAnimation animation = new DoubleAnimation(); animation.To = .8; animation.DecelerationRatio = .5; animation.Duration = s_defaultDuration; animation.Freeze(); return animation; }
private void beginRemoveAnimation(GraphContentPresenter graphContentPresenter, bool isCenter) { Debug.Assert(VisualTreeHelper.GetParent(graphContentPresenter) == this); this.InvalidateVisual(); _fadingGCPList.Add(graphContentPresenter); _isChildCountValid = false; graphContentPresenter.IsHitTestVisible = false; if (isCenter) { graphContentPresenter.WasCenter = true; } ScaleTransform scaleTransform = graphContentPresenter.ScaleTransform; DoubleAnimation doubleAnimation = new DoubleAnimation(0, s_hideDuration); doubleAnimation.Completed += delegate(object sender, EventArgs e) { CleanUpGCP(graphContentPresenter); }; doubleAnimation.FillBehavior = FillBehavior.Stop; doubleAnimation.Freeze(); scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, doubleAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, doubleAnimation); graphContentPresenter.BeginAnimation(OpacityProperty, doubleAnimation); }
void AnimateArrowInFlickDirection(double x1, double y1, double x2, double y2) { Arrow arrow = new Arrow(); arrow.X1 = x1; arrow.Y1 = y1; arrow.X2 = x2; arrow.Y2 = y2; arrow.HeadWidth = 18; arrow.HeadHeight = 10; arrow.Stroke = Brushes.Red; arrow.StrokeThickness = 10.0; this.circuitInkCanvas.Children.Add(arrow); this.CurrentFlickArrow = arrow; DoubleAnimation fadeOutAnimation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(1.0))); fadeOutAnimation.Completed += new EventHandler(ArrowFadeOutAnimationCompleted); fadeOutAnimation.Freeze(); arrow.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); }
/// <summary> /// Sets the fading animation for the captured piece. /// </summary> /// <param name="moveStoryboard"></param> /// <param name="element"></param> /// <param name="duration"></param> private void SetOpacityAnimation(Storyboard moveStoryboard, Rectangle element, int duration) { // animate the captured piece opacity from the current value (1.0) to 0.0 // the animations will not be modified so they will be freezed // set the opacity animation DoubleAnimation opacityAnimation = new DoubleAnimation(); opacityAnimation.To = 0.0; opacityAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(duration)); opacityAnimation.BeginTime = TimeSpan.FromMilliseconds(500); Storyboard.SetTargetName(opacityAnimation, element.Name); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(Rectangle.OpacityProperty)); opacityAnimation.Freeze(); // add the animation to the move storyboard moveStoryboard.Children.Add(opacityAnimation); }
/** * @brief Helper method to create a double animation. * @param fNew The new value we want to move too. * @param fTime The time we want to allow in ms. * @param bFreeze Do we want to freeze this animation (so we can't modify it). */ public static DoubleAnimation createDoubleAnimation(double fNew, double fTime, bool bFreeze) { // Create the animation. DoubleAnimation pAction = new DoubleAnimation(fNew, new Duration(TimeSpan.FromMilliseconds(fTime))) { // Specify settings. AccelerationRatio = 0.1, DecelerationRatio = 0.9, FillBehavior = FillBehavior.HoldEnd }; // Pause the action before starting it and then return it. if (bFreeze) pAction.Freeze(); return pAction; }
private DoubleAnimation CreateAnimation(double from, double to) { DoubleAnimation animation = new DoubleAnimation(); animation.To = to; animation.From = from; animation.Duration = new Duration(TimeSpan.FromMilliseconds(Duration)); animation.Freeze(); return animation; }