예제 #1
0
        /// <summary>
        /// Contains abstract Draw logic for the Menu.
        /// </summary>
        /// <param name="spriteBatch">The SpriteBatch</param>
        protected internal void DrawMenu(SpriteBatch spriteBatch)
        {
            int i = 0;

            foreach (MenuElement element in this._menu.GetDrawableMenuElements())
            {
                //Draw in this order:
                //  BackgroundColor
                //  Texture
                //  Font
                if (element.BackgroundColor.PackedValue != 0)
                {
                    int   activeMenuIndex = _menu.GetActiveMenuIndex();
                    Color bgcolor;
                    bool  currentElementIsActive = this._menu.GetDrawableMenuElements()[i].Equals(this._menu.GetSelectableMenuElements()[activeMenuIndex]);
                    if (currentElementIsActive)
                    {
                        if (element.ActiveBackgroundColor.PackedValue != 0)
                        {
                            bgcolor = element.ActiveBackgroundColor;
                        }
                        else
                        {
                            bgcolor = element.BackgroundColor;
                        }
                    }
                    else
                    {
                        bgcolor = element.BackgroundColor;
                    }

                    _drawingHelper.DefaultDrawRectangle(ref spriteBatch, element.ActiveArea, ref blank, bgcolor);
                }

                if (element.GetTexture() != null)
                {
                    spriteBatch.Draw(element.GetTexture(), element.ActiveArea, Color.White);
                }

                if (element.GetFont() != null && !string.IsNullOrEmpty(element.MenuText))
                {
                    int   activeMenuIndex = _menu.GetActiveMenuIndex();
                    Color fgcolor;

                    MenuElement drawingElemTmp         = this._menu.GetDrawableMenuElements()[i];
                    MenuElement selectedElemTmp        = this._menu.GetSelectableMenuElements()[activeMenuIndex];
                    bool        currentElementIsActive = this._menu.GetDrawableMenuElements()[i].Equals(this._menu.GetSelectableMenuElements()[activeMenuIndex]);
                    if (currentElementIsActive)
                    {
                        if (element.ActiveForegroundColor.PackedValue != 0)
                        {
                            fgcolor = element.ActiveForegroundColor;
                        }
                        else
                        {
                            fgcolor = element.ForegroundColor;
                        }
                    }
                    else
                    {
                        fgcolor = element.ForegroundColor;
                    }

                    spriteBatch.DrawString(element.GetFont(), element.MenuText, new Vector2(element.ActiveArea.X, element.ActiveArea.Y), fgcolor);
                }
                i++;
            }
        }