public static CGPath ToCGPath(BasicPath path) { // TODO: We assume for now that only path lines can exist. var linePoints = new List<PointF>(); foreach (var item in path.Items) { if (item is BasicPathLine) { var line = item as BasicPathLine; linePoints.Add(ToPoint(line.PointA)); linePoints.Add(ToPoint(line.PointB)); } } var cgPath = new CGPath(); cgPath.AddLines(linePoints.ToArray()); return cgPath; }
public static void DrawLine(CGContext context, PointF[] points, float lineWidth, CGColor color) { context.SaveState(); var path = new CGPath(); path.AddLines(points); context.AddPath(path); context.SetLineWidth(lineWidth); context.SetStrokeColor(color); context.StrokePath(); context.RestoreState(); }
/// <summary> /// Draws a polygon. The polygon can have stroke and/or fill. /// </summary> /// <param name="points">The points.</param> /// <param name="fill">The fill color.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The stroke thickness.</param> /// <param name="dashArray">The dash array.</param> /// <param name="lineJoin">The line join type.</param> /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param> public override void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.SetAlias (aliased); var convertedPoints = (aliased ? points.Select (p => p.ConvertAliased ()) : points.Select (p => p.Convert ())).ToArray (); if (fill.IsVisible ()) { this.SetFill (fill); using (var path = new CGPath ()) { path.AddLines (convertedPoints); path.CloseSubpath (); this.gctx.AddPath (path); } this.gctx.DrawPath (CGPathDrawingMode.Fill); } if (stroke.IsVisible () && thickness > 0) { this.SetStroke (stroke, thickness, dashArray, lineJoin); using (var path = new CGPath ()) { path.AddLines (convertedPoints); path.CloseSubpath (); this.gctx.AddPath (path); } this.gctx.DrawPath (CGPathDrawingMode.Stroke); } }