Пример #1
0
        private static PointKeyFrame CreatePointKeyFrmas(KeyFrames <Point> Model)
        {
            PointKeyFrame frame = null;

            switch (Model.Type)
            {
            case KeyFramesType.Spline: frame = new SplinePointKeyFrame()
            {
                    KeySpline = Model.Spline
            }; break;

            case KeyFramesType.Linear: frame = new LinearPointKeyFrame(); break;

            case KeyFramesType.Easing: frame = new EasingPointKeyFrame()
            {
                    EasingFunction = Model.EasingFunction
            }; break;

            case KeyFramesType.Discrete: frame = new DiscretePointKeyFrame(); break;

            default: break;
            }
            frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime));
            frame.Value   = Model.Value;
            return(frame);
        }
Пример #2
0
        // Adds individual animations to the locationAnimation StoryBoard.
        private void AnimateNode(int key, NodePanel np, Duration duration)
        {
            if (key < 0)
            {
                return;
            }
            if (np == null)
            {
                return;
            }

            PointAnimationUsingKeyFrames locationAnimation = new PointAnimationUsingKeyFrames();
            double keyTime = 0.0;

            // Gets the LinearPointKeyFrames for the PointAnimationUsingKeyFrames.
            // Starts at key-1 to account for an initial KeyFrame.
            for (int i = key - 1; i < (key + NumberOfNodes - 1); i++)
            {
                LinearPointKeyFrame lpkf = new LinearPointKeyFrame();
                lpkf.KeyTime = TimeSpan.FromSeconds(keyTime);

                int nextNodeKeyInt = i + 1;
                if (nextNodeKeyInt >= (NumberOfNodes - 1))
                {
                    nextNodeKeyInt = nextNodeKeyInt % (NumberOfNodes - 1);
                }
                MyNodeData nextNodeData = myDiagram.Model.FindNodeByKey((nextNodeKeyInt)) as MyNodeData;
                if (nextNodeData == null || nextNodeData.Location == null)
                {
                    return;
                }
                lpkf.Value = nextNodeData.Location;
                locationAnimation.KeyFrames.Add(lpkf);

                // If duration equals TimeSpan.FromSeconds(NumberOfNodes - 1),
                // then keyTime increases by 1 with each iteration.
                keyTime += ((double)duration.TimeSpan.TotalSeconds) / (NumberOfNodes - 1);
            }

            LocationStoryBoard.Children.Add(locationAnimation);
            Storyboard.SetTarget(locationAnimation, np);
            Storyboard.SetTargetProperty(locationAnimation, new PropertyPath(Node.LocationProperty));
        }