Exemple #1
0
        internal override void Render(SKSurface surface, SKImageInfo info)
        {
            if (Geometry is CompositionPathGeometry cpg)
            {
                if (cpg.Path?.GeometrySource is SkiaGeometrySource2D geometrySource)
                {
                    if (FillBrush != null)
                    {
                        FillBrush.UpdatePaint(TryCreateFillPaint());

                        surface.Canvas.DrawPath(geometrySource.Geometry, _fillPaint);
                    }

                    if (StrokeBrush != null)
                    {
                        var strokePaint = TryCreateStrokePaint();

                        if (StrokeBrush is CompositionColorBrush stroke)
                        {
                            strokePaint.StrokeWidth = StrokeThickness;
                            strokePaint.Color       = stroke.Color.ToSKColor(Compositor.CurrentOpacity);
                        }

                        surface.Canvas.DrawPath(geometrySource.Geometry, _strokePaint);
                    }
                }
                else if (cpg.Path?.GeometrySource is null)
                {
                }
                else
                {
                    throw new InvalidOperationException($"CompositionPath does not support the {cpg.Path?.GeometrySource} geometry source");
                }
            }
        }
Exemple #2
0
        internal override void Render(SKSurface surface, SKImageInfo info)
        {
            SkiaGeometrySource2D?geometrySource = Geometry?.BuildGeometry() as SkiaGeometrySource2D;

            SKPath?geometry = geometrySource?.Geometry;

            if (geometry == null)
            {
                return;
            }

            if (FillBrush != null)
            {
                var fillPaint = TryCreateAndClearFillPaint();

                FillBrush.UpdatePaint(fillPaint, geometry.Bounds);

                surface.Canvas.DrawPath(geometry, fillPaint);
            }

            if (StrokeBrush != null && StrokeThickness > 0)
            {
                var fillPaint   = TryCreateAndClearFillPaint();
                var strokePaint = TryCreateAndClearStrokePaint();

                // Set stroke thickness
                strokePaint.StrokeWidth = StrokeThickness;
                // TODO: Add support for dashes here
                // strokePaint.PathEffect = SKPathEffect.CreateDash();

                // Generate stroke geometry for bounds that will be passed to a brush.
                // - [Future]: This generated geometry should also be used for hit testing.
                using (var strokeGeometry = strokePaint.GetFillPath(geometry))
                {
                    StrokeBrush.UpdatePaint(fillPaint, strokeGeometry.Bounds);

                    surface.Canvas.DrawPath(strokeGeometry, fillPaint);
                }
            }
        }