Beispiel #1
0
        /// <summary>
        /// Create PointAnimation
        /// </summary>
        /// <param name="parentObj">Storyboard parent object</param>
        /// <param name="target">Animation target object</param>
        /// <param name="property">Property path to animate</param>
        /// <param name="beginTime">Animation begin time</param>
        /// <param name="frameTime">Frame time collection</param>
        /// <param name="values">Target value collection</param>
        /// <param name="splines">List of KeySpline</param>
        /// <returns>PointAnimationUsingKeyFrames</returns>
        internal static PointAnimationUsingKeyFrames CreatePointAnimation(FrameworkElement parentObj, DependencyObject target, String property, Double beginTime, DoubleCollection frameTime, PointCollection values, List <KeySpline> splines)
        {
            PointAnimationUsingKeyFrames da = new PointAnimationUsingKeyFrames();

#if WPF
            target.SetValue(FrameworkElement.NameProperty, target.GetType().Name + Guid.NewGuid().ToString().Replace('-', '_'));
            Storyboard.SetTargetName(da, target.GetValue(FrameworkElement.NameProperty).ToString());

            (parentObj as ObservableObject).Chart._rootElement.RegisterName((string)target.GetValue(FrameworkElement.NameProperty), target);
#else
            Storyboard.SetTarget(da, target);
#endif
            Storyboard.SetTargetProperty(da, new PropertyPath(property));

            da.BeginTime = TimeSpan.FromSeconds(beginTime);

            for (Int32 index = 0; index < values.Count; index++)
            {
                SplinePointKeyFrame keyFrame = new SplinePointKeyFrame();

                if (splines != null)
                {
                    keyFrame.KeySpline = splines[index];
                }

                keyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(frameTime[index]));
                keyFrame.Value   = values[index];
                da.KeyFrames.Add(keyFrame);
            }

            return(da);
        }
Beispiel #2
0
        private void StartAnimation()
        {
            const int CSt_MS = 50;
            PointAnimationUsingKeyFrames ptAnim = new PointAnimationUsingKeyFrames();

            ptAnim.KeyFrames.Add(new DiscretePointKeyFrame {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(CSt_MS)), Value = new Point(14.7, 8.5)
            });
            ptAnim.KeyFrames.Add(new DiscretePointKeyFrame {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(CSt_MS)), Value = new Point(15, 9.99)
            });

            Timeline anim = ptAnim;//new PointAnimation();
            //anim.To = new Point(15, 9.99);
            Storyboard sb = new Storyboard();

            sb.Duration = new Duration(TimeSpan.FromMilliseconds(200));
            sb.Children.Add(anim);
            Storyboard.SetTarget(anim, mouseTopPosition);
            Storyboard.SetTargetProperty(anim, new PropertyPath("Point"));

            PointAnimationUsingKeyFrames ptAnim1 = new PointAnimationUsingKeyFrames();

            ptAnim1.KeyFrames.Add(new DiscretePointKeyFrame {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(CSt_MS)), Value = new Point(14.7, 11.5)
            });
            ptAnim1.KeyFrames.Add(new DiscretePointKeyFrame {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(CSt_MS)), Value = new Point(15, 10.01)
            });

            Timeline anim1 = ptAnim1;// new PointAnimation();

            //anim1.To = new Point(15, 10.01);
            sb.Children.Add(anim1);
            Storyboard.SetTarget(anim1, mouseBottomPosition);
            Storyboard.SetTargetProperty(anim1, new PropertyPath("Point"));

            //DoubleAnimation dblAnim = new DoubleAnimation();
            //sb.Children.Add(dblAnim);
            //dblAnim.To = 7;
            //Storyboard.SetTarget(dblAnim, this);
            //Storyboard.SetTargetProperty(dblAnim, new PropertyPath("PacmanWidth"));

            sb.AutoReverse = true;
            sb.Completed  += delegate
            {
                System.Diagnostics.Debug.WriteLine("Completed");
                if (_animforever)
                {
                    System.Diagnostics.Debug.WriteLine("reBegin");
                    StartAnimation();
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("_animationInProgress = false");
                    _animationInProgress = false;
                }
            };
            sb.Begin();
        }
Beispiel #3
0
        public static AnimationClock AnimateElementPoint(DependencyObject element, DependencyProperty property, Point targetValue, double fromTime, double toTime)
        {
            if (!(element is IAnimatable))
            {
                throw new InvalidOperationException("Element must be IAnimatable.");
            }

            Point initialValue = (Point)element.GetValue(property);

            PointAnimationUsingKeyFrames anim = new PointAnimationUsingKeyFrames();

            anim.KeyFrames.Add(new SplinePointKeyFrame(initialValue,
                                                       KeyTime.FromTimeSpan(TimeSpan.FromSeconds(fromTime))));
            anim.KeyFrames.Add(new SplinePointKeyFrame(targetValue,
                                                       KeyTime.FromTimeSpan(TimeSpan.FromSeconds(toTime))
                                                       , new KeySpline(0.0, 0, 0.05, 1))
                               );

            if (fromTime > 0.0)
            {
                return(AnimateElementDelayHelper(element, property, anim, fromTime));
            }
            else
            {
                return(AnimateElementHelper(element, property, anim));
            }
        }
Beispiel #4
0
        // Token: 0x06000D05 RID: 3333 RVA: 0x00030930 File Offset: 0x0002EB30
        private static Point?GetTargetPoint(Timeline timeline, bool isEntering)
        {
            PointAnimation pointAnimation = timeline as PointAnimation;

            if (pointAnimation != null)
            {
                if (pointAnimation.From == null)
                {
                    return(pointAnimation.To);
                }
                return(pointAnimation.From);
            }
            else
            {
                PointAnimationUsingKeyFrames pointAnimationUsingKeyFrames = timeline as PointAnimationUsingKeyFrames;
                if (pointAnimationUsingKeyFrames == null)
                {
                    return(null);
                }
                if (pointAnimationUsingKeyFrames.KeyFrames.Count == 0)
                {
                    return(null);
                }
                PointKeyFrame pointKeyFrame = pointAnimationUsingKeyFrames.KeyFrames[isEntering ? 0 : (pointAnimationUsingKeyFrames.KeyFrames.Count - 1)];
                return(new Point?(pointKeyFrame.Value));
            }
        }
Beispiel #5
0
        void WalkTo()
        {
            sb.Children.Clear();
            Canvas.SetZIndex(button1, 100);
            //throw new NotImplementedException();
            Point lastP = getPosition(button1);
            PointAnimationUsingKeyFrames DAUKF = new PointAnimationUsingKeyFrames()
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(Paths.Count * 100))
            };

            Storyboard.SetTarget(DAUKF, button1);
            Storyboard.SetTargetProperty(DAUKF, new PropertyPath("Coordinate"));
            //DAUKF.KeyFrames.Add(new LinearPointKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100)), Value = lastPoint });
            int i = 0;

            foreach (PathPoints item in Paths)
            {
                item.DotPoint.Opacity = 0.5;
                DAUKF.KeyFrames.Add(new LinearPointKeyFrame()
                {
                    KeyTime = TimeSpan.FromMilliseconds((i + 1) * 100), Value = item.point
                });
                i++;
            }
            sb.Children.Add(DAUKF);
            sb.Begin();
        }
Beispiel #6
0
        public void CreateReversal(double startTime, Button btn, BitmapImage background)
        {
            var chgBg = new ObjectAnimationUsingKeyFrames();
            DiscreteObjectKeyFrame dk = new DiscreteObjectKeyFrame(background);

            dk.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startTime + 0.5));
            dk.Value   = background;
            chgBg.KeyFrames.Add(dk);
            Storyboard.SetTargetName(chgBg, btn.Name);
            DependencyProperty[] propertyChain2 = new DependencyProperty[]
            {
                Button.BackgroundProperty,
                ImageBrush.ImageSourceProperty
            };
            Storyboard.SetTargetProperty(chgBg, new PropertyPath("(0).(1)", propertyChain2));

            var transformOrigin     = new PointAnimationUsingKeyFrames();
            EasingPointKeyFrame kf1 = new EasingPointKeyFrame(new System.Windows.Point(0.5, 0), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
            EasingPointKeyFrame kf2 = new EasingPointKeyFrame(new System.Windows.Point(0.5, 0), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startTime)));
            EasingPointKeyFrame kf3 = new EasingPointKeyFrame(new System.Windows.Point(0.5, 0.5), KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startTime + 1)));

            transformOrigin.KeyFrames.Add(kf1);
            transformOrigin.KeyFrames.Add(kf2);
            transformOrigin.KeyFrames.Add(kf3);
            Storyboard.SetTargetName(transformOrigin, btn.Name);
            DependencyProperty[] propertyChain1 = new DependencyProperty[]
            {
                Button.RenderTransformOriginProperty
            };
            Storyboard.SetTargetProperty(transformOrigin, new PropertyPath(Control.RenderTransformOriginProperty));

            var d_transform          = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame kf4 = new EasingDoubleKeyFrame(-1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
            EasingDoubleKeyFrame kf5 = new EasingDoubleKeyFrame(-1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startTime)));
            EasingDoubleKeyFrame kf6 = new EasingDoubleKeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startTime + 1)));

            d_transform.KeyFrames.Add(kf4);
            d_transform.KeyFrames.Add(kf5);
            d_transform.KeyFrames.Add(kf6);
            Storyboard.SetTargetName(d_transform, btn.Name);
            DependencyProperty[] propertyChain3 = new DependencyProperty[]
            {
                Control.RenderTransformProperty,
                TransformGroup.ChildrenProperty,
                ScaleTransform.ScaleXProperty
            };
            Storyboard.SetTargetProperty(d_transform, new PropertyPath("(0).(1)[0].(2)", propertyChain3));

            reversalSB.Children.Add(transformOrigin);
            reversalSB.Children.Add(d_transform);
            reversalSB.Children.Add(chgBg);
        }
Beispiel #7
0
        private AnimationTimeline CreatePointAnimation(int index)
        {
            PointAnimationUsingKeyFrames anim = new PointAnimationUsingKeyFrames();

            anim.Duration = new Duration(TimeSpan.FromSeconds(30));

            foreach (Point point in points[index])
            {
                anim.KeyFrames.Add(new LinearPointKeyFrame(point));
            }

            return(anim);
        }
Beispiel #8
0
        public override void CreateStoryboard()
        {
            PointAnimationUsingKeyFrames dau = new PointAnimationUsingKeyFrames();

            EasingPointKeyFrame fromk = null;

            if (FromPoint.HasValue)
            {
                fromk = new EasingPointKeyFrame(FromPoint.Value, TimeSpan.FromMilliseconds(AniTime(0)));
                dau.KeyFrames.Add(fromk);
            }

            EasingPointKeyFrame tok = null;

            if (ToPoint.HasValue)
            {
                tok = new EasingPointKeyFrame(ToPoint.Value, TimeSpan.FromMilliseconds(AniTime(1)));
                dau.KeyFrames.Add(tok);
            }


            if (AniEasingFunction != null)
            {
                if (fromk != null)
                {
                    fromk.EasingFunction = AniEasingFunction;
                }
                if (tok != null)
                {
                    tok.EasingFunction = AniEasingFunction;
                }
            }
            else if (CirDefault != null)
            {
                if (fromk != null)
                {
                    fromk.EasingFunction = CirDefault;
                }
                if (tok != null)
                {
                    tok.EasingFunction = CirDefault;
                }
            }

            Storyboard.SetTarget(dau, Element);
            Storyboard.SetTargetProperty(dau, AniPropertyPath);
            Story.Children.Add(dau);
        }
        public static PointAnimationUsingKeyFrames AddDiscreteKeyFrame(
            this PointAnimationUsingKeyFrames animation,
            double seconds, Point value)
        {
            var keyFrame = new DiscretePointKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(seconds)),
                Value   = value,
            };

            animation.KeyFrames.Add(keyFrame);
#if NETFX_CORE || WINDOWS_81_PORTABLE
            animation.EnableDependentAnimation = true;
#endif
            return(animation);
        }
Beispiel #10
0
        /// <summary>
        /// 创建Point类型的关键帧动画
        /// </summary>
        /// <param name="Model">动画数据</param>
        /// <returns></returns>
        public static PointAnimationUsingKeyFrames BuildPointKeyFramesAnimation(PointKeyFramesModel Model)
        {
            PointAnimationUsingKeyFrames _pointAnimation = new PointAnimationUsingKeyFrames();

            _pointAnimation.Duration       = (Model.Duration == 0 ? Duration.Automatic : new Duration(TimeSpan.FromSeconds(Model.Duration)));
            _pointAnimation.AutoReverse    = Model.AutoReverse;
            _pointAnimation.BeginTime      = TimeSpan.FromSeconds(Model.BeginTime);
            _pointAnimation.FillBehavior   = Model.FillBehavior;
            _pointAnimation.RepeatBehavior = Model.RepeatBehavior;
            _pointAnimation.SpeedRatio     = Model.SpeedRatio;
            foreach (var item in Model.KeyFrames)
            {
                _pointAnimation.KeyFrames.Add(CreatePointKeyFrmas(item));
            }
            Storyboard.SetTarget(_pointAnimation, Model.Target);
            Storyboard.SetTargetProperty(_pointAnimation, new PropertyPath(Model.PropertyPath));
            return(_pointAnimation);
        }
Beispiel #11
0
        /// <summary>
        /// Apply Opacity animation to an object
        /// </summary>
        /// <param name="objectToAnimate">Object to animate</param>
        /// <param name="parentObj">Storyboard parent Object</param>
        /// <param name="storyboard">Storyboard reference</param>
        /// <param name="beginTime">Begin time</param>
        /// <param name="duration">Animation duration</param>
        /// <param name="targetValue">Target opacity value</param>
        /// <returns>Storyboard</returns>
        internal static Storyboard ApplyPointAnimation(DependencyObject objectToAnimate, String property, FrameworkElement parentObj, Storyboard storyboard, Double beginTime, Double[] timeCollection, Point[] valueCollection, List <KeySpline> splain, Double speedRatio)
        {
            if (objectToAnimate != null && parentObj != null)
            {
                PointCollection  values     = Graphics.GeneratePointCollection(valueCollection);
                DoubleCollection frameTimes = Graphics.GenerateDoubleCollection(timeCollection);

                PointAnimationUsingKeyFrames animation = AnimationHelper.CreatePointAnimation(parentObj, objectToAnimate, property, beginTime, frameTimes, values, splain);

                if (!Double.IsNaN(speedRatio))
                {
                    animation.SpeedRatio = speedRatio;
                }

                storyboard.Children.Add(animation);
            }

            return(storyboard);
        }
Beispiel #12
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));
        }
Beispiel #13
0
        private static Point?GetTargetPoint(Timeline timeline, bool isEntering)
        {
            PointAnimation pa = timeline as PointAnimation;

            if (pa != null)
            {
                return(pa.From.HasValue ? pa.From : pa.To);
            }

            PointAnimationUsingKeyFrames pak = timeline as PointAnimationUsingKeyFrames;

            if (pak != null)
            {
                if (pak.KeyFrames.Count == 0)
                {
                    return(null);
                }

                PointKeyFrame keyFrame = pak.KeyFrames[isEntering ? 0 : pak.KeyFrames.Count - 1];
                return(keyFrame.Value);
            }

            return(null);
        }
Beispiel #14
0
        public PointAnimationUsingKeyFramesExample()
        {
            Title      = "PointAnimationUsingKeyFrames Example";
            Background = Brushes.White;
            Margin     = new Thickness(20);

            // Create a NameScope for this page so that
            // Storyboards can be used.
            NameScope.SetNameScope(this, new NameScope());

            // Create an EllipseGeometry.
            EllipseGeometry myAnimatedEllipseGeometry =
                new EllipseGeometry(new Point(200, 100), 15, 15);

            // Assign the EllipseGeometry a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName(
                "MyAnimatedEllipseGeometry", myAnimatedEllipseGeometry);

            // Create a Path element to display the geometry.
            Path aPath = new Path();

            aPath.Fill = Brushes.Blue;
            aPath.Data = myAnimatedEllipseGeometry;

            // Create a Canvas to contain the path.
            Canvas containerCanvas = new Canvas();

            containerCanvas.Width  = 500;
            containerCanvas.Height = 400;
            containerCanvas.Children.Add(aPath);

            // Create a PointAnimationUsingKeyFrames to
            // animate the EllipseGeometry.
            PointAnimationUsingKeyFrames centerPointAnimation
                = new PointAnimationUsingKeyFrames();

            centerPointAnimation.Duration = TimeSpan.FromSeconds(5);

            // Animate from the starting position to (100,300)
            // over the first half-second using linear
            // interpolation.
            centerPointAnimation.KeyFrames.Add(
                new LinearPointKeyFrame(
                    new Point(100, 300),                             // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5))) // KeyTime
                );

            // Animate from (100,300) (the value of the previous key frame)
            // to (400,300) at 1 second using discrete interpolation.
            // Because the interpolation is discrete, the ellipse will appear
            // to "jump" to (400,300) at 1 second.
            centerPointAnimation.KeyFrames.Add(
                new DiscretePointKeyFrame(
                    new Point(400, 300),                           // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1))) // KeyTime
                );

            // Animate from (400,300) (the value of the previous key frame) to (200,100)
            // over two seconds, starting at 1 second (the key time of the
            // last key frame) and ending at 3 seconds.
            centerPointAnimation.KeyFrames.Add(
                new SplinePointKeyFrame(
                    new Point(200, 100),                           // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3)), // KeyTime
                    new KeySpline(0.6, 0.0, 0.9, 0.0)              // KeySpline
                    )
                );

            // Set the animation to repeat forever.
            centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Set the animation to target the Center property
            // of the object named "MyAnimatedEllipseGeometry".
            Storyboard.SetTargetName(centerPointAnimation, "MyAnimatedEllipseGeometry");
            Storyboard.SetTargetProperty(
                centerPointAnimation, new PropertyPath(EllipseGeometry.CenterProperty));

            // Create a storyboard to apply the animation.
            Storyboard ellipseStoryboard = new Storyboard();

            ellipseStoryboard.Children.Add(centerPointAnimation);

            // Start the storyboard when the Path loads.
            aPath.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                ellipseStoryboard.Begin(this);
            };

            Content = containerCanvas;
        }
Beispiel #15
0
        internal DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox, bool isSwitch)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            if (viewBox.HasValue)
            {
                grp.ClipGeometry = new RectangleGeometry(viewBox.Value);
            }

            foreach (Shape shape in elements)
            {
                if (isSwitch)
                {
                    if (grp.Children.Count > 0)
                    {
                        break;
                    }
                    if (!string.IsNullOrEmpty(shape.RequiredFeatures))
                    {
                        if (!SVGFeatures.Features.Contains(shape.RequiredFeatures))
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(shape.RequiredExtensions))
                        {
                            continue;
                        }
                    }
                }

                if (shape is AnimationBase)
                {
                    if (UseAnimations)
                    {
                        if (shape is AnimateTransform animateTransform)
                        {
                            if (animateTransform.Type == AnimateTransformType.Rotate)
                            {
                                var animation = new DoubleAnimation
                                {
                                    From     = double.Parse(animateTransform.From),
                                    To       = double.Parse(animateTransform.To),
                                    Duration = animateTransform.Duration
                                };
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                var r = new RotateTransform();
                                grp.Transform = r;
                                r.BeginAnimation(RotateTransform.AngleProperty, animation);
                            }
                        }
                        else if (shape is Animate animate)
                        {
                            var target = this.SVG.GetShape(animate.hRef);
                            var g      = target.geometryElement;
                            //todo : rework this all, generalize it!
                            if (animate.AttributeName == "r")
                            {
                                var animation = new DoubleAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;

                                g.BeginAnimation(EllipseGeometry.RadiusXProperty, animation);
                                g.BeginAnimation(EllipseGeometry.RadiusYProperty, animation);
                            }
                            else if (animate.AttributeName == "cx")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                            else if (animate.AttributeName == "cy")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(((EllipseGeometry)g).Center.X, double.Parse(_)))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                        }
                    }

                    continue;
                }

                if (shape is UseShape)
                {
                    UseShape useshape         = shape as UseShape;
                    Shape    currentUsedShape = this.SVG.GetShape(useshape.hRef);
                    if (currentUsedShape != null)
                    {
                        currentUsedShape.RealParent = useshape;
                        Shape        oldparent = currentUsedShape.Parent;
                        DrawingGroup subgroup;
                        if (currentUsedShape is Group)
                        {
                            subgroup = this.LoadGroup(((Group)currentUsedShape).Elements, null, false);
                        }
                        else
                        {
                            subgroup = this.LoadGroup(new[] { currentUsedShape }, null, false);
                        }
                        if (currentUsedShape.Clip != null)
                        {
                            subgroup.ClipGeometry = currentUsedShape.Clip.ClipGeometry;
                        }
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        if (useshape.Transform != null)
                        {
                            subgroup.Transform = new TransformGroup()
                            {
                                Children = new TransformCollection()
                                {
                                    subgroup.Transform, useshape.Transform
                                }
                            }
                        }
                        ;
                        grp.Children.Add(subgroup);
                        currentUsedShape.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null, false);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group groupShape)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null, groupShape.IsSwitch);
                    AddDrawingToGroup(grp, shape, subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape    r    = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X < 0 ? 0 : r.X, r.Y < 0 ? 0 : r.Y, r.X < 0 ? r.Width + r.X : r.Width, r.Y < 0 ? r.Height + r.Y : r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    var di = this.NewDrawingItem(shape, rect);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is LineShape)
                {
                    LineShape    r    = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    var          di   = this.NewDrawingItem(shape, line);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r    = shape as PolylineShape;
                    PathGeometry  path = new PathGeometry();
                    PathFigure    p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r    = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure   p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is CircleShape)
                {
                    CircleShape     r  = shape as CircleShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is EllipseShape)
                {
                    EllipseShape    r  = shape as EllipseShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                    continue;
                }
                if (shape is ImageShape)
                {
                    ImageShape   image = shape as ImageShape;
                    ImageDrawing i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    AddDrawingToGroup(grp, shape, i);
                    continue;
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                var di = this.NewDrawingItem(tspan, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                            else
                            {
                                var di = this.NewDrawingItem(shape, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                        }
                    }
                    continue;
                }
                if (shape is PathShape)
                {
                    PathShape  r         = shape as PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    PathShape.CurveTo          lastc = null;
                    PathShape.QuadraticCurveTo lastq = null;
                    Point        lastcirPoint        = new Point(0, 0);
                    PathGeometry path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(r.Data));
                    //PathGeometry path = new PathGeometry();

                    /*
                     * foreach (PathShape.PathElement element in r.Elements)
                     * {
                     *  bool isRelative = element.IsRelative;
                     *  if (element is PathShape.MoveTo)
                     *  {
                     *      p = new PathFigure();
                     *      p.IsClosed = r.ClosePath;
                     *      if (isRelative) p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                     *      else p.StartPoint = ((PathShape.MoveTo)element).Point;
                     *      lastPoint = p.StartPoint;
                     *      path.Figures.Add(p);
                     *      continue;
                     *  }
                     *  if (element is PathShape.LineTo)
                     *  {
                     *      PathShape.LineTo lineto = element as PathShape.LineTo;
                     *      foreach (Point point in lineto.Points)
                     *      {
                     *          if (isRelative)
                     *          {
                     *              Point newpoint = lastPoint + (Vector)point;
                     *              lastPoint = newpoint;
                     *              p.Segments.Add(new LineSegment(newpoint, true));
                     *          }
                     *          else
                     *          {
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Point) lastPoint = point;
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Horizontal) lastPoint = new Point(point.X, lastPoint.Y);
                     *              if (lineto.PositionType == PathShape.LineTo.eType.Vertical) lastPoint = new Point(lastPoint.X, point.Y);
                     *              p.Segments.Add(new LineSegment(lastPoint, true));
                     *          }
                     *      }
                     *      continue;
                     *  }
                     *  if (element is PathShape.CurveTo)
                     *  {
                     *      PathShape.CurveTo c = element as PathShape.CurveTo;
                     *      Point startPoint = lastPoint;
                     *      BezierSegment s = new BezierSegment();
                     *      if (isRelative)
                     *      {
                     *          s.Point1 = lastPoint + (Vector)c.CtrlPoint1;
                     *
                     *          if (c.Command == 's')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                     *              double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *              //s.Point1 = lastctrlpoint;
                     *          }
                     *
                     *          s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                     *          s.Point3 = lastPoint + (Vector)c.Point;
                     *      }
                     *      else
                     *      {
                     *          if (c.Command == 's')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                     *              double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *          }
                     *          else s.Point1 = c.CtrlPoint1;
                     *          s.Point2 = c.CtrlPoint2;
                     *          s.Point3 = c.Point;
                     *      }
                     *      lastPoint = s.Point3;
                     *      p.Segments.Add(s);
                     *
                     *      lastc = c;
                     *      lastcirPoint = s.Point3;
                     *
                     *      //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                     *      //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                     *      continue;
                     *  }
                     *  if (element is PathShape.QuadraticCurveTo)
                     *  {
                     *      PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo;
                     *      Point startPoint = lastPoint;
                     *      QuadraticBezierSegment s = new QuadraticBezierSegment();
                     *      if (isRelative)
                     *      {
                     *          s.Point1 = lastPoint + (Vector)c.CtrlPoint1;
                     *
                     *          if (c.Command == 'q' && lastq != null) // fix for horse svg! needed ?? or is it wrong in SVG?
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                     *              double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *              //s.Point1 = lastctrlpoint;
                     *          }
                     *
                     *          s.Point2 = lastPoint + (Vector)c.Point;
                     *      }
                     *      else
                     *      {
                     *          if (c.Command == 'q')
                     *          {
                     *              // first control point is a mirrored point of last end control point
                     *              //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                     *              //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);
                     *
                     *              double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                     *              double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                     *              s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                     *          }
                     *          else s.Point1 = c.CtrlPoint1;
                     *          s.Point2 = c.Point;
                     *      }
                     *      lastPoint = s.Point2;
                     *      p.Segments.Add(s);
                     *
                     *      lastq = c;
                     *      lastcirPoint = s.Point2;
                     *
                     *      //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                     *      //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                     *      continue;
                     *  }
                     *  if (element is PathShape.EllipticalArcTo)
                     *  {
                     *      PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                     *      ArcSegment s = new ArcSegment();
                     *      if (isRelative) s.Point = lastPoint + new Vector(c.X, c.Y);
                     *      else s.Point = new Point(c.X, c.Y);
                     *
                     *      s.Size = new Size(c.RX, c.RY);
                     *      s.RotationAngle = c.AxisRotation;
                     *      s.SweepDirection = SweepDirection.Counterclockwise;
                     *      if (c.Clockwise) s.SweepDirection = SweepDirection.Clockwise;
                     *      s.IsLargeArc = c.LargeArc;
                     *      lastPoint = s.Point;
                     *      p.Segments.Add(s);
                     *      continue;
                     *  }
                     * }
                     */
                    /*
                     * if (r.Transform != null)
                     *  path.Transform = r.Transform;
                     */
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
Beispiel #16
0
        public void MakeRadialAnimation(FrameworkElement animatedElement, TimeSpan timeSpan, string interactionID)
        {
            _interactionId = interactionID;
            _height        = animatedElement.Height;
            _width         = animatedElement.Width;
            double steps     = 2 * (_height + _width);
            double tickTime  = timeSpan.TotalSeconds / steps;
            string topCentre = Convert.ToString(_width / 2) + ",0";
            string centre    = Convert.ToString(_width / 2) + "," + Convert.ToString(_height / 2);

            frameworkElement = animatedElement;
            PathGeometry1    = new PathGeometry();
            //Path1.Data = PathGeometry1;

            PathFigure1            = new PathFigure();
            PathFigure1.StartPoint = ((Point) new PointConverter().ConvertFromString(centre));
            PathGeometry1.Figures.Add(PathFigure1);

            LineSegment LineSegmentdummy = new LineSegment();

            LineSegmentdummy.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegmentdummy);


            LineSegmentseconcorner       = new LineSegment();
            LineSegmentseconcorner.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegmentseconcorner);

            LineSegmentThirdcorner       = new LineSegment();
            LineSegmentThirdcorner.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegmentThirdcorner);

            LineSegmentFourthcorner       = new LineSegment();
            LineSegmentFourthcorner.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegmentFourthcorner);



            LineSegmentFirstcorner       = new LineSegment();
            LineSegmentFirstcorner.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegmentFirstcorner);

            LineSegment2       = new LineSegment();
            LineSegment2.Point = ((Point) new PointConverter().ConvertFromString(topCentre));
            PathFigure1.Segments.Add(LineSegment2);

            frameworkElement.Clip = PathGeometry1;

            PointAnimationUsingKeyFrames pointAnimationUsingKeyFrames = new PointAnimationUsingKeyFrames();
            DiscretePointKeyFrame        discretePointKeyFrame        = new DiscretePointKeyFrame();

            discretePointKeyFrame.Value = new Point(0, 0);

            TimeSpan keyTime = new TimeSpan(0, 0, 1);

            discretePointKeyFrame.KeyTime = keyTime;


            _timer           = new DispatcherTimer();
            _timer.Interval  = TimeSpan.FromSeconds(tickTime);
            _timer.Tick     += new EventHandler(_timer_Tick);
            _timer.IsEnabled = true;
        }