public void Render(IGraphicsContext context) { lock (_locker) { if (_brushBackground == null) { _brushBackground = new BasicBrush(_backgroundColor); _penTransparent = new BasicPen(); _penBorder = new BasicPen(new BasicBrush(_borderColor), 1); _rectText = context.MeasureText("12345:678.90", new BasicRectangle(0, 0, Frame.Width, Frame.Height), "HelveticaNeue", 10); } } _density = context.Density; Frame = new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight); context.DrawRectangle(new BasicRectangle(0, 0, context.BoundsWidth, context.BoundsHeight), _brushBackground, _penTransparent); if (_audioFile == null || _audioFileLength == 0) return; // Check if scale type needs to be updated if (_lastWidth != ContentSize.Width) { _lastWidth = ContentSize.Width; CalculateScale(context.Density); } // Draw scale borders //Console.WriteLine("WaveFormScaleView - scaleType: {0} totalMinutes: {1} totalSeconds: {2} totalMinutesScaled: {3} totalSecondsScaled: {4}", scaleType.ToString(), totalMinutes, totalSeconds, totalMinutesScaled, totalSecondsScaled); context.SetPen(_penBorder); context.StrokeLine(new BasicPoint(0, ContentSize.Height - 1), new BasicPoint(ContentSize.Width, ContentSize.Height - 1)); int firstVisibleIndex = (int)Math.Floor(ContentOffset.X / _tickWidth); int lastVisibleIndex = firstVisibleIndex + (int)Math.Floor(context.BoundsWidth / _tickWidth); float tickX = -ContentOffset.X + (firstVisibleIndex * _tickWidth); int majorTickIndex = (int)Math.Ceiling(firstVisibleIndex / 10f); //for (int a = firstVisibleIndex; a < _tickCount; a++) for (int a = firstVisibleIndex; a < lastVisibleIndex; a++) { // Ignore ticks out of bounds bool isMajorTick = ((a % 10) == 0); if (tickX >= 0 && tickX <= Frame.Width) { //Console.WriteLine("####> WaveFormView - Scale - tick {0} x: {1} isMajorTick: {2} tickCount: {3}", a, tickX, isMajorTick, tickCount); if(isMajorTick) // //context.DrawLine(new BasicPoint(tickX, context.BoundsHeight - (context.BoundsHeight / 1.25f)), new BasicPoint(tickX, context.BoundsHeight), _penMajorTick); context.StrokeLine(new BasicPoint(tickX, 0), new BasicPoint(tickX, ContentSize.Height - 1)); else context.StrokeLine(new BasicPoint(tickX, ContentSize.Height - (ContentSize.Height / 6) - 1), new BasicPoint(tickX, ContentSize.Height - 1)); if (isMajorTick) { // Draw dashed traversal line for major ticks context.StrokeLine(new BasicPoint(tickX, ContentSize.Height - 1), new BasicPoint(tickX, ContentSize.Height - 1)); // Determine major scale text int minutes = 0; int seconds = 0; switch (_scaleType) { case WaveFormScaleType._10minutes: minutes = majorTickIndex * 10; seconds = 0; break; case WaveFormScaleType._5minutes: minutes = majorTickIndex * 5; seconds = 0; break; case WaveFormScaleType._2minutes: minutes = majorTickIndex * 2; seconds = 0; break; case WaveFormScaleType._1minute: minutes = majorTickIndex; seconds = 0; break; case WaveFormScaleType._30seconds: minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier); seconds = (majorTickIndex % _scaleMultiplier == 0) ? 0 : 30; break; case WaveFormScaleType._10seconds: minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier); seconds = ((int)Math.Floor(majorTickIndex % _scaleMultiplier)) * 10; break; case WaveFormScaleType._5seconds: minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier); seconds = ((int)Math.Floor(majorTickIndex % _scaleMultiplier)) * 5; break; case WaveFormScaleType._1second: minutes = (int)Math.Floor(majorTickIndex / _scaleMultiplier); seconds = (int)Math.Floor(majorTickIndex % _scaleMultiplier); break; } // Draw text at every major tick (minute count) string scaleMajorTitle = string.Format("{0}:{1:00}", minutes, seconds); //float y = ContentSize.Height - (ContentSize.Height/12f) - _rectText.Height - (0.5f * context.Density); float y = 3 * context.Density;//ContentSize.Height - _rectText.Height - (10 * context.Density); context.DrawText(scaleMajorTitle, new BasicPoint(tickX + (4 * context.Density), y), _textColor, FontFace, FontSize); } } if(isMajorTick) majorTickIndex++; tickX += _tickWidth; } }
private void DrawLoops(IGraphicsContext context, float cursorHeight, float realScrollBarHeight) { if (_loop != null) { for (int a = 0; a < _loop.Segments.Count; a++) { var nextSegment = _loop.GetNextSegment(a); float segmentPositionPercentage = (float)_loop.Segments[a].PositionBytes / (float)Length; float startX = (segmentPositionPercentage * ContentSize.Width) - ContentOffset.X; float nextSegmentPositionPercentage = 0; float endX = 0; if (nextSegment != null) { nextSegmentPositionPercentage = (float)nextSegment.PositionBytes / (float)Length; endX = (nextSegmentPositionPercentage * ContentSize.Width) - ContentOffset.X; } // Draw loop lines //var pen = _markers[a].MarkerId == _activeMarkerId ? _penSelectedMarkerLine : _penMarkerLine; context.SetPen(_penLoopLine); context.StrokeLine(new BasicPoint(startX, 0), new BasicPoint(startX, cursorHeight)); // Draw text //var rectText = new BasicRectangle(startX, Frame.Height - 12, 12, 12); var rectText = new BasicRectangle(startX, Frame.Height - realScrollBarHeight -12, endX > startX ? endX - startX : 12, 12); //var brush = _markers [a].MarkerId == _activeMarkerId ? _brushSelectedMarkerBackground : _brushMarkerBackground; context.DrawRectangle(rectText, _brushLoopBackground, _penTransparent); context.DrawText((a+1).ToString(), new BasicPoint(startX + 2, Frame.Height - realScrollBarHeight - 12), _textColor, LetterFontFace, LetterFontSize); } } }
private void DrawCursors(IGraphicsContext context, float heightAvailable, float cursorHeight, float scrollBarCursorX) { // Draw cursor line context.SetPen(_penCursorLine); context.StrokeLine(new BasicPoint(_cursorX, 0), new BasicPoint(_cursorX, cursorHeight)); context.StrokeLine(new BasicPoint(scrollBarCursorX, cursorHeight), new BasicPoint(scrollBarCursorX, heightAvailable)); // Check if a secondary cursor must be drawn (i.e. when changing position) if (ShowSecondaryPosition) { float secondaryPositionPercentage = (float)SecondaryPosition / (float)Length; _secondaryCursorX = (secondaryPositionPercentage * ContentSize.Width) - ContentOffset.X; _secondaryCursorX = (float)Math.Round(_secondaryCursorX * 2) / 2; // Round to 0.5 //Console.WriteLine("secondaryPositionPercentage: {0} secondaryCursorX: {1}", secondaryPositionPercentage, _secondaryCursorX); // Draw cursor line context.SetPen(_penSecondaryCursorLine); context.StrokeLine(new BasicPoint(_secondaryCursorX, 0), new BasicPoint(_secondaryCursorX, cursorHeight)); } }
private void DrawMarkers(IGraphicsContext context, float cursorHeight) { for (int a = 0; a < _markers.Count; a++) { float xPct = (float)_markers[a].PositionBytes / (float)Length; float x = (xPct * ContentSize.Width) - ContentOffset.X; // Draw cursor line var pen = _markers[a].MarkerId == _activeMarkerId ? _penSelectedMarkerLine : _penMarkerLine; context.SetPen(pen); context.StrokeLine(new BasicPoint(x, 0), new BasicPoint(x, cursorHeight)); // Draw text var rectText = new BasicRectangle(x, 0, 12, 12); var brush = _markers[a].MarkerId == _activeMarkerId ? _brushSelectedMarkerBackground : _brushMarkerBackground; context.DrawRectangle(rectText, brush, _penTransparent); string letter = Conversion.IndexToLetter(a).ToString(); context.DrawText(letter, new BasicPoint(x + 2, 0), _textColor, LetterFontFace, LetterFontSize); } }