Beyond_Beyaan.BBScrollBar.Initialize C# (CSharp) Метод

Initialize() публичный Метод

public Initialize ( int xPos, int yPos, int length, int amountOfVisibleItems, int amountOfItems, bool isHorizontal, bool isSlider, Random r, string &reason ) : bool
xPos int
yPos int
length int
amountOfVisibleItems int
amountOfItems int
isHorizontal bool
isSlider bool
r System.Random
reason string
Результат bool
        public bool Initialize(int xPos, int yPos, int length, int amountOfVisibleItems, int amountOfItems, bool isHorizontal, bool isSlider, Random r, out string reason)
        {
            this.xPos = xPos;
            this.yPos = yPos;
            Up = new BBButton();
            Down = new BBButton();
            Scroll = new BBUniStretchButton();

            this.amountOfItems = amountOfItems;
            this.amountVisible = amountOfVisibleItems;
            this.isSlider = isSlider;
            this.isHorizontal = isHorizontal;

            scrollBarLength = length - 32;

            if (!isSlider)
            {
                scrollButtonLength = (int)(((float)amountOfVisibleItems / amountOfItems) * scrollBarLength);
                if (!isHorizontal)
                {
                    if (!Up.Initialize("ScrollUpBGButton", "ScrollUpFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Down.Initialize("ScrollDownBGButton", "ScrollDownFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos + length - 16, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Scroll.Initialize(new List<string> { "ScrollVerticalBGButton1", "ScrollVerticalBGButton2", "ScrollVerticalBGButton3" },
                                           new List<string> { "ScrollVerticalFGButton1", "ScrollVerticalFGButton2", "ScrollVerticalFGButton3" },
                                           false, "", ButtonTextAlignment.LEFT, xPos, yPos + 16, 16, 7, 2, scrollButtonLength, r, out reason))
                    {
                        return false;
                    }
                    scrollBar = SpriteManager.GetSprite("ScrollVerticalBar", r);
                    if (scrollBar == null)
                    {
                        reason = "\"ScrollVerticalBar\" sprite does not exist";
                        return false;
                    }
                }
                else
                {
                    if (!Up.Initialize("ScrollLeftBGButton", "ScrollLeftFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Down.Initialize("ScrollRightBGButton", "ScrollRightFGButton", "", ButtonTextAlignment.CENTER, xPos + length - 16, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Scroll.Initialize(new List<string> { "ScrollHorizontalBGButton1", "ScrollHorizontalBGButton2", "ScrollHorizontalBGButton3" },
                                           new List<string> { "ScrollHorizontalFGButton1", "ScrollHorizontalFGButton2", "ScrollHorizontalFGButton3" },
                                           false, "", ButtonTextAlignment.LEFT, xPos + 16, yPos, 16, 7, 2, scrollButtonLength, r, out reason))
                    {
                        return false;
                    }
                    scrollBar = SpriteManager.GetSprite("ScrollHorizontalBar", r);
                    if (scrollBar == null)
                    {
                        reason = "\"ScrollHorizontalBar\" sprite does not exist";
                        return false;
                    }
                }
            }
            else
            {
                scrollButtonLength = 16;
                if (!Up.Initialize("ScrollLeftBGButton", "ScrollLeftFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                {
                    return false;
                }
                if (!Down.Initialize("ScrollRightBGButton", "ScrollRightFGButton", "", ButtonTextAlignment.CENTER, xPos + length - 16, yPos, 16, 16, r, out reason))
                {
                    return false;
                }
                if (!Scroll.Initialize(new List<string> { "SliderHorizontalBGButton1", "SliderHorizontalBGButton2", "SliderHorizontalBGButton3" },
                                       new List<string> { "SliderHorizontalFGButton1", "SliderHorizontalFGButton2", "SliderHorizontalFGButton3" },
                                       true, "", ButtonTextAlignment.LEFT, xPos + 16, yPos, 16, 7, 2, scrollButtonLength, r, out reason))
                {
                    return false;
                }
                scrollBar = SpriteManager.GetSprite("SliderBGBar", r);
                if (scrollBar == null)
                {
                    reason = "\"SliderBGBar\" sprite does not exist";
                    return false;
                }
                highlightedScrollBar = SpriteManager.GetSprite("SliderFGBar", r);
                if (highlightedScrollBar == null)
                {
                    reason = "\"SliderFGBar\" sprite does not exist";
                    return false;
                }
            }

            topIndex = 0;
            scrollPos = 0; //relative to the scrollbar itself
            scrollSelected = false;
            isEnabled = true;
            reason = null;
            return true;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="items"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="maxVisible"></param>
        /// <param name="r"></param>
        /// <param name="reason"></param>
        public bool Initialize(List<string> items, int xPos, int yPos, int width, int height, int maxVisible, Random r, out string reason)
        {
            _items = items;
            _xPos = xPos;
            _yPos = yPos;
            _width = width;
            _height = height;

            _selectedIndex = 0;
            Dropped = false;
            _downArrowSprite = SpriteManager.GetSprite("ScrollDownBGButton", r);

            if (items.Count < maxVisible)
            {
                _haveScroll = false;
                maxVisible = items.Count;
            }
            else if (items.Count > maxVisible)
            {
                _haveScroll = true;
            }

            Enabled = true;

            _buttons = new List<BBInvisibleStretchButton>();
            _dropBackground = new BBStretchableImage();
            _scrollBar = new BBScrollBar();

            for (int i = 0; i <= maxVisible; i++)
            {
                BBInvisibleStretchButton button = new BBInvisibleStretchButton();
                if (!button.Initialize(string.Empty, ButtonTextAlignment.LEFT, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, _xPos, _yPos + (i * height), _width, _height, r, out reason))
                {
                    return false;
                }
                _buttons.Add(button);
            }
            if (!_dropBackground.Initialize(_xPos, _yPos, width, height, StretchableImageType.ThinBorderBG, r, out reason))
            {
                return false;
            }
            if (!_scrollBar.Initialize(_xPos + _width, _yPos + _height, maxVisible * _height, maxVisible, items.Count, false, false, r, out reason))
            {
                return false;
            }
            RefreshSelection();
            RefreshLabels();
            return true;
        }