private void DrawPath(ReticlePath path) { using var canvasPath = mCanvas.CreatePath(); foreach (var pathElement in path.Elements) { switch (pathElement) { case ReticlePathElementMoveTo moveTo: { mTranslator.Transform(moveTo.Position.X, moveTo.Position.Y, out float x, out float y); canvasPath.MoveTo(x, y); } break; case ReticlePathElementLineTo lineTo: { mTranslator.Transform(lineTo.Position.X, lineTo.Position.Y, out float x, out float y); canvasPath.LineTo(x, y); } break; case ReticlePathElementArc arc: { mTranslator.Transform(arc.Position.X, arc.Position.Y, out float x, out float y); canvasPath.Arc(mTranslator.TransformL(arc.Radius), x, y, arc.MajorArc, arc.ClockwiseDirection); } break; } } if (path.Fill ?? false) { canvasPath.Close(); } mCanvas.Path(canvasPath, mTranslator.TransformL(path.LineWidth), path.Fill ?? false, path.Color ?? "black"); }
/// <summary> /// <para>Draw individual element.</para> /// <para>The method may be used to implement additional visualization.</para> /// </summary> /// <param name="element"></param> public void DrawElement(ReticleElement element) { switch (element) { case ReticleLine line: { translator.Transform(line.Start.X, line.Start.Y, out float x0, out float y0); translator.Transform(line.End.X, line.End.Y, out float x1, out float y1); canvas.Line(x0, y0, x1, y1, translator.TransformL(line.LineWidth), line.Color ?? "black"); } break; case ReticleCircle circle: { translator.Transform(circle.Center.X, circle.Center.Y, out float x0, out float y0); canvas.Circle(x0, y0, translator.TransformL(circle.Radius), translator.TransformL(circle.LineWidth), circle.Fill ?? false, circle.Color ?? "black"); } break; case ReticleRectangle rectangle: { translator.Transform(rectangle.TopLeft.X, rectangle.TopLeft.Y, out float x0, out float y0); float x1 = translator.TransformL(rectangle.Size.X); float y1 = translator.TransformL(rectangle.Size.Y); canvas.Rectangle(x0, y0, x0 + x1, y0 + y1, translator.TransformL(rectangle.LineWidth), rectangle.Fill ?? false, rectangle.Color ?? "black"); } break; case ReticleText text: { translator.Transform(text.Position.X, text.Position.Y, out float x0, out float y0); var h = translator.TransformL(text.TextHeight); canvas.Text(x0, y0, h, text.Text, text.Color); } break; case ReticlePath path: { using var path1 = canvas.CreatePath(); foreach (var pathElement in path.Elements) { switch (pathElement) { case ReticlePathElementMoveTo moveTo: { translator.Transform(moveTo.Position.X, moveTo.Position.Y, out float x, out float y); path1.MoveTo(x, y); } break; case ReticlePathElementLineTo lineTo: { translator.Transform(lineTo.Position.X, lineTo.Position.Y, out float x, out float y); path1.LineTo(x, y); } break; case ReticlePathElementArc arc: { translator.Transform(arc.Position.X, arc.Position.Y, out float x, out float y); path1.Arc(translator.TransformL(arc.Radius), x, y, arc.MajorArc, arc.ClockwiseDirection); } break; } } if (path.Fill ?? false) { path1.Close(); } canvas.Path(path1, translator.TransformL(path.LineWidth), path.Fill ?? false, path.Color ?? "black"); } break; } }