Ejemplo n.º 1
0
        public override void DrawRect(CGRect dirtyRect)
        {
            var context = NSGraphicsContext.CurrentContext.GraphicsPort;

            // Engine.Instance.Stats.Charts.Hit (RandomGenerator.GetInt (1024, 1024 * 1024), RandomGenerator.GetInt (1024, 1024 * 1024)); // Debugging

            context.SetFillColor(m_colorBackground);
            context.FillRect(dirtyRect);

            NSColor.Gray.Set();
            NSBezierPath.StrokeRect(Bounds);


            nfloat DX = this.Bounds.Size.Width;
            nfloat DY = this.Bounds.Size.Height;

            m_chartDX     = DX;
            m_chartDY     = DY - m_legendDY;
            m_chartStartX = 0;
            m_chartStartY = m_chartDY;


            float maxY = m_chart.GetMax();

            if (maxY <= 0)
            {
                maxY = 4096;
            }
            else if (maxY > 1000000000000)
            {
                maxY = 1000000000000;
            }

            CGPoint lastPointDown = new CGPoint(-1, -1);
            CGPoint lastPointUp   = new CGPoint(-1, -1);

            nfloat stepX = (m_chartDX - 0) / m_chart.Resolution;

            // Grid lines
            for (int g = 0; g < m_chart.Grid; g++)
            {
                nfloat x = ((m_chartDX - 0) / m_chart.Grid) * g;
                DrawLine(context, m_colorGrid, m_chartStartX + x, 0, m_chartStartX + x, m_chartStartY);
            }

            // Axis line
            DrawLine(context, m_colorAxis, 0, m_chartStartY, m_chartDX, m_chartStartY);

            // Legend

            /*
             * {
             *      string legend = "";
             *      legend += LanguageManager.GetText("ChartRange") + ": " + Utils.FormatSeconds(m_chart.Resolution * m_chart.TimeStep);
             *      legend += "   ";
             *      legend += LanguageManager.GetText("ChartGrid") + ": " + Utils.FormatSeconds(m_chart.Resolution / m_chart.Grid * m_chart.TimeStep);
             *      legend += "   ";
             *      legend += LanguageManager.GetText("ChartStep") + ": " + Utils.FormatSeconds(m_chart.TimeStep);
             *
             *      Point mp = Cursor.Position;
             *      mp = PointToClient(mp);
             *      if ((mp.X > 0) && (mp.Y < chartDX) && (mp.Y > chartDY) && (mp.Y < DY))
             *              legend += " - " + LanguageManager.GetText("ChartClickToChangeResolution");
             *
             *      e.Graphics.DrawString(legend, FontLabel, BrushLegendText, ChartRectangle(0, chartStartY, chartDX, m_legendDY), formatTopCenter);
             * }
             */


            // Graph
            for (int i = 0; i < m_chart.Resolution; i++)
            {
                int p = i + m_chart.Pos + 1;
                if (p >= m_chart.Resolution)
                {
                    p -= m_chart.Resolution;
                }

                nfloat downY = ((m_chart.Download[p]) * (m_chartDY - m_marginTopY)) / maxY;
                nfloat upY   = ((m_chart.Upload[p]) * (m_chartDY - m_marginTopY)) / maxY;

                CGPoint pointDown = ChartPoint(m_chartStartX + stepX * i, m_chartStartY - downY);
                CGPoint pointUp   = ChartPoint(m_chartStartX + stepX * i, m_chartStartY - upY);

                //e.Graphics.DrawLine(Pens.Green, new Point(0,0), point);

                if (lastPointDown.X != -1)
                {
                    DrawLine(context, m_colorDownloadGraph, lastPointDown, pointDown);
                    DrawLine(context, m_colorUploadGraph, lastPointUp, pointUp);
                }

                lastPointDown = pointDown;
                lastPointUp   = pointUp;
            }

            // Download line
            nfloat downCurY = 0;
            {
                long v = m_chart.GetLastDownload();
                downCurY = ((v) * (m_chartDY - m_marginTopY)) / maxY;
                DrawLine(context, m_colorDownloadLine, 0, m_chartStartY - downCurY, m_chartDX, m_chartStartY - downCurY);
                DrawStringOutline(context, LanguageManager.GetText("ChartDownload") + ": " + ValToDesc(v), m_colorDownloadText, ChartRectangle(0, 0, m_chartDX - 10, m_chartStartY - downCurY), 8);
            }

            // Upload line
            {
                long   v   = m_chart.GetLastUpload();
                nfloat y   = ((v) * (m_chartDY - m_marginTopY)) / maxY;
                nfloat dly = 0;
                if (Math.Abs(downCurY - y) < 10)
                {
                    dly = 15;                                              // Download and upload overwrap, distance it.
                }
                DrawLine(context, m_colorUploadLine, 0, m_chartStartY - y, m_chartDX, m_chartStartY - y);
                DrawStringOutline(context, LanguageManager.GetText("ChartUpload") + ": " + ValToDesc(v), m_colorUploadText, ChartRectangle(0, 0, m_chartDX - 10, m_chartStartY - y - dly), 8);
            }

            // Mouse lines
            {
                CGPoint mp = Window.MouseLocationOutsideOfEventStream;
                mp.X -= this.Frame.Left;
                mp.Y -= this.Frame.Top;
                //mp = ParentWindow.ConvertPointToView (mp, this);

                mp = Invert(mp);

                //mp = Window.ConvertScreenToBase (mp);

                if ((mp.X > 0) && (mp.Y < m_chartDX) && (mp.Y > 0) && (mp.Y < m_chartDY))
                {
                    DrawLine(context, m_colorMouse, 0, mp.Y, m_chartDX, mp.Y);
                    DrawLine(context, m_colorMouse, mp.X, 0, mp.X, m_chartDY);

                    nfloat i = (m_chartDX - (mp.X - m_chartStartX)) / stepX;

                    int t = Conversions.ToInt32(i * m_chart.TimeStep);

                    //float y = mp.Y * maxY / (chartDY - m_marginTopY);
                    nfloat y = (m_chartStartY - (mp.Y - m_marginTopY)) * maxY / m_chartDY;

                    String label = ValToDesc(Conversions.ToInt64(y)) + ", " + LanguageManager.FormatSeconds(t) + " ago";

                    int formatAlign = 6;

                    CGRect rect = new CGRect();
                    if (DX - mp.X > DX / 2)
                    //if (mp.X < DX - 200)
                    {
                        if (DY - mp.Y > DY / 2)
                        //if (mp.Y < 20)
                        {
                            formatAlign = 0;
                            rect.X      = mp.X + 5;
                            rect.Y      = mp.Y + 5;
                            rect.Width  = DX;
                            rect.Height = DX;
                        }
                        else
                        {
                            formatAlign = 6;
                            rect.X      = mp.X + 5;
                            rect.Y      = 0;
                            rect.Width  = DX;
                            rect.Height = mp.Y - 5;
                        }
                    }
                    else
                    {
                        if (DY - mp.Y > DY / 2)
                        //if (mp.Y < 40)
                        {
                            formatAlign = 2;
                            rect.X      = 0;
                            rect.Y      = mp.Y;
                            rect.Width  = mp.X - 5;
                            rect.Height = DY;
                        }
                        else
                        {
                            formatAlign = 8;
                            rect.X      = 0;
                            rect.Y      = 0;
                            rect.Width  = mp.X - 5;
                            rect.Height = mp.Y - 5;
                        }
                    }

                    DrawStringOutline(context, label, m_colorMouse, rect, formatAlign);
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            //base.OnPaint(e);
            Form.Skin.GraphicsCommon(e.Graphics);

            try
            {
                int DX = this.ClientRectangle.Width;
                int DY = this.ClientRectangle.Height;

                //e.Graphics.FillRectangle(BrushBackground, this.ClientRectangle);
                Form.DrawImage(e.Graphics, GuiUtils.GetResourceImage("tab_l_bg"), new Rectangle(0, 0, ClientSize.Width, ClientSize.Height));

                m_chartDX     = this.ClientRectangle.Width;
                m_chartDY     = this.ClientRectangle.Height - m_legendDY;
                m_chartStartX = 0;
                m_chartStartY = m_chartDY;


                float maxY = m_chart.GetMax();
                if (maxY <= 0)
                {
                    maxY = 4096;
                }
                else if (maxY > 1000000000000)
                {
                    maxY = 1000000000000;
                }

                Point lastPointDown = new Point(-1, -1);
                Point lastPointUp   = new Point(-1, -1);

                float stepX = (m_chartDX - 0) / m_chart.Resolution;

                // Grid lines
                for (int g = 0; g < m_chart.Grid; g++)
                {
                    float x = ((m_chartDX - 0) / m_chart.Grid) * g;
                    e.Graphics.DrawLine(m_penGrid, m_chartStartX + x, 0, m_chartStartX + x, m_chartStartY);
                }

                // Axis line
                e.Graphics.DrawLine(Pens.Gray, 0, m_chartStartY, m_chartDX, m_chartStartY);

                // Legend

                /*
                 * {
                 *      string legend = "";
                 *      legend += Messages.ChartRange + ": " + Utils.FormatSeconds(m_chart.Resolution * m_chart.TimeStep);
                 *      legend += "   ";
                 *      legend += Messages.ChartGrid + ": " + Utils.FormatSeconds(m_chart.Resolution / m_chart.Grid * m_chart.TimeStep);
                 *      legend += "   ";
                 *      legend += Messages.ChartStep + ": " + Utils.FormatSeconds(m_chart.TimeStep);
                 *
                 *      Point mp = Cursor.Position;
                 *      mp = PointToClient(mp);
                 *      if ((mp.X > 0) && (mp.Y < chartDX) && (mp.Y > chartDY) && (mp.Y < DY))
                 *              legend += " - " + Messages.ChartClickToChangeResolution;
                 *
                 *      e.Graphics.DrawString(legend, FontLabel, BrushLegendText, ChartRectangle(0, chartStartY, chartDX, m_legendDY), formatTopCenter);
                 * }
                 */

                // Graph
                for (int i = 0; i < m_chart.Resolution; i++)
                {
                    int p = i + m_chart.Pos + 1;
                    if (p >= m_chart.Resolution)
                    {
                        p -= m_chart.Resolution;
                    }

                    float downY = ((m_chart.Download[p]) * (m_chartDY - m_marginTopY)) / maxY;
                    float upY   = ((m_chart.Upload[p]) * (m_chartDY - m_marginTopY)) / maxY;

                    Point pointDown = ChartPoint(m_chartStartX + stepX * i, m_chartStartY - downY);
                    Point pointUp   = ChartPoint(m_chartStartX + stepX * i, m_chartStartY - upY);

                    //e.Graphics.DrawLine(Pens.Green, new Point(0,0), point);

                    if (lastPointDown.X != -1)
                    {
                        e.Graphics.DrawLine(m_penDownloadGraph, lastPointDown, pointDown);
                        e.Graphics.DrawLine(m_penUploadGraph, lastPointUp, pointUp);
                    }

                    lastPointDown = pointDown;
                    lastPointUp   = pointUp;
                }

                // Download line
                float downCurY = 0;
                {
                    long v = m_chart.GetLastDownload();
                    downCurY = ((v) * (m_chartDY - m_marginTopY)) / maxY;
                    e.Graphics.DrawLine(m_penDownloadLine, 0, m_chartStartY - downCurY, m_chartDX, m_chartStartY - downCurY);
                    Form.DrawStringOutline(e.Graphics, LanguageManager.GetText("ChartDownload") + ": " + ValToDesc(v), FontLabel, m_brushDownloadText, ChartRectangle(0, 0, m_chartDX, m_chartStartY - downCurY), formatBottomRight);
                }

                // Upload line
                {
                    long  v   = m_chart.GetLastUpload();
                    float y   = ((v) * (m_chartDY - m_marginTopY)) / maxY;
                    float dly = 0;
                    if (Math.Abs(downCurY - y) < 10)
                    {
                        dly = 15;                                                  // Download and upload overwrap, distance it.
                    }
                    e.Graphics.DrawLine(m_penUploadLine, 0, m_chartStartY - y, m_chartDX, m_chartStartY - y);
                    Form.DrawStringOutline(e.Graphics, LanguageManager.GetText("ChartUpload") + ": " + ValToDesc(v), FontLabel, m_brushUploadText, ChartRectangle(0, 0, m_chartDX, m_chartStartY - y - dly), formatBottomRight);
                }

                // Mouse lines
                {
                    Point mp = Cursor.Position;
                    mp = PointToClient(mp);

                    if ((mp.X > 0) && (mp.Y < m_chartDX) && (mp.Y > 0) && (mp.Y < m_chartDY))
                    {
                        e.Graphics.DrawLine(m_penMouse, 0, mp.Y, m_chartDX, mp.Y);
                        e.Graphics.DrawLine(m_penMouse, mp.X, 0, mp.X, m_chartDY);

                        float i = (m_chartDX - (mp.X - m_chartStartX)) / stepX;

                        int t = Conversions.ToInt32(i * m_chart.TimeStep);

                        //float y = mp.Y * maxY / (chartDY - m_marginTopY);
                        float y = (m_chartStartY - (mp.Y - m_marginTopY)) * maxY / m_chartDY;

                        String label = ValToDesc(Conversions.ToInt64(y)) + ", " + LanguageManager.FormatSeconds(t) + " ago";

                        StringFormat formatAlign = formatBottomLeft;
                        Rectangle    rect        = new Rectangle();
                        //if(DX - mp.X > DX / 2)
                        if (mp.X < DX - 150)
                        {
                            //if (DY - mp.Y > DY / 2)
                            if (mp.Y < 20)
                            {
                                formatAlign = formatTopLeft;
                                rect.X      = mp.X + 20;
                                rect.Y      = mp.Y + 5;
                                rect.Width  = DX;
                                rect.Height = DX;
                            }
                            else
                            {
                                formatAlign = formatBottomLeft;
                                rect.X      = mp.X + 20;
                                rect.Y      = 0;
                                rect.Width  = DX;
                                rect.Height = mp.Y - 5;
                            }
                        }
                        else
                        {
                            //if (DY - mp.Y > DY / 2)
                            if (mp.Y < 20)
                            {
                                formatAlign = formatTopRight;
                                rect.X      = 0;
                                rect.Y      = mp.Y;
                                rect.Width  = mp.X - 20;
                                rect.Height = DY;
                            }
                            else
                            {
                                formatAlign = formatBottomRight;
                                rect.X      = 0;
                                rect.Y      = 0;
                                rect.Width  = mp.X - 20;
                                rect.Height = mp.Y - 5;
                            }
                        }

                        Form.DrawStringOutline(e.Graphics, label, FontLabel, m_brushMouse, rect, formatAlign);
                    }
                }
            }
            catch
            {
            }
        }