public static DebugCanvas CreateAndShowCanvas(Size displaySize = default(Size)) { displaySize = displaySize == default(Size) ? new Size(1000, 1000) : displaySize; var drawPadding = new Point(100, 100); var canvas = new DebugCanvas(displaySize, drawPadding, OrthographicXYProjector.Instance); DebugCanvasHost.CreateShow(canvas); return(canvas); }
private static DebugCanvasHost CreateShow(DebugCanvas canvas) { DebugCanvasHost canvasHost = null; var shownLatch = new ManualResetEvent(false); var thread = new Thread(() => { canvasHost = new DebugCanvasHost(canvas); canvasHost.form.Shown += (s, e) => shownLatch.Set(); Application.Run(canvasHost.form); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); shownLatch.WaitOne(); return(canvasHost); }
public DebugCanvasHost(DebugCanvas canvas) { const double scale = 1.0f; form = new Form { ClientSize = new Size((int)(canvas.PaddedSize.Width * scale), (int)(canvas.PaddedSize.Height * scale)) }; form.BackColor = Color.White; form.StartPosition = FormStartPosition.CenterScreen; pb = new PictureBox { Dock = DockStyle.Fill }; pb.SizeMode = PictureBoxSizeMode.Zoom; form.Controls.Add(pb); canvas.Update += (s, e) => { Bitmap clonedBitmap = (Bitmap)e.Bitmap.Clone(); form.BeginInvoke(new Action(() => { pb.Image = clonedBitmap; })); }; }
public IDebugCanvas CreateAndAddCanvas(int timestamp) { var canvas = new DebugCanvas(canvasSize, canvasPadding, projector); lock (synchronization) { frames.Add(new CanvasAndTimeStamp { Canvas = canvas, Timestamp = timestamp }); UpdateSlider(); } canvas.Update += (s, e) => { var bitmapClone = (Bitmap)e.Bitmap.Clone(); form.BeginInvoke(new Action(() => { lock (synchronization) { if (Enumerable.Last(frames, f => f.Timestamp <= slider.Value).Canvas == canvas) { pb.Image = bitmapClone; } } })); }; return(canvas); }