示例#1
0
 public void Render(ICanvas2D canvas)
 {
     foreach (var primitive in _primitives)
     {
         primitive.Render(canvas);
     }
 }
示例#2
0
        public static void DrawPath(ICanvas2D dc, Matrix3x2 xform, string path, OutlineFillStyle style)
        {
            var shapes = ParseShapes(path);

            foreach (var shape in shapes)
            {
                var points = shape.AsSpan();

                if (points[0].Equals(points[points.Length - 1]))
                {
                    points = points.Slice(0, points.Length - 1);
                    dc.DrawPolygon(points, style);
                    continue;
                }

                if (style.HasFill)
                {
                    dc.DrawPolygon(points, style.FillColor);
                }
                if (style.HasOutline)
                {
                    dc.DrawLines(points, style.OutlineWidth, style.OutlineColor);
                }
            }
        }
示例#3
0
        public static void DrawFont(this ICanvas2D dc, XFORM2 xform, String text, FontStyle style)
        {
            float xflip = 1;
            float yflip = 1;

            if (style.Alignment.HasFlag(Fonts.FontAlignStyle.FlipHorizontal))
            {
                xflip = -1;
            }
            if (style.Alignment.HasFlag(Fonts.FontAlignStyle.FlipVertical))
            {
                yflip = -1;
            }

            if (style.Alignment.HasFlag(Fonts.FontAlignStyle.FlipAuto) && dc.TryGetQuadrant(out var q))
            {
                if (q.HasFlag(Quadrant.Top))
                {
                    yflip *= -1;
                }
            }

            style = style.With(style.Alignment & ~(Fonts.FontAlignStyle.FlipHorizontal | Fonts.FontAlignStyle.FlipVertical));

            xform = XFORM2.CreateScale(xflip, yflip) * xform;

            Fonts.FontDrawing.DrawFontAsLines(dc, xform, text, style.Color);
        }
示例#4
0
        /*
         * public static void Project(IDrawing2D dc, CameraProjection3D camera, Model3D scene)
         * {
         *  camera.GetProjectionInfo(out ProjectPointCallback projCallback, out PLANE plane, scene);
         *
         *  var projector = new _RenderTarget2D(dc, projCallback, plane);
         *
         *  projector.Draw(scene);
         * }*/

        private _RenderTarget2D(ICanvas2D dc, ProjectPointCallback prjCallback, PLANE plane)
        {
            _RenderTarget = dc;

            _Proj3Func = prjCallback;

            _FrustumNearPlane = plane; // XYZ must be normalized
            _StrafeVector     = plane.Normal.GetAnyPerpendicular().Normalized();
        }
示例#5
0
        public static void DrawFont(this ICanvas2D dc, POINT2 origin, float size, String text, FontStyle style)
        {
            var xform = XFORM2.CreateScale(size);

            xform.Translation = origin.XY;

            style = style.With(style.Strength * size);

            dc.DrawFont(xform, text, style);
        }
示例#6
0
 public override void Render(ICanvas2D canvas)
 {
     for (var y = _rect.Top; y <= _rect.Bottom; y++)
     {
         for (var x = _rect.Left; x <= _rect.Right; x++)
         {
             if (_line.Test(x, y, 0))
             {
                 canvas.Set(x, y, _color);
             }
         }
     }
 }
示例#7
0
 public override void Render(ICanvas2D canvas)
 {
     if (_v2.X < _v3.X)
     {
         RenderBetween(_v1, _v2, _line1, _line3, canvas);
         RenderBetween(_v2, _v3, _line2, _line3, canvas);
     }
     else
     {
         RenderBetween(_v1, _v2, _line3, _line1, canvas);
         RenderBetween(_v2, _v3, _line3, _line2, canvas);
     }
 }
示例#8
0
        public void DrawTo(ICanvas2D target, System.Numerics.Matrix3x2 transform)
        {
            var tmp = new ImageSource();

            for (int y = 0; y < _Height; ++y)
            {
                for (int x = 0; x < _Width; ++x)
                {
                    var offset = new XY(x * 16, y * 16);

                    var idx = _Tiles[y * _Width + x];

                    _Sprites[idx].CopyTo(tmp, -offset);

                    target.DrawImage(transform, tmp);
                }
            }
        }
示例#9
0
        private static void DrawDirectVsPolygon(ICanvas2D dc)
        {
            var l1style = (COLOR.White, LineCapStyle.Flat, LineCapStyle.Round);
            var l2style = ((COLOR.White, COLOR.Red, 5), LineCapStyle.Flat, LineCapStyle.Round);

            var x = 50; dc.DrawTextLine((x, 30), "Native", 15, FontStyle.VFlip_Gray.With(COLOR.White));

            dc.DrawCircle((x, 50), 10, COLOR.White);
            dc.DrawCircle((x, 100), 10, (COLOR.White, COLOR.Red, 5));
            dc.DrawLine((x, 150), (50, 200), 10, l1style);
            dc.DrawLine((x, 250), (50, 300), 10, l2style);

            x = 100; dc.DrawTextLine((x, 30), "Polygonized", 15, FontStyle.VFlip_Gray.With(COLOR.White));

            var dc2x = new Decompose2D(dc);

            dc2x.DrawEllipse((x, 50), 10, 10, COLOR.Yellow);
            dc2x.DrawEllipse((x, 100), 10, 10, (COLOR.Yellow, COLOR.Red, 5));
            dc2x.DrawLines(new[] { new POINT2(x, 150), new POINT2(x, 200) }, 10, l1style);
            dc2x.DrawLines(new[] { new POINT2(x, 250), new POINT2(x, 300) }, 10, l2style);

            var dc3d = Canvas2DTransform.Create(dc, Matrix3x2.Identity);

            x = 150; dc.DrawTextLine((x, 30), "3D", 15, FontStyle.VFlip_Gray.With(COLOR.White));

            dc3d.DrawSphere((x, 50, 0), 10, COLOR.White);
            dc3d.DrawSphere((x, 100, 0), 10, (COLOR.White, COLOR.Red, 5));
            dc3d.DrawSegment((x, 150, 0), (x, 200, 0), 10, l1style);
            dc3d.DrawSegment((x, 250, 0), (x, 300, 0), 10, l2style);

            x = 200; dc.DrawTextLine((x, 30), "3D Polygonized", 15, FontStyle.VFlip_Gray.With(COLOR.White));

            var dc3x = new Decompose3D(dc3d, 5, 3);

            dc3x.DrawSphere(new Vector3(x, 50, 0), 10, COLOR.Yellow);
            dc3x.DrawSphere(new Vector3(x, 100, 0), 10, (COLOR.Yellow, COLOR.Red, 5));
            dc3x.DrawSegment(new Vector3(x, 150, 0), new Vector3(x, 200, 0), 10, l1style);
            dc3x.DrawSegment(new Vector3(x, 250, 0), new Vector3(x, 300, 0), 10, l2style);
        }
示例#10
0
        private void RenderStroke(int x1, int x2, int y, ICanvas2D canvas)
        {
            if (x1 > x2)
            {
                var d = x1;
                x1 = x2;
                x2 = d;
            }

            if (x1 < _rect.Left)
            {
                x1 = _rect.Left;
            }

            if (x2 > _rect.Right)
            {
                x2 = _rect.Right;
            }

            for (var x = x1; x <= x2; x++)
            {
                canvas.Set(x, y, _color);
            }
        }
示例#11
0
        public static void DrawTextLine(this ICanvas2D dc, POINT2 origin, String text, float size, FontStyle style)
        {
            var xform = XFORM2.CreateTranslation(origin.XY);

            dc.DrawTextLine(xform, text, size, style);
        }
示例#12
0
 public abstract void Render(ICanvas2D canvas);
示例#13
0
 public static ICanvas2D CreateTransformed2D(this ICanvas2D source, XFORM2 xform)
 {
     return(xform.IsIdentity ? source : Transforms.Canvas2DTransform.Create(source, xform));
 }
示例#14
0
 public static void DrawFontAsLines(ICanvas2D dc, in Matrix3x2 xform, string text, ColorStyle color)
示例#15
0
 public Scene2D(ICanvas2D canvas, IIntersectionFactory intersectionFactory)
 {
     _canvas = canvas;
     _intersectionFactory = intersectionFactory;
 }
示例#16
0
        private void RenderBetween(Vector2D v1, Vector2D v2, Line2D line1, Line2D line2, ICanvas2D canvas)
        {
            var y1 = v1.Y;
            var y2 = v2.Y;

            if (line1.IsHorizontal())
            {
                RenderStroke(line1.X1, line1.X2, line1.Y1, canvas);
                return;
            }

            if (line2.IsHorizontal())
            {
                RenderStroke(line2.X1, line2.X2, line2.Y1, canvas);
                return;
            }

            for (var y = y1; y <= y2; y++)
            {
                var x1 = line1.IntersectYToLeft(y);
                if (x1 < _rect.Left)
                {
                    x1 = _rect.Left;
                }

                var x2 = line2.IntersectYToRight(y);
                if (x2 > _rect.Right)
                {
                    x2 = _rect.Right;
                }

                if (x1 == x2)
                {
                    canvas.Set(x1, y, _color);
                }
                else
                {
                    RenderStroke(x1, x2, y, canvas);
                }
            }
        }
示例#17
0
 public override void Render(ICanvas2D canvas)
 {
     canvas.Set(Vector.X, Vector.Y, Color);
 }