Exemplo n.º 1
0
        /// <summary>
        ///   Paints the control.
        /// </summary>
        ///
        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)rangeY.Scale(rangeClientY, data[0]);

                        for (int x = 0; x < clientWidth; x++)
                        {
                            int index = (int)rangeClientX.Scale(rangeX, x);
                            if (index < 0 || index >= data.Length)
                            {
                                index = data.Length - 1;
                            }
                            int y = (int)rangeY.Scale(rangeClientY, data[index]);

                            g.DrawLine(pen, xPrev, yPrev, x, y);

                            xPrev = x;
                            yPrev = y;
                        }
                    }
                }
            }
        }