private void AddLineFor(FrameRecordViewModel newBreak, FrameRecordViewModel previous) { var line = new Line(); // Let's try making this a little thicker so it's easier to read, but transparent so it shows some of the lines behind it byte alpha = 100; Brush brush = new SolidColorBrush(Color.FromArgb(alpha, 0, 0, 0)); line.Stroke = brush; line.StrokeThickness = 5; line.X1 = 0; line.X2 = ViewModel.TimeToX(newBreak.Time); line.Y1 = CountToY(newBreak.RenderBreaks.Count); line.Y2 = line.Y1; if (line.X2 > MainCanvas.Width || double.IsNaN(MainCanvas.Width)) { MainCanvas.Width = line.X2; this.ScrollViewer.ScrollToRightEnd(); } if (previous != null) { line.X1 = ViewModel.TimeToX(previous.Time); line.Y1 = CountToY(previous.RenderBreaks.Count); } lineList.Add(line); this.MainCanvas.Children.Add(line); }
private void HandleRenderBreaksAdded(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { var collection = ViewModel.RecordedFrames; FrameRecordViewModel newFrame = null; FrameRecordViewModel previousFrame = null; if (collection.Count > 0) { newFrame = collection.Last(); } if (collection.Count > 1) { previousFrame = collection[collection.Count - 2]; } if (previousFrame != null && previousFrame.RenderBreaks.Count != newFrame.RenderBreaks.Count) { lineDrawingState = LineDrawingState.NeedsToDrawDiagonalLine; } bool needsNewLine = lineDrawingState == LineDrawingState.NeedsToDrawDiagonalLine || lineDrawingState == LineDrawingState.NeedsToCreateHorizontalLine; if (needsNewLine) { if (lineDrawingState == LineDrawingState.NeedsToDrawDiagonalLine) { lineDrawingState = LineDrawingState.NeedsToCreateHorizontalLine; } else if (lineDrawingState == LineDrawingState.NeedsToCreateHorizontalLine) { lineDrawingState = LineDrawingState.IsExtendingHorizontalLine; } AddLineFor(newFrame, previousFrame); } else { ExtendExistingLineFor(newFrame); } }
private void ExtendExistingLineFor(FrameRecordViewModel newFrame) { var lastLine = lineList.LastOrDefault(); if (lastLine != null) { lastLine.X2 = ViewModel.TimeToX(newFrame.Time); lastLine.Y2 = CountToY(newFrame.RenderBreaks.Count); if (double.IsNaN(MainCanvas.Height) || lastLine.Y2 > MainCanvas.Height) { MainCanvas.Height = lastLine.Y2; } if (lastLine.X2 > MainCanvas.Width || double.IsNaN(MainCanvas.Width)) { MainCanvas.Width = lastLine.X2; this.ScrollViewer.ScrollToRightEnd(); } } }