Example #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="frames"></param>
 /// <param name="animation"></param>
 public ClearFramesCommand(GUIAnimation animation, GUIAnimationChannel animationChannel, int start, int end)
 {
     mAnimation        = animation;
     mAnimationChannel = animationChannel;
     mStart            = start;
     mEnd       = end;
     mKeyFrames = new List <KeyFrame>();
 }
Example #2
0
        /// <summary>
        /// Undoes the command
        /// </summary>
        /// <returns></returns>
        public override bool Undo()
        {
            int numFrames = (mTrimEnd - mTrimStart) + 1;

            if (numFrames <= 0)
            {
                return(false);
            }

            mAnimation.NumFrames  += (uint)numFrames;
            mAnimation.RepeatStart = mOrigRepeatStart;
            mAnimation.RepeatEnd   = mOrigRepeatEnd;

            // Add the trimmed keyframes back in
            for (int i = 0; i < mAnimation.AnimationChannels.Count; i++)
            {
                GUIAnimationChannel channel = mAnimation.AnimationChannels[i];

                foreach (KeyFrame keyFrame in channel.KeyFrames)
                {
                    if (keyFrame.Frame != 0 && keyFrame.Frame >= mTrimStart)
                    {
                        keyFrame.Frame += (uint)numFrames;
                    }
                }

                channel.KeyFrames.AddRange(mRemovedKeyFrames[i]);
                channel.KeyFrames.Sort((a, b) => ((int)a.Frame - (int)b.Frame));
            }

            // Add the trimmed actionlist back in
            foreach (MainChannelFrame actionList in mAnimation.MainChannelFrames)
            {
                if (actionList.Frame >= mTrimStart)
                {
                    actionList.Frame += (uint)numFrames;
                }
            }

            mAnimation.MainChannelFrames.AddRange(mRemovedMainChannelFrames);
            mAnimation.MainChannelFrames.Sort((a, b) => ((int)a.Frame - (int)b.Frame));

            mRemovedMainChannelFrames.Clear();
            mRemovedKeyFrames.Clear();

            return(true);
        }
Example #3
0
        /// <summary>
        /// Sets the control's new parent.  This function will also fix up any
        /// other animations that references the control.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="newParent"></param>
        private static void SetParent(GUIControl control, GUIControl newParent, int index)
        {
            GUIView view = (newParent is GUIView) ? newParent as GUIView : newParent.ParentView;

            Otter.Interface.Matrix invTransform = newParent.FullTransformInv;

            PointF center   = PointF.Empty;
            float  rotation = 0.0f;
            PointF location = PointF.Empty;

            Matrix oldTransformInv = control.TransformInv;
            Matrix newTransform    = control.FullTransform * invTransform;
            Matrix toLocal         = oldTransformInv * newTransform;

            GetComponents(control, ref newTransform, out center, out rotation, out location);

            if (control.ParentView == view)
            {
                GUIAnimation currentAnim  = view.CurrentAnimation;
                uint         currentFrame = currentAnim.Frame;

                foreach (GUIAnimation animation in view.Animations)
                {
                    uint oldFrame = animation.Frame;
                    GUIAnimationChannel channel = animation.GetAnimationChannel(control);

                    if (channel == null)
                    {
                        continue;
                    }

                    view.CurrentAnimation = animation;

                    foreach (KeyFrame keyFrame in channel.KeyFrames)
                    {
                        // This will update the control
                        view.CurrentAnimation.Frame = keyFrame.Frame;

                        PointF kfCenter   = control.Center;
                        float  kfRotation = control.Rotation;
                        PointF kfLocation = control.Location;

                        Matrix kfTransform = control.Transform * toLocal;

                        GetComponents(control, ref kfTransform, out kfCenter, out kfRotation, out kfLocation);

                        keyFrame.Layout.Center   = kfCenter;
                        keyFrame.Layout.Rotation = kfRotation;
                        keyFrame.Layout.Location = kfLocation;
                    }

                    animation.Frame = oldFrame;
                }

                view.CurrentAnimation       = currentAnim;
                view.CurrentAnimation.Frame = currentFrame;

                view.SetNewParent(control, newParent, index);
            }
            else
            {
                control.ParentView.RemoveControl(control);
                view.AddControl(newParent, control);
            }

            control.Center   = center;
            control.Rotation = rotation;
            control.Location = location;
        }
Example #4
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            int numFrames = (mTrimEnd - mTrimStart) + 1;

            if (numFrames <= 0)
            {
                return(false);
            }

            mRemovedMainChannelFrames.Clear();
            mRemovedKeyFrames.Clear();

            Predicate <KeyFrame>         kfPredicate   = (frame) => (frame.Frame != 0 && frame.Frame >= mTrimStart && frame.Frame <= mTrimEnd);
            Predicate <MainChannelFrame> mainPredicate = (frame) => (frame.Frame != 0 && frame.Frame >= mTrimStart && frame.Frame <= mTrimEnd);

            mAnimation.NumFrames -= (uint)numFrames;

            // Remove the keyframes
            for (int i = 0; i < mAnimation.AnimationChannels.Count; i++)
            {
                GUIAnimationChannel channel = mAnimation.AnimationChannels[i];
                mRemovedKeyFrames.Add(channel.KeyFrames.FindAll(kfPredicate));

                // Remove unneeded keyframes
                channel.KeyFrames.RemoveAll(kfPredicate);

                foreach (KeyFrame keyFrame in channel.KeyFrames)
                {
                    if (keyFrame.Frame != 0 && keyFrame.Frame >= mTrimStart)
                    {
                        keyFrame.Frame -= (uint)numFrames;
                    }
                }
            }

            // Remove the action lists
            mRemovedMainChannelFrames.AddRange(mAnimation.MainChannelFrames.FindAll(mainPredicate));
            mAnimation.MainChannelFrames.RemoveAll(mainPredicate);
            foreach (MainChannelFrame actionList in mAnimation.MainChannelFrames)
            {
                if (actionList.Frame >= mTrimStart)
                {
                    actionList.Frame -= (uint)numFrames;
                }
            }

            // Now adjust the loop if necessary
            if (mAnimation.RepeatStart < mAnimation.RepeatEnd)
            {
                // Adjust the start / end frames if necessary
                if (mTrimEnd <= mAnimation.RepeatEnd)
                {
                    mAnimation.RepeatEnd -= numFrames;
                }
                else if (mTrimStart <= mAnimation.RepeatEnd)
                {
                    mAnimation.RepeatEnd = mTrimStart - 1;
                }

                if (mTrimEnd < mAnimation.RepeatStart)
                {
                    mAnimation.RepeatStart -= numFrames;
                }
                else if (mTrimStart <= mAnimation.RepeatStart)
                {
                    mAnimation.RepeatStart = mTrimStart;
                }

                if (mAnimation.RepeatStart > mAnimation.RepeatEnd)
                {
                    mAnimation.RepeatStart = mAnimation.RepeatEnd = -1;
                }
            }

            return(true);
        }