axmol/cocos/ui/UIScrollView.cpp

1108 lines
32 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"
#include "2d/CCTweenFunction.h"
#include "2d/CCCamera.h"
2014-03-11 17:13:54 +08:00
NS_CC_BEGIN
namespace ui {
static const float INERTIA_DEACCELERATION = 3000.0f;
2015-06-20 22:42:37 +08:00
static const float BOUNCE_BACK_DURATION = 0.3f;
#define MOVE_INCH 7.0f/160.0f
2014-03-11 17:13:54 +08:00
static float convertDistanceFromPointToInch(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
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),
_inertiaScrollEnabled(true),
_inertiaScrolling(false),
_inertiaPrevTouchTimestamp(0),
_inertiaScrollExpectedTime(0),
_inertiaScrollElapsedTime(0),
_autoScrolling(false),
_autoScrollAttenuate(true),
_autoScrollDuration(0),
_autoScrollAccumulatedTime(0),
_bounceEnabled(false),
_bouncingBack(false),
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);
2014-03-11 17:13:54 +08:00
}
ScrollView::~ScrollView()
{
_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);
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));
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)
{
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
// Scroll children appropriately
{
float offsetX = originalInnerSize.height - innerSizeHeight;
float offsetY = 0;
if (_innerContainer->getRightBoundary() <= _contentSize.width)
{
offsetX = originalInnerSize.width - innerSizeWidth;
}
if(offsetX != 0 || offsetY != 0)
{
scrollChildren(offsetX, offsetY);
}
}
// Calculate and set the position of the inner container.
Vec2 pos = _innerContainer->getPosition();
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
}
if (_innerContainer->getRightBoundary() < _contentSize.width)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
pos.x = _contentSize.width - ((1.0f - _innerContainer->getAnchorPoint().x) * _innerContainer->getContentSize().width);
2014-03-11 17:13:54 +08:00
}
if (_innerContainer->getPosition().y > 0.0f)
{
2015-06-29 11:52:53 +08:00
pos.y = _innerContainer->getAnchorPoint().y * _innerContainer->getContentSize().height;
2014-03-11 17:13:54 +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
}
2015-06-29 11:52:53 +08:00
_innerContainer->setPosition(pos);
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
}
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);
}
2014-03-11 17:13:54 +08:00
void ScrollView::moveChildren(float offsetX, float offsetY)
{
2015-06-29 11:52:53 +08:00
Vec2 position = _innerContainer->getPosition() + Vec2(offsetX, offsetY);
2015-06-19 11:58:30 +08:00
_innerContainer->setPosition(position);
2014-03-11 17:13:54 +08:00
}
bool ScrollView::startBounceBackIfNeeded()
2014-03-11 17:13:54 +08:00
{
if (!_bounceEnabled)
{
return false;
}
2015-06-29 11:52:53 +08:00
Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO);
if(outOfBoundary == Vec2::ZERO)
{
return false;
}
_bouncingBack = true;
startAutoScroll(outOfBoundary, BOUNCE_BACK_DURATION, true);
return true;
2015-06-20 22:42:37 +08:00
}
Vec2 ScrollView::getHowMuchOutOfBoundary(const Vec2& addition) const
{
2015-06-29 11:52:53 +08:00
Vec2 result;
if(_innerContainer->getLeftBoundary() + addition.x > _leftBoundary)
{
result.x = _leftBoundary - (_innerContainer->getLeftBoundary() + addition.x);
}
else if(_innerContainer->getRightBoundary() + addition.x < _rightBoundary)
{
result.x = _rightBoundary - (_innerContainer->getRightBoundary() + addition.x);
}
if(_innerContainer->getTopBoundary() + addition.y < _topBoundary)
{
result.y = _topBoundary - (_innerContainer->getTopBoundary() + addition.y);
}
else if(_innerContainer->getBottomBoundary() + addition.y > _bottomBoundary)
{
result.y = _bottomBoundary - (_innerContainer->getBottomBoundary() + addition.y);
}
return result;
2015-06-20 22:42:37 +08:00
}
void ScrollView::processAutoScrolling(float deltaTime)
{
2015-06-29 11:52:53 +08:00
_autoScrollAccumulatedTime += deltaTime;
float percentage = _autoScrollAccumulatedTime / _autoScrollDuration;
if(percentage >= 1)
{
_innerContainer->setPosition(_autoScrollStartPosition + _autoScrollTargetDelta);
_autoScrolling = false;
_bouncingBack = false;
}
else
{
if(_autoScrollAttenuate)
{
percentage = tweenfunc::expoEaseOut(percentage);
}
Vec2 moveDelta = _autoScrollTargetDelta * percentage;
// Dispatch related events if bouncing
if(_bouncingBack)
{
if(moveDelta.x > 0)
{
processScrollEvent(MoveDirection::RIGHT, true);
}
else if(moveDelta.x < 0)
{
processScrollEvent(MoveDirection::LEFT, true);
}
if(moveDelta.y > 0)
{
processScrollEvent(MoveDirection::TOP, true);
}
else if(moveDelta.y < 0)
{
processScrollEvent(MoveDirection::BOTTOM, true);
}
}
_innerContainer->setPosition(_autoScrollStartPosition + moveDelta);
}
2015-06-19 17:32:32 +08:00
}
bool ScrollView::isOutOfBoundary(MoveDirection dir) const
{
2015-06-29 11:52:53 +08:00
switch(dir)
{
case MoveDirection::TOP: return _innerContainer->getTopBoundary() < _topBoundary;
case MoveDirection::BOTTOM: return _innerContainer->getBottomBoundary() > _bottomBoundary;
case MoveDirection::LEFT: return _innerContainer->getLeftBoundary() > _leftBoundary;
case MoveDirection::RIGHT: return _innerContainer->getRightBoundary() < _rightBoundary;
}
2015-06-19 17:32:32 +08:00
}
bool ScrollView::isOutOfBoundaryTopOrBottom() const
{
2015-06-29 11:52:53 +08:00
return isOutOfBoundary(MoveDirection::TOP) || isOutOfBoundary(MoveDirection::BOTTOM);
2015-06-19 17:32:32 +08:00
}
2015-06-19 17:32:32 +08:00
bool ScrollView::isOutOfBoundaryLeftOrRight() const
{
2015-06-29 11:52:53 +08:00
return isOutOfBoundary(MoveDirection::LEFT) || isOutOfBoundary(MoveDirection::RIGHT);
2015-06-19 17:32:32 +08:00
}
void ScrollView::startAutoScroll(const Vec2& deltaMove, float duration, bool attenuated)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
_autoScrolling = true;
_autoScrollTargetDelta = deltaMove;
_autoScrollAttenuate = attenuated;
_autoScrollStartPosition = _innerContainer->getPosition();
_autoScrollDuration = duration;
_autoScrollAccumulatedTime = 0;
2014-03-11 17:13:54 +08:00
}
void ScrollView::startAutoScrollChildrenWithDestination(const Vec2& des, float second, bool attenuated)
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
startAutoScroll(des - _innerContainer->getPosition(), second, attenuated);
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
{
float finalOffsetX = des.x;
float finalOffsetY = des.y;
2015-06-29 11:52:53 +08:00
if (des.y <= 0 && _direction != Direction::HORIZONTAL)
{
finalOffsetY = MAX(des.y, _contentSize.height - _innerContainer->getContentSize().height);
}
if (des.x <= 0 && _direction != Direction::VERTICAL)
{
finalOffsetX = MAX(des.x, _contentSize.width - _innerContainer->getContentSize().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
_innerContainer->setPosition(Vec2(finalOffsetX, finalOffsetY));
2014-03-11 17:13:54 +08:00
}
void ScrollView::startInertiaScroll()
2014-03-11 17:13:54 +08:00
{
2015-06-29 11:52:53 +08:00
if(_inertiaTouchTimeDeltas.empty())
{
return;
}
float totalDuration = 0;
for(auto i = _inertiaTouchTimeDeltas.begin(); i != _inertiaTouchTimeDeltas.end(); ++i)
{
totalDuration += (*i);
}
if(totalDuration >= 0.5f)
{
return;
}
_inertiaScrolling = true;
// Calcualte the initial velocity
Vec2 totalMovement;
for(auto i = _inertiaTouchDisplacements.begin(); i != _inertiaTouchDisplacements.end(); ++i)
{
totalMovement += (*i);
}
totalMovement.x = (_direction == Direction::VERTICAL ? 0 : totalMovement.x);
totalMovement.y = (_direction == Direction::HORIZONTAL ? 0 : totalMovement.y);
_inertiaInitiVelocity = totalMovement / totalDuration;
// Calculate values for ease out
_inertiaScrollExpectedTime = _inertiaInitiVelocity.length() / INERTIA_DEACCELERATION;
_inertiaScrollElapsedTime = 0;
2015-06-19 11:58:30 +08:00
}
void ScrollView::processInertiaScrolling(float dt)
{
2015-06-29 11:52:53 +08:00
_inertiaScrollElapsedTime += dt;
if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom())
{
// If the inner container is out of boundary, shorten the inertia time.
_inertiaScrollElapsedTime += dt * 15;
}
float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime;
if(percentage >= 1)
{
_inertiaScrolling = false;
startBounceBackIfNeeded();
return;
}
percentage = tweenfunc::expoEaseOut(percentage);
Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage);
Vec2 displacement = inertiaVelocity * dt;
if(!_bounceEnabled)
{
Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement);
if(outOfBoundary != Vec2::ZERO)
{
// Don't allow to go out of boundary
displacement += outOfBoundary;
_inertiaScrolling = false;
}
}
moveChildren(displacement.x, displacement.y);
}
2015-06-19 11:58:30 +08:00
bool ScrollView::processScrollUp(float* offsetYResult, float touchOffsetY)
{
2015-06-29 11:52:53 +08:00
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY < _bottomBoundary)
{
return true;
}
else if(!_bounceEnabled)
{
(*offsetYResult) = _bottomBoundary - icBottomPos;
}
processScrollEvent(MoveDirection::BOTTOM, false);
return false;
}
2015-06-19 11:58:30 +08:00
bool ScrollView::processScrollDown(float* offsetYResult, float touchOffsetY)
{
2015-06-29 11:52:53 +08:00
float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY > _topBoundary)
{
return true;
}
else if(!_bounceEnabled)
{
(*offsetYResult) = _topBoundary - icTopPos;
}
processScrollEvent(MoveDirection::TOP, false);
return false;
}
bool ScrollView::processScrollLeft(float* offsetXResult, float touchOffsetX)
{
2015-06-29 11:52:53 +08:00
float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX > _rightBoundary)
{
return true;
}
else if(!_bounceEnabled)
{
(*offsetXResult) = _rightBoundary - icRightPos;
}
processScrollEvent(MoveDirection::RIGHT, false);
return false;
}
bool ScrollView::processScrollRight(float* offsetXResult, float touchOffsetX)
{
2015-06-29 11:52:53 +08:00
float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX < _leftBoundary)
{
return true;
}
else if(!_bounceEnabled)
{
(*offsetXResult) = _leftBoundary - icLeftPos;
}
processScrollEvent(MoveDirection::LEFT, false);
return false;
}
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
{
processScrollingEvent();
2015-06-29 11:52:53 +08:00
touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX);
touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY);
if(_bounceEnabled)
{
// If the position of the inner container is out of the boundary, the offsets should be divided by two.
touchOffsetX *= (isOutOfBoundaryLeftOrRight() ? 0.5f : 1);
touchOffsetY *= (isOutOfBoundaryTopOrBottom() ? 0.5f : 1);
}
float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY;
bool scrollEnabledUpDown = true;
bool scrollEnabledLeftRight = true;
if (touchOffsetY > 0.0f) // up
{
scrollEnabledUpDown = processScrollUp(&realOffsetY, touchOffsetY);
}
else if (touchOffsetY < 0.0f) // down
{
scrollEnabledUpDown = processScrollDown(&realOffsetY, touchOffsetY);
}
if (touchOffsetX < 0.0f) // left
{
scrollEnabledLeftRight = processScrollLeft(&realOffsetX, touchOffsetX);
}
else if (touchOffsetX > 0.0f) // right
{
scrollEnabledLeftRight = processScrollRight(&realOffsetX, touchOffsetX);
}
moveChildren(realOffsetX, realOffsetY);
return scrollEnabledUpDown || scrollEnabledLeftRight;
}
void ScrollView::scrollToBottom(float second, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, 0.0f), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTop(float second, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x,
_contentSize.height - _innerContainer->getContentSize().height), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToLeft(float second, bool attenuated)
2014-03-11 17:13:54 +08:00
{
startAutoScrollChildrenWithDestination(Vec2(0.0f, _innerContainer->getPosition().y), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToRight(float second, bool attenuated)
2014-03-11 17:13:54 +08:00
{
2014-06-20 11:18:53 +08:00
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width,
_innerContainer->getPosition().y), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTopLeft(float second, 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
{
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2(0.0f, _contentSize.height - _innerContainer->getContentSize().height), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToTopRight(float second, 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
{
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), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToBottomLeft(float second, 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
{
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2::ZERO, second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToBottomRight(float second, 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
{
CCLOG("Scroll diretion is not both!");
return;
}
startAutoScrollChildrenWithDestination(Vec2(_contentSize.width - _innerContainer->getContentSize().width, 0.0f), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentVertical(float percent, float second, 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;
startAutoScrollChildrenWithDestination(Vec2(_innerContainer->getPosition().x, minY + percent * h / 100.0f), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentHorizontal(float percent, float second, 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;
startAutoScrollChildrenWithDestination(Vec2(-(percent * w / 100.0f), _innerContainer->getPosition().y), second, attenuated);
2014-03-11 17:13:54 +08:00
}
void ScrollView::scrollToPercentBothDirection(const Vec2& percent, float second, 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;
startAutoScrollChildrenWithDestination(Vec2(-(percent.x * w / 100.0f), minY + percent.y * h / 100.0f), second, 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
{
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;
}
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
{
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;
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
}
void ScrollView::startRecordSlidAction()
{
if (_inertiaScrolling)
2014-03-11 17:13:54 +08:00
{
_inertiaScrolling = false;
2014-03-11 17:13:54 +08:00
}
if(_autoScrolling)
{
_autoScrolling = false;
_bouncingBack = false;
}
2014-03-11 17:13:54 +08:00
}
void ScrollView::endRecordSlidAction()
{
bool bounceBackStarted = startBounceBackIfNeeded();
if(!bounceBackStarted && _inertiaScrollEnabled)
{
startInertiaScroll();
2014-03-11 17:13:54 +08:00
}
}
2014-06-06 16:48:49 +08:00
void ScrollView::handlePressLogic(Touch *touch)
{
2014-03-11 17:13:54 +08:00
startRecordSlidAction();
_bePressed = true;
2015-06-29 11:52:53 +08:00
_inertiaPrevTouchTimestamp = utils::getTimeInMilliseconds();
_inertiaTouchDisplacements.clear();
_inertiaTouchTimeDeltas.clear();
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 (nullptr == _hittedByCamera ||
false == hitTest(touch->getLocation(), _hittedByCamera, &currPt) ||
false == hitTest(touch->getPreviousLocation(), _hittedByCamera, &prevPt))
{
return;
}
Vec3 delta3 = currPt - prevPt;
Vec2 delta(delta3.x, delta3.y);
2015-06-29 11:52:53 +08:00
scrollChildren(delta.x, delta.y);
while(_inertiaTouchDisplacements.size() > 5)
{
_inertiaTouchDisplacements.pop_front();
_inertiaTouchTimeDeltas.pop_front();
}
_inertiaTouchDisplacements.push_back(delta);
long long timestamp = utils::getTimeInMilliseconds();
_inertiaTouchTimeDeltas.push_back((timestamp - _inertiaPrevTouchTimestamp) / 1000.0f);
_inertiaPrevTouchTimestamp = timestamp;
2014-03-11 17:13:54 +08:00
}
2014-06-06 16:48:49 +08:00
void ScrollView::handleReleaseLogic(Touch *touch)
2014-03-11 17:13:54 +08:00
{
endRecordSlidAction();
_bePressed = false;
}
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 (_inertiaScrolling)
2014-03-11 17:13:54 +08:00
{
processInertiaScrolling(dt);
2014-03-11 17:13:54 +08:00
}
else if (_autoScrolling)
{
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
{
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-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;
}
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;
}
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);
2015-06-29 11:52:53 +08:00
_innerContainer = scrollView->_innerContainer;
2014-03-11 17:13:54 +08:00
setDirection(scrollView->_direction);
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;
2014-03-11 17:13:54 +08:00
setInertiaScrollEnabled(scrollView->_inertiaScrollEnabled);
2015-06-29 11:52:53 +08:00
_inertiaScrolling = scrollView->_inertiaScrolling;
_inertiaInitiVelocity = scrollView->_inertiaInitiVelocity;
_inertiaTouchDisplacements = scrollView->_inertiaTouchDisplacements;
_inertiaTouchTimeDeltas = scrollView->_inertiaTouchTimeDeltas;
_inertiaPrevTouchTimestamp = scrollView->_inertiaPrevTouchTimestamp;
_inertiaScrollExpectedTime = scrollView->_inertiaScrollExpectedTime;
_inertiaScrollElapsedTime = scrollView->_inertiaScrollElapsedTime;
_autoScrolling = scrollView->_autoScrolling;
_autoScrollAttenuate = scrollView->_autoScrollAttenuate;
_autoScrollStartPosition = scrollView->_autoScrollStartPosition;
_autoScrollTargetDelta = scrollView->_autoScrollTargetDelta;
_autoScrollDuration = scrollView->_autoScrollDuration;
_autoScrollAccumulatedTime = scrollView->_autoScrollAccumulatedTime;
setBounceEnabled(scrollView->_bounceEnabled);
_bouncingBack = scrollView->_bouncingBack;
2014-05-23 15:03:46 +08:00
_scrollViewEventListener = scrollView->_scrollViewEventListener;
_scrollViewEventSelector = scrollView->_scrollViewEventSelector;
_eventCallback = scrollView->_eventCallback;
_ccEventCallback = scrollView->_ccEventCallback;
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)
{
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