Ejemplo n.º 1
0
        /// <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:
            {
                mTranslator.Transform(line.Start.X, line.Start.Y, out float x0, out float y0);
                mTranslator.Transform(line.End.X, line.End.Y, out float x1, out float y1);
                mCanvas.Line(x0, y0, x1, y1, mTranslator.TransformL(line.LineWidth), line.Color ?? "black");
            }
            break;

            case ReticleCircle circle:
            {
                mTranslator.Transform(circle.Center.X, circle.Center.Y, out float x0, out float y0);
                mCanvas.Circle(x0, y0, mTranslator.TransformL(circle.Radius), mTranslator.TransformL(circle.LineWidth), circle.Fill ?? false, circle.Color ?? "black");
            }
            break;

            case ReticleRectangle rectangle:
            {
                mTranslator.Transform(rectangle.TopLeft.X, rectangle.TopLeft.Y, out float x0, out float y0);
                float x1 = mTranslator.TransformL(rectangle.Size.X);
                float y1 = mTranslator.TransformL(rectangle.Size.Y);
                mCanvas.Rectangle(x0, y0, x0 + x1, y0 + y1, mTranslator.TransformL(rectangle.LineWidth), rectangle.Fill ?? false, rectangle.Color ?? "black");
            }
            break;

            case ReticleText text:
            {
                mTranslator.Transform(text.Position.X, text.Position.Y, out float x0, out float y0);
                var h = mTranslator.TransformL(text.TextHeight);
                mCanvas.Text(x0, y0, h, text.Text, text.Color);
            }
            break;

            case ReticlePath path:
                DrawPath(path);
                break;
            }
        }
Ejemplo n.º 2
0
        /// <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;
            }
        }