Beyond_Beyaan.BBScrollBarNoArrows.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)
        {
            _xPos = xPos;
            _yPos = yPos;
            _scroll = new BBUniStretchButton();

            _amountOfItems = amountOfItems;
            _amountVisible = amountOfVisibleItems;
            _isSlider = isSlider;
            _isHorizontal = isHorizontal;

            _scrollBarLength = length;

            if (!isSlider)
            {
                _scrollButtonLength = (int)(((float)amountOfVisibleItems / amountOfItems) * _scrollBarLength);
                if (!isHorizontal)
                {
                    if (!_scroll.Initialize(new List<string> { "TinyScrollVerticalBGButton1", "TinyScrollVerticalBGButton2", "TinyScrollVerticalBGButton3" },
                                           new List<string> { "TinyScrollVerticalFGButton1", "TinyScrollVerticalFGButton2", "TinyScrollVerticalFGButton3" },
                                           isHorizontal, "", ButtonTextAlignment.LEFT, xPos, yPos, 5, _scrollButtonLength, 3, 1, r, out reason))
                    {
                        return false;
                    }
                    _scrollBar = SpriteManager.GetSprite("TinyScrollVerticalBar", r);
                    if (_scrollBar == null)
                    {
                        reason = "\"TinyScrollVerticalBar\" sprite does not exist";
                        return false;
                    }
                }
                else
                {
                    if (!_scroll.Initialize(new List<string> { "TinyScrollHorizontalBGButton1", "TinyScrollHorizontalBGButton2", "TinyScrollHorizontalBGButton3" },
                                           new List<string> { "TinyScrollHorizontalFGButton1", "TinyScrollHorizontalFGButton2", "TinyScrollHorizontalFGButton3" },
                                           isHorizontal, "", ButtonTextAlignment.LEFT, xPos, yPos, _scrollButtonLength, 5, 3, 1, r, out reason))
                    {
                        return false;
                    }
                    _scrollBar = SpriteManager.GetSprite("TinyScrollHorizontalBar", r);
                    if (_scrollBar == null)
                    {
                        reason = "\"TinyScrollHorizontalBar\" sprite does not exist";
                        return false;
                    }
                }
            }
            else
            {
                _scrollButtonLength = 16;
                if (!_scroll.Initialize(new List<string> { "TinySliderHorizontalBGButton1", "TinySliderHorizontalBGButton2", "TinySliderHorizontalBGButton3" },
                                       new List<string> { "TinySliderHorizontalFGButton1", "TinySliderHorizontalFGButton2", "TinySliderHorizontalFGButton3" },
                                       true, "", ButtonTextAlignment.LEFT, xPos, yPos, _scrollButtonLength, 5, 3, 1, r, out reason))
                {
                    return false;
                }
                _scrollBar = SpriteManager.GetSprite("TinySliderBGBar", r);
                if (_scrollBar == null)
                {
                    reason = "\"TinySliderBGBar\" sprite does not exist";
                    return false;
                }
                _highlightedScrollBar = SpriteManager.GetSprite("TinySliderFGBar", 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
        public bool Initialize(int xPos, int yPos, int width, int height, bool wrapText, bool allowScrollbar, string name, Random r, out string reason)
        {
            //If using scrollbar, then shrink the actual width by 16 to allow for scrollbar, even if it's not visible
            _x = xPos;
            _y = yPos;
            _maxWidth = width;
            Width = width;
            Height = height == 0 ? 1 : height;
            _wrapText = wrapText;
            _scrollbarVisible = false;
            _textScrollBar = new BBScrollBarNoArrows();
            _allowScrollbar = allowScrollbar;
            if (_allowScrollbar)
            {
                if (_wrapText)
                {
                    if (!_textScrollBar.Initialize(xPos + _maxWidth - 5, yPos, Height, Height, 1, false, false, r, out reason))
                    {
                        return false;
                    }
                    _wrapView = new Viewport(0, 0, _maxWidth - 5, Height);

                    _target = new RenderImage(name + "render", _maxWidth - 5, Height, ImageBufferFormats.BufferRGB888A8);
                }
                else
                {
                    if (!_textScrollBar.Initialize(xPos, yPos + Height - 5, _maxWidth, _maxWidth, 1, true, false, r, out reason))
                    {
                        return false;
                    }
                    _wrapView = new Viewport(0, 0, _maxWidth, Height - 5);

                    _target = new RenderImage(name + "render", _maxWidth, Height - 5, ImageBufferFormats.BufferRGB888A8);
                }
            }
            else
            {
                _wrapView = new Viewport(0, 0, _maxWidth, Height);

                _target = new RenderImage(name + "render", _maxWidth, Height, ImageBufferFormats.BufferRGB888A8);
            }
            _textSprite = new TextSprite(name, string.Empty, FontManager.GetDefaultFont());
            _textSprite.WordWrap = _wrapText;
            if (_allowScrollbar || _wrapText)
            {
                _textSprite.Bounds = _wrapView;
            }
            _target.BlendingMode = BlendingModes.Modulated;
            reason = null;
            return true;
        }