Example #1
0
    // OnRender
    protected override void OnRender()
    {
        if ((Texture == null) || (Font == null))
        {
            return;
        }

        Color colour        = Color.White;
        Color colourCurrent = Color.Orange;

        float x = Padding;
        float y = Padding;

        SpriteBatch.Begin();

        // backing
        Color c1 = Color.Black * 0.85f;
        Color c2 = Color.Black * 0.85f;

        float sx1 = (SizeX1 + Padding);
        float sx2 = (SizeX2 + Padding);

        SpriteBatch.Draw(Texture, new Rectangle((int)(x - (Padding * 0.5f)), (int)(y - (Padding * 0.5f)), (int)sx1, (int)(SizeY + Padding)), new Rectangle(1, 1, 30, 30), c1);
        SpriteBatch.Draw(Texture, new Rectangle((int)(x + sx1 - (Padding * 0.5f)), (int)(y - (Padding * 0.5f)), (int)sx2, (int)(SizeY + Padding)), new Rectangle(1, 1, 30, 30), c2);

        // options - start at top
        Debug.MenuItem v = (Current.Parent != null) ? Current.Parent.Child1 : Current;

        // find out what index we're at
        // - could probs just update this on up/down instead
        int index = 0;

        for (Debug.MenuItem vv = v; ((vv != null) && (vv != Current)); vv = vv.Next)
        {
            ++index;
        }

        // what we shall render
        int low = index - (MaxRenderCount / 2);

        if (low < 0)
        {
            low = 0;
        }

        int high = low + MaxRenderCount - 1;

        if (high >= Count)
        {
            high = Count - 1;
            low  = Count - MaxRenderCount;
        }

        // now render down
        int sCount = 0;

        for ( ; v != null; ++sCount, v = v.Next)
        {
            if ((sCount < low) || (sCount > high))
            {
                continue;
            }

            x = Padding;

            Color c = (v == Current) ? colourCurrent : colour;

            SpriteBatch.DrawString(Font, v.Name, new Vector2(x, y), c);

            Vector2 size = Font.MeasureString(v.AsString(TempString));
            SpriteBatch.DrawString(Font, TempString, new Vector2(x + SizeX1 + (SizeX2 / 2.0f) + Padding - (size.X / 2.0f), y), c);

            // arrows
            if (v == Current)
            {
                int yt = (int)(y + (H / 2.0f) - (ArrowH / 2.0f));

                if (CanDecrease())
                {
                    SpriteBatch.Draw(Texture, new Rectangle((int)(x + SizeX1 + Padding), yt, (int)ArrowH, (int)ArrowH), new Rectangle(64, 0, -32, 32), c);
                }
                if (CanIncrease())
                {
                    SpriteBatch.Draw(Texture, new Rectangle((int)(x + SizeX1 + SizeX2 - ArrowH + Padding), yt, (int)ArrowH, (int)ArrowH), new Rectangle(32, 0, 32, 32), c);
                }
            }

            y += H;
        }

        SpriteBatch.End();
    }