示例#1
0
 private void ReadyWaves()
 {
     for (int i = 0; i < _WaveCount; ++i)
     {
         WaveProperty wp = _Waves[i];
         wp.Values = new double[_PointCount];
         for (int j = 0; j < this._PointCount; ++j)
         {
             wp.Values[j] = (wp.Max - wp.Min) / _WaveCount * (i + 0.5);
         }
     }
     valIndex   = _PointCount - 1;
     valueCount = 0;
 }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            int      h = this.Height;
            int      w = this.Width;

            if (!Authed || Expired)
            {
                SizeF size = g.MeasureString(AU_str, AU_font);
                Color c    = Color.FromArgb(255 - BackColor.R, 255 - BackColor.G, 255 - BackColor.B);
                g.DrawString(AU_str, AU_font, new SolidBrush(c), new PointF(w - size.Width, h - size.Height));
            }



            // 网格
            if (this._ShowGrid)
            {
                int gw = (int)(w / _GridSize);
                for (int i = 0; i <= gw; ++i)
                {
                    g.DrawLine(_GridPen, i * _GridSize, 0, i * _GridSize, h);
                }
                int gh = (int)(h / _GridSize);
                for (int i = 0; i <= gh; ++i)
                {
                    g.DrawLine(_GridPen, 0, i * _GridSize, w, i * _GridSize);
                }
            }

            if (Expired)
            {
                return;
            }

            if (this._WaveCount > 0)
            {
                // 绘制各个波
                int stix = (valIndex) % _PointCount;
                for (int i = 0; i < _WaveCount; ++i)
                {
                    WaveProperty wp = _Waves[i];
                    if (!wp.Enable)
                    {
                        continue;
                    }
                    double k = wp.Max == wp.Min ? 0 : (this.Height - 8) / (wp.Max - wp.Min);
                    for (int j = 0; j < (this._PointCount - 1); ++j)
                    {
                        int cj = (stix + j) % _PointCount;
                        int nj = (stix + j + 1) % _PointCount;
                        if (cj > valueCount)
                        {
                            continue;
                        }
                        int y1 = h - (int)((wp.Values[cj] - wp.Min) * k) - 4;
                        int y2 = h - (int)((wp.Values[nj] - wp.Min) * k) - 4;
                        if (y1 < 0)
                        {
                            y1 = 0;
                        }
                        if (y1 > h)
                        {
                            y1 = h;
                        }

                        if (y2 < 0)
                        {
                            y2 = 0;
                        }
                        if (y2 > h)
                        {
                            y2 = h;
                        }

                        g.DrawLine(wp.Pen, xLocations[j], y1, xLocations[j + 1], y2);
                    }
                }


                // 位置线
                if (_ShowValueLine && _ValueLineIndex >= 0)
                {
                    g.DrawLine(_ValueLinePen, xLocations[_ValueLineIndex], 0, xLocations[_ValueLineIndex], h);
                    int ix = (valIndex + _ValueLineIndex) % _PointCount;
                    for (int j = 0; j < _WaveCount; ++j)
                    {
                        WaveProperty wp = _Waves[j];
                        wp.CurVal = wp.Values[ix];
                    }
                }

                // 标注
                if (_ShowLegend)
                {
                    int titleh = 20;
                    int titlel = 20;
                    for (int i = 0; i < _WaveCount; ++i)
                    {
                        WaveProperty wp = _Waves[i];
                        if (wp.ShowTitle)
                        {
                            g.DrawLine(wp.Pen, 0, titleh * i + titleh / 2, titlel, titleh * i + titleh / 2);
                            g.DrawString(wp.GetTitle(), new Font(FontFamily.Families[0], titleh / 2), wp.Brush, new Point(titlel, titleh * i));
                        }
                    }
                }
            }
            else
            {
                // 没有波形事的图案
                SizeF  size = g.MeasureString(AU_str, AU_font);
                Font   font = new Font(FontFamily.Families[0], 24);
                String s    = "MultiWaveView";
                SizeF  sz   = g.MeasureString(s, font);
                g.DrawString(s, font, Brushes.Red, new PointF((w - sz.Width) / 2, (h - sz.Height) / 2));
            }
        }