Example #1
0
    // UpdateBounds
    protected void UpdateBounds()
    {
        Debug.MenuItem v = (Current.Parent != null) ? Current.Parent.Child1 : Current;

        Count  = 0;
        SizeX1 = 0.0f;
        SizeX2 = 0.0f;
        SizeY  = 0.0f;

        while (v != null)
        {
            SizeX1 = Math.Max(SizeX1, Font.MeasureString(v.Name).X);
            SizeY += H;

            ++Count;
            v = v.Next;
        }

        if (Count > MaxRenderCount)
        {
            SizeY = (MaxRenderCount * H);
        }

        SizeX2 = 200.0f + (ArrowH * 2.0f);           // TODO - properly - mebs
    }
Example #2
0
        // Menu
        public Menu()
        {
            Active = false;

            // create root
            Root = new MenuItem( "Root" );
            Current = Root;

            Init();
        }
Example #3
0
        // Init
        public void Init()
        {
            // add the vars
            for ( VarBaseD v = DebugVariables.Root; v != null; v = v.Next )
            {
            string[] items = v.Name.Split( '.' );
            MenuItem c = Root;

            // drill down - adding new levels if required
            for ( int i = 0; i < items.Length; ++i )
            {
                // attempt to find at this level
                MenuItem ci = null;

                for ( ci = c.Child1; ci != null; ci = ci.Next )
                {
                    if ( items[ i ] == ci.Name )
                    {
                        if ( ( i == ( items.Length - 1 ) ) || ( c.Child1 == null ) )
                            ci = null; // we've got a duplicate between a level and var or two vars with the same name

                        break;
                    }
                }

                if ( ci == null )
                {
                    // add new
                    if ( i == ( items.Length - 1 ) )
                        ci = new MenuItem( items[ i ], v ); // item
                    else
                        ci = new MenuItem( items[ i ] ); // submenu

                    c.Add( ci );
                }

                // move down to new level
                c = ci;
            }
            }
        }
Example #4
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();
    }
Example #5
0
        // Add
        public void Add( MenuItem v )
        {
            MenuItem i = Child1;
            MenuItem iPrev = null;

            while ( i != null )
            {
            if ( String.Compare( v.Name, i.Name ) < 0 ) // alpha sort
                break;

            iPrev = i;
            i = i.Next;
            }

            // add in-between iPrev and i
            v.Prev = iPrev;
            v.Next = i;

            if ( iPrev != null )
            iPrev.Next = v;
            else
            Child1 = v;

            if ( i != null )
            i.Prev = v;

            v.Parent = this;
        }
Example #6
0
 // Up
 protected void Up()
 {
     if ( Current.Prev != null )
     Current = Current.Prev;
     else
     while ( Current.Next != null )
         Current = Current.Next; // wrap to bottom
 }
Example #7
0
        // Next
        protected void Next()
        {
            if ( Current.Child1 != null )
            {
            Current = Current.Child1;
            OnNext();
            }
            else
            {
            if ( ( Current.Var != null ) && ( Current.Var.Type == E_VarType.Function ) )
            {
                FunctionD v = (FunctionD)Current.Var;

                if ( v.F != null )
                    v.F();
            }
            }
        }
Example #8
0
 // Down
 protected void Down()
 {
     if ( Current.Next != null )
     Current = Current.Next;
     else
     while ( Current.Prev != null )
         Current = Current.Prev; // wrap to top
 }
Example #9
0
 // Back
 protected void Back()
 {
     if ( Current.Parent != null )
     {
     Current = Current.Parent;
     OnBack();
     }
     else
     Active = false;
 }