/// <summary> /// Draws a polygon. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="points">The points.</param> /// <param name="style">The style.</param> public void DrawPolygon(Rect bounds, Point[] points, DrawingStyle style) { _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds); var pp = points.Select(x => x.ToSKPoint()).ToArray(); SKPath path = new SKPath(); path.AddPoly(pp, true); path.Offset(bounds.Left.ToFloat(), bounds.Top.ToFloat()); if (style.HasFill) { SKPaint paintFill = new SKPaint(); paintFill.ApplyFill(bounds, style); _canvas.DrawPath(path, paintFill); } if (style.HasStroke) { SKPaint paintStroke = new SKPaint(); paintStroke.ApplyStroke(bounds, style); _canvas.DrawPath(path, paintStroke); } _canvas.ResetMatrix(); }
/// <summary> /// Draws the specified geometry. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="geometry">The geometry.</param> /// <param name="style">The style.</param> public void DrawGeometry(Rect bounds, Geometry geometry, DrawingStyle style) { _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds); PathGeometry g = geometry as PathGeometry; if (g == null) { g = (geometry as StreamGeometry).GetWidenedPathGeometry(new Pen(Brushes.Chartreuse, 2d)); } SKPath skPath = g.ToSKPath(); skPath.Offset(bounds.TopLeft.ToSKPoint()); if (style.HasFill) { SKPaint paintFill = new SKPaint(); paintFill.ApplyFill(bounds, style); _canvas.DrawPath(skPath, paintFill); } if (style.HasStroke) { SKPaint paintStroke = new SKPaint(); paintStroke.ApplyStroke(bounds, style); _canvas.DrawPath(skPath, paintStroke); } _canvas.ResetMatrix(); }
/// <summary> /// Draws a line. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="p1">The p1.</param> /// <param name="p2">The p2.</param> /// <param name="style">The style.</param> public void DrawLine(Rect bounds, Point p1, Point p2, DrawingStyle style) { _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds); SKPaint paint = new SKPaint(); paint.ApplyStroke(bounds, style); _canvas.DrawLine(p1.ToSKPoint(), p2.ToSKPoint(), paint); _canvas.ResetMatrix(); }
/// <summary> /// Draws an ellipse. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="style">The style.</param> public void DrawEllipse(Rect bounds, DrawingStyle style) { _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds); if (style.HasFill) { SKPaint paintFill = new SKPaint(); paintFill.ApplyFill(bounds, style); _canvas.DrawOval(bounds.ToSKRectStroke(style.StrokeThickness), paintFill); } if (style.HasStroke) { SKPaint paintStroke = new SKPaint(); paintStroke.ApplyStroke(bounds, style); _canvas.DrawOval(bounds.ToSKRectStroke(style.StrokeThickness), paintStroke); } _canvas.ResetMatrix(); }
/// <summary> /// Draws a rectangle. Rounded rectangle can be specified using the <see cref="DrawingStyle.CornerRadius" /> property. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="style">The style.</param> public void DrawRect(Rect bounds, DrawingStyle style) { _canvas.ApplyTransform(style.Transform, style.TransformOrigin, bounds); bool isRounded = style.CornerRadius.TopLeft > 0; if (style.HasFill) { SKPaint paintFill = new SKPaint(); paintFill.ApplyFill(bounds, style); if (isRounded) { _canvas.DrawRoundRect(new SKRoundRect(bounds.ToSKRectStroke(style.StrokeThickness), style.CornerRadius.TopLeft.ToFloat(), style.CornerRadius.TopRight.ToFloat()), paintFill); } else { _canvas.DrawRect(bounds.ToSKRectStroke(style.StrokeThickness), paintFill); } } if (style.HasStroke) { SKPaint paintStroke = new SKPaint(); paintStroke.ApplyStroke(bounds, style); if (isRounded) { _canvas.DrawRoundRect(new SKRoundRect(bounds.ToSKRectStroke(style.StrokeThickness), style.CornerRadius.TopLeft.ToFloat(), style.CornerRadius.TopRight.ToFloat()), paintStroke); } else { _canvas.DrawRect(bounds.ToSKRectStroke(style.StrokeThickness), paintStroke); } } _canvas.ResetMatrix(); }