コード例 #1
0
        /// <inheritdoc/>
        public IPathShape ToFillPathShape(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape);

            if (path == null)
            {
                return(null);
            }
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

            using var brush = SkiaSharpDrawUtil.ToSKPaintBrush(style.Fill);
            var result = brush.GetFillPath(path, 1.0f);

            if (result != null)
            {
                if (result.IsEmpty)
                {
                    result.Dispose();
                    return(null);
                }
                var geometry  = PathGeometryConverter.ToPathGeometry(result, factory);
                var pathShape = factory.CreatePathShape(
                    "Path",
                    style,
                    geometry,
                    false,
                    true);
                result.Dispose();
                return(pathShape);
            }
            return(null);
        }
コード例 #2
0
ファイル: GridDrawNode.cs プロジェクト: bangush/Core2D
 public override void UpdateStyle()
 {
     if (Grid.GridStrokeColor != null)
     {
         Stroke = SkiaSharpDrawUtil.ToSKPaintPen(Grid.GridStrokeColor, Grid.GridStrokeThickness);
     }
     else
     {
         Stroke = null;
     }
 }
コード例 #3
0
ファイル: TextDrawNode.cs プロジェクト: bangush/Core2D
        protected void UpdateTextGeometry()
        {
            BoundText = Text.GetProperty(nameof(ITextShape.Text)) is string boundText ? boundText : Text.Text;

            if (BoundText == null)
            {
                return;
            }

            if (Style.TextStyle.FontSize < 0.0)
            {
                return;
            }

            FormattedText = SkiaSharpDrawUtil.GetSKPaint(BoundText, Style, Text.TopLeft, Text.BottomRight, out var origin);

            Origin = origin;
        }
コード例 #4
0
        /// <inheritdoc/>
        public IPathShape ToStrokePathShape(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape);

            if (path == null)
            {
                return(null);
            }
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var stroke = (IColor)style.Stroke.Copy(null);
            var fill   = (IColor)style.Fill.Copy(null);

            style.Stroke  = fill;
            style.Fill    = stroke;
            using var pen = SkiaSharpDrawUtil.ToSKPaintPen(style, style.Thickness);
            var result = pen.GetFillPath(path, 1.0f);

            if (result != null)
            {
                if (result.IsEmpty)
                {
                    result.Dispose();
                    return(null);
                }
                var geometry  = PathGeometryConverter.ToPathGeometry(result, factory);
                var pathShape = factory.CreatePathShape(
                    "Path",
                    style,
                    geometry,
                    true,
                    false);
                result.Dispose();
                return(pathShape);
            }
            return(null);
        }
コード例 #5
0
ファイル: DrawNode.cs プロジェクト: bangush/Core2D
 public virtual void UpdateStyle()
 {
     Fill   = SkiaSharpDrawUtil.ToSKPaintBrush(Style.Fill);
     Stroke = SkiaSharpDrawUtil.ToSKPaintPen(Style, Style.Thickness);
 }
コード例 #6
0
        public static SKPath ToSKPath(this IEnumerable <IBaseShape> shapes)
        {
            var path = new SKPath
            {
                FillType = SKPathFillType.Winding
            };
            var previous = default(IPointShape);

            foreach (var shape in shapes)
            {
                switch (shape)
                {
                case ILineShape lineShape:
                {
                    if (previous == null || previous != lineShape.Start)
                    {
                        path.MoveTo(
                            (float)(lineShape.Start.X),
                            (float)(lineShape.Start.Y));
                    }
                    path.LineTo(
                        (float)(lineShape.End.X),
                        (float)(lineShape.End.Y));
                    previous = lineShape.End;
                }
                break;

                case IRectangleShape rectangleShape:
                {
                    path.AddRect(
                        SkiaSharpDrawUtil.CreateRect(rectangleShape.TopLeft, rectangleShape.BottomRight),
                        SKPathDirection.Clockwise);
                }
                break;

                case IEllipseShape ellipseShape:
                {
                    path.AddOval(
                        SkiaSharpDrawUtil.CreateRect(ellipseShape.TopLeft, ellipseShape.BottomRight),
                        SKPathDirection.Clockwise);
                }
                break;

                case IArcShape arcShape:
                {
                    var a = new GdiArc(
                        Point2.FromXY(arcShape.Point1.X, arcShape.Point1.Y),
                        Point2.FromXY(arcShape.Point2.X, arcShape.Point2.Y),
                        Point2.FromXY(arcShape.Point3.X, arcShape.Point3.Y),
                        Point2.FromXY(arcShape.Point4.X, arcShape.Point4.Y));
                    var rect = new SKRect(
                        (float)(a.X),
                        (float)(a.Y),
                        (float)(a.X + a.Width),
                        (float)(a.Y + a.Height));
                    path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle);
                }
                break;

                case ICubicBezierShape cubicBezierShape:
                {
                    if (previous == null || previous != cubicBezierShape.Point1)
                    {
                        path.MoveTo(
                            (float)(cubicBezierShape.Point1.X),
                            (float)(cubicBezierShape.Point1.Y));
                    }
                    path.CubicTo(
                        (float)(cubicBezierShape.Point2.X),
                        (float)(cubicBezierShape.Point2.Y),
                        (float)(cubicBezierShape.Point3.X),
                        (float)(cubicBezierShape.Point3.Y),
                        (float)(cubicBezierShape.Point4.X),
                        (float)(cubicBezierShape.Point4.Y));
                    previous = cubicBezierShape.Point4;
                }
                break;

                case IQuadraticBezierShape quadraticBezierShape:
                {
                    if (previous == null || previous != quadraticBezierShape.Point1)
                    {
                        path.MoveTo(
                            (float)(quadraticBezierShape.Point1.X),
                            (float)(quadraticBezierShape.Point1.Y));
                    }
                    path.QuadTo(
                        (float)(quadraticBezierShape.Point2.X),
                        (float)(quadraticBezierShape.Point2.Y),
                        (float)(quadraticBezierShape.Point3.X),
                        (float)(quadraticBezierShape.Point3.Y));
                    previous = quadraticBezierShape.Point3;
                }
                break;

                case ITextShape textShape:
                {
                    var resultPath = ToSKPath(textShape);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;

                case IPathShape pathShape:
                {
                    var resultPath = ToSKPath(pathShape);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;

                case IGroupShape groupShape:
                {
                    var resultPath = ToSKPath(groupShape.Shapes);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;
                }
            }
            return(path);
        }
コード例 #7
0
 public override void UpdateStyle()
 {
     Fill = SkiaSharpDrawUtil.ToSKPaintBrush(Color);
 }