Exemple #1
0
        public override void Draw(Batcher batcher, float parentAlpha)
        {
            Validate();

            IDrawable background;

            if (_isDisabled && style.BackgroundDisabled != null)
            {
                background = style.BackgroundDisabled;
            }
            else if (_selectBoxList.HasParent() && style.BackgroundOpen != null)
            {
                background = style.BackgroundOpen;
            }
            else if (_isMouseOver && style.BackgroundOver != null)
            {
                background = style.BackgroundOver;
            }
            else if (style.Background != null)
            {
                background = style.Background;
            }
            else
            {
                background = null;
            }

            var font      = style.Font;
            var fontColor = _isDisabled ? style.DisabledFontColor : style.FontColor;

            var color = GetColor();

            color = ColorExt.Create(color, (int)(color.A * parentAlpha));
            float x      = GetX();
            float y      = GetY();
            float width  = GetWidth();
            float height = GetHeight();

            if (background != null)
            {
                background.Draw(batcher, x, y, width, height, color);
            }

            var selected = _selection.First();

            if (selected != null)
            {
                var str = selected.ToString();
                if (background != null)
                {
                    width  -= background.LeftWidth + background.RightWidth;
                    height -= background.BottomHeight + background.TopHeight;
                    x      += background.LeftWidth;
                    y      += (int)(height / 2 + background.BottomHeight - font.LineHeight / 2);
                }
                else
                {
                    y += (int)(height / 2 + font.LineHeight / 2);
                }

                fontColor = ColorExt.Create(fontColor, (int)(fontColor.A * parentAlpha));
                batcher.DrawString(font, str, new Vector2(x, y), fontColor);
            }
        }
Exemple #2
0
 /// <summary>
 /// Returns the first selected item, or null
 /// </summary>
 /// <returns>The selected.</returns>
 public T GetSelected()
 {
     return(_selection.First());
 }