public void DrawRectangleSimple() { var buffer = new ConsoleBuffer(3); buffer.DrawRectangle(new Rect(0, 0, 3, 3), Red, LineWidth.Single); var c0m = new ConsoleChar(); var ctl = new ConsoleChar { LineChar = LineCharBottomRight(LineWidth.Single, LineWidth.Single), ForegroundColor = Red }; var ctr = new ConsoleChar { LineChar = LineCharBottomLeft(LineWidth.Single, LineWidth.Single), ForegroundColor = Red }; var cbl = new ConsoleChar { LineChar = LineCharTopRight(LineWidth.Single, LineWidth.Single), ForegroundColor = Red }; var cbr = new ConsoleChar { LineChar = LineCharTopLeft(LineWidth.Single, LineWidth.Single), ForegroundColor = Red }; var chm = new ConsoleChar { LineChar = LineCharHorizontal, ForegroundColor = Red }; var cvm = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Red }; buffer.GetLine(0).Should().Equal(ctl, chm, ctr); buffer.GetLine(1).Should().Equal(cvm, c0m, cvm); buffer.GetLine(2).Should().Equal(cbl, chm, cbr); }
public void DrawVerticalLineCapFull() { var buffer = new ConsoleBuffer(4); buffer.DrawVerticalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapFull); buffer.DrawVerticalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapFull); buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Double, DrawLineFlags.CapFull); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Green }; var cb = new ConsoleChar { LineChar = LineCharVerticalDouble, ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillForegroundVerticalLine() { var buffer = new ConsoleBuffer(4); buffer.FillForegroundVerticalLine(0, 0, 5, Red, '|'); buffer.FillForegroundVerticalLine(1, 1, 3, Green, ':'); buffer.FillForegroundVerticalLine(3, -1, 10, Blue, '*'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '|', ForegroundColor = Red }; var cg = new ConsoleChar { Char = ':', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '*', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillBackgroundVerticalLine() { var buffer = new ConsoleBuffer(4); buffer.FillBackgroundVerticalLine(0, 0, 5, Red); buffer.FillBackgroundVerticalLine(1, 1, 3, Green); buffer.FillBackgroundVerticalLine(3, -1, 10, Blue); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; var cb = new ConsoleChar { BackgroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void DrawVerticalLine() { var buffer = new ConsoleBuffer(4); buffer.DrawVerticalLine(0, 0, 5, Red); buffer.DrawVerticalLine(1, 1, 3, Green); buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Green }; var cb = new ConsoleChar { LineChar = LineChar.Vertical | LineChar.VerticalWide, ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void DrawHorizontalLine () { var buffer = new ConsoleBuffer(5); buffer.DrawHorizontalLine(0, 0, 5, Red); buffer.DrawHorizontalLine(1, 1, 3, Green); buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Green }; var cb = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr); buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0); buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0); buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb); }
public void DrawVerticalLineCapCenter() { var buffer = new ConsoleBuffer(4); buffer.DrawVerticalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapCenter); buffer.DrawVerticalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapStartCenter); buffer.DrawVerticalLine(2, 2, 2, Blue, LineWidth.Double, DrawLineFlags.CapEndCenter); buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Double, DrawLineFlags.CapCenter); var c0m = new ConsoleChar(); var crs = new ConsoleChar { LineChar = LineCharBottom(LineWidth.Single), ForegroundColor = Red }; var crm = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Red }; var cre = new ConsoleChar { LineChar = LineCharTop(LineWidth.Single), ForegroundColor = Red }; var cgs = new ConsoleChar { LineChar = LineCharBottom(LineWidth.Single), ForegroundColor = Green }; var cgm = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Green }; var cge = new ConsoleChar { LineChar = LineChar.None, ForegroundColor = Green }; var cbs = new ConsoleChar { LineChar = LineChar.None, ForegroundColor = Blue }; var cbm = new ConsoleChar { LineChar = LineCharVerticalDouble, ForegroundColor = Blue }; var cbe = new ConsoleChar { LineChar = LineCharTop(LineWidth.Double), ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(crs, c0m, c0m, cbm); buffer.GetLine(1).Should().Equal(crm, cgs, c0m, cbm); buffer.GetLine(2).Should().Equal(crm, cgm, cbs, cbm); buffer.GetLine(3).Should().Equal(crm, cge, cbe, cbm); buffer.GetLine(4).Should().Equal(cre, c0m, c0m, cbm); }
public void FillBackgroundLine() { var buffer = new ConsoleBuffer(3); buffer.FillBackgroundLine(Line.Vertical(1, 0, 3), Red); buffer.FillBackgroundLine(Line.Horizontal(0, 1, 3), Green); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cg, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void DrawHorizontalLineCapCenter() { var buffer = new ConsoleBuffer(5); buffer.DrawHorizontalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapCenter); buffer.DrawHorizontalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapStartCenter); buffer.DrawHorizontalLine(2, 2, 2, Blue, LineWidth.Double, DrawLineFlags.CapEndCenter); buffer.DrawHorizontalLine(-1, 3, 10, Blue, LineWidth.Double, DrawLineFlags.CapCenter); var c0m = new ConsoleChar(); var crs = new ConsoleChar { LineChar = LineCharRight(LineWidth.Single), ForegroundColor = Red }; var crm = new ConsoleChar { LineChar = LineCharHorizontal, ForegroundColor = Red }; var cre = new ConsoleChar { LineChar = LineCharLeft(LineWidth.Single), ForegroundColor = Red }; var cgs = new ConsoleChar { LineChar = LineCharRight(LineWidth.Single), ForegroundColor = Green }; var cgm = new ConsoleChar { LineChar = LineCharHorizontal, ForegroundColor = Green }; var cge = new ConsoleChar { LineChar = LineChar.None, ForegroundColor = Green }; var cbs = new ConsoleChar { LineChar = LineChar.None, ForegroundColor = Blue }; var cbm = new ConsoleChar { LineChar = LineCharHorizontalDouble, ForegroundColor = Blue }; var cbe = new ConsoleChar { LineChar = LineCharLeft(LineWidth.Double), ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(crs, crm, crm, crm, cre); buffer.GetLine(1).Should().Equal(c0m, cgs, cgm, cge, c0m); buffer.GetLine(2).Should().Equal(c0m, c0m, cbs, cbe, c0m); buffer.GetLine(3).Should().Equal(cbm, cbm, cbm, cbm, cbm); }
public void DrawRectangleSimple() { var buffer = new ConsoleBuffer(3); buffer.DrawRectangle(new Rect(0, 0, 3, 3), Red, LineWidth.Single); var c0 = new ConsoleChar(); var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.Vertical, ForegroundColor = Red }; var ch = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red }; var cv = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; buffer.GetLine(0).Should().Equal(cx, ch, cx); buffer.GetLine(1).Should().Equal(cv, c0, cv); buffer.GetLine(2).Should().Equal(cx, ch, cx); }
public void DrawLine() { var buffer = new ConsoleBuffer(3); buffer.DrawLine(Line.Vertical(1, 0, 3), Red); buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Green }; var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide | LineChar.Vertical, ForegroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cx, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void DrawLine() { var buffer = new ConsoleBuffer(3); buffer.DrawLine(Line.Vertical(1, 0, 3), Red, LineWidth.Single, DrawLineFlags.CapFull); buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Double, DrawLineFlags.CapFull); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineCharVertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineCharHorizontalDouble, ForegroundColor = Green }; var cx = new ConsoleChar { LineChar = LineCharHorizontalDoubleVertical, ForegroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cx, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void ApplyColorMap() { var buffer = new ConsoleBuffer(2); buffer.ApplyBackgroundColorMap(new Rect(0, 0, 1, 1), ColorMaps.Invert); buffer.ApplyForegroundColorMap(new Rect(1, 0, 1, 1), ColorMaps.Invert); buffer.GetLine(0).Should().Equal( new ConsoleChar { BackgroundColor = White }, new ConsoleChar { ForegroundColor = White }); }
public void FillForegroundHorizontalLine() { var buffer = new ConsoleBuffer(5); buffer.FillForegroundHorizontalLine(0, 0, 5, Red, '-'); buffer.FillForegroundHorizontalLine(1, 1, 3, Green, '='); buffer.FillForegroundHorizontalLine(-1, 3, 10, Blue, '_'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '-', ForegroundColor = Red }; var cg = new ConsoleChar { Char = '=', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '_', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr); buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0); buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0); buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb); }
public static void DrawImage([NotNull] this ConsoleBuffer @this, [NotNull] ImageSource imageSource, int x, int y, int width, int height) { if (@this == null) { throw new ArgumentNullException(nameof(@this)); } var bmp = imageSource as BitmapSource ?? throw new ArgumentException("Only rendering of bitmap source is supported."); @this.OffsetX(ref x).OffsetY(ref y); int x1 = x, x2 = x + width, y1 = y, y2 = y + height; if ([email protected](ref x1, ref y1, ref x2, ref y2)) { return; } if (width != bmp.PixelWidth || height != bmp.PixelHeight) { bmp = new TransformedBitmap(bmp, new ScaleTransform((double)width / bmp.PixelWidth, (double)height / bmp.PixelHeight)); } if (bmp.Format != PixelFormats.Indexed4) { bmp = new FormatConvertedBitmap(bmp, PixelFormats.Indexed4, BitmapPalettes.Halftone8Transparent, 0.5); } const int bitsPerPixel = 4; int stride = 4 * (bmp.PixelWidth * bitsPerPixel + 31) / 32; byte[] bytes = new byte[stride * bmp.PixelHeight]; bmp.CopyPixels(bytes, stride, 0); Debug.Assert(bmp.Palette != null); for (int iy = y1, py = 0; iy < y2; iy++, py++) { ConsoleChar[] charsLine = @this.GetLine(iy); for (int ix = x1, px = 0; ix < x2; ix++, px++) { int byteIndex = stride * py + px / 2; int bitOffset = px % 2 == 0 ? 4 : 0; SetColor(ref charsLine[ix], bmp.Palette, (bytes[byteIndex] >> bitOffset) & 0b1111); } } }
public void FillForegroundHorizontalLine () { var buffer = new ConsoleBuffer(5); buffer.FillForegroundHorizontalLine(0, 0, 5, Red, '-'); buffer.FillForegroundHorizontalLine(1, 1, 3, Green, '='); buffer.FillForegroundHorizontalLine(-1, 3, 10, Blue, '_'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '-', ForegroundColor = Red }; var cg = new ConsoleChar { Char = '=', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '_', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, cr, cr, cr, cr); buffer.GetLine(1).Should().Equal(c0, cg, cg, cg, c0); buffer.GetLine(2).Should().Equal(c0, c0, c0, c0, c0); buffer.GetLine(3).Should().Equal(cb, cb, cb, cb, cb); }
public void FillForegroundVerticalLine () { var buffer = new ConsoleBuffer(4); buffer.FillForegroundVerticalLine(0, 0, 5, Red, '|'); buffer.FillForegroundVerticalLine(1, 1, 3, Green, ':'); buffer.FillForegroundVerticalLine(3, -1, 10, Blue, '*'); var c0 = new ConsoleChar(); var cr = new ConsoleChar { Char = '|', ForegroundColor = Red }; var cg = new ConsoleChar { Char = ':', ForegroundColor = Green }; var cb = new ConsoleChar { Char = '*', ForegroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillBackgroundVerticalLine () { var buffer = new ConsoleBuffer(4); buffer.FillBackgroundVerticalLine(0, 0, 5, Red); buffer.FillBackgroundVerticalLine(1, 1, 3, Green); buffer.FillBackgroundVerticalLine(3, -1, 10, Blue); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; var cb = new ConsoleChar { BackgroundColor = Blue }; buffer.GetLine(0).Should().Equal(cr, c0, c0, cb); buffer.GetLine(1).Should().Equal(cr, cg, c0, cb); buffer.GetLine(2).Should().Equal(cr, cg, c0, cb); buffer.GetLine(3).Should().Equal(cr, cg, c0, cb); buffer.GetLine(4).Should().Equal(cr, c0, c0, cb); }
public void FillBackgroundLine () { var buffer = new ConsoleBuffer(3); buffer.FillBackgroundLine(Line.Vertical(1, 0, 3), Red); buffer.FillBackgroundLine(Line.Horizontal(0, 1, 3), Green); var c0 = new ConsoleChar(); var cr = new ConsoleChar { BackgroundColor = Red }; var cg = new ConsoleChar { BackgroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cg, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void ApplyColorMap () { var buffer = new ConsoleBuffer(2); buffer.ApplyBackgroundColorMap(new Rect(0, 0, 1, 1), ColorMaps.Invert); buffer.ApplyForegroundColorMap(new Rect(1, 0, 1, 1), ColorMaps.Invert); buffer.GetLine(0).Should().Equal( new ConsoleChar { BackgroundColor = White }, new ConsoleChar { ForegroundColor = White }); }
public void DrawLine () { var buffer = new ConsoleBuffer(3); buffer.DrawLine(Line.Vertical(1, 0, 3), Red); buffer.DrawLine(Line.Horizontal(0, 1, 3), Green, LineWidth.Wide); var c0 = new ConsoleChar(); var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; var cg = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide, ForegroundColor = Green }; var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.HorizontalWide | LineChar.Vertical, ForegroundColor = Green }; buffer.GetLine(0).Should().Equal(c0, cr, c0); buffer.GetLine(1).Should().Equal(cg, cx, cg); buffer.GetLine(2).Should().Equal(c0, cr, c0); }
public void DrawRectangleSimple () { var buffer = new ConsoleBuffer(3); buffer.DrawRectangle(new Rect(0, 0, 3, 3), Red, LineWidth.Single); var c0 = new ConsoleChar(); var cx = new ConsoleChar { LineChar = LineChar.Horizontal | LineChar.Vertical, ForegroundColor = Red }; var ch = new ConsoleChar { LineChar = LineChar.Horizontal, ForegroundColor = Red }; var cv = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red }; buffer.GetLine(0).Should().Equal(cx, ch, cx); buffer.GetLine(1).Should().Equal(cv, c0, cv); buffer.GetLine(2).Should().Equal(cx, ch, cx); }