2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "ui/UIScrollView.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
|
|
|
|
static const float AUTOSCROLLMAXSPEED = 1000.0f;
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec2 SCROLLDIR_UP = Vec2(0.0f, 1.0f);
|
|
|
|
const Vec2 SCROLLDIR_DOWN = Vec2(0.0f, -1.0f);
|
|
|
|
const Vec2 SCROLLDIR_LEFT = Vec2(-1.0f, 0.0f);
|
|
|
|
const Vec2 SCROLLDIR_RIGHT = Vec2(1.0f, 0.0f);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
IMPLEMENT_CLASS_GUI_INFO(ScrollView)
|
|
|
|
|
|
|
|
ScrollView::ScrollView():
|
|
|
|
_innerContainer(nullptr),
|
2014-05-12 11:08:10 +08:00
|
|
|
_direction(Direction::VERTICAL),
|
2014-05-15 01:07:09 +08:00
|
|
|
_autoScrollDir(Vec2::ZERO),
|
2014-03-11 17:13:54 +08:00
|
|
|
_topBoundary(0.0f),
|
|
|
|
_bottomBoundary(0.0f),
|
|
|
|
_leftBoundary(0.0f),
|
|
|
|
_rightBoundary(0.0f),
|
|
|
|
_bounceTopBoundary(0.0f),
|
|
|
|
_bounceBottomBoundary(0.0f),
|
|
|
|
_bounceLeftBoundary(0.0f),
|
|
|
|
_bounceRightBoundary(0.0f),
|
|
|
|
_autoScroll(false),
|
|
|
|
_autoScrollAddUpTime(0.0f),
|
|
|
|
_autoScrollOriginalSpeed(0.0f),
|
|
|
|
_autoScrollAcceleration(-1000.0f),
|
|
|
|
_isAutoScrollSpeedAttenuated(false),
|
|
|
|
_needCheckAutoScrollDestination(false),
|
2014-05-15 01:07:09 +08:00
|
|
|
_autoScrollDestination(Vec2::ZERO),
|
2014-03-11 17:13:54 +08:00
|
|
|
_bePressed(false),
|
|
|
|
_slidTime(0.0f),
|
2014-05-15 01:07:09 +08:00
|
|
|
_moveChildPoint(Vec2::ZERO),
|
2014-03-11 17:13:54 +08:00
|
|
|
_childFocusCancelOffset(5.0f),
|
|
|
|
_leftBounceNeeded(false),
|
|
|
|
_topBounceNeeded(false),
|
|
|
|
_rightBounceNeeded(false),
|
|
|
|
_bottomBounceNeeded(false),
|
|
|
|
_bounceEnabled(false),
|
|
|
|
_bouncing(false),
|
2014-05-15 01:07:09 +08:00
|
|
|
_bounceDir(Vec2::ZERO),
|
2014-03-11 17:13:54 +08:00
|
|
|
_bounceOriginalSpeed(0.0f),
|
|
|
|
_inertiaScrollEnabled(true),
|
|
|
|
_scrollViewEventListener(nullptr),
|
2014-05-12 11:08:10 +08:00
|
|
|
_scrollViewEventSelector(nullptr),
|
|
|
|
_eventCallback(nullptr)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollView::~ScrollView()
|
|
|
|
{
|
|
|
|
_scrollViewEventListener = nullptr;
|
|
|
|
_scrollViewEventSelector = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollView* ScrollView::create()
|
|
|
|
{
|
|
|
|
ScrollView* widget = new ScrollView();
|
|
|
|
if (widget && widget->init())
|
|
|
|
{
|
|
|
|
widget->autorelease();
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(widget);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::onEnter()
|
|
|
|
{
|
2014-06-13 17:59:23 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
|
|
|
if (_scriptType == kScriptTypeJavascript)
|
|
|
|
{
|
2014-06-18 11:51:52 +08:00
|
|
|
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
|
2014-06-13 17:59:23 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Layout::onEnter();
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::init()
|
|
|
|
{
|
|
|
|
if (Layout::init())
|
|
|
|
{
|
|
|
|
setClippingEnabled(true);
|
|
|
|
_innerContainer->setTouchEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::initRenderer()
|
|
|
|
{
|
|
|
|
Layout::initRenderer();
|
|
|
|
_innerContainer = Layout::create();
|
2014-05-22 17:49:19 +08:00
|
|
|
addProtectedChild(_innerContainer, 1, 1);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::onSizeChanged()
|
|
|
|
{
|
|
|
|
Layout::onSizeChanged();
|
2014-06-20 10:40:16 +08:00
|
|
|
_topBoundary = _contentSize.height;
|
|
|
|
_rightBoundary = _contentSize.width;
|
|
|
|
float bounceBoundaryParameterX = _contentSize.width / 3.0f;
|
|
|
|
float bounceBoundaryParameterY = _contentSize.height / 3.0f;
|
|
|
|
_bounceTopBoundary = _contentSize.height - bounceBoundaryParameterY;
|
2014-03-11 17:13:54 +08:00
|
|
|
_bounceBottomBoundary = bounceBoundaryParameterY;
|
|
|
|
_bounceLeftBoundary = bounceBoundaryParameterX;
|
2014-06-20 10:40:16 +08:00
|
|
|
_bounceRightBoundary = _contentSize.width - bounceBoundaryParameterX;
|
2014-06-20 11:18:53 +08:00
|
|
|
Size innerSize = _innerContainer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
float orginInnerSizeWidth = innerSize.width;
|
|
|
|
float orginInnerSizeHeight = innerSize.height;
|
2014-06-20 10:40:16 +08:00
|
|
|
float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width);
|
|
|
|
float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height);
|
2014-06-20 14:03:33 +08:00
|
|
|
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
|
2014-06-20 11:18:53 +08:00
|
|
|
_innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::setInnerContainerSize(const Size &size)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
float innerSizeWidth = _contentSize.width;
|
|
|
|
float innerSizeHeight = _contentSize.height;
|
2014-06-20 11:18:53 +08:00
|
|
|
Size originalInnerSize = _innerContainer->getContentSize();
|
2014-06-20 10:40:16 +08:00
|
|
|
if (size.width < _contentSize.width)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Inner width <= scrollview width, it will be force sized!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
innerSizeWidth = size.width;
|
|
|
|
}
|
2014-06-20 10:40:16 +08:00
|
|
|
if (size.height < _contentSize.height)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Inner height <= scrollview height, it will be force sized!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
innerSizeHeight = size.height;
|
|
|
|
}
|
2014-06-20 14:03:33 +08:00
|
|
|
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
switch (_direction)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::VERTICAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size newInnerSize = _innerContainer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
float offset = originalInnerSize.height - newInnerSize.height;
|
|
|
|
scrollChildren(0.0f, offset);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::HORIZONTAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
if (_innerContainer->getRightBoundary() <= _contentSize.width)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size newInnerSize = _innerContainer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
float offset = originalInnerSize.width - newInnerSize.width;
|
|
|
|
scrollChildren(offset, 0.0f);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::BOTH:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size newInnerSize = _innerContainer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
float offsetY = originalInnerSize.height - newInnerSize.height;
|
|
|
|
float offsetX = 0.0f;
|
2014-06-20 10:40:16 +08:00
|
|
|
if (_innerContainer->getRightBoundary() <= _contentSize.width)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
offsetX = originalInnerSize.width - newInnerSize.width;
|
|
|
|
}
|
|
|
|
scrollChildren(offsetX, offsetY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
if (_innerContainer->getLeftBoundary() > 0.0f)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
_innerContainer->setPosition(Vec2(_innerContainer->getAnchorPoint().x * _innerContainer->getContentSize().width,
|
2014-06-20 10:40:16 +08:00
|
|
|
_innerContainer->getPosition().y));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-06-20 10:40:16 +08:00
|
|
|
if (_innerContainer->getRightBoundary() < _contentSize.width)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
_innerContainer->setPosition(Vec2(_contentSize.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getContentSize().width),
|
2014-06-20 10:40:16 +08:00
|
|
|
_innerContainer->getPosition().y));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
if (_innerContainer->getPosition().y > 0.0f)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x,
|
2014-06-20 11:18:53 +08:00
|
|
|
_innerContainer->getAnchorPoint().y * _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-06-20 10:40:16 +08:00
|
|
|
if (_innerContainer->getTopBoundary() < _contentSize.height)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
_innerContainer->setPosition(Vec2(_innerContainer->getPosition().x,
|
2014-06-20 11:18:53 +08:00
|
|
|
_contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Size& ScrollView::getInnerContainerSize() const
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
return _innerContainer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::addChild(Node *child)
|
|
|
|
{
|
2014-05-21 16:40:42 +08:00
|
|
|
ScrollView::addChild(child, child->getZOrder(), child->getTag());
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::addChild(Node * child, int zOrder)
|
|
|
|
{
|
2014-05-21 16:40:42 +08:00
|
|
|
ScrollView::addChild(child, zOrder, child->getTag());
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::addChild(Node *child, int zOrder, int tag)
|
|
|
|
{
|
2014-03-13 10:11:41 +08:00
|
|
|
_innerContainer->addChild(child, zOrder, tag);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::removeAllChildren()
|
|
|
|
{
|
|
|
|
removeAllChildrenWithCleanup(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::removeAllChildrenWithCleanup(bool cleanup)
|
|
|
|
{
|
|
|
|
_innerContainer->removeAllChildrenWithCleanup(cleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::removeChild(Node* child, bool cleanup)
|
|
|
|
{
|
|
|
|
return _innerContainer->removeChild(child, cleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Node*>& ScrollView::getChildren()
|
|
|
|
{
|
|
|
|
return _innerContainer->getChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vector<Node*>& ScrollView::getChildren() const
|
|
|
|
{
|
|
|
|
return _innerContainer->getChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t ScrollView::getChildrenCount() const
|
|
|
|
{
|
|
|
|
return _innerContainer->getChildrenCount();
|
|
|
|
}
|
|
|
|
|
2014-05-17 15:40:36 +08:00
|
|
|
Node* ScrollView::getChildByTag(int tag) const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _innerContainer->getChildByTag(tag);
|
|
|
|
}
|
|
|
|
|
2014-06-11 16:57:43 +08:00
|
|
|
Node* ScrollView::getChildByName(const std::string& name)const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _innerContainer->getChildByName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::moveChildren(float offsetX, float offsetY)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
_moveChildPoint = _innerContainer->getPosition() + Vec2(offsetX, offsetY);
|
2014-03-11 17:13:54 +08:00
|
|
|
_innerContainer->setPosition(_moveChildPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::autoScrollChildren(float dt)
|
|
|
|
{
|
|
|
|
float lastTime = _autoScrollAddUpTime;
|
|
|
|
_autoScrollAddUpTime += dt;
|
|
|
|
if (_isAutoScrollSpeedAttenuated)
|
|
|
|
{
|
|
|
|
float nowSpeed = _autoScrollOriginalSpeed + _autoScrollAcceleration * _autoScrollAddUpTime;
|
|
|
|
if (nowSpeed <= 0.0f)
|
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
checkNeedBounce();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float timeParam = lastTime * 2 + dt;
|
|
|
|
float offset = (_autoScrollOriginalSpeed + _autoScrollAcceleration * timeParam * 0.5f) * dt;
|
|
|
|
float offsetX = offset * _autoScrollDir.x;
|
|
|
|
float offsetY = offset * _autoScrollDir.y;
|
|
|
|
if (!scrollChildren(offsetX, offsetY))
|
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
checkNeedBounce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_needCheckAutoScrollDestination)
|
|
|
|
{
|
|
|
|
float xOffset = _autoScrollDir.x * dt * _autoScrollOriginalSpeed;
|
|
|
|
float yOffset = _autoScrollDir.y * dt * _autoScrollOriginalSpeed;
|
|
|
|
bool notDone = checkCustomScrollDestination(&xOffset, &yOffset);
|
|
|
|
bool scrollCheck = scrollChildren(xOffset, yOffset);
|
|
|
|
if (!notDone || !scrollCheck)
|
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
checkNeedBounce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!scrollChildren(_autoScrollDir.x * dt * _autoScrollOriginalSpeed, _autoScrollDir.y * dt * _autoScrollOriginalSpeed))
|
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
checkNeedBounce();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::bounceChildren(float dt)
|
|
|
|
{
|
|
|
|
if (_bounceOriginalSpeed <= 0.0f)
|
|
|
|
{
|
|
|
|
stopBounceChildren();
|
|
|
|
}
|
|
|
|
if (!bounceScrollChildren(_bounceDir.x * dt * _bounceOriginalSpeed, _bounceDir.y * dt * _bounceOriginalSpeed))
|
|
|
|
{
|
|
|
|
stopBounceChildren();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::checkNeedBounce()
|
|
|
|
{
|
|
|
|
if (!_bounceEnabled)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
checkBounceBoundary();
|
|
|
|
if (_topBounceNeeded || _bottomBounceNeeded || _leftBounceNeeded || _rightBounceNeeded)
|
|
|
|
{
|
|
|
|
if (_topBounceNeeded && _leftBounceNeeded)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getTopBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_topBounceNeeded && _rightBounceNeeded)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
Vec2 scrollVector = Vec2(_contentSize.width, _contentSize.height) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getTopBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_bottomBounceNeeded && _leftBounceNeeded)
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftBoundary(), _innerContainer->getBottomBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_bottomBounceNeeded && _rightBounceNeeded)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), _innerContainer->getBottomBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_topBounceNeeded)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
Vec2 scrollVector = Vec2(0.0f, _contentSize.height) - Vec2(0.0f, _innerContainer->getTopBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_bottomBounceNeeded)
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
Vec2 scrollVector = Vec2::ZERO - Vec2(0.0f, _innerContainer->getBottomBoundary());
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_leftBounceNeeded)
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
Vec2 scrollVector = Vec2::ZERO - Vec2(_innerContainer->getLeftBoundary(), 0.0f);
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
else if (_rightBounceNeeded)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
Vec2 scrollVector = Vec2(_contentSize.width, 0.0f) - Vec2(_innerContainer->getRightBoundary(), 0.0f);
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = scrollVector.getLength()/(0.2f);
|
2014-05-01 01:10:18 +08:00
|
|
|
_bounceDir = scrollVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
startBounceChildren(orSpeed);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::checkBounceBoundary()
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos > _bottomBoundary)
|
|
|
|
{
|
|
|
|
scrollToBottomEvent();
|
|
|
|
_bottomBounceNeeded = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_bottomBounceNeeded = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos < _topBoundary)
|
|
|
|
{
|
|
|
|
scrollToTopEvent();
|
|
|
|
_topBounceNeeded = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_topBounceNeeded = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos < _rightBoundary)
|
|
|
|
{
|
|
|
|
scrollToRightEvent();
|
|
|
|
_rightBounceNeeded = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_rightBounceNeeded = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos > _leftBoundary)
|
|
|
|
{
|
|
|
|
scrollToLeftEvent();
|
|
|
|
_leftBounceNeeded = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_leftBounceNeeded = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::startBounceChildren(float v)
|
|
|
|
{
|
|
|
|
_bounceOriginalSpeed = v;
|
|
|
|
_bouncing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::stopBounceChildren()
|
|
|
|
{
|
|
|
|
_bouncing = false;
|
|
|
|
_bounceOriginalSpeed = 0.0f;
|
|
|
|
_leftBounceNeeded = false;
|
|
|
|
_rightBounceNeeded = false;
|
|
|
|
_topBounceNeeded = false;
|
|
|
|
_bottomBounceNeeded = false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::startAutoScrollChildrenWithOriginalSpeed(const Vec2& dir, float v, bool attenuated, float acceleration)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
_autoScrollDir = dir;
|
|
|
|
_isAutoScrollSpeedAttenuated = attenuated;
|
|
|
|
_autoScrollOriginalSpeed = v;
|
|
|
|
_autoScroll = true;
|
|
|
|
_autoScrollAcceleration = acceleration;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::startAutoScrollChildrenWithDestination(const Vec2& des, float time, bool attenuated)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
_needCheckAutoScrollDestination = false;
|
|
|
|
_autoScrollDestination = des;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 dis = des - _innerContainer->getPosition();
|
|
|
|
Vec2 dir = dis.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
float orSpeed = 0.0f;
|
|
|
|
float acceleration = -1000.0f;
|
|
|
|
if (attenuated)
|
|
|
|
{
|
|
|
|
acceleration = (-(2 * dis.getLength())) / (time * time);
|
|
|
|
orSpeed = 2 * dis.getLength() / time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_needCheckAutoScrollDestination = true;
|
|
|
|
orSpeed = dis.getLength() / time;
|
|
|
|
}
|
|
|
|
startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, attenuated, acceleration);
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::jumpToDestination(const Vec2 &des)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
float finalOffsetX = des.x;
|
|
|
|
float finalOffsetY = des.y;
|
|
|
|
switch (_direction)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::VERTICAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
if (des.y <= 0)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::HORIZONTAL:
|
2014-03-11 17:13:54 +08:00
|
|
|
if (des.x <= 0)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::BOTH:
|
2014-03-11 17:13:54 +08:00
|
|
|
if (des.y <= 0)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
if (des.x <= 0)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().width);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
_innerContainer->setPosition(Vec2(finalOffsetX, finalOffsetY));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::stopAutoScrollChildren()
|
|
|
|
{
|
|
|
|
_autoScroll = false;
|
|
|
|
_autoScrollOriginalSpeed = 0.0f;
|
|
|
|
_autoScrollAddUpTime = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
|
|
|
|
{
|
|
|
|
bool scrollenabled = true;
|
|
|
|
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) //first quadrant //bounce to top-right
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + realOffsetX >= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
bounceRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + touchOffsetY >= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
bounceTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, realOffsetY);
|
|
|
|
}
|
|
|
|
else if(touchOffsetX < 0.0f && touchOffsetY > 0.0f) //second quadrant //bounce to top-left
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLefrPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLefrPos + realOffsetX <= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLefrPos;
|
|
|
|
bounceLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + touchOffsetY >= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
bounceTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, realOffsetY);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) //third quadrant //bounce to bottom-left
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLefrPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLefrPos + realOffsetX <= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLefrPos;
|
|
|
|
bounceLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + touchOffsetY <= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
bounceBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, realOffsetY);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) //forth quadrant //bounce to bottom-right
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + realOffsetX >= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
bounceRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + touchOffsetY <= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
bounceBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, realOffsetY);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top
|
|
|
|
{
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + touchOffsetY >= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
bounceTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(0.0f, realOffsetY);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom
|
|
|
|
{
|
|
|
|
float realOffsetY = touchOffsetY;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + touchOffsetY <= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
bounceBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(0.0f, realOffsetY);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + realOffsetX >= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
bounceRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, 0.0f);
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left
|
|
|
|
{
|
|
|
|
float realOffsetX = touchOffsetX;
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + realOffsetX <= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLeftPos;
|
|
|
|
bounceLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, 0.0f);
|
|
|
|
}
|
|
|
|
return scrollenabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchOffsetY)
|
|
|
|
{
|
|
|
|
bool scrollenabled = true;
|
|
|
|
switch (_direction)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::VERTICAL: // vertical
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
if (_autoScrollDir.y > 0)
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icBottomPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + *touchOffsetY <= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icBottomPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::HORIZONTAL: // horizontal
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
if (_autoScrollDir.x > 0)
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icLeftPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + *touchOffsetX <= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icLeftPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::BOTH:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
if (*touchOffsetX > 0.0f && *touchOffsetY > 0.0f) // up right
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icLeftPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icBottomPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX < 0.0f && *touchOffsetY > 0.0f) // up left
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icRightPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icBottomPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX < 0.0f && *touchOffsetY < 0.0f) // down left
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icRightPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icTopPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX > 0.0f && *touchOffsetY < 0.0f) // down right
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icLeftPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icTopPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX == 0.0f && *touchOffsetY > 0.0f) // up
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icBottomPos + *touchOffsetY >= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icBottomPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX < 0.0f && *touchOffsetY == 0.0f) // left
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icRightPos + *touchOffsetX <= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icRightPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX == 0.0f && *touchOffsetY < 0.0f) // down
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icTopPos + *touchOffsetY <= _autoScrollDestination.y)
|
|
|
|
{
|
|
|
|
*touchOffsetY = _autoScrollDestination.y - icTopPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*touchOffsetX > 0.0f && *touchOffsetY == 0.0f) // right
|
|
|
|
{
|
2014-05-19 17:18:04 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (icLeftPos + *touchOffsetX >= _autoScrollDestination.x)
|
|
|
|
{
|
|
|
|
*touchOffsetX = _autoScrollDestination.x - icLeftPos;
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return scrollenabled;
|
|
|
|
}
|
2014-05-23 10:08:53 +08:00
|
|
|
|
|
|
|
bool ScrollView::scrollChildrenVertical(float touchOffsetX, float touchOffsetY)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
float realOffset = touchOffsetY;
|
|
|
|
bool scrollEnabled = false;
|
|
|
|
if (_bounceEnabled)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-26 17:34:56 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _bounceBottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollEnabled = false;
|
|
|
|
}
|
2014-05-26 17:34:56 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _bounceTopBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffset = _bounceTopBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollEnabled = false;
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-26 17:34:56 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _bottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollEnabled = false;
|
|
|
|
}
|
2014-05-26 17:34:56 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _topBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveChildren(0.0f, realOffset);
|
|
|
|
return scrollEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::scrollChildrenHorizontal(float touchOffsetX, float touchOffestY)
|
|
|
|
{
|
|
|
|
bool scrollenabled;
|
|
|
|
float realOffset = touchOffsetX;
|
|
|
|
if (_bounceEnabled)
|
|
|
|
{
|
2014-05-26 17:34:56 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _bounceRightBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _bounceRightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 17:34:56 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _bounceLeftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-26 17:34:56 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _rightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 17:34:56 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffset = _leftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveChildren(realOffset, 0.0f);
|
|
|
|
return scrollenabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::scrollChildrenBoth(float touchOffsetX, float touchOffsetY)
|
|
|
|
{
|
|
|
|
bool scrollenabled = false;
|
|
|
|
float realOffsetX = touchOffsetX;
|
|
|
|
float realOffsetY = touchOffsetY;
|
|
|
|
if (_bounceEnabled)
|
|
|
|
{
|
|
|
|
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right
|
|
|
|
{
|
2014-05-26 17:34:56 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetX = _bounceLeftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetY = _bounceBottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 10:08:53 +08:00
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _bounceRightBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetX = _bounceRightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetY = _bounceBottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 10:08:53 +08:00
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _bounceRightBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetX = _bounceRightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _bounceTopBoundary)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-23 10:08:53 +08:00
|
|
|
realOffsetY = _bounceTopBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _bounceLeftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _bounceTopBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bounceTopBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bounceBottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bounceBottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _bounceRightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _bounceRightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _bounceTopBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bounceTopBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _bounceLeftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _bounceLeftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) // up right
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY > 0.0f) // up left
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) // down left
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) // down right
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
}
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // up
|
|
|
|
{
|
2014-05-19 17:34:48 +08:00
|
|
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icBottomPos + touchOffsetY >= _bottomBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _bottomBoundary - icBottomPos;
|
|
|
|
scrollToBottomEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) // left
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icRightPos = _innerContainer->getRightBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icRightPos + touchOffsetX <= _rightBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _rightBoundary - icRightPos;
|
|
|
|
scrollToRightEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) // down
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icTopPos = _innerContainer->getTopBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icTopPos + touchOffsetY <= _topBoundary)
|
|
|
|
{
|
|
|
|
realOffsetY = _topBoundary - icTopPos;
|
|
|
|
scrollToTopEvent();
|
|
|
|
scrollenabled = false;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-05-23 10:08:53 +08:00
|
|
|
}
|
|
|
|
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) // right
|
|
|
|
{
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-19 17:34:48 +08:00
|
|
|
float icLeftPos = _innerContainer->getLeftBoundary();
|
2014-05-23 10:08:53 +08:00
|
|
|
if (icLeftPos + touchOffsetX >= _leftBoundary)
|
|
|
|
{
|
|
|
|
realOffsetX = _leftBoundary - icLeftPos;
|
|
|
|
scrollToLeftEvent();
|
|
|
|
scrollenabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveChildren(realOffsetX, realOffsetY);
|
|
|
|
return scrollenabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
|
|
|
{
|
|
|
|
bool scrollenabled = true;
|
|
|
|
scrollingEvent();
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
switch (_direction)
|
|
|
|
{
|
|
|
|
case Direction::VERTICAL: // vertical
|
|
|
|
{
|
|
|
|
scrollenabled = scrollChildrenVertical(touchOffsetX, touchOffsetY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Direction::HORIZONTAL: // horizontal
|
|
|
|
{
|
|
|
|
scrollenabled = scrollChildrenHorizontal(touchOffsetX, touchOffsetY);
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-05-23 10:08:53 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Direction::BOTH:
|
|
|
|
{
|
|
|
|
scrollenabled = scrollChildrenBoth(touchOffsetX, touchOffsetY);
|
2014-05-26 14:00:23 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return scrollenabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToBottom(float time, bool attenuated)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, 0.0f), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToTop(float time, bool attenuated)
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x,
|
2014-06-20 11:18:53 +08:00
|
|
|
_contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToLeft(float time, bool attenuated)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(0.0f, _innerContainer->getPosition().y), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToRight(float time, bool attenuated)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
|
2014-06-20 10:40:16 +08:00
|
|
|
_innerContainer->getPosition().y), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToTopLeft(float time, bool attenuated)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToTopRight(float time, bool attenuated)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
|
|
|
|
_contentSize.height - _innerContainer->getContentSize().height), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToBottomLeft(float time, bool attenuated)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2::ZERO, time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToBottomRight(float time, bool attenuated)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToPercentVertical(float percent, float time, bool attenuated)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
float minY = _contentSize.height - _innerContainer->getContentSize().height;
|
2014-03-11 17:13:54 +08:00
|
|
|
float h = - minY;
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToPercentHorizontal(float percent, float time, bool attenuated)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
float w = _innerContainer->getContentSize().width - _contentSize.width;
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::scrollToPercentBothDirection(const Vec2& percent, float time, bool attenuated)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
float minY = _contentSize.height - _innerContainer->getContentSize().height;
|
2014-03-11 17:13:54 +08:00
|
|
|
float h = - minY;
|
2014-06-20 11:18:53 +08:00
|
|
|
float w = _innerContainer->getContentSize().width - _contentSize.width;
|
2014-05-15 01:07:09 +08:00
|
|
|
startAutoScrollChildrenWithDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), time, attenuated);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToBottom()
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2(_innerContainer->getPosition().x, 0.0f));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToTop()
|
|
|
|
{
|
2014-06-20 10:40:16 +08:00
|
|
|
jumpToDestination(Vec2(_innerContainer->getPosition().x,
|
2014-06-20 11:18:53 +08:00
|
|
|
_contentSize.height - _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToLeft()
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2(0.0f, _innerContainer->getPosition().y));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToRight()
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, _innerContainer->getPosition().y));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToTopLeft()
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
jumpToDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToTopRight()
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
|
|
|
|
_contentSize.height - _innerContainer->getContentSize().height));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToBottomLeft()
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2::ZERO);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToBottomRight()
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
CCLOG("Scroll diretion is not both!");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
jumpToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToPercentVertical(float percent)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
float minY = _contentSize.height - _innerContainer->getContentSize().height;
|
2014-03-11 17:13:54 +08:00
|
|
|
float h = - minY;
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::jumpToPercentHorizontal(float percent)
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
float w = _innerContainer->getContentSize().width - _contentSize.width;
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ScrollView::jumpToPercentBothDirection(const Vec2& percent)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_direction != Direction::BOTH)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 11:18:53 +08:00
|
|
|
float minY = _contentSize.height - _innerContainer->getContentSize().height;
|
2014-03-11 17:13:54 +08:00
|
|
|
float h = - minY;
|
2014-06-20 11:18:53 +08:00
|
|
|
float w = _innerContainer->getContentSize().width - _contentSize.width;
|
2014-05-15 01:07:09 +08:00
|
|
|
jumpToDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f));
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::startRecordSlidAction()
|
|
|
|
{
|
|
|
|
if (_autoScroll)
|
|
|
|
{
|
|
|
|
stopAutoScrollChildren();
|
|
|
|
}
|
|
|
|
if (_bouncing)
|
|
|
|
{
|
|
|
|
stopBounceChildren();
|
|
|
|
}
|
|
|
|
_slidTime = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::endRecordSlidAction()
|
|
|
|
{
|
|
|
|
if (!checkNeedBounce() && _inertiaScrollEnabled)
|
|
|
|
{
|
|
|
|
if (_slidTime <= 0.016f)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float totalDis = 0.0f;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 dir;
|
2014-03-11 17:13:54 +08:00
|
|
|
switch (_direction)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::VERTICAL:
|
2014-06-06 16:48:49 +08:00
|
|
|
totalDis = _touchEndPosition.y - _touchBeganPosition.y;
|
2014-03-11 17:13:54 +08:00
|
|
|
if (totalDis < 0.0f)
|
|
|
|
{
|
|
|
|
dir = SCROLLDIR_DOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dir = SCROLLDIR_UP;
|
|
|
|
}
|
|
|
|
break;
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::HORIZONTAL:
|
2014-06-06 16:48:49 +08:00
|
|
|
totalDis = _touchEndPosition.x - _touchBeganPosition.x;
|
2014-03-11 17:13:54 +08:00
|
|
|
if (totalDis < 0.0f)
|
|
|
|
{
|
|
|
|
dir = SCROLLDIR_LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dir = SCROLLDIR_RIGHT;
|
|
|
|
}
|
|
|
|
break;
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::BOTH:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-06 16:48:49 +08:00
|
|
|
Vec2 subVector = _touchEndPosition - _touchBeganPosition;
|
2014-03-11 17:13:54 +08:00
|
|
|
totalDis = subVector.getLength();
|
2014-05-01 01:10:18 +08:00
|
|
|
dir = subVector.getNormalized();
|
2014-03-11 17:13:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float orSpeed = MIN(fabs(totalDis)/(_slidTime), AUTOSCROLLMAXSPEED);
|
|
|
|
startAutoScrollChildrenWithOriginalSpeed(dir, orSpeed, true, -1000);
|
|
|
|
_slidTime = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
void ScrollView::handlePressLogic(Touch *touch)
|
|
|
|
{
|
2014-03-11 17:13:54 +08:00
|
|
|
startRecordSlidAction();
|
|
|
|
_bePressed = true;
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
void ScrollView::handleMoveLogic(Touch *touch)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-06 16:48:49 +08:00
|
|
|
Vec2 delta = touch->getLocation() - touch->getPreviousLocation();
|
2014-03-11 17:13:54 +08:00
|
|
|
switch (_direction)
|
|
|
|
{
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::VERTICAL: // vertical
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
scrollChildren(0.0f, delta.y);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::HORIZONTAL: // horizontal
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
scrollChildren(delta.x, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
case Direction::BOTH: // both
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
scrollChildren(delta.x, delta.y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
void ScrollView::handleReleaseLogic(Touch *touch)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
endRecordSlidAction();
|
|
|
|
_bePressed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent)
|
|
|
|
{
|
|
|
|
bool pass = Layout::onTouchBegan(touch, unusedEvent);
|
|
|
|
if (_hitted)
|
|
|
|
{
|
2014-06-06 16:48:49 +08:00
|
|
|
handlePressLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::onTouchMoved(Touch *touch, Event *unusedEvent)
|
|
|
|
{
|
|
|
|
Layout::onTouchMoved(touch, unusedEvent);
|
2014-06-06 16:48:49 +08:00
|
|
|
handleMoveLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::onTouchEnded(Touch *touch, Event *unusedEvent)
|
|
|
|
{
|
|
|
|
Layout::onTouchEnded(touch, unusedEvent);
|
2014-06-06 16:48:49 +08:00
|
|
|
handleReleaseLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::onTouchCancelled(Touch *touch, Event *unusedEvent)
|
|
|
|
{
|
|
|
|
Layout::onTouchCancelled(touch, unusedEvent);
|
2014-06-06 16:48:49 +08:00
|
|
|
handleReleaseLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::update(float dt)
|
|
|
|
{
|
|
|
|
if (_autoScroll)
|
|
|
|
{
|
|
|
|
autoScrollChildren(dt);
|
|
|
|
}
|
|
|
|
if (_bouncing)
|
|
|
|
{
|
|
|
|
bounceChildren(dt);
|
|
|
|
}
|
|
|
|
recordSlidTime(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::recordSlidTime(float dt)
|
|
|
|
{
|
|
|
|
if (_bePressed)
|
|
|
|
{
|
|
|
|
_slidTime += dt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:48:49 +08:00
|
|
|
void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sender,Touch* touch)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-06 16:48:49 +08:00
|
|
|
Vec2 touchPoint = touch->getLocation();
|
2014-05-22 15:23:13 +08:00
|
|
|
switch (event)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-22 15:23:13 +08:00
|
|
|
case TouchEventType::BEGAN:
|
2014-06-06 16:48:49 +08:00
|
|
|
handlePressLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
break;
|
|
|
|
|
2014-05-22 15:23:13 +08:00
|
|
|
case TouchEventType::MOVED:
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-06-06 16:48:49 +08:00
|
|
|
float offset = (sender->getTouchBeganPosition() - touchPoint).getLength();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (offset > _childFocusCancelOffset)
|
|
|
|
{
|
2014-05-06 12:04:52 +08:00
|
|
|
sender->setHighlighted(false);
|
2014-06-06 16:48:49 +08:00
|
|
|
handleMoveLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-05-22 15:23:13 +08:00
|
|
|
case TouchEventType::CANCELED:
|
|
|
|
case TouchEventType::ENDED:
|
2014-06-06 16:48:49 +08:00
|
|
|
handleReleaseLogic(touch);
|
2014-03-11 17:13:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollView::scrollToTopEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::SCROLL_TO_TOP);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToBottomEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::SCROLL_TO_BOTTOM);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToLeftEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::SCROLL_TO_LEFT);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollToRightEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::SCROLL_TO_RIGHT);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::scrollingEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLLING);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::SCROLLING);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::bounceTopEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_TOP);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::BOUNCE_TOP);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::bounceBottomEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_BOTTOM);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::BOUNCE_BOTTOM);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::bounceLeftEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_LEFT);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::BOUNCE_LEFT);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::bounceRightEvent()
|
|
|
|
{
|
|
|
|
if (_scrollViewEventListener && _scrollViewEventSelector)
|
|
|
|
{
|
|
|
|
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_RIGHT);
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
if (_eventCallback) {
|
|
|
|
_eventCallback(this,EventType::BOUNCE_RIGHT);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::addEventListenerScrollView(Ref *target, SEL_ScrollViewEvent selector)
|
|
|
|
{
|
|
|
|
_scrollViewEventListener = target;
|
|
|
|
_scrollViewEventSelector = selector;
|
|
|
|
}
|
2014-05-12 11:08:10 +08:00
|
|
|
|
2014-05-14 16:14:28 +08:00
|
|
|
void ScrollView::addEventListener(const ccScrollViewCallback& callback)
|
2014-05-12 11:08:10 +08:00
|
|
|
{
|
|
|
|
_eventCallback = callback;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2014-05-12 11:08:10 +08:00
|
|
|
void ScrollView::setDirection(Direction dir)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
_direction = dir;
|
|
|
|
}
|
|
|
|
|
2014-05-27 10:48:53 +08:00
|
|
|
ScrollView::Direction ScrollView::getDirection()const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::setBounceEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
_bounceEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::isBounceEnabled() const
|
|
|
|
{
|
|
|
|
return _bounceEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::setInertiaScrollEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
_inertiaScrollEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollView::isInertiaScrollEnabled() const
|
|
|
|
{
|
|
|
|
return _inertiaScrollEnabled;
|
|
|
|
}
|
|
|
|
|
2014-05-27 10:48:53 +08:00
|
|
|
Layout* ScrollView::getInnerContainer()const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _innerContainer;
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:00:54 +08:00
|
|
|
void ScrollView::setLayoutType(Type type)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
_innerContainer->setLayoutType(type);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:00:54 +08:00
|
|
|
Layout::Type ScrollView::getLayoutType() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _innerContainer->getLayoutType();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::doLayout()
|
|
|
|
{
|
|
|
|
if (!_doLayoutDirty)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_doLayoutDirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ScrollView::getDescription() const
|
|
|
|
{
|
|
|
|
return "ScrollView";
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* ScrollView::createCloneInstance()
|
|
|
|
{
|
|
|
|
return ScrollView::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::copyClonedWidgetChildren(Widget* model)
|
|
|
|
{
|
|
|
|
Layout::copyClonedWidgetChildren(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollView::copySpecialProperties(Widget *widget)
|
|
|
|
{
|
|
|
|
ScrollView* scrollView = dynamic_cast<ScrollView*>(widget);
|
|
|
|
if (scrollView)
|
|
|
|
{
|
|
|
|
Layout::copySpecialProperties(widget);
|
|
|
|
setInnerContainerSize(scrollView->getInnerContainerSize());
|
|
|
|
setDirection(scrollView->_direction);
|
|
|
|
setBounceEnabled(scrollView->_bounceEnabled);
|
|
|
|
setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled);
|
2014-05-23 15:03:46 +08:00
|
|
|
_scrollViewEventListener = scrollView->_scrollViewEventListener;
|
|
|
|
_scrollViewEventSelector = scrollView->_scrollViewEventSelector;
|
|
|
|
_eventCallback = scrollView->_eventCallback;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 10:59:18 +08:00
|
|
|
|
|
|
|
Widget* ScrollView::findNextFocusedWidget(cocos2d::ui::Widget::FocusDirection direction, cocos2d::ui::Widget *current)
|
|
|
|
{
|
|
|
|
if (this->getLayoutType() == Layout::Type::VERTICAL
|
|
|
|
|| this->getLayoutType() == Layout::Type::HORIZONTAL) {
|
|
|
|
return _innerContainer->findNextFocusedWidget(direction, current);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Widget::findNextFocusedWidget(direction, current);
|
|
|
|
}
|
|
|
|
}
|
2014-05-23 11:18:26 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|