axmol/cocos/ui/UIScrollView.cpp

1442 lines
41 KiB
C++
Raw Normal View History

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"
#include "base/CCDirector.h"
2015-06-29 11:52:53 +08:00
#include "base/ccUtils.h"
#include "platform/CCDevice.h"
2015-07-01 11:41:47 +08:00
#include "ui/UIScrollViewBar.h"
#include "2d/CCTweenFunction.h"
#include "2d/CCCamera.h"
2014-03-11 17:13:54 +08:00
NS_CC_BEGIN
static const int NUMBER_OF_GATHERED_TOUCHES_FOR_MOVE_SPEED = 5;
static const float OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05f;
2015-07-01 11:41:47 +08:00
static const float BOUNCE_BACK_DURATION = 1.0f;
#define MOVE_INCH 7.0f/160.0f
2014-03-11 17:13:54 +08:00
2015-07-01 11:41:47 +08:00
static float convertDistanceFromPointToInch(const Vec2& dis)
{
auto glview = Director::getInstance()->getOpenGLView();
int dpi = Device::getDPI();
float distance = Vec2(dis.x * glview->getScaleX() / dpi, dis.y * glview->getScaleY() / dpi).getLength();
return distance;
}
2015-06-20 22:42:37 +08:00
2015-07-19 10:41:20 +08:00
namespace ui {
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-03-11 17:13:54 +08:00
_topBoundary(0.0f),
_bottomBoundary(0.0f),
_leftBoundary(0.0f),
_rightBoundary(0.0f),
_bePressed(false),
_childFocusCancelOffsetInInch(MOVE_INCH),
_touchMovePreviousTimestamp(0),
_autoScrolling(false),
_autoScrollAttenuate(true),
_autoScrollTotalTime(0),
_autoScrollAccumulatedTime(0),
_autoScrollCurrentlyOutOfBoundary(false),
_autoScrollBraking(false),
_inertiaScrollEnabled(true),
_bounceEnabled(false),
_outOfBoundaryAmountDirty(true),
2015-07-01 11:41:47 +08:00
_scrollBarEnabled(true),
_verticalScrollBar(nullptr),
_horizontalScrollBar(nullptr),
2014-03-11 17:13:54 +08:00
_scrollViewEventListener(nullptr),
2014-05-12 11:08:10 +08:00
_scrollViewEventSelector(nullptr),
_eventCallback(nullptr)
2014-03-11 17:13:54 +08:00
{
2014-06-24 15:51:14 +08:00
setTouchEnabled(true);
_propagateTouchEvents = false;
2014-03-11 17:13:54 +08:00
}
ScrollView::~ScrollView()
{
2015-07-03 21:17:54 +08:00
_verticalScrollBar = nullptr;
_horizontalScrollBar = nullptr;
2014-03-11 17:13:54 +08:00
_scrollViewEventListener = nullptr;
_scrollViewEventSelector = nullptr;
}
ScrollView* ScrollView::create()
{
ScrollView* widget = new (std::nothrow) ScrollView();
2014-03-11 17:13:54 +08:00
if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return nullptr;
}
2014-03-11 17:13:54 +08:00
void ScrollView::onEnter()
{
#if CC_ENABLE_SCRIPT_BINDING
if (_scriptType == kScriptTypeJavascript)
{
if (ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter))
return;
}
#endif
2014-03-11 17:13:54 +08:00
Layout::onEnter();
scheduleUpdate();
}
bool ScrollView::init()
{
if (Layout::init())
{
setClippingEnabled(true);
_innerContainer->setTouchEnabled(false);
if(_scrollBarEnabled)
{
initScrollBar();
}
2014-03-11 17:13:54 +08:00
return true;
}
return false;
}
void ScrollView::initRenderer()
{
Layout::initRenderer();
_innerContainer = Layout::create();
2014-10-09 18:28:09 +08:00
_innerContainer->setColor(Color3B(255,255,255));
_innerContainer->setOpacity(255);
_innerContainer->setCascadeColorEnabled(true);
_innerContainer->setCascadeOpacityEnabled(true);
addProtectedChild(_innerContainer, 1, 1);
2014-03-11 17:13:54 +08:00
}
void ScrollView::onSizeChanged()
{
Layout::onSizeChanged();
_topBoundary = _contentSize.height;
_rightBoundary = _contentSize.width;
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;
float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width);
float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height);
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
setInnerContainerPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height));
2014-03-11 17:13:54 +08:00
}
void ScrollView::setInnerContainerSize(const Size &size)
{
float innerSizeWidth = _contentSize.width;
float innerSizeHeight = _contentSize.height;
2014-06-20 11:18:53 +08:00
Size originalInnerSize = _innerContainer->getContentSize();
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;
}
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;
}
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
2015-06-29 11:52:53 +08:00
// Calculate and set the position of the inner container.
Vec2 pos = _innerContainer->getPosition();
2015-12-10 13:37:07 +08:00
if (_innerContainer->getLeftBoundary() != 0.0f)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
pos.x = _innerContainer->getAnchorPoint().x * _innerContainer->getContentSize().width;
2014-03-11 17:13:54 +08:00
}
2015-12-10 13:37:07 +08:00
if (_innerContainer->getTopBoundary() != _contentSize.height)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height;
2014-03-11 17:13:54 +08:00
}
setInnerContainerPosition(pos);
updateScrollBar(Vec2::ZERO);
2014-03-11 17:13:54 +08:00
}
const Size& ScrollView::getInnerContainerSize() const
{
2015-06-29 11:52:53 +08:00
return _innerContainer->getContentSize();
2014-03-11 17:13:54 +08:00
}
void ScrollView::setInnerContainerPosition(const Vec2 &position)
{
if(position == _innerContainer->getPosition())
{
return;
}
_innerContainer->setPosition(position);
_outOfBoundaryAmountDirty = true;
// Process bouncing events
if(_bounceEnabled)
{
for(int direction = (int) MoveDirection::TOP; direction < (int) MoveDirection::RIGHT; ++direction)
{
if(isOutOfBoundary((MoveDirection) direction))
{
processScrollEvent((MoveDirection) direction, true);
}
}
}
this->retain();
if (_eventCallback)
{
_eventCallback(this, EventType::CONTAINER_MOVED);
}
if (_ccEventCallback)
{
_ccEventCallback(this, static_cast<int>(EventType::CONTAINER_MOVED));
}
this->release();
}
const Vec2 ScrollView::getInnerContainerPosition() const
{
return _innerContainer->getPosition();
}
2014-06-25 16:17:16 +08:00
void ScrollView::addChild(Node* child)
{
ScrollView::addChild(child, child->getLocalZOrder(), child->getTag());
}
2014-06-25 16:17:16 +08:00
void ScrollView::addChild(Node * child, int localZOrder)
{
ScrollView::addChild(child, localZOrder, 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
}
2014-06-25 11:27:48 +08:00
void ScrollView::addChild(Node* child, int zOrder, const std::string &name)
{
_innerContainer->addChild(child, zOrder, name);
}
2014-03-11 17:13:54 +08:00
void ScrollView::removeAllChildren()
{
removeAllChildrenWithCleanup(true);
}
2014-03-11 17:13:54 +08:00
void ScrollView::removeAllChildrenWithCleanup(bool cleanup)
{
_innerContainer->removeAllChildrenWithCleanup(cleanup);
}
void ScrollView::removeChild(Node* child, bool cleanup)
{
2015-06-29 11:52:53 +08:00
return _innerContainer->removeChild(child, cleanup);
2014-03-11 17:13:54 +08:00
}
Vector<Node*>& ScrollView::getChildren()
{
return _innerContainer->getChildren();
}
const Vector<Node*>& ScrollView::getChildren() const
{
return _innerContainer->getChildren();
}
ssize_t ScrollView::getChildrenCount() const
{
return _innerContainer->getChildrenCount();
}
Node* ScrollView::getChildByTag(int tag) const
2014-03-11 17:13:54 +08:00
{
return _innerContainer->getChildByTag(tag);
}
Node* ScrollView::getChildByName(const std::string& name)const
2014-03-11 17:13:54 +08:00
{
return _innerContainer->getChildByName(name);
}
void ScrollView::moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack)
2014-03-11 17:13:54 +08:00
{
Vec2 adjustedMove = flattenVectorByDirection(deltaMove);
setInnerContainerPosition(getInnerContainerPosition() + adjustedMove);
Vec2 outOfBoundary = getHowMuchOutOfBoundary();
2015-07-03 21:17:54 +08:00
updateScrollBar(outOfBoundary);
if(_bounceEnabled && canStartBounceBack)
{
startBounceBackIfNeeded();
}
2015-07-01 11:41:47 +08:00
}
void ScrollView::updateScrollBar(const Vec2& outOfBoundary)
{
2015-07-03 21:17:54 +08:00
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->onScrolled(outOfBoundary);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->onScrolled(outOfBoundary);
}
2014-03-11 17:13:54 +08:00
}
Vec2 ScrollView::calculateTouchMoveVelocity() const
{
float totalTime = 0;
for(auto &timeDelta : _touchMoveTimeDeltas)
{
totalTime += timeDelta;
}
if(totalTime == 0 || totalTime >= 0.5f)
{
return Vec2::ZERO;
}
Vec2 totalMovement;
for(auto &displacement : _touchMoveDisplacements)
{
totalMovement += displacement;
}
return totalMovement / totalTime;
}
void ScrollView::startInertiaScroll(const Vec2& touchMoveVelocity)
{
const float MOVEMENT_FACTOR = 0.7f;
Vec2 inertiaTotalMovement = touchMoveVelocity * MOVEMENT_FACTOR;
startAttenuatingAutoScroll(inertiaTotalMovement, touchMoveVelocity);
}
bool ScrollView::startBounceBackIfNeeded()
2014-03-11 17:13:54 +08:00
{
if (!_bounceEnabled)
{
return false;
}
Vec2 bounceBackAmount = getHowMuchOutOfBoundary();
if(bounceBackAmount == Vec2::ZERO)
2015-06-29 11:52:53 +08:00
{
return false;
}
startAutoScroll(bounceBackAmount, BOUNCE_BACK_DURATION, true);
2015-06-29 11:52:53 +08:00
return true;
2015-06-20 22:42:37 +08:00
}
Vec2 ScrollView::flattenVectorByDirection(const Vec2& vector)
2015-06-20 22:42:37 +08:00
{
Vec2 result = vector;
result.x = (_direction == Direction::VERTICAL ? 0 : result.x);
result.y = (_direction == Direction::HORIZONTAL ? 0 : result.y);
return result;
}
2015-06-29 11:52:53 +08:00
Vec2 ScrollView::getHowMuchOutOfBoundary(const Vec2& addition)
{
if(addition == Vec2::ZERO && !_outOfBoundaryAmountDirty)
{
return _outOfBoundaryAmount;
}
Vec2 outOfBoundaryAmount;
2015-06-29 11:52:53 +08:00
if(_innerContainer->getLeftBoundary() + addition.x > _leftBoundary)
{
outOfBoundaryAmount.x = _leftBoundary - (_innerContainer->getLeftBoundary() + addition.x);
2015-06-29 11:52:53 +08:00
}
else if(_innerContainer->getRightBoundary() + addition.x < _rightBoundary)
{
outOfBoundaryAmount.x = _rightBoundary - (_innerContainer->getRightBoundary() + addition.x);
2015-06-29 11:52:53 +08:00
}
2015-06-29 11:52:53 +08:00
if(_innerContainer->getTopBoundary() + addition.y < _topBoundary)
{
outOfBoundaryAmount.y = _topBoundary - (_innerContainer->getTopBoundary() + addition.y);
2015-06-29 11:52:53 +08:00
}
else if(_innerContainer->getBottomBoundary() + addition.y > _bottomBoundary)
{
outOfBoundaryAmount.y = _bottomBoundary - (_innerContainer->getBottomBoundary() + addition.y);
2015-06-29 11:52:53 +08:00
}
if(addition == Vec2::ZERO)
{
_outOfBoundaryAmount = outOfBoundaryAmount;
_outOfBoundaryAmountDirty = false;
}
return outOfBoundaryAmount;
}
bool ScrollView::isOutOfBoundary(MoveDirection dir)
2015-06-19 17:32:32 +08:00
{
Vec2 outOfBoundary = getHowMuchOutOfBoundary();
2015-06-29 11:52:53 +08:00
switch(dir)
{
case MoveDirection::TOP: return outOfBoundary.y > 0;
case MoveDirection::BOTTOM: return outOfBoundary.y < 0;
case MoveDirection::LEFT: return outOfBoundary.x < 0;
case MoveDirection::RIGHT: return outOfBoundary.x > 0;
2015-06-29 11:52:53 +08:00
}
return false;
2015-06-19 17:32:32 +08:00
}
bool ScrollView::isOutOfBoundary()
{
return getHowMuchOutOfBoundary() != Vec2::ZERO;
}
void ScrollView::startAutoScrollToDestination(const Vec2& destination, float timeInSec, bool attenuated)
{
startAutoScroll(destination - _innerContainer->getPosition(), timeInSec, attenuated);
}
static float calculateAutoScrollTimeByInitialSpeed(float initialSpeed)
{
// Calculate the time from the initial speed according to quintic polynomial.
float time = sqrtf(sqrtf(initialSpeed / 5));
return time;
}
void ScrollView::startAttenuatingAutoScroll(const Vec2& deltaMove, const Vec2& initialVelocity)
{
float time = calculateAutoScrollTimeByInitialSpeed(initialVelocity.length());
startAutoScroll(deltaMove, time, true);
}
void ScrollView::startAutoScroll(const Vec2& deltaMove, float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
Vec2 adjustedDeltaMove = flattenVectorByDirection(deltaMove);
2015-06-29 11:52:53 +08:00
_autoScrolling = true;
_autoScrollTargetDelta = adjustedDeltaMove;
2015-06-29 11:52:53 +08:00
_autoScrollAttenuate = attenuated;
_autoScrollStartPosition = _innerContainer->getPosition();
_autoScrollTotalTime = timeInSec;
2015-06-29 11:52:53 +08:00
_autoScrollAccumulatedTime = 0;
_autoScrollBraking = false;
_autoScrollBrakingStartPosition = Vec2::ZERO;
// If the destination is also out of boundary of same side, start brake from beginning.
Vec2 currentOutOfBoundary = getHowMuchOutOfBoundary();
if(currentOutOfBoundary != Vec2::ZERO)
{
_autoScrollCurrentlyOutOfBoundary = true;
Vec2 afterOutOfBoundary = getHowMuchOutOfBoundary(adjustedDeltaMove);
if(currentOutOfBoundary.x * afterOutOfBoundary.x > 0 || currentOutOfBoundary.y * afterOutOfBoundary.y > 0)
{
_autoScrollBraking = true;
}
}
2014-03-11 17:13:54 +08:00
}
bool ScrollView::isNecessaryAutoScrollBrake()
2014-03-11 17:13:54 +08:00
{
if(_autoScrollBraking)
{
return true;
}
if(isOutOfBoundary())
{
// It just went out of boundary.
if(!_autoScrollCurrentlyOutOfBoundary)
{
_autoScrollCurrentlyOutOfBoundary = true;
_autoScrollBraking = true;
_autoScrollBrakingStartPosition = getInnerContainerPosition();
return true;
}
}
else
{
_autoScrollCurrentlyOutOfBoundary = false;
}
return false;
}
void ScrollView::processAutoScrolling(float deltaTime)
{
// Make auto scroll shorter if it needs to deaccelerate.
float brakingFactor = (isNecessaryAutoScrollBrake() ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1);
// Elapsed time
_autoScrollAccumulatedTime += deltaTime * (1 / brakingFactor);
// Calculate the progress percentage
float percentage = MIN(1, _autoScrollAccumulatedTime / _autoScrollTotalTime);
if(_autoScrollAttenuate)
{
// Use quintic(5th degree) polynomial
percentage = tweenfunc::quintEaseOut(percentage);
}
// Calculate the new position
Vec2 newPosition = _autoScrollStartPosition + (_autoScrollTargetDelta * percentage);
bool reachedEnd = (percentage == 1);
if(_bounceEnabled)
{
// The new position is adjusted if out of boundary
newPosition = _autoScrollBrakingStartPosition + (newPosition - _autoScrollBrakingStartPosition) * brakingFactor;
}
else
{
// Don't let go out of boundary
Vec2 moveDelta = newPosition - getInnerContainerPosition();
Vec2 outOfBoundary = getHowMuchOutOfBoundary(moveDelta);
if(outOfBoundary != Vec2::ZERO)
{
newPosition += outOfBoundary;
reachedEnd = true;
}
}
// Finish auto scroll if it ended
if(reachedEnd)
{
_autoScrolling = false;
}
moveInnerContainer(newPosition - getInnerContainerPosition(), reachedEnd);
2014-03-11 17:13:54 +08:00
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void ScrollView::jumpToDestination(const Vec2 &des)
2014-03-11 17:13:54 +08:00
{
_autoScrolling = false;
moveInnerContainer(des - getInnerContainerPosition(), true);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollChildren(const Vec2& deltaMove)
{
Vec2 realMove = deltaMove;
2015-07-03 21:17:54 +08:00
if(_bounceEnabled)
{
// If the position of the inner container is out of the boundary, the offsets should be divided by two.
Vec2 outOfBoundary = getHowMuchOutOfBoundary();
realMove.x *= (outOfBoundary.x == 0 ? 1 : 0.5f);
realMove.y *= (outOfBoundary.y == 0 ? 1 : 0.5f);
2015-07-03 21:17:54 +08:00
}
if(!_bounceEnabled)
{
Vec2 outOfBoundary = getHowMuchOutOfBoundary(realMove);
realMove += outOfBoundary;
}
2015-07-03 21:17:54 +08:00
bool scrolledToLeft = false;
bool scrolledToRight = false;
bool scrolledToTop = false;
bool scrolledToBottom = false;
if (realMove.y > 0.0f) // up
2015-07-03 21:17:54 +08:00
{
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + realMove.y >= _bottomBoundary)
2015-07-03 21:17:54 +08:00
{
scrolledToBottom = true;
2015-07-03 21:17:54 +08:00
}
}
else if (realMove.y < 0.0f) // down
2015-07-03 21:17:54 +08:00
{
float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + realMove.y <= _topBoundary)
2015-07-03 21:17:54 +08:00
{
scrolledToTop = true;
2015-07-03 21:17:54 +08:00
}
}
if (realMove.x < 0.0f) // left
2015-07-03 21:17:54 +08:00
{
float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realMove.x <= _rightBoundary)
2015-07-03 21:17:54 +08:00
{
scrolledToRight = true;
2015-07-03 21:17:54 +08:00
}
}
else if (realMove.x > 0.0f) // right
2015-07-03 21:17:54 +08:00
{
float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + realMove.x >= _leftBoundary)
2015-07-03 21:17:54 +08:00
{
scrolledToLeft = true;
2015-07-03 21:17:54 +08:00
}
}
moveInnerContainer(realMove, false);
if(realMove.x != 0 || realMove.y != 0)
{
processScrollingEvent();
}
if(scrolledToBottom)
{
processScrollEvent(MoveDirection::BOTTOM, false);
}
if(scrolledToTop)
{
processScrollEvent(MoveDirection::TOP, false);
}
if(scrolledToLeft)
{
processScrollEvent(MoveDirection::LEFT, false);
}
if(scrolledToRight)
{
processScrollEvent(MoveDirection::RIGHT, false);
}
}
void ScrollView::scrollToBottom(float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollToDestination(Vec2(_innerContainer->getPosition().x, 0.0f), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTop(float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollToDestination(Vec2(_innerContainer->getPosition().x,
_contentSize.height - _innerContainer->getContentSize().height), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToLeft(float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollToDestination(Vec2(0.0f, _innerContainer->getPosition().y), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToRight(float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_innerContainer->getPosition().y), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTopLeft(float timeInSec, 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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
return;
}
startAutoScrollToDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTopRight(float timeInSec, 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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
return;
}
startAutoScrollToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_contentSize.height - _innerContainer->getContentSize().height), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToBottomLeft(float timeInSec, 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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
return;
}
startAutoScrollToDestination(Vec2::ZERO, timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToBottomRight(float timeInSec, 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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
return;
}
startAutoScrollToDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentVertical(float percent, float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
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;
startAutoScrollToDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentHorizontal(float percent, float timeInSec, bool attenuated)
2014-03-11 17:13:54 +08:00
{
2014-06-20 11:18:53 +08:00
float w = _innerContainer->getContentSize().width - _contentSize.width;
startAutoScrollToDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentBothDirection(const Vec2& percent, float timeInSec, 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;
startAutoScrollToDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), timeInSec, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::jumpToBottom()
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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()
{
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()
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
return;
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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
{
2015-07-01 11:41:47 +08:00
CCLOG("Scroll direction is not both!");
2014-03-11 17:13:54 +08:00
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;
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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;
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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;
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
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
}
bool ScrollView::calculateCurrAndPrevTouchPoints(Touch* touch, Vec3* currPt, Vec3* prevPt)
{
if (nullptr == _hittedByCamera ||
false == hitTest(touch->getLocation(), _hittedByCamera, currPt) ||
false == hitTest(touch->getPreviousLocation(), _hittedByCamera, prevPt))
{
return false;
}
return true;
}
void ScrollView::gatherTouchMove(const Vec2& delta)
{
while(_touchMoveDisplacements.size() >= NUMBER_OF_GATHERED_TOUCHES_FOR_MOVE_SPEED)
{
_touchMoveDisplacements.pop_front();
_touchMoveTimeDeltas.pop_front();
}
_touchMoveDisplacements.push_back(delta);
long long timestamp = utils::getTimeInMilliseconds();
_touchMoveTimeDeltas.push_back((timestamp - _touchMovePreviousTimestamp) / 1000.0f);
_touchMovePreviousTimestamp = timestamp;
}
2015-07-19 10:41:20 +08:00
void ScrollView::handlePressLogic(Touch *touch)
2014-03-11 17:13:54 +08:00
{
2015-07-19 10:41:20 +08:00
_bePressed = true;
_autoScrolling = false;
2015-07-19 10:41:20 +08:00
// Clear gathered touch move information
{
_touchMovePreviousTimestamp = utils::getTimeInMilliseconds();
_touchMoveDisplacements.clear();
_touchMoveTimeDeltas.clear();
}
2015-07-03 21:17:54 +08:00
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->onTouchBegan();
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->onTouchBegan();
}
2014-03-11 17:13:54 +08:00
}
2014-06-06 16:48:49 +08:00
void ScrollView::handleMoveLogic(Touch *touch)
2014-03-11 17:13:54 +08:00
{
Vec3 currPt, prevPt;
if(!calculateCurrAndPrevTouchPoints(touch, &currPt, &prevPt))
{
return;
}
Vec3 delta3 = currPt - prevPt;
Vec2 delta(delta3.x, delta3.y);
scrollChildren(delta);
2015-07-19 10:41:20 +08:00
// Gather touch move information for speed calculation
gatherTouchMove(delta);
}
void ScrollView::handleReleaseLogic(Touch *touch)
{
// Gather the last touch information when released
2015-06-29 11:52:53 +08:00
{
Vec3 currPt, prevPt;
if(calculateCurrAndPrevTouchPoints(touch, &currPt, &prevPt))
2015-07-19 10:41:20 +08:00
{
Vec3 delta3 = currPt - prevPt;
Vec2 delta(delta3.x, delta3.y);
gatherTouchMove(delta);
2015-07-19 10:41:20 +08:00
}
2015-06-29 11:52:53 +08:00
}
2014-03-11 17:13:54 +08:00
_bePressed = false;
2015-07-03 21:17:54 +08:00
2015-07-19 10:41:20 +08:00
bool bounceBackStarted = startBounceBackIfNeeded();
if(!bounceBackStarted && _inertiaScrollEnabled)
{
Vec2 touchMoveVelocity = calculateTouchMoveVelocity();
if(touchMoveVelocity != Vec2::ZERO)
{
startInertiaScroll(touchMoveVelocity);
}
2015-07-19 10:41:20 +08:00
}
2015-07-03 21:17:54 +08:00
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->onTouchEnded();
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->onTouchEnded();
}
}
2014-03-11 17:13:54 +08:00
bool ScrollView::onTouchBegan(Touch *touch, Event *unusedEvent)
{
bool pass = Layout::onTouchBegan(touch, unusedEvent);
if (!_isInterceptTouch)
2014-03-11 17:13:54 +08:00
{
if (_hitted)
{
handlePressLogic(touch);
}
2014-03-11 17:13:54 +08:00
}
return pass;
}
void ScrollView::onTouchMoved(Touch *touch, Event *unusedEvent)
{
Layout::onTouchMoved(touch, unusedEvent);
if (!_isInterceptTouch)
{
handleMoveLogic(touch);
}
2014-03-11 17:13:54 +08:00
}
void ScrollView::onTouchEnded(Touch *touch, Event *unusedEvent)
{
Layout::onTouchEnded(touch, unusedEvent);
if (!_isInterceptTouch)
{
handleReleaseLogic(touch);
}
_isInterceptTouch = false;
2014-03-11 17:13:54 +08:00
}
void ScrollView::onTouchCancelled(Touch *touch, Event *unusedEvent)
{
Layout::onTouchCancelled(touch, unusedEvent);
if (!_isInterceptTouch)
{
handleReleaseLogic(touch);
}
_isInterceptTouch = false;
2014-03-11 17:13:54 +08:00
}
void ScrollView::update(float dt)
{
if (_autoScrolling)
2015-07-03 21:17:54 +08:00
{
processAutoScrolling(dt);
}
2014-03-11 17:13:54 +08:00
}
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
{
if(!_touchEnabled)
{
Layout::interceptTouchEvent(event, sender, touch);
return;
}
2014-06-06 16:48:49 +08:00
Vec2 touchPoint = touch->getLocation();
switch (event)
2014-03-11 17:13:54 +08:00
{
case TouchEventType::BEGAN:
{
_isInterceptTouch = true;
2014-06-25 10:45:08 +08:00
_touchBeganPosition = touch->getLocation();
2014-06-06 16:48:49 +08:00
handlePressLogic(touch);
}
break;
case TouchEventType::MOVED:
2014-03-11 17:13:54 +08:00
{
2014-08-19 15:14:07 +08:00
_touchMovePosition = touch->getLocation();
// calculates move offset in points
float offsetInInch = 0;
switch (_direction)
{
case Direction::HORIZONTAL:
offsetInInch = convertDistanceFromPointToInch(Vec2(fabs(sender->getTouchBeganPosition().x - touchPoint.x), 0));
break;
case Direction::VERTICAL:
offsetInInch = convertDistanceFromPointToInch(Vec2(0, fabs(sender->getTouchBeganPosition().y - touchPoint.y)));
break;
case Direction::BOTH:
offsetInInch = convertDistanceFromPointToInch(sender->getTouchBeganPosition() - touchPoint);
break;
default:
break;
}
if (offsetInInch > _childFocusCancelOffsetInInch)
2014-03-11 17:13:54 +08:00
{
sender->setHighlighted(false);
2014-06-06 16:48:49 +08:00
handleMoveLogic(touch);
2014-03-11 17:13:54 +08:00
}
}
break;
case TouchEventType::CANCELED:
case TouchEventType::ENDED:
{
2014-06-25 10:45:08 +08:00
_touchEndPosition = touch->getLocation();
2014-06-06 16:48:49 +08:00
handleReleaseLogic(touch);
if (sender->isSwallowTouches())
{
_isInterceptTouch = false;
}
}
break;
2014-03-11 17:13:54 +08:00
}
}
void ScrollView::processScrollEvent(MoveDirection dir, bool bounce)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
ScrollviewEventType scrollEventType;
EventType eventType;
switch(dir) {
case MoveDirection::TOP:
{
scrollEventType = (bounce ? SCROLLVIEW_EVENT_BOUNCE_TOP : SCROLLVIEW_EVENT_SCROLL_TO_TOP);
eventType = (bounce ? EventType::BOUNCE_TOP : EventType::SCROLL_TO_TOP);
break;
}
case MoveDirection::BOTTOM:
{
scrollEventType = (bounce ? SCROLLVIEW_EVENT_BOUNCE_BOTTOM : SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM);
eventType = (bounce ? EventType::BOUNCE_BOTTOM : EventType::SCROLL_TO_BOTTOM);
break;
}
case MoveDirection::LEFT:
{
scrollEventType = (bounce ? SCROLLVIEW_EVENT_BOUNCE_LEFT : SCROLLVIEW_EVENT_SCROLL_TO_LEFT);
eventType = (bounce ? EventType::BOUNCE_LEFT : EventType::SCROLL_TO_LEFT);
break;
}
case MoveDirection::RIGHT:
{
scrollEventType = (bounce ? SCROLLVIEW_EVENT_BOUNCE_RIGHT : SCROLLVIEW_EVENT_SCROLL_TO_RIGHT);
eventType = (bounce ? EventType::BOUNCE_RIGHT : EventType::SCROLL_TO_RIGHT);
break;
2015-07-03 21:17:54 +08:00
}
2015-06-29 11:52:53 +08:00
}
dispatchEvent(scrollEventType, eventType);
2014-03-11 17:13:54 +08:00
}
void ScrollView::processScrollingEvent()
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
dispatchEvent(SCROLLVIEW_EVENT_SCROLLING, EventType::SCROLLING);
2014-03-11 17:13:54 +08:00
}
void ScrollView::dispatchEvent(ScrollviewEventType scrollEventType, EventType eventType)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, scrollEventType);
}
if (_eventCallback)
{
_eventCallback(this, eventType);
}
if (_ccEventCallback)
{
_ccEventCallback(this, static_cast<int>(eventType));
}
this->release();
2014-03-11 17:13:54 +08:00
}
void ScrollView::addEventListenerScrollView(Ref *target, SEL_ScrollViewEvent selector)
{
_scrollViewEventListener = target;
_scrollViewEventSelector = selector;
}
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;
if(_scrollBarEnabled)
{
removeScrollBar();
initScrollBar();
}
2014-03-11 17:13:54 +08:00
}
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;
}
2015-07-01 11:41:47 +08:00
void ScrollView::setScrollBarEnabled(bool enabled)
{
2015-11-10 20:03:51 +08:00
if(_scrollBarEnabled == enabled)
{
return;
}
if(_scrollBarEnabled)
{
removeScrollBar();
}
2015-07-03 21:17:54 +08:00
_scrollBarEnabled = enabled;
if(_scrollBarEnabled)
{
initScrollBar();
}
2015-07-01 11:41:47 +08:00
}
bool ScrollView::isScrollBarEnabled() const
{
2015-07-03 21:17:54 +08:00
return _scrollBarEnabled;
2015-07-01 11:41:47 +08:00
}
void ScrollView::setScrollBarPositionFromCorner(const Vec2& positionFromCorner)
{
if(_direction != Direction::HORIZONTAL)
{
setScrollBarPositionFromCornerForVertical(positionFromCorner);
}
if(_direction != Direction::VERTICAL)
{
setScrollBarPositionFromCornerForHorizontal(positionFromCorner);
}
}
void ScrollView::setScrollBarPositionFromCornerForVertical(const Vec2& positionFromCorner)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
CCASSERT(_direction != Direction::HORIZONTAL, "Scroll view doesn't have a vertical scroll bar!");
_verticalScrollBar->setPositionFromCorner(positionFromCorner);
}
2015-07-04 14:40:47 +08:00
Vec2 ScrollView::getScrollBarPositionFromCornerForVertical() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
CCASSERT(_direction != Direction::HORIZONTAL, "Scroll view doesn't have a vertical scroll bar!");
return _verticalScrollBar->getPositionFromCorner();
}
void ScrollView::setScrollBarPositionFromCornerForHorizontal(const Vec2& positionFromCorner)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
CCASSERT(_direction != Direction::VERTICAL, "Scroll view doesn't have a horizontal scroll bar!");
_horizontalScrollBar->setPositionFromCorner(positionFromCorner);
}
2015-07-04 14:40:47 +08:00
Vec2 ScrollView::getScrollBarPositionFromCornerForHorizontal() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
CCASSERT(_direction != Direction::VERTICAL, "Scroll view doesn't have a horizontal scroll bar!");
return _horizontalScrollBar->getPositionFromCorner();
}
void ScrollView::setScrollBarWidth(float width)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->setWidth(width);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->setWidth(width);
}
}
float ScrollView::getScrollBarWidth() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
return _verticalScrollBar->getWidth();
}
else if(_horizontalScrollBar != nullptr)
{
return _horizontalScrollBar->getWidth();
}
return 0;
}
void ScrollView::setScrollBarColor(const Color3B& color)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->setColor(color);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->setColor(color);
}
}
const Color3B& ScrollView::getScrollBarColor() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
return _verticalScrollBar->getColor();
}
else if(_horizontalScrollBar != nullptr)
{
return _horizontalScrollBar->getColor();
}
return Color3B::WHITE;
}
void ScrollView::setScrollBarOpacity(GLubyte opacity)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->setOpacity(opacity);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->setOpacity(opacity);
}
}
GLubyte ScrollView::getScrollBarOpacity() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
return _verticalScrollBar->getOpacity();
}
else if(_horizontalScrollBar != nullptr)
{
return _horizontalScrollBar->getOpacity();
}
return -1;
}
void ScrollView::setScrollBarAutoHideEnabled(bool autoHideEnabled)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->setAutoHideEnabled(autoHideEnabled);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->setAutoHideEnabled(autoHideEnabled);
}
}
bool ScrollView::isScrollBarAutoHideEnabled() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
return _verticalScrollBar->isAutoHideEnabled();
}
else if(_horizontalScrollBar != nullptr)
{
return _horizontalScrollBar->isAutoHideEnabled();
}
return false;
}
void ScrollView::setScrollBarAutoHideTime(float autoHideTime)
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
_verticalScrollBar->setAutoHideTime(autoHideTime);
}
if(_horizontalScrollBar != nullptr)
{
_horizontalScrollBar->setAutoHideTime(autoHideTime);
}
}
float ScrollView::getScrollBarAutoHideTime() const
{
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
if(_verticalScrollBar != nullptr)
{
return _verticalScrollBar->getAutoHideTime();
}
else if(_horizontalScrollBar != nullptr)
{
return _horizontalScrollBar->getAutoHideTime();
}
return 0;
}
2014-05-27 10:48:53 +08:00
Layout* ScrollView::getInnerContainer()const
2014-03-11 17:13:54 +08:00
{
return _innerContainer;
}
void ScrollView::setLayoutType(Type type)
2014-03-11 17:13:54 +08:00
{
_innerContainer->setLayoutType(type);
}
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);
setDirection(scrollView->_direction);
setInnerContainerPosition(scrollView->getInnerContainerPosition());
2015-06-29 11:52:53 +08:00
setInnerContainerSize(scrollView->getInnerContainerSize());
_topBoundary = scrollView->_topBoundary;
_bottomBoundary = scrollView->_bottomBoundary;
_leftBoundary = scrollView->_leftBoundary;
_rightBoundary = scrollView->_rightBoundary;
_bePressed = scrollView->_bePressed;
_childFocusCancelOffsetInInch = scrollView->_childFocusCancelOffsetInInch;
_touchMoveDisplacements = scrollView->_touchMoveDisplacements;
_touchMoveTimeDeltas = scrollView->_touchMoveTimeDeltas;
_touchMovePreviousTimestamp = scrollView->_touchMovePreviousTimestamp;
2015-06-29 11:52:53 +08:00
_autoScrolling = scrollView->_autoScrolling;
_autoScrollAttenuate = scrollView->_autoScrollAttenuate;
_autoScrollStartPosition = scrollView->_autoScrollStartPosition;
_autoScrollTargetDelta = scrollView->_autoScrollTargetDelta;
_autoScrollTotalTime = scrollView->_autoScrollTotalTime;
2015-06-29 11:52:53 +08:00
_autoScrollAccumulatedTime = scrollView->_autoScrollAccumulatedTime;
_autoScrollCurrentlyOutOfBoundary = scrollView->_autoScrollCurrentlyOutOfBoundary;
_autoScrollBraking = scrollView->_autoScrollBraking;
_autoScrollBrakingStartPosition = scrollView->_autoScrollBrakingStartPosition;
setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled);
2015-06-29 11:52:53 +08:00
setBounceEnabled(scrollView->_bounceEnabled);
2014-05-23 15:03:46 +08:00
_scrollViewEventListener = scrollView->_scrollViewEventListener;
_scrollViewEventSelector = scrollView->_scrollViewEventSelector;
_eventCallback = scrollView->_eventCallback;
_ccEventCallback = scrollView->_ccEventCallback;
setScrollBarEnabled(scrollView->isScrollBarEnabled());
if(isScrollBarEnabled())
{
if(_direction != Direction::HORIZONTAL)
{
setScrollBarPositionFromCornerForVertical(scrollView->getScrollBarPositionFromCornerForVertical());
}
if(_direction != Direction::VERTICAL)
{
setScrollBarPositionFromCornerForHorizontal(scrollView->getScrollBarPositionFromCornerForHorizontal());
}
setScrollBarWidth(scrollView->getScrollBarWidth());
setScrollBarColor(scrollView->getScrollBarColor());
setScrollBarAutoHideEnabled(scrollView->isScrollBarAutoHideEnabled());
setScrollBarAutoHideTime(scrollView->getScrollBarAutoHideTime());
}
2014-03-11 17:13:54 +08:00
}
}
2015-07-01 11:41:47 +08:00
void ScrollView::initScrollBar()
{
2015-07-03 21:17:54 +08:00
if(_direction != Direction::HORIZONTAL && _verticalScrollBar == nullptr)
{
_verticalScrollBar = ScrollViewBar::create(this, Direction::VERTICAL);
addProtectedChild(_verticalScrollBar, 2);
}
if(_direction != Direction::VERTICAL && _horizontalScrollBar == nullptr)
{
_horizontalScrollBar = ScrollViewBar::create(this, Direction::HORIZONTAL);
addProtectedChild(_horizontalScrollBar, 2);
}
2015-07-01 11:41:47 +08:00
}
void ScrollView::removeScrollBar()
{
2015-07-03 21:17:54 +08:00
if(_verticalScrollBar != nullptr)
{
removeProtectedChild(_verticalScrollBar);
_verticalScrollBar = nullptr;
}
if(_horizontalScrollBar != nullptr)
{
removeProtectedChild(_horizontalScrollBar);
_horizontalScrollBar = nullptr;
}
2015-07-01 11:41:47 +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)
{
2014-05-23 10:59:18 +08:00
return _innerContainer->findNextFocusedWidget(direction, current);
}
else
{
return Widget::findNextFocusedWidget(direction, current);
}
}
2014-03-11 17:13:54 +08:00
}
NS_CC_END