public ScrollPane(GComponent owner,
ScrollType scrollType,
Margin scrollBarMargin,
ScrollBarDisplayType scrollBarDisplay,
int flags,
string vtScrollBarRes,
string hzScrollBarRes)
{
onScroll = new EventListener(this, "onScroll");
onScrollEnd = new EventListener(this, "onScrollEnd");
onPullDownRelease = new EventListener(this, "onPullDownRelease");
onPullUpRelease = new EventListener(this, "onPullUpRelease");
_refreshDelegate = Refresh;
_touchEndDelegate = __touchEnd;
_touchMoveDelegate = __touchMove;
_throwTween = new ThrowTween();
_owner = owner;
_maskContainer = new Container();
_owner.rootContainer.AddChild(_maskContainer);
_container = _owner.container;
_container.x = 0;
_container.y = 0;
_maskContainer.AddChild(_container);
_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;
_inertiaDisabled = (flags & 256) != 0;
_maskDisabled = (flags & 512) != 0;
_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);
_owner.rootContainer.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);
_owner.rootContainer.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;
_owner.rootContainer.onRollOver.Add(__rollOver);
_owner.rootContainer.onRollOut.Add(__rollOut);
}
}
else
_mouseWheelEnabled = false;
if (!_maskDisabled && (_vtScrollBar != null || _hzScrollBar != null))
{
//当有滚动条对象时,为了避免滚动条变化时触发重新合批,这里给rootContainer也加上剪裁。但这可能会增加额外dc。
_owner.rootContainer.clipRect = new Rect(0, 0, _owner.width, _owner.height);
}
SetSize(owner.width, owner.height);
_owner.rootContainer.onMouseWheel.Add(__mouseWheel);
_owner.rootContainer.onTouchBegin.Add(__touchBegin);
}