public void Render(ICanvas2D canvas) { foreach (var primitive in _primitives) { primitive.Render(canvas); } }
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); } } }
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); }
/* * 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(); }
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); }
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); } } } }
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); } }
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); } } }
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); }
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); } }
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); }
public abstract void Render(ICanvas2D canvas);
public static ICanvas2D CreateTransformed2D(this ICanvas2D source, XFORM2 xform) { return(xform.IsIdentity ? source : Transforms.Canvas2DTransform.Create(source, xform)); }
public static void DrawFontAsLines(ICanvas2D dc, in Matrix3x2 xform, string text, ColorStyle color)
public Scene2D(ICanvas2D canvas, IIntersectionFactory intersectionFactory) { _canvas = canvas; _intersectionFactory = intersectionFactory; }
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); } } }
public override void Render(ICanvas2D canvas) { canvas.Set(Vector.X, Vector.Y, Color); }