Beispiel #1
0
        public StreamGeometryPolyQuadraticBezierToExample()
        {
            // 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 PolyQuadraticBezierTo
                // Method to create two quadratic Bezier curves.
                List <Point> pointList = new List <Point>();

                // First quadratic Bezier curve is specified with these two points.

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

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

                // Second quadratic Bezier curve is specified with these two points.

                // Control point for second quadratic Bezier curve.
                pointList.Add(new Point(300, 300));

                // End point for second quadratic Bezier curve.
                pointList.Add(new Point(400, 100));

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

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

            // specify the shape (quadratic Benzier 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;
        }
        private static void DeserializePolyQuadraticBezierTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc)
        {
            bool          isStroked;
            bool          isSmoothJoin;
            IList <Point> points;

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

            sc.PolyQuadraticBezierTo(points, isStroked, isSmoothJoin);
        }
Beispiel #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)
            {
                if (segment is LineSegment lineSegment)
                {
                    ctx.LineTo(lineSegment.Point, lineSegment.IsStroked, lineSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is BezierSegment bezierSegment)
                {
                    ctx.BezierTo(bezierSegment.Point1, bezierSegment.Point2, bezierSegment.Point3, bezierSegment.IsStroked, bezierSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is QuadraticBezierSegment quadraticSegment)
                {
                    ctx.QuadraticBezierTo(quadraticSegment.Point1, quadraticSegment.Point2, quadraticSegment.IsStroked, quadraticSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is PolyLineSegment polyLineSegment)
                {
                    ctx.PolyLineTo(polyLineSegment.Points, polyLineSegment.IsStroked, polyLineSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is PolyBezierSegment polyBezierSegment)
                {
                    ctx.PolyBezierTo(polyBezierSegment.Points, polyBezierSegment.IsStroked, polyBezierSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is PolyQuadraticBezierSegment polyQuadraticSegment)
                {
                    ctx.PolyQuadraticBezierTo(polyQuadraticSegment.Points, polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin);
                    continue;
                }

                if (segment is ArcSegment arcSegment)
                {
                    ctx.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, arcSegment.IsStroked, arcSegment.IsSmoothJoin);
                    continue;
                }
            }
        }
        public static void DrawFigure(StreamGeometryContext ctx, PathFigure figure)
        {
            ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed);
            foreach (var segment in figure.Segments)
            {
                var lineSegment = segment as WpfLineSegment;
                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;
                }
            }
        }
Beispiel #5
0
        public static void Write(this StreamGeometryContext ctx, PathSegment pathSegment)
        {
            switch (pathSegment)
            {
            case ArcSegment arc:
                ctx.ArcTo(arc.Point, arc.Size, arc.RotationAngle, arc.IsLargeArc, arc.SweepDirection, false, false);
                break;

            case BezierSegment bezier:
                ctx.BezierTo(bezier.Point1, bezier.Point2, bezier.Point3, false, false);
                break;

            case PolyBezierSegment polyBezier:
                ctx.PolyBezierTo(polyBezier.Points, false, false);
                break;

            case PolyLineSegment polyLine:
                ctx.PolyLineTo(polyLine.Points, false, false);
                break;

            case QuadraticBezierSegment quadraticBezier:
                ctx.QuadraticBezierTo(quadraticBezier.Point1, quadraticBezier.Point2, false, false);
                break;

            case PolyQuadraticBezierSegment polyQuadraticBezier:
                ctx.PolyQuadraticBezierTo(polyQuadraticBezier.Points, false, false);
                break;

            case LineSegment line:
                ctx.LineTo(line.Point, false, false);
                break;

            default:
                break;
            }
        }
        private static void DeserializePolyQuadraticBezierTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc)
        {
            bool isStroked;
            bool isSmoothJoin;
            IList<Point> points;

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

            sc.PolyQuadraticBezierTo(points, isStroked, isSmoothJoin);
        }