Exemplo n.º 1
0
        /// <summary>
        /// 通过点的集合获取三次贝赛尔曲线
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        private PathGeometry GetCurveGeometry(IEnumerable <Point> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            var screenPoints = points.Select(x => CADScreenConverter.ToScreen(x)).ToArray();
            var bezier       = new PolyBezierSegment(screenPoints, true);
            var pathFigure   = new PathFigure();
            var pathGeometry = new PathGeometry();

            pathFigure.Segments.Add(bezier);
            pathGeometry.Figures.Add(pathFigure);

            if (screenPoints.Length >= 1)
            {
                pathFigure.StartPoint = screenPoints[0];

                //因为此处使用的三次贝塞尔曲线要求点的数量为3的倍数,所以在未能正处情况下,重复最后一项至下一个三的倍数;
                var repeatCount = (3 - (screenPoints.Length % 3)) % 3;

                var lastScreenPoint = screenPoints[screenPoints.Length - 1];
                for (int i = 0; i < repeatCount; i++)
                {
                    bezier.Points.Add(lastScreenPoint);
                }
            }

            return(pathGeometry);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns new PolyBezierSegment by easing startValue to endValue using a time percentage 0 -> 1.
 /// </summary>
 /// <example>XAML: Points="0,0 200,0 300,100 300,0 400,0 600,100"</example>
 /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.polybeziersegment.aspx"/>
 public static PolyBezierSegment EaseValue(PolyBezierSegment startValue, PolyBezierSegment endValue, double percent)
 {
     return(new PolyBezierSegment
     {
         Points = EaseValue(startValue.Points, endValue.Points, percent),
     });
 }
Exemplo n.º 3
0
        private void DrawLine(PointCollection points)
        {
            var line = new PolyBezierSegment()
            {
                Points       = points,
                IsSmoothJoin = true
            };

            var pathFigure = new PathFigure()
            {
                Segments = new PathSegmentCollection()
                {
                    line
                },
                StartPoint = points[0]
            };

            var gObj = new PathGeometry(new List <PathFigure>()
            {
                pathFigure
            });

            path = new Path()
            {
                Data            = gObj,
                Stroke          = Brushes.Blue,
                StrokeThickness = 4
            };
            Canvas.Children.Add(path);
        }
Exemplo n.º 4
0
        // }
        //public void animateMove(int from, int to, double dur, int ellipse)
        //{
        //    TranslateTransform animatedTranslateTransform =
        //        new TranslateTransform();

        //    // Register the transform's name with the page
        //    // so that they it be targeted by a Storyboard.
        //    cnv1.RegisterName("AnimatedTranslateTransform", animatedTranslateTransform);
        //    ell[ellipse].RenderTransform = animatedTranslateTransform;
        //    ell[ellipse].RenderTransformOrigin = new System.Windows.Point(200, 150);

        //    PathGeometry animationPath = new PathGeometry();
        //    PathFigure pFigure = new PathFigure();
        //    pFigure.StartPoint = new System.Windows.Point(0, 0);
        //    PolyBezierSegment pBezierSegment = new PolyBezierSegment();
        //    System.Windows.Point start = new System.Windows.Point(0, 0);
        //    System.Windows.Point end = new System.Windows.Point(445, 185);
        //    LoadPathPoints(pBezierSegment, from, to, dur, ellipse);
        //    pFigure.Segments.Add(pBezierSegment);
        //    animationPath.Figures.Add(pFigure);

        //    animationPath.Freeze();

        //    DoubleAnimationUsingPath translateXAnimation =
        //        new DoubleAnimationUsingPath();
        //    translateXAnimation.PathGeometry = animationPath;
        //    translateXAnimation.Duration = TimeSpan.FromSeconds(5);

        //    translateXAnimation.Source = PathAnimationSource.X;

        //    Storyboard.SetTargetName(translateXAnimation, "AnimatedTranslateTransform");
        //    Storyboard.SetTargetProperty(translateXAnimation,
        //        new PropertyPath(TranslateTransform.XProperty));

        //    DoubleAnimationUsingPath translateYAnimation =
        //        new DoubleAnimationUsingPath();
        //    translateYAnimation.PathGeometry = animationPath;
        //    translateYAnimation.Duration = TimeSpan.FromSeconds(5);


        //    translateYAnimation.Source = PathAnimationSource.Y;


        //    Storyboard.SetTargetName(translateYAnimation, "AnimatedTranslateTransform");
        //    Storyboard.SetTargetProperty(translateYAnimation,
        //        new PropertyPath(TranslateTransform.YProperty));

        //    // Create a Storyboard to contain and apply the animations.
        //    Storyboard pathAnimationStoryboard = new Storyboard();
        //    pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
        //    pathAnimationStoryboard.Children.Add(translateXAnimation);
        //    pathAnimationStoryboard.Children.Add(translateYAnimation);
        //    // Start the animations.

        //    pathAnimationStoryboard.Begin(ell[ellipse]);

        //}

        public void LoadPathPoints(PolyBezierSegment pBezierSegment, int from, int to, double dur, int ellipse)
        {
            //double x = 235, y = 105, angle;
            //for (int i = from; i <= to; i++)
            //{
            //    angle = (i + 0.5) * angleInc * Math.PI / 180;
            //    x = 87.5 * Math.Cos(angle);
            //    y = 87.5 * Math.Sin(angle);
            //    if (angle <= 180) { x = 235 + x; y = 105 - y; }
            //    if (angle > 180) { x = 235 + x; y = 105 + y; }
            //double incrx = (end.X - start.X) / 5;
            //double incry = (end.Y - start.Y) / 5;
            //int i;
            //double x, y;
            //x = start.X; y = start.Y;
            //for (i = 0; i < 6; i++)
            //{
            pBezierSegment.Points.Add(new System.Windows.Point(0, 0));
            pBezierSegment.Points.Add(new System.Windows.Point(50, 50));
            pBezierSegment.Points.Add(new System.Windows.Point(100, 100));

            //    x += incrx;
            //    y += incry;
            //}
        }
Exemplo n.º 5
0
        private void TestPathPolyBezier_Click(object sender, RoutedEventArgs e)
        {
            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry.Figures = new PathFigureCollection();
            PathFigure figure = new PathFigure()
            {
                IsClosed = false, IsFilled = false, StartPoint = new Point(10, 10)
            };

            figure.Segments = new PathSegmentCollection();

            polyBezier = new PolyBezierSegment();
            PointCollection points = new PointCollection();

            points.Add(new Point(250, 0));
            points.Add(new Point(250, 0));
            points.Add(new Point(150, 200));
            points.Add(new Point(100, 250));
            points.Add(new Point(300, 0));
            points.Add(new Point(50, 100));
            polyBezier.Points = points;
            figure.Segments.Add(polyBezier);

            pathGeometry.Figures.Add(figure);
            path1.Data = pathGeometry;

            PathArcButtons.Visibility           = Visibility.Collapsed;
            PathBezierButtons.Visibility        = Visibility.Collapsed;
            PathLineButtons.Visibility          = Visibility.Collapsed;
            PathPolyBezierButtons.Visibility    = Visibility.Visible;
            PathPolyLineButtons.Visibility      = Visibility.Collapsed;
            PathPolyQuadraticButtons.Visibility = Visibility.Collapsed;
            PathQuadraticButtons.Visibility     = Visibility.Collapsed;
        }
Exemplo n.º 6
0
        private Path MakeBezierPath(Point[] points)
        {
            Path         path         = new Path();
            PathGeometry pathGeometry = new PathGeometry();

            path.Data = pathGeometry;
            PathFigure pathFigure = new PathFigure();

            pathGeometry.Figures.Add(pathFigure);
            pathFigure.StartPoint = points[0];
            PathSegmentCollection pathSegments = new PathSegmentCollection();

            pathFigure.Segments = pathSegments;
            PointCollection pointsCollection = new PointCollection(points.Length - 1);

            for (int i = 1; i < points.Length; i++)
            {
                pointsCollection.Add(points[i]);
            }
            PolyBezierSegment polyBezierSegment = new PolyBezierSegment();

            polyBezierSegment.Points = pointsCollection;
            pathSegments.Add(polyBezierSegment);
            return(path);
        }
Exemplo n.º 7
0
        private PathGeometry CreateAreaCurveGeometry()
        {
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure();

            pathGeometry.Figures.Add(pathFigure);

            Point[] catmullRomPoints = new Point[_childrenPositions.Count];
            _childrenPositions.CopyTo(catmullRomPoints, 0);
            Point[] bezierPoints = GeometryOperation.CatmullRom(catmullRomPoints);
            pathFigure.StartPoint = bezierPoints[0];
            PolyBezierSegment pbs = new PolyBezierSegment();

            for (int i = 1; i < bezierPoints.GetLength(0); i++)
            {
                pbs.Points.Add(bezierPoints[i]);
            }
            pathFigure.Segments.Add(pbs);
            if (AreaBrush != null)
            {
                pathFigure.Segments.Add(new LineSegment(new Point(_childrenPositions[_childrenPositions.Count - 1].X, GetHorizontalAxis(this)), false));
                pathFigure.Segments.Add(new LineSegment(new Point(_childrenPositions[0].X, GetHorizontalAxis(this)), false));
            }
            return(pathGeometry);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static PathGeometry DrawPolyBezier(Point[] input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (input.Length == 0)
            {
                throw new InvalidOperationException();
            }

            PathGeometry pg = new PathGeometry();
            PathFigure   pf = new PathFigure();

            pf.StartPoint = input[0];
            PolyBezierSegment pbs = new PolyBezierSegment();

            for (int i = 1; i < input.GetLength(0); i++)
            {
                pbs.Points.Add(input[i]);
            }
            pf.Segments.Add(pbs);
            pg.Figures.Add(pf);
            return(pg);
        }
Exemplo n.º 9
0
        //アンカー点となるPointCollectionからベジェ曲線のPathGeometryを作成
        private PathGeometry MakeBezierPathGeometry(PointCollection pc)
        {
            //PolyBezierSegment作成
            //PointCollectionをアンカー点に見立てて、その制御点を追加していく
            PolyBezierSegment seg = new PolyBezierSegment();

            seg.Points.Add(pc[0]);//始点制御点
            for (int i = 1; i < pc.Count - 1; i++)
            {
                seg.Points.Add(pc[i]);        //制御点
                seg.Points.Add(pc[i]);        //アンカー
                seg.Points.Add(pc[i]);        //制御点
            }
            seg.Points.Add(pc[pc.Count - 1]); //終点制御点
            seg.Points.Add(pc[pc.Count - 1]); //終点アンカー

            //
            var fig = new PathFigure();

            fig.StartPoint = pc[0];
            fig.Segments.Add(seg);
            var pg = new PathGeometry();

            pg.Figures.Add(fig);
            return(pg);
        }
Exemplo n.º 10
0
        private Path CreateTrack(PointCollection ps)
        {
            Path Track = new Path()
            {
                Stroke = new SolidColorBrush()
                {
                    Color = Colors.LightGray
                }, StrokeThickness = 1.0, StrokeDashArray = new DoubleCollection()
                {
                    2, 3
                }
            };

            Track.MouseLeftButtonDown += Track_MouseLeftButtonDown;
            PathGeometry pgTrack = new PathGeometry();
            PathFigure   pfTrack = new PathFigure()
            {
                StartPoint = ps[0]
            };
            PolyBezierSegment psTrack = new PolyBezierSegment()
            {
                Points = new PointCollection(ps.Skip(1).Take(ps.Count - 1))
            };

            pfTrack.Segments.Add(psTrack);
            pgTrack.Figures.Add(pfTrack);
            Track.Data = pgTrack;
            Container.Children.Add(Track);
            return(Track);
        }
Exemplo n.º 11
0
		/*Draw Spline*/
		public static void DrawSpline(Spline xLine, Canvas mainCanvas)
		{
			
			System.Windows.Shapes.Path wPath = new System.Windows.Shapes.Path();
			
			
			/*List<PolyQuadraticBezierSegment> segments = new List<PolyQuadraticBezierSegment>(1);
			PolyQuadraticBezierSegment segment = new PolyQuadraticBezierSegment();
			 */
			List<PolyBezierSegment> segments = new List<PolyBezierSegment>();
			PolyBezierSegment segment = new PolyBezierSegment();
			
			int i = 0;
			foreach (netDxf.Entities.SplineVertex spVertex in xLine.ControlPoints) {
				if (i > 0)
					segment.Points.Add(TypeConverter.Vertex3ToPoint(spVertex.Position, mainCanvas.Height));
				/*DrawUtils.DrawPoint(spVertex.Position,i.ToString(),mainCanvas,Colors.Red,5,0.5);*/
				i++;
			}
			segments.Add(segment);
			List<PathFigure> figures = new List<PathFigure>();
			System.Windows.Point p0 = TypeConverter.Vertex3ToPoint(xLine.ControlPoints[0].Position, mainCanvas.Height);
			
			/*System.Windows.Point p0 = new System.Windows.Point(710,mainCanvas.Height+100);*/
			PathFigure pf = new PathFigure(p0, segments, true);
			pf.IsClosed = false;
			figures.Add(pf);

			Geometry g = new PathGeometry(figures, FillRule.EvenOdd, null);
			wPath.Data = g;
			
			TypeConverter.Entity2Shape(xLine, wPath);
			mainCanvas.Children.Add(wPath);

		}
Exemplo n.º 12
0
        /// <summary>
        /// Parses a PolyBezierSegment element.
        /// </summary>
        PolyBezierSegment ParsePolyBezierSegment()
        {
            Debug.Assert(reader.Name == "PolyBezierSegment");
            PolyBezierSegment seg = new PolyBezierSegment();

            while (MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "IsStroked":
                    seg.IsStroked = ParseBool(reader.Value);
                    break;

                case "Points":
                    seg.Points = Point.ParsePoints(reader.Value);
                    break;

                default:
                    UnexpectedAttribute(reader.Name);
                    break;
                }
            }
            MoveBeyondThisElement();
            return(seg);
        }
Exemplo n.º 13
0
        private void Show_Click(object sender, RoutedEventArgs e)
        {
            if (curveButtonPressed && points.Count > 1)
            {
                PathFigure pthFigure = new PathFigure();
                pthFigure.StartPoint = points[0];
                PolyBezierSegment     pbzSeg = new PolyBezierSegment();
                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                if (points.Count == 2)
                {
                    pbzSeg.Points.Add(points[1]);
                    pbzSeg.Points.Add(points[1]);
                    pbzSeg.Points.Add(points[1]);
                }
                else if (points.Count == 3)
                {
                    pbzSeg.Points.Add(points[1]);
                    pbzSeg.Points.Add(points[2]);
                    pbzSeg.Points.Add(points[2]);
                }
                else if (points.Count % 3 == 1)
                {
                    for (int i = 1; i < points.Count; i++)
                    {
                        pbzSeg.Points.Add(points[i]);
                    }
                }
                else
                {
                    for (int i = 1; i < points.Count; i++)
                    {
                        pbzSeg.Points.Add(points[i]);
                    }

                    pbzSeg.Points.Add(points[points.Count - 1]);
                    if (points.Count % 3 == 2)
                    {
                        pbzSeg.Points.Add(points[points.Count - 1]);
                    }
                }

                myPathSegmentCollection.Add(pbzSeg);
                pthFigure.Segments = myPathSegmentCollection;

                PathFigureCollection pthFigureCollection = new PathFigureCollection();
                pthFigureCollection.Add(pthFigure);

                PathGeometry pthGeometry = new PathGeometry();
                pthGeometry.Figures = pthFigureCollection;

                Path arcPath = new Path();
                arcPath.Stroke          = new SolidColorBrush(Colors.Black);
                arcPath.StrokeThickness = 3;
                arcPath.Data            = pthGeometry;
                //arcPath.Fill = new SolidColorBrush(Colors.Yellow);

                PaintGrid.Children.Add(arcPath);
                points.Clear();
            }
        }
Exemplo n.º 14
0
        Shape CreateHandleSine(Point pt, string tag)
        {
            const int thickness        = 3;
            const int width            = 5;
            const int control_strength = 10;

            Path         path = new Path();
            PathGeometry pg   = new PathGeometry();
            PathFigure   pf   = new PathFigure();

            pf.StartPoint = new Point(-width, 0);
            var seg = new PolyBezierSegment();

            pf.Segments.Add(seg);
            pg.Figures.Add(pf);
            pg.FillRule = FillRule.EvenOdd;
            path.Data   = pg;
            path.Tag    = tag;

            seg.Points.Add(new Point(0, control_strength));
            seg.Points.Add(new Point(0, -control_strength));
            seg.Points.Add(new Point(width, 0));

            seg.IsStroked = true;
            pf.IsClosed   = false;
            pf.IsFilled   = false;

            path.Stroke          = new SolidColorBrush(Colors.Black);
            path.StrokeThickness = thickness;

            PlacePolygonHandle(pt, path);
            AddHandle(tag, path);

            return(path);
        }
        public PolyBezierSegmentExample()
        {
            // Create a PathFigure to be used for the PathGeometry of myPath.
            PathFigure myPathFigure = new PathFigure();

            // Set the starting point for the PathFigure specifying that the
            // geometry starts at point 10,100.
            myPathFigure.StartPoint = new Point(10, 100);

            // Create a PointCollection that holds the Points used to specify
            // the points of the PolyBezierSegment below.
            PointCollection myPointCollection = new PointCollection(6);

            myPointCollection.Add(new Point(0, 0));
            myPointCollection.Add(new Point(200, 0));
            myPointCollection.Add(new Point(300, 100));
            myPointCollection.Add(new Point(300, 0));
            myPointCollection.Add(new Point(400, 0));
            myPointCollection.Add(new Point(600, 100));

            // The PolyBezierSegment specifies two cubic Bezier curves.
            // The first curve is from 10,100 (start point specified by the PathFigure)
            // to 300,100 with a control point of 0,0 and another control point
            // of 200,0. The second curve is from 300,100 (end of the last curve) to
            // 600,100 with a control point of 300,0 and another control point of 400,0.
            PolyBezierSegment myBezierSegment = new PolyBezierSegment();

            myBezierSegment.Points = myPointCollection;

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myBezierSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            // Create a path to draw a geometry with.
            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;

            // specify the shape (quadratic Bezier curve) of the path using the StreamGeometry.
            myPath.Data = myPathGeometry;

            // Add path shape to the UI.
            StackPanel mainPanel = new StackPanel();

            mainPanel.Children.Add(myPath);
            this.Content = mainPanel;
        }
Exemplo n.º 16
0
        public override void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y)
        {
            PolyBezierSegment segment = new PolyBezierSegment();

            segment.Points.Add(new Point(c1x, c1y));
            segment.Points.Add(new Point(c2x, c2y));
            segment.Points.Add(new Point(x, y));
            _pathFigure.Segments.Add(segment);
        }
Exemplo n.º 17
0
        public void TestPolyBezierSegmentConstructor(string points, int count)
        {
            var pointCollection = (PointCollection)_pointCollectionConverter.ConvertFromInvariantString(points);

            var polyBezierSegment = new PolyBezierSegment(pointCollection);

            Assert.IsNotNull(polyBezierSegment);
            Assert.AreEqual(count, polyBezierSegment.Points.Count);
        }
Exemplo n.º 18
0
        private PolyBezierSegment GetPolyBezierSegment1()
        {
            PolyBezierSegment polyBezierSegment = new PolyBezierSegment();
            PointCollection   pointCollection   = new PointCollection(GetPoints());

            polyBezierSegment.Points = pointCollection;

            return(polyBezierSegment);
        }
Exemplo n.º 19
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Count() != 2)
            {
                return(null);
            }

            gTopology.PointList        pointlist       = values[0] as gTopology.PointList;
            List <gTopology.PointList> insidepointlist = values[1] as List <gTopology.PointList>;

            if (pointlist == null || pointlist.Count == 0)
            {
                return(null);
            }

            PathGeometry geom = new PathGeometry();

            {
                PathFigure figure = new PathFigure()
                {
                    StartPoint = pointlist[0], IsClosed = true
                };
                PointCollection   pc    = new PointCollection(pointlist.GetRange(1, pointlist.Count - 1));
                PolyBezierSegment pbseg = new PolyBezierSegment()
                {
                    Points = pc
                };
                figure.Segments.Add(pbseg);
                geom.Figures.Add(figure);
            }

            if (insidepointlist != null)
            {
                for (int i = 0; i < insidepointlist.Count; i++)
                {
                    gTopology.PointList templist = insidepointlist[i];
                    if (templist.Count == 0)
                    {
                        continue;
                    }
                    PathFigure figure = new PathFigure()
                    {
                        StartPoint = templist[0], IsClosed = true
                    };
                    PointCollection   pc    = new PointCollection(templist.GetRange(1, templist.Count - 1));
                    PolyBezierSegment pbseg = new PolyBezierSegment()
                    {
                        Points = pc
                    };
                    figure.Segments.Add(pbseg);
                    geom.Figures.Add(figure);
                }
            }

            return(geom);
        }
Exemplo n.º 20
0
        static IEnumerable <PathPoint> EnumeratePathPoints(Path p)
        {
            PathGeometry pg = p.Data as PathGeometry;

            if (pg == null)
            {
                yield break;
            }

            foreach (PathFigure pf in pg.Figures)
            {
                yield return(new PathPoint {
                    path = p, fig = pf, v = pf.StartPoint
                });

                foreach (PathSegment seg in pf.Segments)
                {
                    if (seg is LineSegment)
                    {
                        LineSegment ls = seg as LineSegment;
                        yield return(new PathPoint {
                            path = p, fig = pf, lineseg = ls, v = ls.Point
                        });
                    }
                    else if (seg is PolyLineSegment)
                    {
                        PolyLineSegment polyseg = seg as PolyLineSegment;

                        for (int i = 0; i < polyseg.Points.Count; i++)
                        {
                            yield return(new PathPoint {
                                path = p, fig = pf, polyseg = polyseg, v = polyseg.Points[i], ipoint = i
                            });
                        }
                    }
                    else if (seg is BezierSegment)
                    {
                        BezierSegment bs = seg as BezierSegment;
                        yield return(new PathPoint {
                            path = p, fig = pf, bezseg = bs, v = bs.Point3
                        });
                    }
                    else if (seg is PolyBezierSegment)
                    {
                        PolyBezierSegment polyseg = seg as PolyBezierSegment;

                        for (int i = 2; i < polyseg.Points.Count; i += 3)
                        {
                            yield return(new PathPoint {
                                path = p, fig = pf, polybezseg = polyseg, v = polyseg.Points[i], ipoint = i
                            });
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        private static void Points_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //todo: find a way to know when the points changed in the collection
            PolyBezierSegment segment = (PolyBezierSegment)d;

            if (segment.ParentPath != null)
            {
                segment.ParentPath.ScheduleRedraw();
            }
        }
Exemplo n.º 22
0
        /*
         * Animation Helper Methods
         */
        private void moveCard(Image cardImage, int absoluteX, int absoluteY)
        {
            string transformName = "theTransform";
            int    x             = absoluteX - (int)cardImage.Margin.Left;
            int    y             = absoluteY - (int)cardImage.Margin.Top;

            if (x != 0 && y != 0)
            {
                //create translateTransform
                TranslateTransform moveCard9 = new TranslateTransform();
                this.RegisterName(transformName, moveCard9);
                cardImage.RenderTransform = moveCard9;

                //create the path
                PathGeometry animationPath9 = new PathGeometry();
                PathFigure   pFigure9       = new PathFigure();
                pFigure9.StartPoint = new Point(0, 0);
                PolyBezierSegment pBezierSegment9 = new PolyBezierSegment();
                pBezierSegment9.Points.Add(new Point(x, y));
                pBezierSegment9.Points.Add(new Point(x, y));
                pBezierSegment9.Points.Add(new Point(x, y));
                pFigure9.Segments.Add(pBezierSegment9);
                animationPath9.Figures.Add(pFigure9);

                //freeze path for performance benefits
                animationPath9.Freeze();

                //create the animation to move the card horizontally
                DoubleAnimationUsingPath translateXAnimation9 = new DoubleAnimationUsingPath();
                translateXAnimation9.PathGeometry = animationPath9;
                translateXAnimation9.Duration     = TimeSpan.FromSeconds(1);
                translateXAnimation9.Source       = PathAnimationSource.X;

                Storyboard.SetTargetName(translateXAnimation9, transformName);
                Storyboard.SetTargetProperty(translateXAnimation9, new PropertyPath(TranslateTransform.XProperty));

                //create the animation to move the card vertically
                DoubleAnimationUsingPath translateYAnimation9 = new DoubleAnimationUsingPath();
                translateYAnimation9.PathGeometry = animationPath9;
                translateYAnimation9.Duration     = TimeSpan.FromSeconds(1);
                translateYAnimation9.Source       = PathAnimationSource.Y;

                Storyboard.SetTargetName(translateYAnimation9, transformName);
                Storyboard.SetTargetProperty(translateYAnimation9, new PropertyPath(TranslateTransform.YProperty));

                //create a storyboard
                Storyboard pathAnimationStoryboard = new Storyboard();
                pathAnimationStoryboard.Children.Add(translateXAnimation9);
                pathAnimationStoryboard.Children.Add(translateYAnimation9);

                //begin the storyboard
                pathAnimationStoryboard.Begin(this);
                this.UnregisterName(transformName);
            }
        }
Exemplo n.º 23
0
        private PathGeometry GetGeometry(PiecePosition position)
        {
            var tabCoords = new double[]
            {
                0, 0, 35, 15, 37, 5,
                37, 5, 40, 0, 38, -5,
                38, -5, 20, -20, 50, -20,
                50, -20, 80, -20, 62, -5,
                62, -5, 60, 0, 63, 5,
                63, 5, 65, 15, 100, 0
            };

            int upperConnection  = BoolToTab(!position.HasFlag(PiecePosition.Top)),
                rightConnection  = BoolToTab(!position.HasFlag(PiecePosition.Right), true),
                bottomConnection = BoolToTab(!position.HasFlag(PiecePosition.Bottom), true),
                leftConnection   = BoolToTab(!position.HasFlag(PiecePosition.Left));

            var upperPoints  = new List <Point>();
            var rightPoints  = new List <Point>();
            var bottomPoints = new List <Point>();
            var leftPoints   = new List <Point>();

            for (var i = 0; i < (tabCoords.Length / 2); i++)
            {
                double[] upperCoords  = tabCoords;
                double[] rightCoords  = tabCoords;
                double[] bottomCoords = tabCoords;
                double[] leftCoords   = tabCoords;

                upperPoints.Add(new Point(upperCoords[i * 2], 0 + upperCoords[i * 2 + 1] * upperConnection));
                rightPoints.Add(new Point(100 - rightCoords[i * 2 + 1] * rightConnection, rightCoords[i * 2]));
                bottomPoints.Add(new Point(100 - bottomCoords[i * 2], 100 - bottomCoords[i * 2 + 1] * bottomConnection));
                leftPoints.Add(new Point(0 + leftCoords[i * 2 + 1] * leftConnection, 100 - leftCoords[i * 2]));
            }
            var upperSegment  = new PolyBezierSegment(upperPoints, true);
            var rightSegment  = new PolyBezierSegment(rightPoints, true);
            var bottomSegment = new PolyBezierSegment(bottomPoints, true);
            var leftSegment   = new PolyBezierSegment(leftPoints, true);

            var pathFigure = new PathFigure()
            {
                IsClosed   = false,
                StartPoint = new Point(0, 0)
            };

            pathFigure.Segments.Add(upperSegment);
            pathFigure.Segments.Add(rightSegment);
            pathFigure.Segments.Add(bottomSegment);
            pathFigure.Segments.Add(leftSegment);

            var pathGeometry = new PathGeometry();

            pathGeometry.Figures.Add(pathFigure);
            return(pathGeometry);
        }
Exemplo n.º 24
0
        //Path.Dataを作成
        private void MyInitialize()
        {
            MySegment = new PolyBezierSegment();
            var pf = new PathFigure();

            pf.Segments.Add(MySegment);
            var pg = new PathGeometry();

            pg.Figures.Add(pf);
            MyPath.Data = pg;
        }
Exemplo n.º 25
0
        // Make a Path holding a series of Bezier curves.
        // The points parameter includes the points of the inscribing polygon
        private Path MakeBezierPath(Point[] points)
        {
            // Create a Path to hold the geometry.
            Path path = new Path();

            // Add a PathGeometry.
            PathGeometry path_geometry = new PathGeometry();

            path.Data = path_geometry;

            // Create a PathFigure.
            PathFigure path_figure = new PathFigure();

            path_geometry.Figures.Add(path_figure);

            // Create a PathSegmentCollection.
            PathSegmentCollection path_segment_collection =
                new PathSegmentCollection();

            path_figure.Segments = path_segment_collection;

            // Add the rest of the points to a PointCollection.
            PointCollection point_collection = new PointCollection();

            for (int i = 0; i < points.Length; i++)
            {
                //polygon vertice as 2 controls for the curve
                var control_point = points[i];
                point_collection.Add(control_point);
                point_collection.Add(control_point);

                //end point is the middle of next curve
                var endpoint = new Point(
                    (points[i].X + points[(i + 1 + points.Length) % points.Length].X) / 2,
                    (points[i].Y + points[(i + 1 + points.Length) % points.Length].Y) / 2);

                point_collection.Add(endpoint);
            }

            // Start at the first point.
            path_figure.StartPoint = point_collection.Last();

            // Make a PolyBezierSegment from the points.
            PolyBezierSegment bezier_segment = new PolyBezierSegment
            {
                Points = point_collection
            };

            // Add the PolyBezierSegment to othe segment collection.
            path_segment_collection.Add(bezier_segment);
            path.Stroke = Brushes.Orange;
            thePath     = path;
            return(path);
        }
Exemplo n.º 26
0
        //PathGeometry作成してPathのDataに指定
        private void MyInitialize()
        {
            MySegment = new PolyBezierSegment(new PointCollection(), true);
            var pathFigure = new PathFigure();

            pathFigure.Segments.Add(MySegment);
            var pathGeometry = new PathGeometry();

            pathGeometry.Figures.Add(pathFigure);
            MyPath.Data = pathGeometry;
        }
Exemplo n.º 27
0
 public static PathSegmentImplementation Create(PolyBezierSegment source)
 {
     if (source != null)
     {
         return new PolyBezierSegmentImplementation {
                    _segment = source
         }
     }
     ;
     return(null);
 }
Exemplo n.º 28
0
        /// <summary>
        /// Bottom segment drawing
        /// </summary>
        protected PathGeometry BottomSegement()
        {
            BottomSegmPoints = GetBottomSegmPoints();
            Point startPoint = BottomSegmPoints[1];

            LineSegment line0 = new LineSegment(BottomSegmPoints[0], true);
            LineSegment line1 = new LineSegment(BottomSegmPoints[1], true);
            LineSegment line2 = new LineSegment(BottomSegmPoints[2], true);
            LineSegment line3 = new LineSegment(BottomSegmPoints[3], true);
            LineSegment line4 = new LineSegment(BottomSegmPoints[4], true);
            LineSegment line6 = new LineSegment(BottomSegmPoints[6], true);
            LineSegment line7 = new LineSegment(BottomSegmPoints[7], true);


            // The right Bezier curve for rounded corners
            var pointsBezierRight = new PointCollection
            {
                BottomSegmPoints[4], BottomSegmPoints[5], BottomSegmPoints[6]
            };

            PolyBezierSegment bezRight = new PolyBezierSegment
            {
                Points = new PointCollection(pointsBezierRight)
            };

            // The left Bezier curve for rounded corners
            var pointsBezierLeft = new PointCollection
            {
                BottomSegmPoints[7], BottomSegmPoints[0], BottomSegmPoints[1]
            };

            PolyBezierSegment bezLeft = new PolyBezierSegment
            {
                Points = new PointCollection(pointsBezierLeft)
            };

            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure();

            pathFigure.StartPoint = startPoint;
            pathFigure.IsClosed   = true;
            pathGeometry.Figures.Add(pathFigure);

            pathFigure.Segments.Add(line1);
            pathFigure.Segments.Add(line2);
            pathFigure.Segments.Add(line3);
            pathFigure.Segments.Add(line4);
            pathFigure.Segments.Add(bezRight);
            pathFigure.Segments.Add(line6);
            pathFigure.Segments.Add(line7);
            pathFigure.Segments.Add(bezLeft);

            return(pathGeometry);
        }
Exemplo n.º 29
0
        void addAPathJust(string gName, EllipseGeometry animatedEllipseGeometry, Canvas mainPanel, Brush brush, Point[] m_psCAMINHO, Point[] m_psFigFinal)
        {
            int Ynum = m_rr.Next((int)mainPanel.Height);
            int Xnum = m_rr.Next((int)mainPanel.Width);
            // Create the animation path.
            PathGeometry animationPath = new PathGeometry();
            PathFigure   pFigure       = new PathFigure();

            pFigure.StartPoint = new Point(animatedEllipseGeometry.Center.X, animatedEllipseGeometry.Center.Y);
            PolyBezierSegment pBezierSegment = new PolyBezierSegment();

            // Point[] m_ps = { new Point(123, 42), new Point(923, 43), new Point(1858, 52), new Point(1846, 960), new Point(948, 968), new Point(103, 956), new Point(124, 47) };
            for (int i = 0; i < m_psCAMINHO.Length; i++)
            {
                pBezierSegment.Points.Add(m_psCAMINHO[i]);
            }
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal % m_psFigFinal.Length]);
            pBezierSegment.Points.Add(m_psFigFinal[contaFelizNatal++ % m_psFigFinal.Length]);
            //pBezierSegment.Points.Add(new Point(35 + Xnum, 0 + Ynum ));
            pFigure.Segments.Add(pBezierSegment);
            animationPath.Figures.Add(pFigure);


            // Freeze the PathGeometry for performance benefits.
            animationPath.Freeze();

            // Create a PointAnimationgUsingPath to move
            // the EllipseGeometry along the animation path.
            PointAnimationUsingPath centerPointAnimation =
                new PointAnimationUsingPath();

            centerPointAnimation.PathGeometry = animationPath;
            centerPointAnimation.Duration     = TimeSpan.FromSeconds(1 + m_rr.Next(18));
            centerPointAnimation.BeginTime    = TimeSpan.FromSeconds(1 + m_rr.Next(3));
            centerPointAnimation.IsCumulative = true;
            // centerPointAnimation.RepeatBehavior = RepeatBehavior.Forever;
            // centerPointAnimation.AutoReverse = true;



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

            // pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            //*** pathAnimationStoryboard.AutoReverse = true;
            pathAnimationStoryboard.Children.Add(centerPointAnimation);
        }
Exemplo n.º 30
0
        static bool TryExtractSegmentEnd(PathSegment ps, out double x, out double y)
        {
            x = 0;
            y = 0;

            if (ps == null)
            {
                return(false);
            }

            if (ps is LineSegment)
            {
                LineSegment ls = ps as LineSegment;
                x = ls.Point.X;
                y = ls.Point.Y;
                return(true);
            }
            else if (ps is PolyBezierSegment)
            {
                PolyBezierSegment ls = ps as PolyBezierSegment;
                if (ls.Points.Count == 0)
                {
                    return(false);
                }

                int last = ls.Points.Count - 1;
                x = ls.Points[last].X;
                y = ls.Points[last].Y;
                return(true);
            }
            else if (ps is PolyLineSegment)
            {
                PolyLineSegment ls = ps as PolyLineSegment;
                if (ls.Points.Count == 0)
                {
                    return(false);
                }

                int last = ls.Points.Count - 1;
                x = ls.Points[last].X;
                y = ls.Points[last].Y;
                return(true);
            }
            else if (ps is BezierSegment)
            {
                BezierSegment bs = ps as BezierSegment;
                x = bs.Point3.X;
                y = bs.Point3.Y;
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Returns new PolyBezierSegment by easing startValue to endValue using a time percentage 0 -> 1.
 /// </summary>
 /// <example>XAML: Points="0,0 200,0 300,100 300,0 400,0 600,100"</example>
 /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.polybeziersegment.aspx"/>
 public static PolyBezierSegment EaseValue(PolyBezierSegment startValue, PolyBezierSegment endValue, double percent)
 {
     return new PolyBezierSegment
     {
         Points = EaseValue(startValue.Points, endValue.Points, percent),
     };
 }