Exemple #1
0
    /// <summary>
    /// Draw a graph into the scene using the given parameters.
    /// </summary>
    /// <param name="posX">Bottom left X coordinate.</param>
    /// <param name="posY">Bottom left Y coordinate.</param>
    /// <param name="sizeX">Size of the graph in X direction. Must be lower than or equal to data array size!</param>
    /// <param name="sizeY">Size of the graph in Y direction. Any value higher than this will be clamped and treated as "outlier".</param>
    /// <param name="data">Data source for the graph.</param>
    /// <param name="color_graph">Color used for drawing the graph.</param>
    /// <param name="color_outlier">Color used to highlight outliers.</param>
    void DrawGraph(float posX, float posY, int sizeX, int sizeY, float[] data, int color_graph, int color_outlier)
    {
        int color_background = Game.ColorFromArgb(80, 0, 0, 0);

        // draw background
        const int margin = 4;

        m.Draw2dTexture(m.WhiteTexture(), posX - margin, posY + margin, sizeX + 2 * margin, -sizeY - 2 * margin, null, color_background);

        // assemble the graph
        for (int i = 0; i < sizeX; i++)
        {
            todraw[i].x1        = posX + i;
            todraw[i].y1        = posY - data[i];
            todraw[i].width     = 1;
            todraw[i].height    = data[i];
            todraw[i].inAtlasId = null;
            todraw[i].color     = color_graph;
            if (data[i] > sizeY)
            {
                // value too big. clamp and mark
                todraw[i].y1     = posY - sizeY;
                todraw[i].height = sizeY;
                todraw[i].color  = color_outlier;
            }
        }
        // draw the result
        m.Draw2dTextures(todraw, sizeX, m.WhiteTexture());
    }
    void DrawGraph()
    {
        float maxtime = 0;

        for (int i = 0; i < MaxCount; i++)
        {
            float v = dtHistory[i];
            if (v > maxtime)
            {
                maxtime = v;
            }
        }
        int historyheight = 80;
        int posx          = 25;
        int posy          = m.GetWindowHeight() - historyheight - 20;

        int[] colors = new int[2];
        colors[0] = Game.ColorFromArgb(255, 0, 0, 0);
        colors[1] = Game.ColorFromArgb(255, 255, 0, 0);
        int linecolor = Game.ColorFromArgb(255, 255, 255, 255);

        for (int i = 0; i < MaxCount; i++)
        {
            float time = dtHistory[i];
            time = (time * 60) * historyheight;
            int c = InterpolationCi.InterpolateColor(m.GetPlatform(), (one * i) / MaxCount, colors, 2);
            todraw[i].x1        = posx + i;
            todraw[i].y1        = posy - time;
            todraw[i].width     = 1;
            todraw[i].height    = time;
            todraw[i].inAtlasId = null;
            todraw[i].color     = c;
        }
        m.Draw2dTextures(todraw, MaxCount, m.WhiteTexture());

        m.Draw2dTexture(m.WhiteTexture(), posx, posy - historyheight, MaxCount, 1, null, linecolor);
        m.Draw2dTexture(m.WhiteTexture(), posx, posy - historyheight * (one * 60 / 75), MaxCount, 1, null, linecolor);
        m.Draw2dTexture(m.WhiteTexture(), posx, posy - historyheight * (one * 60 / 30), MaxCount, 1, null, linecolor);
        m.Draw2dTexture(m.WhiteTexture(), posx, posy - historyheight * (one * 60 / 150), MaxCount, 1, null, linecolor);
        m.Draw2dText("60", posx, posy - historyheight * (one * 60 / 60), 6);
        m.Draw2dText("75", posx, posy - historyheight * (one * 60 / 75), 6);
        m.Draw2dText("30", posx, posy - historyheight * (one * 60 / 30), 6);
        m.Draw2dText("150", posx, posy - historyheight * (one * 60 / 150), 6);
    }