protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
int clientWidth = ClientRectangle.Width;
int clientHeight = ClientRectangle.Height;
// fill with background
g.FillRectangle(backgroundBrush, 0, 0, clientWidth - 1, clientHeight - 1);
// draw borders
g.DrawRectangle(bordersPen, 0, 0, clientWidth - 1, clientHeight - 1);
if (DesignMode)
return;
DoubleRange rangeClientX = new DoubleRange(0, clientWidth);
DoubleRange rangeClientY = new DoubleRange(clientHeight, 0);
// walk through all data series
foreach (Waveform waveform in waveTable.Values)
{
// get data of the waveform
float[] data = waveform.data;
// check for available data
if (data == null) continue;
using (Pen pen = new Pen(waveform.color, waveform.width))
{
if (SimpleMode)
{
int blockSize = waveform.samples / clientWidth;
for (int x = 0; x < clientWidth; x++)
{
double max = data.RootMeanSquare(x * blockSize, blockSize);
int y = clientHeight / 2 + (int)(max * clientHeight);
g.DrawLine(pen, x, clientHeight - y, x, y);
}
}
else
{
int xPrev = 0;
int yPrev = (int)Vector.Scale(data[0], rangeY, rangeClientY);
for (int x = 0; x < clientWidth; x++)
{
int index = (int)Vector.Scale(x, rangeClientX, rangeX);
if (index < 0 || index >= data.Length)
index = data.Length - 1;
int y = (int)Vector.Scale(data[index], rangeY, rangeClientY);
g.DrawLine(pen, xPrev, yPrev, x, y);
xPrev = x;
yPrev = y;
}
}
}
}
}