/// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            PlaneProjection projection = info.Target.Projection as PlaneProjection;

            if (projection == null)
            {
                return;
            }

            double direction = this.Direction == PerspectiveAnimationDirection.Clockwise ? -1 : 1;
            double rotation;

            PerspectiveAnimationAxis axes = this.Axes;
            bool autoReverse = this.GetAutoReverse();

            if ((axes & PerspectiveAnimationAxis.X) == PerspectiveAnimationAxis.X)
            {
                rotation             = autoReverse ? this.StartAngleX : this.EndAngleX;
                projection.RotationX = rotation * direction;
            }
            if ((axes & PerspectiveAnimationAxis.Y) == PerspectiveAnimationAxis.Y)
            {
                rotation             = autoReverse ? this.StartAngleY : this.EndAngleY;
                projection.RotationY = rotation * direction;
            }
            if ((axes & PerspectiveAnimationAxis.Z) == PerspectiveAnimationAxis.Z)
            {
                rotation             = autoReverse ? this.StartAngleZ : this.EndAngleZ;
                projection.RotationZ = rotation * direction;
            }
        }
        private static bool PlayCore(PlayAnimationInfo animationInfo, Action completeCallback, params object[] args)
        {
            if (!CanAnimate(animationInfo.Target))
            {
                BeginInvokeCallback(completeCallback, animationInfo.Target);
                return(false);
            }

            Storyboard storyboard = animationInfo.Storyboard;

            // associate the animation info with the storyboard
            storyboard.SetValue(AnimationInfoProperty, animationInfo);
            storyboard.Completed += OnStoryboardCompleted;

            if (completeCallback != null)
            {
                AddCallback(storyboard, completeCallback);
            }

            animationInfo.Animation.UpdateAnimation(animationInfo.Target, storyboard, args);
            storyboard.Begin();
            animationInfo.Animation.OnStarted(animationInfo);

            return(true);
        }
        /// <summary>
        /// Plays the provides animation on the specified target.
        /// </summary>
        /// <param name="target">The <see cref="T:System.Windows.UIElement"/> instance to be animated.</param>
        /// <param name="animation">The <see cref="RadAnimation"/> instance that describes the animation process.</param>
        /// <param name="completedCallback">Optional callback to notify the caller for animation completion.</param>
        /// <returns>True if the animation has been successfully executed, false otherwise.</returns>
        public static bool Play(UIElement target, RadAnimation animation, Action completedCallback)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (animation == null)
            {
                throw new ArgumentNullException("animation");
            }

            PlayAnimationInfo info = GetAnimationInfo(arg => arg.Target == target && arg.Animation == animation);

            if (info != null)
            {
                StopStoryboard(info);
            }

            Storyboard storyboard = animation.CreateStoryboard(target);

            info = CreatePlayAnimationInfo(target, animation, storyboard);

            return(PlayCore(info, completedCallback));
        }
Example #4
0
 /// <summary>
 /// Called by the animation manager before an associated storyboard is stopped.
 /// Allows inheritors to store any animated values to be restored later, when the storyboard is already stopped.
 /// </summary>
 /// <param name="info">The info.</param>
 internal void OnStopping(PlayAnimationInfo info)
 {
     if (this.FillBehavior != AnimationFillBehavior.Stop && info.Target != null)
     {
         this.CopyAnimationValues(info);
     }
 }
Example #5
0
        /// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            UIElement target = info.Target;
            double    height = this.GetAutoReverse() ? GetHeight(target, this.StartHeight) : GetHeight(target, this.EndHeight);

            target.SetValue(FrameworkElement.HeightProperty, height);
        }
        /// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            double endY = 0;

            FrameworkElement target = info.Target as FrameworkElement;

            if (this.GetAutoReverse())
            {
                if (this.PointMode == MoveAnimationPointMode.Absolute)
                {
                    endY = GetY(target, this.StartY);
                }
                else
                {
                    endY = GetRelativeY(target, this.StartY);
                }
            }
            else
            {
                if (this.PointMode == MoveAnimationPointMode.Absolute)
                {
                    endY = GetY(target, this.EndY);
                }
                else
                {
                    endY = GetRelativeY(target, this.EndY);
                }
            }

            target.GetTranslateTransform().Y = endY;
        }
 /// <summary>
 /// Applies already stored (if any) animated values.
 /// </summary>
 /// <param name="info"></param>
 protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
 {
     foreach (RadAnimation animation in this.Children)
     {
         animation.ApplyAnimationValues(info);
     }
 }
        /// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            UIElement target = info.Target;
            double    width  = this.GetAutoReverse() ? GetWidth(target, this.StartWidth) : GetWidth(target, this.EndWidth);

            target.SetValue(FrameworkElement.WidthProperty, width);
        }
        private static void OnStoryboardCompleted(object sender, object e)
        {
            Storyboard        storyboard = sender as Storyboard;
            PlayAnimationInfo info       = storyboard.GetValue(AnimationInfoProperty) as PlayAnimationInfo;

            Debug.Assert(info != null, "Must have PlayAnimationInfo associated.");
            StopStoryboard(info);
        }
Example #10
0
        /// <summary>
        /// Called by the animation manager after an associated storyboard has been stopped.
        /// Allows inheritors to apply previously stored (if any) animated values.
        /// </summary>
        /// <param name="info">The info.</param>
        internal void OnStopped(PlayAnimationInfo info)
        {
            if (this.FillBehavior != AnimationFillBehavior.Stop && info.Target != null)
            {
                this.ApplyAnimationValues(info);
            }

            this.OnEnded(info);
        }
Example #11
0
        /// <summary>
        /// Fires the <see cref="RadAnimation.Ended" /> event for the specific target provided
        /// in the <see cref="PlayAnimationInfo" /> object.
        /// </summary>
        /// <param name="info">The info.</param>
        protected virtual void OnEnded(PlayAnimationInfo info)
        {
            if (this.Ended == null)
            {
                System.Diagnostics.Debug.WriteLine("no ended handler");
            }

            if (this.Ended != null)
            {
                this.Ended(this, new AnimationEndedEventArgs(info));
            }
        }
 /// <summary>
 /// Applies already stored (if any) animated values.
 /// </summary>
 /// <param name="info"></param>
 protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
 {
     if (this.itemsToAnimate != null)
     {
         for (int i = 0; i < this.itemsToAnimate.Count; i++)
         {
             FrameworkElement itemToAnimate = this.itemsToAnimate[i];
             this.SetItemOriginalTransform(itemToAnimate);
         }
     }
     base.ApplyAnimationValues(info);
 }
        private static Storyboard GetStoryboard(UIElement target, Func <PlayAnimationInfo, bool> predicate)
        {
            List <PlayAnimationInfo> infos = null;

            if (!RunningAnimations.TryGetValue(target.GetHashCode(), out infos))
            {
                return(null);
            }

            PlayAnimationInfo result = infos.SingleOrDefault <PlayAnimationInfo>(arg => predicate(arg));

            return(result == null ? null : result.Storyboard);
        }
Example #14
0
        /// <inheritdoc/>
        protected override void OnEnded(PlayAnimationInfo info)
        {
            this.itemsOriginalTransform.Clear();
            this.containerToAnimate = null;
            this.elementToDelay     = null;

            if (this.itemsToAnimate != null)
            {
                this.itemsToAnimate.Clear();
                this.itemsToAnimate = null;
            }

            base.OnEnded(info);
        }
        private static void StopStoryboard(PlayAnimationInfo info)
        {
            // try to notify the associated animation for stopping the storyboard
            // this is needed to record the final animation values as Local if needed
            info.Animation.OnStopping(info);

            info.Storyboard.Stop();
            info.Animation.OnStopped(info);

            info.Storyboard.Children.Clear();
            info.Storyboard.Completed -= OnStoryboardCompleted;

            RemoveAnimationInfo(info);
            InvokeCallbacks(info.Storyboard);
        }
        private static void RemoveAnimationInfo(PlayAnimationInfo info)
        {
            int targetHash = info.TargetHashCode;
            List <PlayAnimationInfo> playPasses = RunningAnimations[targetHash];

            Debug.Assert(playPasses != null && playPasses.Count > 0, "PlayInfo must be registered.");
            playPasses.Remove(info);

            if (playPasses.Count == 0)
            {
                RunningAnimations.Remove(targetHash);
            }

            info.Storyboard.ClearValue(AnimationInfoProperty);
        }
        /// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            double?scaleX;

            if (this.GetAutoReverse())
            {
                scaleX = this.StartScaleX;
            }
            else
            {
                scaleX = this.EndScaleX;
            }

            ScaleTransform transform = info.Target.GetScaleTransform();

            transform.ScaleX = scaleX.HasValue ? scaleX.Value : transform.ScaleX;
        }
Example #18
0
        /// <summary>
        /// Applies already stored (if any) animated values.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            double opacity = 0;

            if (this.GetAutoReverse())
            {
                opacity = this.StartOpacity;
            }
            else
            {
                opacity = this.EndOpacity;
            }

            if (info.Target.Opacity != opacity)
            {
                info.Target.Opacity = opacity;
            }
        }
Example #19
0
        /// <summary>
        /// Called by the animation manager when the storyboard has been started.
        /// </summary>
        /// <param name="info"></param>
        protected internal override void OnStarted(PlayAnimationInfo info)
        {
            if (this.headerElementScreenShotInfo != null)
            {
                RadAnimationManager.Play(this.headerElementScreenShotInfo.ScreenShotContainer, this.headerElementAnimation);
            }

            if (this.applicationHeaderElementScreenShotInfo != null)
            {
                RadAnimationManager.Play(this.applicationHeaderElementScreenShotInfo.ScreenShotContainer, this.applicationHeaderElementAnimation);
            }

            if (this.pageAnimation != null)
            {
                RadAnimationManager.Play(info.Target, this.pageAnimation);
            }

            base.OnStarted(info);
        }
        private static PlayAnimationInfo CreatePlayAnimationInfo(UIElement target, RadAnimation animation, Storyboard storyboard)
        {
            int hash = target.GetHashCode();

            List <PlayAnimationInfo> animations = null;

            PlayAnimationInfo result = new PlayAnimationInfo(storyboard, animation, target);

            if (!RunningAnimations.TryGetValue(hash, out animations))
            {
                animations = new List <PlayAnimationInfo>();
                animations.Add(result);
                RunningAnimations[hash] = animations;
            }
            else
            {
                animations.Add(result);
            }

            return(result);
        }
Example #21
0
        /// <inheritdoc/>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            if (info == null)
            {
                return;
            }

            double?scaleY;

            if (this.GetAutoReverse())
            {
                scaleY = this.StartScaleY;
            }
            else
            {
                scaleY = this.EndScaleY;
            }

            ScaleTransform transform = info.Target.GetScaleTransform();

            transform.ScaleY = scaleY.HasValue ? scaleY.Value : transform.ScaleY;
        }
Example #22
0
        /// <inheritdoc/>
        protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
        {
            if (info == null)
            {
                return;
            }

            double endX = 0;

            FrameworkElement target = info.Target as FrameworkElement;

            if (this.GetAutoReverse())
            {
                if (this.PointMode == MoveAnimationPointMode.Absolute)
                {
                    endX = GetX(target, this.StartX);
                }
                else
                {
                    endX = GetRelativeX(target, this.StartX);
                }
            }
            else
            {
                if (this.PointMode == MoveAnimationPointMode.Absolute)
                {
                    endX = GetX(target, this.EndX);
                }
                else
                {
                    endX = GetRelativeX(target, this.EndX);
                }
            }

            target.GetTranslateTransform().X = endX;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AnimationEndedEventArgs" /> class.
 /// </summary>
 /// <param name="target">The target.</param>
 internal AnimationEndedEventArgs(PlayAnimationInfo target)
 {
     this.AnimationInfo = target;
 }
Example #24
0
 /// <summary>
 /// Applies already stored (if any) animated values.
 /// </summary>
 /// <param name="info">The animation info.</param>
 protected internal virtual void ApplyAnimationValues(PlayAnimationInfo info)
 {
 }
Example #25
0
 /// <summary>
 /// Called by the animation manager when the storyboard has been started.
 /// </summary>
 /// <param name="info">The info.</param>
 protected internal virtual void OnStarted(PlayAnimationInfo info)
 {
 }
Example #26
0
 /// <summary>
 /// Allows inheritors to store the animated values.
 /// This is useful if the animation wants to keep the final values upon storyboard stopping.
 /// </summary>
 /// <param name="info">The info.</param>
 protected virtual void CopyAnimationValues(PlayAnimationInfo info)
 {
 }
Example #27
0
 /// <summary>
 /// Applies already stored (if any) animated values.
 /// </summary>
 /// <param name="info"></param>
 protected internal override void ApplyAnimationValues(PlayAnimationInfo info)
 {
     base.ApplyAnimationValues(info);
 }