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

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

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();

            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry
            // object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {
                // Set the begin point of the shape.
                ctx.BeginFigure(new Point(10, 100), true /* is filled */, false /* is closed */);

                // Create a collection of Point structures that will be used with the PolyBezierTo
                // Method to create the Bezier curve.
                List <Point> pointList = new List <Point>();

                // First Bezier curve is specified with these three points.

                // First control point for first Bezier curve.
                pointList.Add(new Point(100, 0));

                // Second control point for first Bezier curve.
                pointList.Add(new Point(200, 200));

                // Destination point for first Bezier curve.
                pointList.Add(new Point(300, 100));

                // Second Bezier curve is specified with these three points.

                // First control point for second Bezier curve.
                pointList.Add(new Point(400, 0));

                // Second control point for second Bezier curve.
                pointList.Add(new Point(500, 200));

                // Destination point for second Bezier curve.
                pointList.Add(new Point(600, 100));

                // Create a Bezier curve using the collection of Point Structures.
                ctx.PolyBezierTo(pointList, true /* is stroked */, false /* is smooth join */);
            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

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

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

            mainPanel.Children.Add(myPath);
            this.Content = mainPanel;
        }
Exemplo n.º 2
0
        private static void DeserializePolyBezierTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc)
        {
            bool isStroked;
            bool isSmoothJoin;
            IList<Point> points;

            points = DeserializeListOfPointsAndTwoBools(br, firstByte, out isStroked, out isSmoothJoin);

            sc.PolyBezierTo(points, isStroked, isSmoothJoin);
        }
Exemplo n.º 3
0
        public static void DrawFigure(this StreamGeometryContext ctx, PathFigure figure)
        {
            ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed);

            foreach (var segment in figure.Segments)
            {
                var lineSegment = segment as LineSegment;

                if (lineSegment != null)
                {
                    ctx.LineTo(lineSegment.Point, lineSegment.IsStroked, lineSegment.IsSmoothJoin);
                    continue;
                }

                var bezierSegment = segment as BezierSegment;

                if (bezierSegment != null)
                {
                    ctx.BezierTo(bezierSegment.Point1, bezierSegment.Point2, bezierSegment.Point3, bezierSegment.IsStroked, bezierSegment.IsSmoothJoin);
                    continue;
                }

                var quadraticSegment = segment as QuadraticBezierSegment;

                if (quadraticSegment != null)
                {
                    ctx.QuadraticBezierTo(quadraticSegment.Point1, quadraticSegment.Point2, quadraticSegment.IsStroked, quadraticSegment.IsSmoothJoin);
                    continue;
                }

                var polylineSegment = segment as PolyLineSegment;

                if (polylineSegment != null)
                {
                    ctx.PolyLineTo(polylineSegment.Points, polylineSegment.IsStroked, polylineSegment.IsSmoothJoin);
                    continue;
                }

                var polyBezierSegment = segment as PolyBezierSegment;

                if (polyBezierSegment != null)
                {
                    ctx.PolyBezierTo(polyBezierSegment.Points, polyBezierSegment.IsStroked, polyBezierSegment.IsSmoothJoin);
                    continue;
                }

                var polyQuadraticSegment = segment as PolyQuadraticBezierSegment;

                if (polyQuadraticSegment != null)
                {
                    ctx.PolyQuadraticBezierTo(polyQuadraticSegment.Points, polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin);
                    continue;
                }

                var arcSegment = segment as ArcSegment;

                if (arcSegment != null)
                {
                    ctx.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, arcSegment.IsStroked, arcSegment.IsSmoothJoin);
                    continue;
                }
            }
        }