protected override void OnPaint(ConsoleBitmap context) { var indicator = (Element as LooseWeapon).InnerWeapon.GetType().Name[0]; context.Pen = new PowerArgs.ConsoleCharacter(indicator, Foreground, Background); context.DrawPoint(0, 0); }
public void TestRecordVideoLargeVideo() { ConsoleBitmap bitmap = new ConsoleBitmap(1, 1); var numFrames = 10000; using (var sharedStream = new MemoryStream()) { var bitmapVideoWriter = new ConsoleBitmapStreamWriter(sharedStream) { CloseInnerStream = false }; for (var i = 0; i < numFrames; i++) { bitmapVideoWriter.WriteFrame(bitmap, true, TimeSpan.FromMilliseconds(i)); } bitmapVideoWriter.Dispose(); sharedStream.Position = 0; // rewind the stream to the beginning to read it back var destination = TimeSpan.Zero; var reader = new ConsoleBitmapStreamReader(sharedStream); var video = reader.ReadToEnd(); var lastFrameIndex = 0; var sw = Stopwatch.StartNew(); while ((lastFrameIndex = video.Seek(destination, out bitmap, lastFrameIndex >= 0 ? lastFrameIndex : 0)) != numFrames - 1) { destination = destination.Add(TimeSpan.FromMilliseconds(1)); } sw.Stop(); Assert.IsTrue(sw.ElapsedMilliseconds < 10); Console.WriteLine($"Playback took {sw.ElapsedMilliseconds} ms"); } }
private ConsoleBitmapDiffFrame PrepareDiffFrame(ConsoleBitmapRawFrame previous, ConsoleBitmap bitmap) { ConsoleBitmapDiffFrame diff = new ConsoleBitmapDiffFrame(); diff.Diffs = new List <ConsoleBitmapPixelDiff>(); int changes = 0; for (int y = 0; y < GetEffectiveHeight(bitmap); y++) { for (int x = 0; x < GetEffectiveWidth(bitmap); x++) { var pixel = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y); var hasPreviousPixel = previous.Pixels.Length == GetEffectiveWidth(bitmap) && previous.Pixels[0].Length == GetEffectiveHeight(bitmap); var previousPixel = hasPreviousPixel ? previous.Pixels[x][y] : default(ConsoleCharacter); if (hasPreviousPixel == false || (pixel.EqualsIn(previousPixel) == false)) { changes++; diff.Diffs.Add(new ConsoleBitmapPixelDiff() { X = x, Y = y, Value = pixel }); } } } return(diff); }
public void TestRecordVideoBasic() { ConsoleBitmap bitmap = new ConsoleBitmap(4, 2), redBitmap = null, greenBitmap = null, magentaPixelBitmap = null; using (var sharedStream = new MemoryStream()) { using (var bitmapVideoWriter = new ConsoleBitmapStreamWriter(sharedStream) { CloseInnerStream = false }) { bitmap = new ConsoleBitmap(4, 2); redBitmap = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.RedBG())).Clone(); greenBitmap = bitmapVideoWriter.WriteFrame(bitmap.FillRect(ConsoleCharacter.GreenBG())).Clone(); magentaPixelBitmap = bitmapVideoWriter.WriteFrame(bitmap.DrawPoint(ConsoleCharacter.MagentaBG(), 0, 0)).Clone(); } sharedStream.Position = 0; // rewind the stream to the beginning to read it back // create a reader and make sure we can read each frame back exactly as they were written var bitmapVideoReader = new ConsoleBitmapStreamReader(sharedStream); Assert.AreEqual(redBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.AreEqual(greenBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.AreEqual(magentaPixelBitmap, bitmapVideoReader.ReadFrame().CurrentBitmap); Assert.IsNull(bitmapVideoReader.ReadFrame().CurrentFrame); } }
public void Clear() { Buffer = new ConsoleBitmap(0, 0, this.BufferWidth, this.WindowHeight); this.BufferWidth = Buffer.Width; this.CursorLeft = 0; this.CursorTop = 0; }
protected override void OnPaint(ConsoleBitmap context) { if ((Element as Waypoint).IsHighlighted) { context.Pen = new PowerArgs.ConsoleCharacter('W', backgroundColor: ConsoleColor.Cyan); context.FillRect(0, 0, Width, Height); } }
protected override void OnPaint(ConsoleBitmap context) { var state = (Element as Door).State; var pen = state == DoorState.Locked ? new ConsoleCharacter('X', ConsoleColor.Black, ConsoleColor.Cyan) : new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Cyan); context.FillRect(pen, 0, 0, Width, Height); }
protected override void OnPaint(ConsoleBitmap context) { if ((Element as Projectile).Pen != null && (Element as Projectile).Pen.Length > 0) { context.Pen = (Element as Projectile).Pen[0]; } context.FillRectUnsafe(0, 0, Width, Height); }
protected override void OnPaint(ConsoleBitmap context) { if ((Element as Portal).LevelId == null) { Style = new ConsoleCharacter('?', ConsoleColor.Black, ConsoleColor.Magenta); } base.OnPaint(context); }
public void Clear() { Buffer = new ConsoleBitmap(0, 0, w, h); InputQueue = new Queue <ConsoleKeyInfo>(); this.BufferWidth = Buffer.Width; this.CursorLeft = 0; this.CursorTop = 0; }
private void InitPlainCase() { continuousBitmaps = new ConsoleBitmap[100]; for (var i = 0; i < continuousBitmaps.Length; i++) { continuousBitmaps[i] = new ConsoleBitmap(80, 30); continuousBitmaps[i].FillRect(pen, 0, 0, continuousBitmaps[i].Width, continuousBitmaps[i].Height); } }
protected override void OnPaint(ConsoleBitmap context) { context.Pen = new ConsoleCharacter('F', ConsoleColor.Green); if ((Element as Character).Symbol.HasValue) { context.Pen = new ConsoleCharacter((Element as Character).Symbol.Value, context.Pen.ForegroundColor, context.Pen.BackgroundColor); } context.FillRect(0, 0, Width, Height); }
protected override void Initiate() { if (enemy != null) { bgArt = new ConsoleBitmap($"{AppDomain.CurrentDomain.BaseDirectory}Assets\\BG\\bg01.png"); enemyArt = new ConsoleBitmap($"{AppDomain.CurrentDomain.BaseDirectory}Assets\\Enemy\\femaleDjin01.png", ConsoleColor.Magenta); DialogHelper.WriteDialog(ConsoleColor.Red, ConsoleColor.Black, 90, 3, 50, enemy.Name, $"{enemy.Race.Name} {enemy.Class.Name}"); Singleton <Media.Music> .GetInstance().Play(@"Music\Battle with the Circus Freaks.mp3"); } }
private void InitFewShapesCase() { aFewShapesBitmaps = new ConsoleBitmap[100]; for (var i = 0; i < aFewShapesBitmaps.Length; i++) { aFewShapesBitmaps[i] = new ConsoleBitmap(80, 30); aFewShapesBitmaps[i].FillRect(pen, 0, 0, 10, 5); aFewShapesBitmaps[i].FillRect(pen, 10, 10, 10, 5); aFewShapesBitmaps[i].FillRect(pen, 13, 12, 10, 5); } }
protected override void OnPaint(ConsoleBitmap context) { if (Element.Pen.HasValue) { context.FillRect(Element.Pen.Value, 0, 0, Width, Height); } else { base.OnPaint(context); } }
protected override void OnPaint(ConsoleBitmap context) { context.Pen = new ConsoleCharacter(' ', backgroundColor: BorderElement.BackgroundColor); context.FillRectUnsafe(0, 0, Width, Height); context.Pen = new ConsoleCharacter(' ', backgroundColor: BorderElement.BorderColor); context.DrawLine(0, 0, 0, Height); context.DrawLine(1, 0, 1, Height); context.DrawLine(Width - 1, 0, Width - 1, Height); context.DrawLine(Width - 2, 0, Width - 2, Height); context.DrawLine(0, 0, Width, 0); context.DrawLine(0, Height - 1, Width, Height - 1); }
protected override void OnPaint(ConsoleBitmap context) { if ((Thing as Zombie).IsBeingTargeted) { context.Pen = new PowerArgs.ConsoleCharacter('Z', (Thing as Zombie).HealthPoints < 2 ? ConsoleColor.Gray : ConsoleColor.DarkRed, ConsoleColor.Cyan); } else { context.Pen = new PowerArgs.ConsoleCharacter('Z', (Thing as Zombie).HealthPoints < 2 ? ConsoleColor.Gray : ConsoleColor.DarkRed); } context.FillRect(0, 0, Width, Height); }
protected override void OnPaint(ConsoleBitmap context) { var primarySymbol = (Element as Fire).SymbolOverride.HasValue ? (Element as Fire).SymbolOverride.Value : BurnSymbol1; if (r.NextDouble() < .9) { var color = r.NextDouble() < .8 ? PrimaryBurnColor : SecondaryBurnColor; var symbol = r.NextDouble() < .65 ? primarySymbol : BurnSymbol2; context.Pen = new ConsoleCharacter(symbol, color); context.FillRect(0, 0, Width, Height); } }
protected override void OnPaint(ConsoleBitmap context) { for (var x = 0; x < context.Width; x++) { for (var y = 0; y < context.Height; y++) { context.DrawPoint(_even ? evenPen : oddPen, x, y); _even = !_even; } } _even = !_even; ConsoleApp.Current.RequestPaint(); }
public void TestPlaybackEndToEnd() { int w = 10, h = 1; var temp = Path.GetTempFileName(); using (var stream = File.OpenWrite(temp)) { var writer = new ConsoleBitmapStreamWriter(stream) { CloseInnerStream = false }; var bitmap = new ConsoleBitmap(w, h); for (var i = 0; i < bitmap.Width; i++) { bitmap.Pen = new ConsoleCharacter(' '); bitmap.FillRect(0, 0, bitmap.Width, bitmap.Height); bitmap.Pen = new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red); bitmap.DrawPoint(i, 0); writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.5 * i)); } writer.Dispose(); } var app = new CliTestHarness(this.TestContext, 80, 30); app.QueueAction(() => { var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill(); player.Load(File.OpenRead(temp)); app.SetTimeout(() => app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false)), TimeSpan.FromMilliseconds(100)); var playStarted = false; player.SubscribeForLifetime(nameof(player.State), () => { if (player.State == PlayerState.Playing) { playStarted = true; } else if (player.State == PlayerState.Stopped && playStarted) { app.Stop(); } }, app); }); app.Start().Wait(); Thread.Sleep(100); app.AssertThisTestMatchesLKGFirstAndLastFrame(); }
protected override void OnPaint(ConsoleBitmap context) { for (var x = 0; x < Width && x < Bitmap.Width; x++) { for (var y = 0; y < Height & Y < Bitmap.Height; y++) { var c = Bitmap.GetPixel(x, y).Value; if (c.HasValue) { context.Pen = c.Value; context.DrawPoint(x, y); } } } }
protected override void OnPaint(ConsoleBitmap context) { var w = Element as Wall; if (w.Pen.HasValue) { context.Pen = w.Pen.Value; } else { context.Pen = Style; } context.FillRect(0, 0, Width, Height); }
protected override void OnPaint(ConsoleBitmap context) { if (Character.IsVisible == false) { return; } char c; var angle = Character.Speed.Angle; c = Geometry.GetArrowPointedAt(angle); context.Pen = new ConsoleCharacter(c, Character.Color); context.FillRect(0, 0, Width, Height); }
public void TestPlaybackEndToEnd() { var app = new CliTestHarness(this.TestContext, 80, 30); app.InvokeNextCycle(async() => { int w = 10, h = 1; var temp = Path.GetTempFileName(); using (var stream = File.OpenWrite(temp)) { var writer = new ConsoleBitmapVideoWriter(s => stream.Write(Encoding.Default.GetBytes(s))); var bitmap = new ConsoleBitmap(w, h); for (var i = 0; i < bitmap.Width; i++) { bitmap.Fill(new ConsoleCharacter(' ')); bitmap.DrawPoint(new ConsoleCharacter(' ', backgroundColor: ConsoleColor.Red), i, 0); writer.WriteFrame(bitmap, true, TimeSpan.FromSeconds(.1 * i)); } writer.Finish(); } var player = app.LayoutRoot.Add(new ConsoleBitmapPlayer()).Fill(); Assert.IsFalse(player.Width == 0); Assert.IsFalse(player.Height == 0); player.Load(File.OpenRead(temp)); var playStarted = false; player.SubscribeForLifetime(nameof(player.State), () => { if (player.State == PlayerState.Playing) { playStarted = true; } else if (player.State == PlayerState.Stopped && playStarted) { app.Stop(); } }, app); await Task.Delay(100); await app.SendKey(new ConsoleKeyInfo('p', ConsoleKey.P, false, false, false)); }); app.Start().Wait(); Thread.Sleep(100); app.AssertThisTestMatchesLKGFirstAndLastFrame(); }
private ConsoleBitmapRawFrame GetRawFrame(ConsoleBitmap bitmap) { var rawFrame = new ConsoleBitmapRawFrame(); rawFrame.Pixels = new ConsoleCharacter[GetEffectiveWidth(bitmap)][]; for (int x = 0; x < GetEffectiveWidth(bitmap); x++) { rawFrame.Pixels[x] = new ConsoleCharacter[GetEffectiveHeight(bitmap)]; for (int y = 0; y < GetEffectiveHeight(bitmap); y++) { var pixel = bitmap.GetPixel(GetEffectiveLeft + x, GetEffectiveTop + y); rawFrame.Pixels[x][y] = pixel; } } return(rawFrame); }
protected override void OnPaint(ConsoleBitmap context) { if (Character.IsVisible == false) { context.Pen = new ConsoleCharacter(' ', RGB.Black); context.FillRectUnsafe(0, 0, Width, Height); return; } char c; var angle = Character.Velocity.Angle; c = Geometry.GetArrowPointedAt(angle); context.Pen = Character.Pen.HasValue ? Character.Pen.Value : new ConsoleCharacter(c, Character.Color); context.FillRectUnsafe(0, 0, Width, Height); }
protected override void OnPaint(ConsoleBitmap context) { var state = (Element as ProximityMine).State; if (state == ProximityMineState.NoNearbyThreats) { context.FillRect(new ConsoleCharacter('#', ConsoleColor.DarkGray), 0, 0, Width, Height); } else if (state == ProximityMineState.ThreatApproaching) { context.FillRect(new ConsoleCharacter('#', ConsoleColor.Black, ConsoleColor.DarkYellow), 0, 0, Width, Height); } else if (state == ProximityMineState.ThreatNearby) { context.FillRect(new ConsoleCharacter('#', ConsoleColor.Black, ConsoleColor.Red), 0, 0, Width, Height); } }
protected override void OnPaint(ConsoleBitmap context) { if ((Element as Enemy).IsBeingTargeted) { context.Pen = TargetedStyle; } else { context.Pen = (Element as Enemy).HealthPoints >= 3 ? NormalStyle : HurtStyle; } if ((Element as Character).Symbol.HasValue) { context.Pen = new ConsoleCharacter((Element as Character).Symbol.Value, context.Pen.ForegroundColor, context.Pen.BackgroundColor); } context.FillRect(0, 0, Width, Height); }
protected override ConsoleBitmap DoRender() { if (ActualSize.IsZero()) { return(ConsoleBitmap.Empty); } var contentBitmap = Content?.Render().WithMaxSize(ActualInnerSize) ?? ConsoleBitmap.Empty; var bitmap = new ConsoleBitmap(ActualSize) .WithInserted(PaddingLeft, PaddingTop, contentBitmap); if (BackgroundColor.HasValue) { bitmap = bitmap.WithFilledBackground(BackgroundColor.Value); } return(bitmap); }
private void InitWorstCase() { worstCasebitmaps = new ConsoleBitmap[100]; var on = true; for (var i = 0; i < continuousBitmaps.Length; i++) { worstCasebitmaps[i] = new ConsoleBitmap(80, 30); for (var x = 0; x < worstCasebitmaps[i].Width; x++) { for (var y = 0; y < worstCasebitmaps[i].Height; y++) { on = !on; worstCasebitmaps[i].DrawPoint(new ConsoleCharacter('X', on ? RGB.Red : RGB.Green, on ? RGB.Black : RGB.Cyan), x, y); } } } }
public WinFormsTestConsole(int w, int h) { this.BufferWidth = w; this.WindowHeight = h; buffer = new ConsoleBitmap(0, 0, w, h); var timer = new System.Windows.Forms.Timer(); timer.Interval = 100; timer.Tick += Timer_Tick; timer.Start(); offsreenBuffer = new Bitmap(1000, 1000); onScreenBuffer = new Bitmap(1000, 1000); onScreenGraphics = Graphics.FromImage(onScreenBuffer); offScreenGraphics = Graphics.FromImage(offsreenBuffer); this.Font = new Font("Consolas", 12); this.charSize = onScreenGraphics.MeasureString("1", Font); }