示例#1
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            ISceneDrawable background;

            if (_list != null && _list.Parent != null && _style.BackgroundOpen != null)
            {
                background = _style.BackgroundOpen;
            }
            else if (IsDisabled && _style.BackgroundDisabled != null)
            {
                background = _style.BackgroundDisabled;
            }
            else if (_pointerIsOver && _style.BackgroundOver != null)
            {
                background = _style.BackgroundOver;
            }
            else
            {
                background = _style.Background;
            }

            BitmapFont font      = _style.Font;
            Color      fontColor = _style.FontColor;

            if (IsDisabled && _style.FontColorDisabled != null)
            {
                fontColor = _style.FontColorDisabled.Value;
            }

            float x      = (int)X;
            float y      = (int)Y;
            float width  = Width;
            float height = Height;

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
            background.Draw(spriteBatch, x, y, width, height);

            if (_items.Length > 0)
            {
                float availableWidth = width - background.LeftWidth - background.RightWidth;
                int   numGlyphs      = font.ComputeVisibleGlyphs(_itemsText[SelectionIndex], 0, _itemsText[SelectionIndex].Length, availableWidth);
                _bounds = font.GetBounds(_itemsText[SelectionIndex]);

                height -= background.BottomHeight + background.TopHeight;
                float textY = (int)(height / 2 + background.BottomHeight + _bounds.Height / 2);

                font.Color = fontColor.MultiplyAlpha(parentAlpha);
                font.Draw(spriteBatch, _itemsText[SelectionIndex], x + background.LeftWidth, y + textY, 0, numGlyphs);
            }
        }