Skip to content

Commit

Permalink
simplify vector draw
Browse files Browse the repository at this point in the history
The fill and stroke paints are handled by the
skiasharpodrawing context, there is no need to handle
them in the vector.draw() geometry.
  • Loading branch information
beto-rodriguez committed Dec 11, 2024
1 parent cdb0758 commit 070fb55
Showing 1 changed file with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Collections.Generic;
using LiveChartsCore.Drawing;
using LiveChartsCore.Drawing.Segments;
using LiveChartsCore.Painting;
using SkiaSharp;

namespace LiveChartsCore.SkiaSharpView.Drawing.Geometries;
Expand Down Expand Up @@ -103,35 +101,7 @@ public void Draw(SkiaSharpDrawingContext context)

if (last is not null) OnClose(context, path, last);

var hasGeometryOpacity = Opacity < 1;

if (Fill is null && Stroke is null)
{
if (hasGeometryOpacity) context.ActiveLvcPaint.ApplyOpacityMask(context, Opacity);
context.Canvas.DrawPath(path, context.ActiveSkiaPaint);
if (hasGeometryOpacity) context.ActiveLvcPaint.RestoreOpacityMask(context, Opacity);
}
else if (Fill is not null)
{
var originalPaint = context.ActiveSkiaPaint;
var originalTask = context.ActiveLvcPaint;

Fill.PaintStyle = PaintStyle.Fill;
Fill.InitializeTask(context);

if (hasGeometryOpacity) Fill.ApplyOpacityMask(context, Opacity);
context.Canvas.DrawPath(path, context.ActiveSkiaPaint);
if (hasGeometryOpacity) Fill.RestoreOpacityMask(context, Opacity);

Fill.Dispose();

context.ActiveSkiaPaint = originalPaint;
context.ActiveLvcPaint = originalTask;
}
else
{
throw new NotImplementedException("Fill and Stroke per vector is experiental.");
}
context.Canvas.DrawPath(path, context.ActiveSkiaPaint);

if (!isValid) IsValid = false;
}
Expand Down

0 comments on commit 070fb55

Please sign in to comment.