protected override void OnRender(DrawingContext drawingContext) { double zoomRatio = MusicMath.getZoomRatio(QuarterWidth, BeatPerBar, BeatUnit, MinTickWidth); double interval = zoomRatio * QuarterWidth; int tick = (int)((OffsetX + QuarterOffset * QuarterWidth) / interval) + 1; double left = tick * interval - OffsetX - QuarterOffset * QuarterWidth; while (left < _size.Width) { double snappedLeft = Math.Round(left) + 0.5; if ((tick * zoomRatio * BeatUnit) % (BeatPerBar * 4) == 0) { drawingContext.DrawLine(darkPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } else if ((tick * zoomRatio * BeatUnit) % 4 == 0) { if (TickMode == 1) { drawingContext.DrawLine(darkPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } else { drawingContext.DrawLine(lightPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } } else if ((tick * zoomRatio * BeatUnit) % 1 == 0) { if (TickMode == 1) { drawingContext.DrawLine(lightPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } else { drawingContext.DrawLine(dashedPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } } else { drawingContext.DrawLine(dashedPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } left += interval; tick++; } }
protected override void OnRender(DrawingContext drawingContext) { double zoomRatio = MusicMath.getZoomRatio(QuarterWidth, BeatPerBar, BeatUnit, MinTickWidth); double interval = zoomRatio * QuarterWidth; int tick = (int)((OffsetX + QuarterOffset * QuarterWidth) / interval); double left = tick * interval - OffsetX - QuarterOffset * QuarterWidth; bool first_tick = true; while (left < _size.Width) { double snappedLeft = Math.Round(left) + 0.5; if ((tick * zoomRatio * BeatUnit) % (BeatPerBar * 4) == 0) { if (!first_tick) { drawingContext.DrawLine(darkPen, new Point(snappedLeft, -0.5), new Point(snappedLeft, ActualHeight + 0.5)); } int barNumber = (int)((tick * zoomRatio * BeatUnit) / BeatPerBar / 4 + 1); FormattedText fText; if (!fTextPool.ContainsKey(barNumber)) { fText = new FormattedText( barNumber.ToString(), System.Threading.Thread.CurrentThread.CurrentUICulture, FlowDirection.LeftToRight, SystemFonts.CaptionFontFamily.GetTypefaces().First(), 12, darkPen.Brush, VisualTreeHelper.GetDpi(this).PixelsPerDip); fTextPool.Add(barNumber, fText); } else { fText = fTextPool[barNumber]; } drawingContext.DrawText(fText, new Point(snappedLeft + 3, 3)); } left += interval; tick++; first_tick = false; } }