//private void CalVoiceSpecturumArea(WavePlotPara plotPara, out int begeinIndex, out int endIndex) //{ // int frameCount = plotPara.FrameCount; // begeinIndex = (int)(frameCount * plotPara.SBTOMillisecond / plotPara.DurationMillisecond); // endIndex = (int)(frameCount * plotPara.GetSETOMillisecond() / plotPara.DurationMillisecond); // if (begeinIndex < 0) // { // int offset = Math.Abs(begeinIndex); // begeinIndex = 0; // endIndex += offset; // if (endIndex > frameCount) // { // endIndex = frameCount; // } // } // else // { // if (endIndex > frameCount) // { // begeinIndex = begeinIndex - (endIndex - frameCount); // endIndex = frameCount; // if (begeinIndex < 0) // { // begeinIndex = 0; // } // } // } //} private void CalWavSpecturumArea(WavePlotPara plotPara, out int begeinIndex, out int endIndex) { int sourceFFTDataLength = plotPara.SourcePcmDataLength; begeinIndex = (int)(sourceFFTDataLength * plotPara.SBTOMillisecond / plotPara.DurationMillisecond); endIndex = (int)(sourceFFTDataLength * plotPara.GetSETOMillisecond() / plotPara.DurationMillisecond); if (begeinIndex < 0) { int offset = Math.Abs(begeinIndex); begeinIndex = 0; endIndex += offset; if (endIndex > sourceFFTDataLength) { endIndex = sourceFFTDataLength; } } else { if (endIndex > sourceFFTDataLength) { begeinIndex = begeinIndex - (endIndex - sourceFFTDataLength); endIndex = sourceFFTDataLength; if (begeinIndex < 0) { begeinIndex = 0; } } } }
/// <summary> /// 获取指定点所对应在UI中的区域 /// </summary> /// <param name="point">指定点</param> /// <param name="plotPara"></param> /// <param name="selectedInfo"></param> /// <returns>指定点所对应在UI中的区域</returns> internal UIArea GetUIArea(Point point, WavePlotPara plotPara, SelectedInfo selectedInfo) { if (this.Inner(point, this._globalView)) { if (plotPara != null) { double unitWidth = this._content.Area.Width / plotPara.DurationMillisecond; double sbx = unitWidth * plotPara.SBTOMillisecond; double sex = unitWidth * plotPara.GetSETOMillisecond(); if (point.X - sbx > PlotConstant.ZEROR_D && point.X - sex < PlotConstant.ZEROR_D) { return(UIArea.GlobalViewZoomDisplay); } } return(UIArea.GlobalView); } if (this.Inner(point, this._xAxis)) { return(UIArea.TimeArea); } if (this.Inner(point, this._content)) { return(UIArea.Wave); } return(UIArea.Other); }
private RectangleF?DrawWaveSpecturum(Graphics graphics, WavePlotPara plotPara, IEnumerable <ChannelPlotData> plotDatas) { PlotElementInfoAbs wave = this._content; if (wave == null) { return(null); } //填充主波形背景 if (wave.BackgroudColor != null) { graphics.FillRectangle(wave.BackgroudColor, wave.Area); } if (plotPara == null || plotDatas == null) { return(null); } double sbto = plotPara.SBTOMillisecond; //显示区域起始时间 double seto = plotPara.GetSETOMillisecond(); //显示区域结束时间 RectangleF?wavSelectedArea = this.GetSelectedAreaBackground(wave.Area, plotPara, sbto, seto); if (wavSelectedArea.HasValue) { //填充主波形选中背景 graphics.FillRectangle(this._seleactionAreaBrush, wavSelectedArea.Value); } //绘制波形图 this.DrawWaveDb(graphics, wave, plotPara, plotDatas, false); return(wavSelectedArea); }
private void UpdatePlotPara(WavePlotPara plotPara) { double setoMillisecond = plotPara.GetSETOMillisecond(); double middle = plotPara.SBTOMillisecond + (setoMillisecond - plotPara.SBTOMillisecond) / 2; double showAreaMillisecond = plotPara.DurationMillisecond / this._zoomMultiple; double showAreaHalfMillisecond = showAreaMillisecond / 2; plotPara.SBTOMillisecond = middle - showAreaHalfMillisecond; plotPara.UpdateSETOMillisecond(middle + showAreaHalfMillisecond); }
private RectangleF?DrawGlobalView(Graphics graphics, WavePlotPara plotPara, IEnumerable <ChannelPlotData> plotDatas) { GlobalViewPlotElementInfo globalView = this._globalView; if (globalView == null) { return(null); } //填充整体视图波形背景 if (globalView.BackgroudColor != null) { graphics.FillRectangle(globalView.BackgroudColor, globalView.Area); } if (plotDatas == null) { return(null); } //整体视图中缩放后显示区域 RectangleF?globalViewZoomArea = null; if (this._zoomInfo.HasZoom()) { float x1 = (float)(globalView.Area.Width * plotPara.SBTOMillisecond / plotPara.DurationMillisecond); float x2 = (float)(globalView.Area.Width * plotPara.GetSETOMillisecond() / plotPara.DurationMillisecond); globalViewZoomArea = new RectangleF(x1, globalView.Area.Y, x2 - x1, globalView.Area.Height); graphics.FillRectangle(globalView.GlobalViewZoomAreaBackBrush, globalViewZoomArea.Value); } RectangleF?wavSelectedArea = this.GetSelectedAreaBackground(globalView.Area, plotPara, PlotConstant.ZEROR_D, plotPara.DurationMillisecond); if (wavSelectedArea.HasValue) { //填充选中背景 graphics.FillRectangle(this._seleactionGlobalViewAreaBrush, wavSelectedArea.Value); } //绘制整体视图波形 this.DrawWaveDb(graphics, globalView, plotPara, plotDatas, true); if (globalViewZoomArea.HasValue) { this.DrawDisplayAreaStyle(globalView, graphics, globalViewZoomArea.Value); } return(wavSelectedArea); }
/// <summary> /// 更新播放位置指示线 /// </summary> /// <param name="plotPara"></param> /// <param name="offsetTimeMilliseconds">播放时间</param> private void PrimitiveUpdatePostionLine(WavePlotPara plotPara, double offsetTimeMilliseconds) { if (!this._playPositionLine) { return; } this.AddPartRefreshArea(this._globalViewLastPlayPositionLineArea); this.AddPartRefreshArea(this._waveLastPlayPositionLineArea); //全部绘制 Graphics graphics = this._grafx.Graphics; IEnumerable <ChannelPlotData> plotDatas = this._plotDatas; //全局视图 this.DrawGlobalView(graphics, plotPara, plotDatas); //波形图 this.DrawWaveSpecturum(graphics, plotPara, plotDatas); ContentPlotElementInfo content = this._content; float maxX = content.Area.X + content.Area.Width; const int OFFSET1 = 1; const int OFFSET2 = 2; //缩略波形图播放位置指示线 var globalView = this._globalView; if (globalView != null) { float globalViewX = (float)(content.Area.Width * offsetTimeMilliseconds / plotPara.DurationMillisecond); if (globalViewX + globalView.PlayLineChannelPen.Width < maxX) { PointF zoomP1 = new PointF(globalViewX, globalView.Area.Y); PointF zoomP2 = new PointF(globalViewX, globalView.Area.Y + globalView.Area.Height); graphics.DrawLine(globalView.PlayLineChannelPen, zoomP1, zoomP2); this._globalViewLastPlayPositionLineArea = new RectangleF(globalViewX - OFFSET1, globalView.Area.Y - OFFSET1, globalView.PlayLineChannelPen.Width + OFFSET2, globalView.Area.Height + OFFSET2); this.AddPartRefreshArea(this._globalViewLastPlayPositionLineArea); } } else { this._globalViewLastPlayPositionLineArea = null; } //主波形图播放位置指示线 double sbto = plotPara.SBTOMillisecond; double seto = plotPara.GetSETOMillisecond(); double timeArea = seto - sbto; float contentX = (float)(content.Area.Width * (offsetTimeMilliseconds - sbto) / timeArea); bool drawWavePlayLine = plotPara.ContainsShowTime(offsetTimeMilliseconds); if (drawWavePlayLine && contentX > PlotConstant.ZEROR_D && this.Width - contentX > PlotConstant.ZEROR_D) { if (contentX + content.PlayLineChannelPen.Width - maxX < PlotConstant.ZEROR_D) { var contentArea = content.Area; PointF wavP1 = new PointF(contentX, contentArea.Y); PointF wavP2 = new PointF(contentX, contentArea.Y + contentArea.Height); graphics.DrawLine(content.PlayLineChannelPen, wavP1, wavP2); this._waveLastPlayPositionLineArea = new RectangleF(contentX - OFFSET1, contentArea.Y - OFFSET1, content.PlayLineChannelPen.Width + OFFSET2, contentArea.Height + OFFSET2); this.AddPartRefreshArea(this._waveLastPlayPositionLineArea); } } else { this._waveLastPlayPositionLineArea = null; } this.RefreshInvalidateArea(); }
private void DrawTimeAxis(Graphics graphics, WavePlotPara plotPara) { XAxisPlotElementInfo axisX = this._xAxis; if (axisX == null) { return; } //时间图背景 RectangleF rectangleTimeArea = axisX.Area; graphics.FillRectangle(axisX.BackgroudColor, rectangleTimeArea); if (plotPara == null) { return; } //边框 //graphics.DrawLine(this._borderPen, rectangleTimeArea.X, rectangleTimeArea.Y, rectangleTimeArea.X, rectangleTimeArea.Y + rectangleTimeArea.Height); //float borderX = rectangleTimeArea.X + rectangleTimeArea.Width - this._borderPen.Width; //graphics.DrawLine(this._borderPen, borderX, rectangleTimeArea.Y, borderX, rectangleTimeArea.Y + rectangleTimeArea.Height); //graphics.DrawLine(this._borderPen, rectangleTimeArea.X, rectangleTimeArea.Y, rectangleTimeArea.X + rectangleTimeArea.Width, rectangleTimeArea.Y); //绘制起始时间-毫秒 double beginTimeMillisecond = plotPara.SBTOMillisecond; //绘制结束时间-毫秒 double endTimeMillisecond = plotPara.GetSETOMillisecond(); //绘制总时长 double durationTimeMillisecond = endTimeMillisecond - beginTimeMillisecond; if (durationTimeMillisecond <= 0d) { return; } //绘制时间间隔 double separatorSecond = this.CalSegDurationSecond(axisX, graphics, durationTimeMillisecond); //绘制起始时间-秒 double beginTimeSecond = beginTimeMillisecond / 1000; //绘制时间-秒 double timeSecond = PlotConstant.ZEROR_D; if (beginTimeMillisecond > PlotConstant.ZEROR_D) { int mult = (int)(beginTimeSecond / separatorSecond); double mod = beginTimeSecond % separatorSecond; if (mod - separatorSecond < PlotConstant.ZEROR_D) { mult = mult + 1; } timeSecond = separatorSecond * mult; } //绘制时间 DateTime time = plotPara.BaseTime.AddSeconds(timeSecond); DateTime endTime = plotPara.BaseTime.AddMilliseconds(endTimeMillisecond); float labelHeight = rectangleTimeArea.Height / 3; float y1 = rectangleTimeArea.Y + rectangleTimeArea.Height; float y2 = y1 - labelHeight; float y3 = y1 - labelHeight / 2; float labelX, labelSmallX; double separatorSecondHalf = separatorSecond / 2; float secondLength = (float)(axisX.Area.Width / (durationTimeMillisecond / 1000)); string labelText; SizeF labelTextSize; float labelTextX, lastLabelTextRightX = 0f; float labelTextY = rectangleTimeArea.Y + labelHeight / 2; AxisLabelLocation labelTextLocation = AxisLabelLocation.First; var contentWidth = axisX.Area.Width; Pen pen = axisX.Pen; while (true) { //刻度-x labelX = (float)(secondLength * (timeSecond - beginTimeSecond)); labelSmallX = (float)(secondLength * (timeSecond - beginTimeSecond - separatorSecondHalf)); //绘制刻度文本 labelText = this.GetLabelText(time, separatorSecond); labelTextSize = graphics.MeasureString(labelText, axisX.Font); labelTextX = labelX - labelTextSize.Width / 2; switch (labelTextLocation) { case AxisLabelLocation.First: if (labelTextX < PlotConstant.ZEROR_D && beginTimeMillisecond <= PlotConstant.ZEROR_D) { labelTextX = (float)PlotConstant.ZEROR_D; } labelTextLocation = AxisLabelLocation.Middle; break; case AxisLabelLocation.Middle: if (labelTextX + labelTextSize.Width - contentWidth > PlotConstant.ZEROR_D) { labelTextX = contentWidth - labelTextSize.Width; } break; case AxisLabelLocation.Last: if (labelTextX + labelTextSize.Width - contentWidth > PlotConstant.ZEROR_D) { labelTextX = contentWidth - labelTextSize.Width; if (labelTextX - lastLabelTextRightX < PlotConstant.ZEROR_D) { if (labelSmallX - contentWidth < PlotConstant.ZEROR_D) { graphics.DrawLine(pen, labelSmallX, y1, labelSmallX, y3); } return; } } break; default: throw new NotImplementedException(); } graphics.DrawString(labelText, axisX.Font, axisX.ForeColor, labelTextX, labelTextY); lastLabelTextRightX = labelTextX + labelTextSize.Width; //绘制刻度 if (labelSmallX > PlotConstant.ZEROR_D) { graphics.DrawLine(pen, labelSmallX, y1, labelSmallX, y3); } if (labelX - contentWidth < PlotConstant.ZEROR_D) { graphics.DrawLine(pen, labelX, y1, labelX, y2); } if (labelTextLocation == AxisLabelLocation.Last) { break; } timeSecond += separatorSecond; time = plotPara.BaseTime.AddSeconds(timeSecond); if (time >= endTime) { time = endTime; labelTextLocation = AxisLabelLocation.Last; } } }