Beispiel #1
0
        public static void CreateFigure(this IPathFigure pathFigure, SKPath path)
        {
            path.MoveTo(
                (float)(pathFigure.StartPoint.X),
                (float)(pathFigure.StartPoint.Y));

            foreach (var segment in pathFigure.Segments)
            {
                if (segment is ILineSegment lineSegment)
                {
                    path.LineTo(
                        (float)(lineSegment.Point.X),
                        (float)(lineSegment.Point.Y));
                }
                else if (segment is IQuadraticBezierSegment quadraticBezierSegment)
                {
                    path.QuadTo(
                        (float)(quadraticBezierSegment.Point1.X),
                        (float)(quadraticBezierSegment.Point1.Y),
                        (float)(quadraticBezierSegment.Point2.X),
                        (float)(quadraticBezierSegment.Point2.Y));
                }
                else if (segment is ICubicBezierSegment cubicBezierSegment)
                {
                    path.CubicTo(
                        (float)(cubicBezierSegment.Point1.X),
                        (float)(cubicBezierSegment.Point1.Y),
                        (float)(cubicBezierSegment.Point2.X),
                        (float)(cubicBezierSegment.Point2.Y),
                        (float)(cubicBezierSegment.Point3.X),
                        (float)(cubicBezierSegment.Point3.Y));
                }
                else if (segment is IArcSegment arcSegment)
                {
                    path.ArcTo(
                        (float)(arcSegment.Size.Width),
                        (float)(arcSegment.Size.Height),
                        (float)arcSegment.RotationAngle,
                        arcSegment.IsLargeArc ? SKPathArcSize.Large : SKPathArcSize.Small,
                        arcSegment.SweepDirection == SweepDirection.Clockwise ? SKPathDirection.Clockwise : SKPathDirection.CounterClockwise,
                        (float)(arcSegment.Point.X),
                        (float)(arcSegment.Point.Y));
                }
                else
                {
                    throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                }
            }

            if (pathFigure.IsClosed)
            {
                path.Close();
            }
        }
        private void FinishFigure()
        {
            if (_currentFigure == null)
            {
                return;
            }

            FinishSegment();

            IPathFigure pathFigure = _geometryFactory.CreatePathFigure(_currentFigure.Segments, _currentFigure.StartPoint,
                                                                       isClosed: _currentFigure.IsClosed, isFilled: _currentFigure.IsFilled);

            _pathGeometry.Figures.Add(pathFigure);

            _currentFigure = null;
        }
Beispiel #3
0
        private void Remove(IPathFigure figure)
        {
            if (figure == null)
            {
                return;
            }

            figure.PropertyChanged -= ObserveShape;

            if (figure.StartPoint != null)
            {
                figure.StartPoint.PropertyChanged -= ObserveShape;
            }

            if (figure.Segments != null)
            {
                Remove(figure.Segments);
            }
        }
Beispiel #4
0
        public void BreakPathFigure(IPathFigure pathFigure, IShapeStyle style, bool isStroked, bool isFilled, List <IBaseShape> result)
        {
            var factory = _serviceProvider.GetService <IFactory>();

            var firstPoint = pathFigure.StartPoint;
            var lastPoint  = pathFigure.StartPoint;

            foreach (var segment in pathFigure.Segments)
            {
                switch (segment)
                {
                case ILineSegment lineSegment:
                {
                    var convertedStyle = style != null ?
                                         (IShapeStyle)style?.Copy(null) :
                                         factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

                    var convertedPathShape = factory.CreateLineShape(
                        lastPoint,
                        lineSegment.Point,
                        convertedStyle,
                        isStroked);

                    lastPoint = lineSegment.Point;

                    result.Add(convertedPathShape);
                }
                break;

                case IQuadraticBezierSegment quadraticBezierSegment:
                {
                    var convertedStyle = style != null ?
                                         (IShapeStyle)style?.Copy(null) :
                                         factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

                    var convertedPathShape = factory.CreateQuadraticBezierShape(
                        lastPoint,
                        quadraticBezierSegment.Point1,
                        quadraticBezierSegment.Point2,
                        convertedStyle,
                        isStroked,
                        isFilled);

                    lastPoint = quadraticBezierSegment.Point2;

                    result.Add(convertedPathShape);
                }
                break;

                case ICubicBezierSegment cubicBezierSegment:
                {
                    var convertedStyle = style != null ?
                                         (IShapeStyle)style?.Copy(null) :
                                         factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

                    var convertedPathShape = factory.CreateCubicBezierShape(
                        lastPoint,
                        cubicBezierSegment.Point1,
                        cubicBezierSegment.Point2,
                        cubicBezierSegment.Point3,
                        convertedStyle,
                        isStroked,
                        isFilled);

                    lastPoint = cubicBezierSegment.Point3;

                    result.Add(convertedPathShape);
                }
                break;

                case IArcSegment arcSegment:
                {
                    var convertedStyle = style != null ?
                                         (IShapeStyle)style?.Copy(null) :
                                         factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

                    var point2 = factory.CreatePointShape(0, 0);         // TODO:

                    var point3 = factory.CreatePointShape(0, 0);         // TODO:

                    var convertedPathShape = factory.CreateArcShape(
                        lastPoint,
                        point2,
                        point3,
                        arcSegment.Point,
                        convertedStyle,
                        isStroked,
                        isFilled);

                    lastPoint = arcSegment.Point;

                    result.Add(convertedPathShape);
                }
                break;
                }
            }

            if (pathFigure.Segments.Length > 0 && pathFigure.IsClosed)
            {
                var convertedStyle = style != null ?
                                     (IShapeStyle)style?.Copy(null) :
                                     factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

                var convertedPathShape = factory.CreateLineShape(
                    lastPoint,
                    firstPoint,
                    convertedStyle,
                    isStroked);

                result.Add(convertedPathShape);
            }
        }
Beispiel #5
0
 /// <inheritdoc/>
 public void BeginFigure(IPointShape startPoint, bool isFilled = true, bool isClosed = true)
 {
     _currentFigure    = _factory.CreatePathFigure(startPoint, isFilled, isClosed);
     _geometry.Figures = _geometry.Figures.Add(_currentFigure);
 }