Esempio n. 1
0
        public override void draw(Graphics graphics, float parentAlpha)
        {
            // update our hoved item if the mouse is over the list
            if (_isMouseOverList)
            {
                var mousePos = screenToLocalCoordinates(stage.getMousePosition());
                _hoveredItemIndex = getItemIndexUnderMousePosition(mousePos);
            }

            validate();

            var font             = _style.font;
            var selectedDrawable = _style.selection;

            var color = getColor();

            color = new Color(color, color.A * parentAlpha);

            float x = getX(), y = getY(), width = getWidth(), height = getHeight();
            var   itemY = 0f;

            var background = _style.background;

            if (background != null)
            {
                background.draw(graphics, x, y, width, height, color);
                var leftWidth = background.leftWidth;
                x     += leftWidth;
                itemY += background.topHeight;
                width -= leftWidth + background.rightWidth;
            }

            var   unselectedFontColor = new Color(_style.fontColorUnselected, _style.fontColorUnselected.A * parentAlpha);
            var   selectedFontColor   = new Color(_style.fontColorSelected, _style.fontColorSelected.A * parentAlpha);
            var   hoveredFontColor    = new Color(_style.fontColorHovered, _style.fontColorHovered.A * parentAlpha);
            Color fontColor;

            for (var i = 0; i < _items.Count; i++)
            {
                if (!_cullingArea.HasValue || (itemY - _itemHeight <= _cullingArea.Value.Y + _cullingArea.Value.Height && itemY >= _cullingArea.Value.Y))
                {
                    var item     = _items[i];
                    var selected = _selection.contains(item);
                    if (selected)
                    {
                        selectedDrawable.draw(graphics, x, y + itemY, width, _itemHeight, color);
                        fontColor = selectedFontColor;
                    }
                    else if (i == _hoveredItemIndex && _style.hoverSelection != null)
                    {
                        _style.hoverSelection.draw(graphics, x, y + itemY, width, _itemHeight, color);
                        fontColor = hoveredFontColor;
                    }
                    else
                    {
                        fontColor = unselectedFontColor;
                    }

                    var textPos = new Vector2(x + _textOffsetX, y + itemY + _textOffsetY);
                    graphics.batcher.drawString(font, item.ToString(), textPos, fontColor);
                }
                else if (itemY < _cullingArea.Value.Y)
                {
                    break;
                }

                itemY += _itemHeight;
            }
        }