From 2427c15b602d5cc66fa9a84159024eba9c7fd21f Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 3 Aug 2015 11:38:23 +0800 Subject: [PATCH] modify vertical scroll direction --- .../js-bindings/script/ccui/jsb_cocos2d_ui.js | 2 + .../lua-bindings/script/ui/GuiConstants.lua | 2 + cocos/ui/UIPageView.cpp | 87 +++++++++++++------ 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js index 772230c7e5..4842c14cdb 100644 --- a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js +++ b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js @@ -248,6 +248,8 @@ ccui.PageView.EVENT_TURNING = 0; //PageView touch direction ccui.PageView.TOUCH_DIR_LEFT = 0; ccui.PageView.TOUCH_DIR_RIGHT = 1; +ccui.PageView.TOUCH_DIR_UP = 2; +ccui.PageView.TOUCH_DIR_DOWN = 3; //PageView direction ccui.PageView.DIRECTION_HORIZONTAL = 0; diff --git a/cocos/scripting/lua-bindings/script/ui/GuiConstants.lua b/cocos/scripting/lua-bindings/script/ui/GuiConstants.lua index 43d6e450e0..80ae6d2d15 100644 --- a/cocos/scripting/lua-bindings/script/ui/GuiConstants.lua +++ b/cocos/scripting/lua-bindings/script/ui/GuiConstants.lua @@ -169,6 +169,8 @@ ccui.PageViewDirection = { ccui.PVTouchDir = { touchLeft = 0, touchRight = 1, + touchUp = 2, + touchDown = 3 } ccui.ListViewGravity = { diff --git a/cocos/ui/UIPageView.cpp b/cocos/ui/UIPageView.cpp index 841cdcab08..c0d45f70c4 100644 --- a/cocos/ui/UIPageView.cpp +++ b/cocos/ui/UIPageView.cpp @@ -291,7 +291,7 @@ void PageView::updateAllPagesPosition() else if(_direction == Direction::VERTICAL) { float pageHeight = getContentSize().height; - newPosition = Vec2(0,(i-_curPageIdx) * pageHeight); + newPosition = Vec2(0,(i-_curPageIdx) * pageHeight * -1); } page->setPosition(newPosition); @@ -330,14 +330,14 @@ void PageView::scrollToPage(ssize_t idx) } else if(_direction == Direction::VERTICAL) { - _autoScrollDistance = -(curPage->getPosition().y); + _autoScrollDistance = -curPage->getPosition().y; if (_autoScrollDistance > 0) { - _autoScrollDirection = AutoScrollDirection::UP; + _autoScrollDirection = AutoScrollDirection::DOWN; } else { - _autoScrollDirection = AutoScrollDirection::DOWN; + _autoScrollDirection = AutoScrollDirection::UP; } } _autoScrollSpeed = fabs(_autoScrollDistance)/0.2f; @@ -369,7 +369,7 @@ void PageView::autoScroll(float dt) switch (_autoScrollDirection) { case AutoScrollDirection::LEFT: - case AutoScrollDirection::DOWN: + case AutoScrollDirection::UP: { if (_autoScrollDistance + step >= 0.0f) { @@ -386,7 +386,7 @@ void PageView::autoScroll(float dt) } break; case AutoScrollDirection::RIGHT: - case AutoScrollDirection::UP: + case AutoScrollDirection::DOWN: { if (_autoScrollDistance - step <= 0.0f) { @@ -515,19 +515,20 @@ bool PageView::scrollPages(Vec2 touchOffset) break; case TouchDirection::UP: { - if (_leftBoundaryChild->getBottomBoundary() + touchOffset.y >= _leftBoundary) + if (_rightBoundaryChild->getBottomBoundary() + touchOffset.y >= _leftBoundary) { - realOffset.y = _leftBoundary - _leftBoundaryChild->getBottomBoundary(); + realOffset.y = _leftBoundary - _rightBoundaryChild->getBottomBoundary(); realOffset.x = 0; movePages(realOffset); return false; } + }break; case TouchDirection::DOWN: { - if (_rightBoundaryChild->getTopBoundary() + touchOffset.y <= _rightBoundary) + if (_leftBoundaryChild->getTopBoundary() + touchOffset.y <= _rightBoundary) { - realOffset.y = _rightBoundary - _rightBoundaryChild->getTopBoundary(); + realOffset.y = _rightBoundary - _leftBoundaryChild->getTopBoundary(); realOffset.x = 0; movePages(realOffset); return false; @@ -564,14 +565,14 @@ void PageView::handleMoveLogic(Touch *touch) else { offset.x = 0; - if(offset.y < 0) - { - _touchMoveDirection = TouchDirection::DOWN; - } - else if(offset.y > 0) + if(offset.y > 0) { _touchMoveDirection = TouchDirection::UP; } + else if(offset.y < 0) + { + _touchMoveDirection = TouchDirection::DOWN; + } } scrollPages(offset); @@ -634,32 +635,64 @@ void PageView::handleReleaseLogic(Touch *touch) } float boundary = _customScrollThreshold; - if (moveBoundray <= -boundary) + if (_direction == Direction::HORIZONTAL) { - if (_curPageIdx >= pageCount-1) + if (moveBoundray <= -boundary) { - scrollPages(curPagePos); + if (_curPageIdx >= pageCount-1) + { + scrollPages(curPagePos); + } + else + { + scrollToPage(_curPageIdx+1); + } + } + else if (moveBoundray >= boundary) + { + if (_curPageIdx <= 0) + { + scrollPages(curPagePos); + } + else + { + scrollToPage(_curPageIdx-1); + } } else { - scrollToPage(_curPageIdx+1); + scrollToPage(_curPageIdx); } } - else if (moveBoundray >= boundary) + else if(_direction == Direction::VERTICAL) { - if (_curPageIdx <= 0) + if (moveBoundray >= boundary) { - scrollPages(curPagePos); + if (_curPageIdx >= pageCount-1) + { + scrollPages(curPagePos); + } + else + { + scrollToPage(_curPageIdx+1); + } + } + else if (moveBoundray <= -boundary) + { + if (_curPageIdx <= 0) + { + scrollPages(curPagePos); + } + else + { + scrollToPage(_curPageIdx-1); + } } else { - scrollToPage(_curPageIdx-1); + scrollToPage(_curPageIdx); } } - else - { - scrollToPage(_curPageIdx); - } } }