示例#1
0
        private void AnimateMatchingShapes(PowerPoint.Shape[] currentSlideShapes, PowerPoint.Shape[] nextSlideSlideShapes, int[] matchingShapeIDs)
        {
            int matchingShapeIndex;

            // Copy the shapes as the list may be modified when iterating
            PowerPoint.Shape[] slideShapesCopy = new PowerPoint.Shape[_slide.Shapes.Count];
            for (int i = 0; i < slideShapesCopy.Length; i++)
            {
                slideShapesCopy[i] = _slide.Shapes[i + 1];
            }

            foreach (PowerPoint.Shape sh in slideShapesCopy)
            {
                if (matchingShapeIDs.Contains(sh.Id))
                {
                    matchingShapeIndex = Array.IndexOf(matchingShapeIDs, sh.Id);
                    if (matchingShapeIndex < matchingShapeIDs.Count() && sh.Id == matchingShapeIDs[matchingShapeIndex])
                    {
                        DeleteShapeAnimations(sh);
                        PowerPoint.MsoAnimTriggerType trigger = (matchingShapeIndex == 0) ? PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious : PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
                        if (NeedsFrameAnimation(sh, nextSlideSlideShapes[matchingShapeIndex]))
                        {
                            FrameMotionAnimation.animationType = FrameMotionAnimation.FrameMotionAnimationType.kAutoAnimate;
                            FrameMotionAnimation.AddFrameMotionAnimation(this, sh, nextSlideSlideShapes[matchingShapeIndex], AnimationLabSettings.AnimationDuration);
                        }
                        else
                        {
                            DefaultMotionAnimation.AddDefaultMotionAnimation(this, sh, nextSlideSlideShapes[matchingShapeIndex], AnimationLabSettings.AnimationDuration, trigger);
                        }
                    }
                }
            }
        }
        private void AnimateMatchingShapes(PowerPoint.Shape[] currentSlideShapes, PowerPoint.Shape[] nextSlideSlideShapes, int[] matchingShapeIDs)
        {
            int matchingShapeIndex;

            foreach (PowerPoint.Shape sh in _slide.Shapes)
            {
                if (matchingShapeIDs.Contains(sh.Id))
                {
                    matchingShapeIndex = Array.IndexOf(matchingShapeIDs, sh.Id);
                    if (matchingShapeIndex < matchingShapeIDs.Count() && sh.Id == matchingShapeIDs[matchingShapeIndex])
                    {
                        DeleteShapeAnimations(sh);
                        PowerPoint.MsoAnimTriggerType trigger = (matchingShapeIndex == 0) ? PowerPoint.MsoAnimTriggerType.msoAnimTriggerAfterPrevious : PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
                        if (NeedsFrameAnimation(sh, nextSlideSlideShapes[matchingShapeIndex]))
                        {
                            FrameMotionAnimation.animationType = FrameMotionAnimation.FrameMotionAnimationType.kAutoAnimate;
                            FrameMotionAnimation.AddFrameMotionAnimation(this, sh, nextSlideSlideShapes[matchingShapeIndex], AutoAnimate.defaultDuration);
                        }
                        else
                        {
                            DefaultMotionAnimation.AddDefaultMotionAnimation(this, sh, nextSlideSlideShapes[matchingShapeIndex], AutoAnimate.defaultDuration, trigger);
                        }
                    }
                }
            }
        }
 private void AddSliderEndEffect(Shape shape, PowerPoint.MsoAnimTriggerType trigger)
 {
     PowerPoint.Effect sliderEndEffect = this.GetCurrentSlide().TimeLine.MainSequence.AddEffect(
         shape,
         PowerPoint.MsoAnimEffect.msoAnimEffectDarken,
         PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone,
         trigger);
     sliderEndEffect.Timing.Duration = TimerLabConstants.ColorChangeDuration;
 }
#pragma warning disable 0618
        //Use initial shape and final shape to calculate intial and final positions
        //Add motion, resize and rotation animations to shape
        public static void AddDefaultMotionAnimation(
            PowerPointSlide animationSlide,
            PowerPoint.Shape initialShape,
            PowerPoint.Shape finalShape,
            float duration,
            PowerPoint.MsoAnimTriggerType trigger)
        {
            float initialX        = (initialShape.Left + (initialShape.Width) / 2);
            float initialY        = (initialShape.Top + (initialShape.Height) / 2);
            float initialRotation = initialShape.Rotation;
            float initialWidth    = initialShape.Width;
            float initialHeight   = initialShape.Height;

            float finalX        = (finalShape.Left + (finalShape.Width) / 2);
            float finalY        = (finalShape.Top + (finalShape.Height) / 2);
            float finalRotation = finalShape.Rotation;
            float finalWidth    = finalShape.Width;
            float finalHeight   = finalShape.Height;

            if (Utils.ShapeUtil.IsStraightLine(initialShape))
            {
                double initialAngle = GetLineAngle(initialShape);
                double finalAngle   = GetLineAngle(finalShape);
                double deltaAngle   = initialAngle - finalAngle;
                finalRotation = (float)(RadiansToDegrees(deltaAngle));

                float initialLength      = (float)Math.Sqrt(initialWidth * initialWidth + initialHeight * initialHeight);
                float finalLength        = (float)Math.Sqrt(finalWidth * finalWidth + finalHeight * finalHeight);
                float initialAngleCosine = initialWidth / initialLength;
                float initialAngleSine   = initialHeight / initialLength;
                finalWidth  = finalLength * initialAngleCosine;
                finalHeight = finalLength * initialAngleSine;

                initialShape = MakePivotCenteredLine(animationSlide, initialShape);
            }

            AddMotionAnimation(animationSlide, initialShape, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, initialShape, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);
            AddRotationAnimation(animationSlide, initialShape, initialRotation, finalRotation, duration, ref trigger);
        }
示例#5
0
#pragma warning disable 0618
        //Use initial shape and final shape to calculate intial and final positions
        //Add motion, resize and rotation animations to shape
        public static void AddDefaultMotionAnimation(
            PowerPointSlide animationSlide,
            PowerPoint.Shape initialShape,
            PowerPoint.Shape finalShape,
            float duration,
            PowerPoint.MsoAnimTriggerType trigger)
        {
            float initialX        = (initialShape.Left + (initialShape.Width) / 2);
            float initialY        = (initialShape.Top + (initialShape.Height) / 2);
            float initialRotation = initialShape.Rotation;
            float initialWidth    = initialShape.Width;
            float initialHeight   = initialShape.Height;

            float finalX        = (finalShape.Left + (finalShape.Width) / 2);
            float finalY        = (finalShape.Top + (finalShape.Height) / 2);
            float finalRotation = finalShape.Rotation;
            float finalWidth    = finalShape.Width;
            float finalHeight   = finalShape.Height;

            AddMotionAnimation(animationSlide, initialShape, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, initialShape, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);
            AddRotationAnimation(animationSlide, initialShape, initialRotation, finalRotation, duration, ref trigger);
        }
        //Use initial shape and final shape to calculate intial and final positions.
        //Add motion and resize animations to shapeToZoom
        public static void AddZoomToAreaMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape shapeToZoom, PowerPoint.Shape initialShape, PowerPoint.Shape finalShape, float duration, PowerPoint.MsoAnimTriggerType trigger)
        {
            float initialWidth  = initialShape.Width;
            float finalWidth    = finalShape.Width;
            float initialHeight = initialShape.Height;
            float finalHeight   = finalShape.Height;

            float initialX = (initialShape.Left + (initialShape.Width) / 2) * (finalWidth / initialWidth);
            float finalX   = (finalShape.Left + (finalShape.Width) / 2) * (finalWidth / initialWidth);
            float initialY = (initialShape.Top + (initialShape.Height) / 2) * (finalHeight / initialHeight);
            float finalY   = (finalShape.Top + (finalShape.Height) / 2) * (finalHeight / initialHeight);

            AddMotionAnimation(animationSlide, shapeToZoom, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, shapeToZoom, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);
        }
        //Use shapeToZoom and reference shape to calculate intial and final positions
        //Add motion and resize animations to shapeToZoom
        public static void AddStepBackMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape shapeToZoom, PowerPoint.Shape referenceShape, float duration, PowerPoint.MsoAnimTriggerType trigger)
        {
            float initialX = (shapeToZoom.Left + (shapeToZoom.Width) / 2);
            float finalX   = (referenceShape.Left + (referenceShape.Width) / 2);
            float initialY = (shapeToZoom.Top + (shapeToZoom.Height) / 2);
            float finalY   = (referenceShape.Top + (referenceShape.Height) / 2);

            float initialWidth  = shapeToZoom.Width;
            float finalWidth    = referenceShape.Width;
            float initialHeight = shapeToZoom.Height;
            float finalHeight   = referenceShape.Height;

            AddMotionAnimation(animationSlide, shapeToZoom, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, shapeToZoom, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);
        }
        //Use reference shape and slide dimensions to calculate intial and final positions
        //Add motion and resize animations to shapeToZoom
        public static void AddDrillDownMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape shapeToZoom, PowerPoint.Shape referenceShape, float duration, PowerPoint.MsoAnimTriggerType trigger)
        {
            float finalWidth    = PowerPointPresentation.Current.SlideWidth;
            float initialWidth  = referenceShape.Width;
            float finalHeight   = PowerPointPresentation.Current.SlideHeight;
            float initialHeight = referenceShape.Height;

            float finalX   = (PowerPointPresentation.Current.SlideWidth / 2) * (finalWidth / initialWidth);
            float initialX = (referenceShape.Left + (referenceShape.Width) / 2) * (finalWidth / initialWidth);
            float finalY   = (PowerPointPresentation.Current.SlideHeight / 2) * (finalHeight / initialHeight);
            float initialY = (referenceShape.Top + (referenceShape.Height) / 2) * (finalHeight / initialHeight);

            AddMotionAnimation(animationSlide, shapeToZoom, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, shapeToZoom, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);
        }
        private static PowerPoint.Effect AddResizeAnimation(PowerPointSlide animationSlide, PowerPoint.Shape animationShape, float initialWidth, float initialHeight, float finalWidth, float finalHeight, float duration, ref PowerPoint.MsoAnimTriggerType trigger)
        {
            // To prevent zero multiplication and zero division
            initialWidth  = SetToPositiveMinIfIsZero(initialWidth);
            initialHeight = SetToPositiveMinIfIsZero(initialHeight);
            finalWidth    = SetToPositiveMinIfIsZero(finalWidth);
            finalHeight   = SetToPositiveMinIfIsZero(finalHeight);

            if ((finalWidth != initialWidth) || (finalHeight != initialHeight))
            {
                animationShape.LockAspectRatio = Office.MsoTriState.msoFalse;
                PowerPoint.Effect            effectResize = animationSlide.TimeLine.MainSequence.AddEffect(animationShape, PowerPoint.MsoAnimEffect.msoAnimEffectGrowShrink, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, trigger);
                PowerPoint.AnimationBehavior resize       = effectResize.Behaviors[1];

                effectResize.Timing.Duration = duration;

                resize.ScaleEffect.ByX = (finalWidth / initialWidth) * 100;
                resize.ScaleEffect.ByY = (finalHeight / initialHeight) * 100;

                trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
                return(effectResize);
            }
            return(null);
        }
 private static PowerPoint.Effect AddRotationAnimation(PowerPointSlide animationSlide, PowerPoint.Shape animationShape, float initialRotation, float finalRotation, float duration, ref PowerPoint.MsoAnimTriggerType trigger)
 {
     if (finalRotation != initialRotation)
     {
         PowerPoint.Effect            effectRotate = animationSlide.TimeLine.MainSequence.AddEffect(animationShape, PowerPoint.MsoAnimEffect.msoAnimEffectSpin, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, trigger);
         PowerPoint.AnimationBehavior rotate       = effectRotate.Behaviors[1];
         effectRotate.Timing.Duration         = duration;
         effectRotate.EffectParameters.Amount = LegacyShapeUtil.GetMinimumRotation(initialRotation, finalRotation);
         trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;
         return(effectRotate);
     }
     return(null);
 }
        private static PowerPoint.Effect AddMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape animationShape, float initialX, float initialY, float finalX, float finalY, float duration, ref PowerPoint.MsoAnimTriggerType trigger)
        {
            if ((finalX != initialX) || (finalY != initialY))
            {
                PowerPoint.Effect            effectMotion = animationSlide.TimeLine.MainSequence.AddEffect(animationShape, PowerPoint.MsoAnimEffect.msoAnimEffectPathDown, PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone, trigger);
                PowerPoint.AnimationBehavior motion       = effectMotion.Behaviors[1];
                effectMotion.Timing.Duration = duration;
                trigger = PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious;

                //Create VML path for the motion path
                //This path needs to be a curved path to allow the user to edit points
                float point1X = ((finalX - initialX) / 2f) / PowerPointPresentation.Current.SlideWidth;
                float point1Y = ((finalY - initialY) / 2f) / PowerPointPresentation.Current.SlideHeight;
                float point2X = (finalX - initialX) / PowerPointPresentation.Current.SlideWidth;
                float point2Y = (finalY - initialY) / PowerPointPresentation.Current.SlideHeight;
                motion.MotionEffect.Path = "M 0 0 C "
                                           + point1X.ToString(CultureInfo.InvariantCulture) + " "
                                           + point1Y.ToString(CultureInfo.InvariantCulture) + " "
                                           + point1X.ToString(CultureInfo.InvariantCulture) + " "
                                           + point1Y.ToString(CultureInfo.InvariantCulture) + " "
                                           + point2X.ToString(CultureInfo.InvariantCulture) + " "
                                           + point2Y.ToString(CultureInfo.InvariantCulture) + " E";
                effectMotion.Timing.SmoothStart = Office.MsoTriState.msoFalse;
                effectMotion.Timing.SmoothEnd   = Office.MsoTriState.msoFalse;
                return(effectMotion);
            }
            return(null);
        }
        /// <summary>
        /// Zoom out from initial shape to the full slide.
        /// Returns the final disappear effect for initialShape.
        /// </summary>
        public static PowerPoint.Effect AddZoomOutMotionAnimation(PowerPointSlide animationSlide, PowerPoint.Shape initialShape, PowerPoint.MsoAnimTriggerType trigger)
        {
            float initialX      = (initialShape.Left + (initialShape.Width) / 2);
            float initialY      = (initialShape.Top + (initialShape.Height) / 2);
            float initialWidth  = initialShape.Width;
            float initialHeight = initialShape.Height;

            float finalX      = PowerPointPresentation.Current.SlideWidth / 2;
            float finalY      = PowerPointPresentation.Current.SlideHeight / 2;
            float finalWidth  = PowerPointPresentation.Current.SlideWidth;
            float finalHeight = PowerPointPresentation.Current.SlideHeight;

            float duration = 0.4f;

            AddMotionAnimation(animationSlide, initialShape, initialX, initialY, finalX, finalY, duration, ref trigger);
            AddResizeAnimation(animationSlide, initialShape, initialWidth, initialHeight, finalWidth, finalHeight, duration, ref trigger);

            Sequence sequence        = animationSlide.TimeLine.MainSequence;
            Effect   effectDisappear = sequence.AddEffect(initialShape, PowerPoint.MsoAnimEffect.msoAnimEffectFade,
                                                          PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone,
                                                          PowerPoint.MsoAnimTriggerType.msoAnimTriggerWithPrevious);

            effectDisappear.Exit            = Office.MsoTriState.msoTrue;
            effectDisappear.Timing.Duration = 0.01f;
            return(effectDisappear);
        }
        private void AddSliderMotionEffect(Shape shape, int duration, float timerWidth, float slideWidth, PowerPoint.MsoAnimTriggerType trigger)
        {
            PowerPoint.Effect sliderMotionEffect = this.GetCurrentSlide().TimeLine.MainSequence.AddEffect(
                shape,
                PowerPoint.MsoAnimEffect.msoAnimEffectPathRight,
                PowerPoint.MsoAnimateByLevel.msoAnimateLevelNone,
                trigger);
            PowerPoint.AnimationBehavior motion = sliderMotionEffect.Behaviors[1];
            float end = timerWidth / slideWidth;

            motion.MotionEffect.Path              = "M 0 0 L " + end + " 0 E";
            sliderMotionEffect.Timing.Duration    = duration;
            sliderMotionEffect.Timing.SmoothStart = Microsoft.Office.Core.MsoTriState.msoFalse;
            sliderMotionEffect.Timing.SmoothEnd   = Microsoft.Office.Core.MsoTriState.msoFalse;
        }