コード例 #1
0
        public ScrollPane(GComponent owner,
                                    ScrollType scrollType,
                                    Margin margin,
                                    Margin scrollBarMargin,
                                    ScrollBarDisplayType scrollBarDisplay,
                                    int flags)
        {
            _throwTween = new ThrowTween();

            _owner = owner;
            _container = _owner.rootContainer;

            _maskHolder = new Container();
            _container.AddChild(_maskHolder);

            _maskContentHolder = _owner.container;
            _maskContentHolder.x = 0;
            _maskContentHolder.y = 0;
            _maskHolder.AddChild(_maskContentHolder);

            if (Stage.touchScreen)
                _holdArea = 20;
            else
                _holdArea = 5;
            _holdAreaPoint = new Vector2();
            _margin = margin;
            _scrollBarMargin = scrollBarMargin;
            _bouncebackEffect = UIConfig.defaultScrollBounceEffect;
            _touchEffect = UIConfig.defaultScrollTouchEffect;
            _xPerc = 0;
            _yPerc = 0;
            _aniFlag = true;
            _scrollBarVisible = true;
            _scrollSpeed = UIConfig.defaultScrollSpeed;
            _mouseWheelSpeed = _scrollSpeed * 2;
            _displayOnLeft = (flags & 1) != 0;
            _snapToItem = (flags & 2) != 0;
            _displayInDemand = (flags & 4) != 0;
            _scrollType = scrollType;
            _mouseWheelEnabled = true;

            if (scrollBarDisplay == ScrollBarDisplayType.Default)
                scrollBarDisplay = UIConfig.defaultScrollBarDisplay;

            if (scrollBarDisplay != ScrollBarDisplayType.Hidden)
            {
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
                {
                    if (UIConfig.verticalScrollBar != null)
                    {
                        _vtScrollBar = UIPackage.CreateObjectFromURL(UIConfig.verticalScrollBar) as GScrollBar;
                        if (_vtScrollBar == null)
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.verticalScrollBar);
                        else
                        {
                            _vtScrollBar.SetScrollPane(this, true);
                            _container.AddChild(_vtScrollBar.displayObject);
                        }
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    if (UIConfig.horizontalScrollBar != null)
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(UIConfig.horizontalScrollBar) as GScrollBar;
                        if (_hzScrollBar == null)
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.horizontalScrollBar);
                        else
                        {
                            _hzScrollBar.SetScrollPane(this, false);
                            _container.AddChild(_hzScrollBar.displayObject);
                        }
                    }
                }

                _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto;
                if (_scrollBarDisplayAuto)
                {
                    if (_vtScrollBar != null)
                        _vtScrollBar.displayObject.visible = false;
                    if (_hzScrollBar != null)
                        _hzScrollBar.displayObject.visible = false;
                    _scrollBarVisible = false;

                    _container.onRollOver.Add(__rollOver);
                    _container.onRollOut.Add(__rollOut);
                }
            }
            else
                _mouseWheelEnabled = false;

            if (_displayOnLeft && _vtScrollBar != null)
                _maskHolder.x = Mathf.FloorToInt((_margin.left + _vtScrollBar.width) * GRoot.contentScaleFactor);
            else
                _maskHolder.x = Mathf.FloorToInt(_margin.left * GRoot.contentScaleFactor);
            _maskHolder.y = Mathf.FloorToInt(_margin.top * GRoot.contentScaleFactor);

            SetSize(owner.width, owner.height);
            SetContentSize(owner.Bounds.width, owner.Bounds.height);

            _container.onMouseWheel.Add(__mouseWheel);
            _container.onMouseDown.Add(__mouseDown);
        }
コード例 #2
0
        public ScrollPane(GComponent owner,
                          ScrollType scrollType,
                          Margin margin,
                          Margin scrollBarMargin,
                          ScrollBarDisplayType scrollBarDisplay,
                          int flags)
        {
            _throwTween = new ThrowTween();

            _owner     = owner;
            _container = _owner.rootContainer;

            _maskHolder = new Container();
            _container.AddChild(_maskHolder);

            _maskContentHolder   = _owner.container;
            _maskContentHolder.x = 0;
            _maskContentHolder.y = 0;
            _maskHolder.AddChild(_maskContentHolder);

            if (Stage.touchScreen)
            {
                _holdArea = 20;
            }
            else
            {
                _holdArea = 5;
            }
            _holdAreaPoint     = new Vector2();
            _margin            = margin;
            _scrollBarMargin   = scrollBarMargin;
            _bouncebackEffect  = UIConfig.defaultScrollBounceEffect;
            _touchEffect       = UIConfig.defaultScrollTouchEffect;
            _xPerc             = 0;
            _yPerc             = 0;
            _aniFlag           = true;
            _scrollBarVisible  = true;
            _scrollSpeed       = UIConfig.defaultScrollSpeed;
            _mouseWheelSpeed   = _scrollSpeed * 2;
            _displayOnLeft     = (flags & 1) != 0;
            _snapToItem        = (flags & 2) != 0;
            _displayInDemand   = (flags & 4) != 0;
            _scrollType        = scrollType;
            _mouseWheelEnabled = true;

            if (scrollBarDisplay == ScrollBarDisplayType.Default)
            {
                scrollBarDisplay = UIConfig.defaultScrollBarDisplay;
            }

            if (scrollBarDisplay != ScrollBarDisplayType.Hidden)
            {
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
                {
                    if (UIConfig.verticalScrollBar != null)
                    {
                        _vtScrollBar = UIPackage.CreateObjectFromURL(UIConfig.verticalScrollBar) as GScrollBar;
                        if (_vtScrollBar == null)
                        {
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.verticalScrollBar);
                        }
                        else
                        {
                            _vtScrollBar.SetScrollPane(this, true);
                            _container.AddChild(_vtScrollBar.displayObject);
                        }
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    if (UIConfig.horizontalScrollBar != null)
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(UIConfig.horizontalScrollBar) as GScrollBar;
                        if (_hzScrollBar == null)
                        {
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.horizontalScrollBar);
                        }
                        else
                        {
                            _hzScrollBar.SetScrollPane(this, false);
                            _container.AddChild(_hzScrollBar.displayObject);
                        }
                    }
                }

                _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto;
                if (_scrollBarDisplayAuto)
                {
                    if (_vtScrollBar != null)
                    {
                        _vtScrollBar.displayObject.visible = false;
                    }
                    if (_hzScrollBar != null)
                    {
                        _hzScrollBar.displayObject.visible = false;
                    }
                    _scrollBarVisible = false;

                    _container.onRollOver.Add(__rollOver);
                    _container.onRollOut.Add(__rollOut);
                }
            }
            else
            {
                _mouseWheelEnabled = false;
            }

            if (_displayOnLeft && _vtScrollBar != null)
            {
                _maskHolder.x = Mathf.FloorToInt((_margin.left + _vtScrollBar.width) * GRoot.contentScaleFactor);
            }
            else
            {
                _maskHolder.x = Mathf.FloorToInt(_margin.left * GRoot.contentScaleFactor);
            }
            _maskHolder.y = Mathf.FloorToInt(_margin.top * GRoot.contentScaleFactor);

            SetSize(owner.width, owner.height);
            SetContentSize(owner.Bounds.width, owner.Bounds.height);

            _container.onMouseWheel.Add(__mouseWheel);
            _container.onMouseDown.Add(__mouseDown);
        }
コード例 #3
0
ファイル: ScrollPane.cs プロジェクト: yinlei/Fishing
        public ScrollPane(GComponent owner,
            ScrollType scrollType,
            Margin scrollBarMargin,
            ScrollBarDisplayType scrollBarDisplay,
            int flags,
            string vtScrollBarRes,
            string hzScrollBarRes)
        {
            onScroll = new EventListener(this, "onScroll");
            _refreshDelegate = Refresh;

            _throwTween = new ThrowTween();
            _owner = owner;
            _container = _owner.rootContainer;

            _maskHolder = new Container();
            _container.AddChild(_maskHolder);

            _maskContentHolder = _owner.container;
            _maskContentHolder.x = 0;
            _maskContentHolder.y = 0;
            _maskHolder.AddChild(_maskContentHolder);

            _scrollBarMargin = scrollBarMargin;
            _scrollType = scrollType;
            _scrollSpeed = UIConfig.defaultScrollSpeed;
            _mouseWheelSpeed = _scrollSpeed * 2;
            _softnessOnTopOrLeftSide = UIConfig.allowSoftnessOnTopOrLeftSide;

            _displayOnLeft = (flags & 1) != 0;
            _snapToItem = (flags & 2) != 0;
            _displayInDemand = (flags & 4) != 0;
            _pageMode = (flags & 8) != 0;
            if ((flags & 16) != 0)
                _touchEffect = true;
            else if ((flags & 32) != 0)
                _touchEffect = false;
            else
                _touchEffect = UIConfig.defaultScrollTouchEffect;
            if ((flags & 64) != 0)
                _bouncebackEffect = true;
            else if ((flags & 128) != 0)
                _bouncebackEffect = false;
            else
                _bouncebackEffect = UIConfig.defaultScrollBounceEffect;

            _xPerc = 0;
            _yPerc = 0;
            _aniFlag = true;
            _scrollBarVisible = true;
            _mouseWheelEnabled = true;
            _holdAreaPoint = new Vector2();
            _pageSize = Vector2.one;

            if (scrollBarDisplay == ScrollBarDisplayType.Default)
            {
                if (Application.isMobilePlatform)
                    scrollBarDisplay = ScrollBarDisplayType.Auto;
                else
                    scrollBarDisplay = UIConfig.defaultScrollBarDisplay;
            }

            if (scrollBarDisplay != ScrollBarDisplayType.Hidden)
            {
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
                {
                    string res = string.IsNullOrEmpty(vtScrollBarRes) ? UIConfig.verticalScrollBar : vtScrollBarRes;
                    if (!string.IsNullOrEmpty(res))
                    {
                        _vtScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar;
                        if (_vtScrollBar == null)
                            Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res);
                        else
                        {
                            _vtScrollBar.SetScrollPane(this, true);
                            _container.AddChild(_vtScrollBar.displayObject);
                        }
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    string res = string.IsNullOrEmpty(hzScrollBarRes) ? UIConfig.horizontalScrollBar : hzScrollBarRes;
                    if (!string.IsNullOrEmpty(res))
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar;
                        if (_hzScrollBar == null)
                            Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res);
                        else
                        {
                            _hzScrollBar.SetScrollPane(this, false);
                            _container.AddChild(_hzScrollBar.displayObject);
                        }
                    }
                }

                _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto;
                if (_scrollBarDisplayAuto)
                {
                    if (_vtScrollBar != null)
                        _vtScrollBar.displayObject.visible = false;
                    if (_hzScrollBar != null)
                        _hzScrollBar.displayObject.visible = false;
                    _scrollBarVisible = false;

                    _container.onRollOver.Add(__rollOver);
                    _container.onRollOut.Add(__rollOut);
                }
            }
            else
                _mouseWheelEnabled = false;

            SetSize(owner.width, owner.height);

            _container.onMouseWheel.Add(__mouseWheel);
            _container.onTouchBegin.Add(__touchBegin);
        }
コード例 #4
0
        private void __mouseUp(EventContext context)
        {
            if (!_touchEffect)
            {
                _isMouseMoved = false;
                return;
            }

            InputEvent evt = context.inputEvent;

            if (_touchId != evt.touchId)
            {
                return;
            }

            _container.stage.onMouseMove.Remove(__mouseMove);
            _container.stage.onMouseUp.Remove(__mouseUp);

            if (!_isMouseMoved)
            {
                return;
            }

            _isMouseMoved = false;

            float time = Time.time - _time2;

            if (time == 0)
            {
                time = 0.001f;
            }
            float yVelocity = (_maskContentHolder.y - _y2) / time;
            float xVelocity = (_maskContentHolder.x - _x2) / time;

            float minDuration = _bouncebackEffect ? 0.3f : 0;
            float maxDuration = 0.5f;
            int   overShoot   = _bouncebackEffect ? 1 : 0;

            float xMin = -_xOverlap, yMin = -_yOverlap;
            float xMax = 0, yMax = 0;

            float duration = 0f;

            if (_hScroll)
            {
                ThrowTween.CalculateDuration(_maskContentHolder.x, xMin, xMax, xVelocity, overShoot, ref duration);
            }
            if (_vScroll)
            {
                ThrowTween.CalculateDuration(_maskContentHolder.y, yMin, yMax, yVelocity, overShoot, ref duration);
            }

            if (duration > maxDuration)
            {
                duration = maxDuration;
            }
            else if (duration < minDuration)
            {
                duration = minDuration;
            }

            _throwTween.start.x = _maskContentHolder.x;
            _throwTween.start.y = _maskContentHolder.y;

            Vector2 change1, change2;
            float   endX = 0, endY = 0;

            if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
            {
                change1.x = ThrowTween.CalculateChange(xVelocity, duration);
                change2.x = 0;
                endX      = _maskContentHolder.x + change1.x;
            }
            else
            {
                change1.x = change2.x = 0;
            }

            if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
            {
                change1.y = ThrowTween.CalculateChange(yVelocity, duration);
                change2.y = 0;
                endY      = _maskContentHolder.y + change1.y;
            }
            else
            {
                change1.y = change2.y = 0;
            }

            if (_snapToItem)
            {
                endX = -endX / GRoot.contentScaleFactor;
                endY = -endY / GRoot.contentScaleFactor;
                _owner.FindObjectNear(ref endX, ref endY);
                endX      = -endX * GRoot.contentScaleFactor;
                endY      = -endY * GRoot.contentScaleFactor;
                change1.x = endX - _maskContentHolder.x;
                change1.y = endY - _maskContentHolder.y;
            }

            if (xMax < endX)
            {
                change2.x = xMax - _maskContentHolder.x - change1.x;
            }
            else if (xMin > endX)
            {
                change2.x = xMin - _maskContentHolder.x - change1.x;
            }

            if (yMax < endY)
            {
                change2.y = yMax - _maskContentHolder.y - change1.y;
            }
            else if (yMin > endY)
            {
                change2.y = yMin - _maskContentHolder.y - change1.y;
            }

            _throwTween.value   = 0;
            _throwTween.change1 = change1;
            _throwTween.change2 = change2;

            if (_tweener != null)
            {
                _tweener.Complete();
            }

            _tweener = DOTween.To(() => _throwTween.value, v => _throwTween.value = v, 1, duration)
                       .SetEase(Ease.OutCubic)
                       .OnUpdate(__tweenUpdate2)
                       .OnComplete(__tweenComplete2);
        }