An animation that composes a set of multiple animations playing simulataneously.
Inheritance: ProceduralAnimation
Exemple #1
0
        protected override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            ScaleTransform scaleTransform = target.RenderTransform as ScaleTransform;
            if (scaleTransform == null) {
                scaleTransform = new ScaleTransform();
                target.RenderTransform = scaleTransform;
                target.RenderTransformOrigin = new Point(0.5, 0.5);
            }

            TimeSpan halfDuration = TimeSpan.FromMilliseconds(Duration.TotalMilliseconds / 2);
            TweenInterpolation interpolation = GetEffectiveInterpolation();

            // A FlashBulb effect basically grows the element and makes it transparent
            // half way and then restores the element to its initial state during the
            // 2nd half of the animation.
            // This is accomplished with three animations that auto-reverse.
            // As a result the animations are the same regardless of effect direction.
            DoubleAnimation opacityAnimation =
                new DoubleAnimation(target, UIElement.OpacityProperty, halfDuration, 0.25);
            DoubleAnimation scaleXAnimation =
                new DoubleAnimation(scaleTransform, ScaleTransform.ScaleXProperty, halfDuration, 1.1);
            DoubleAnimation scaleYAnimation =
                new DoubleAnimation(scaleTransform, ScaleTransform.ScaleYProperty, halfDuration, 1.1);

            opacityAnimation.Interpolation = interpolation;
            scaleXAnimation.Interpolation = interpolation;
            scaleYAnimation.Interpolation = interpolation;

            // Create a composite animation that plays all three in parallel
            ProceduralAnimation animation =
                new ProceduralAnimationSet(opacityAnimation, scaleXAnimation, scaleYAnimation);
            animation.AutoReverse = true;

            return animation;
        }
Exemple #2
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(EffectDirection direction)
        {
            if (_scaleTransform == null) {
                Transform existingTransform = GetTarget().RenderTransform;
                if (existingTransform != null) {
                    _scaleTransform = existingTransform as ScaleTransform;

                    if (_scaleTransform == null) {
                        TransformGroup transformGroup = existingTransform as TransformGroup;

                        if (transformGroup != null) {
                            foreach (Transform transform in transformGroup.Children) {
                                _scaleTransform = transform as ScaleTransform;
                                if (_scaleTransform != null) {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (_scaleTransform == null) {
                    throw new InvalidOperationException("The element does not have a scale transform associated with it.");
                }

                _initialX = _scaleTransform.ScaleX;
                _initialY = _scaleTransform.ScaleY;
            }

            TweenInterpolation interpolation = GetEffectiveInterpolation();
            DoubleAnimation xAnimation = null;
            DoubleAnimation yAnimation = null;

            if (_scaleXRatio != 1) {
                double targetValue = direction == EffectDirection.Forward ? _initialX * _scaleXRatio : _initialX;

                xAnimation = new DoubleAnimation(_scaleTransform, ScaleTransform.ScaleXProperty, Duration,
                                                 targetValue);
                xAnimation.Interpolation = interpolation;
            }

            if (_scaleYRatio != 1) {
                double targetValue = direction == EffectDirection.Forward ? _initialY * _scaleYRatio : _initialY;

                yAnimation = new DoubleAnimation(_scaleTransform, ScaleTransform.ScaleYProperty, Duration,
                                                 targetValue);
                yAnimation.Interpolation = interpolation;
            }

            if ((xAnimation != null) && (yAnimation != null)) {
                ProceduralAnimationSet animation = new ProceduralAnimationSet(xAnimation, yAnimation);
                animation.AutoReverse = AutoReverse;

                return animation;
            }
            else if (xAnimation != null) {
                xAnimation.AutoReverse = AutoReverse;
                return xAnimation;
            }
            else if (yAnimation != null) {
                yAnimation.AutoReverse = AutoReverse;
                return yAnimation;
            }
            return null;
        }
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            if (_effects.Count == 0) {
                throw new InvalidOperationException("A CompositeEffect must have more than 1 nested child effect.");
            }

            if (_childrenInitialized == false) {
                foreach (AnimationEffect childEffect in _effects) {
                    ((IAttachedObject)childEffect).Attach(AssociatedObject);
                }

                _childrenInitialized = true;
            }

            List<ProceduralAnimation> animations = new List<ProceduralAnimation>(_effects.Count);
            foreach (AnimationEffect childEffect in _effects) {
                AnimationEffectDirection childDirection = direction;
                if (childEffect.AutoReverse) {
                    childDirection = AnimationEffectDirection.Forward;
                }

                ProceduralAnimation childAnimation = childEffect.CreateEffectAnimation(childDirection);
                if (childAnimation != null) {
                    animations.Add(childAnimation);
                }
            }

            if (animations.Count != 0) {
                ProceduralAnimation[] animationItems = animations.ToArray();

                if (_composition == AnimationComposition.Parallel) {
                    ProceduralAnimationSet animation = new ProceduralAnimationSet(animationItems);
                    animation.AutoReverse = AutoReverse;

                    return animation;
                }
                else {
                    ProceduralAnimationSequence animation = new ProceduralAnimationSequence(animationItems);
                    animation.AutoReverse = AutoReverse;

                    return animation;
                }
            }

            return null;
        }
Exemple #4
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            if (_projection == null) {
                _projection = target.Projection as PlaneProjection;
                if (_projection == null) {
                    _projection = new PlaneProjection();
                    _projection.CenterOfRotationX = 0.5;
                    _projection.CenterOfRotationY = 0.5;
                    _projection.CenterOfRotationZ = 0.5;

                    target.Projection = _projection;
                }
            }

            DoubleAnimation zOffsetAnimation =
                new DoubleAnimation(_projection, PlaneProjection.GlobalOffsetZProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? Distance : 0));
            zOffsetAnimation.Interpolation = GetEffectiveInterpolation();

            if (_shadowLength == 0) {
                zOffsetAnimation.AutoReverse = AutoReverse;

                return zOffsetAnimation;
            }

            if (_dropShadow == null) {
                _dropShadow = target.Effect as DropShadowEffect;
                if (_dropShadow == null) {
                    _dropShadow = new DropShadowEffect();
                    _dropShadow.BlurRadius = 0;
                    _dropShadow.ShadowDepth = 0;
                    _dropShadow.Color = Colors.Black;
                    _dropShadow.Opacity = 0.5;

                    target.Effect = _dropShadow;
                }
            }

            DoubleAnimation shadowAnimation =
                new DoubleAnimation(_dropShadow, DropShadowEffect.BlurRadiusProperty, Duration,
                                    (direction == AnimationEffectDirection.Forward ? _shadowLength : 0));
            shadowAnimation.Interpolation = GetEffectiveInterpolation();

            ProceduralAnimationSet animationSet = new ProceduralAnimationSet(zOffsetAnimation, shadowAnimation);
            animationSet.AutoReverse = AutoReverse;

            return animationSet;
        }
Exemple #5
0
        /// <internalonly />
        protected internal override ProceduralAnimation CreateEffectAnimation(AnimationEffectDirection direction)
        {
            FrameworkElement target = GetTarget();

            if (_projection == null) {
                _projection = target.Projection as PlaneProjection;
                if (_projection == null) {
                    _projection = new PlaneProjection();
                    _projection.CenterOfRotationX = 0.5;
                    _projection.CenterOfRotationY = 0.5;
                    _projection.CenterOfRotationZ = 0.5;
                    target.Projection = _projection;
                }
            }

            List<ProceduralAnimation> animations = new List<ProceduralAnimation>();

            if (_spinAroundXAxis) {
                DoubleAnimation xAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationXProperty, Duration, 360);
                xAnimation.Interpolation = GetEffectiveInterpolation();
                xAnimation.AutoReverse = true;
                animations.Add(xAnimation);
            }
            if (_spinAroundYAxis) {
                DoubleAnimation yAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationYProperty, Duration, 360);
                yAnimation.Interpolation = GetEffectiveInterpolation();
                yAnimation.AutoReverse = true;
                animations.Add(yAnimation);
            }
            if (_spinAroundZAxis) {
                DoubleAnimation zAnimation =
                    new DoubleAnimation(_projection, PlaneProjection.RotationZProperty, Duration, 360);
                zAnimation.Interpolation = GetEffectiveInterpolation();
                zAnimation.AutoReverse = true;
                animations.Add(zAnimation);
            }

            ProceduralAnimationSet animationSet = new ProceduralAnimationSet(animations.ToArray());
            animationSet.AutoReverse = AutoReverse;

            return animationSet;
        }