void PageView::update(float dt) { if (_isAutoScrolling) { switch (_autoScrollDir) { case 0: { float step = _autoScrollSpeed*dt; if (_autoScrollDistance + step >= 0.0f) { step = -_autoScrollDistance; _autoScrollDistance = 0.0f; _isAutoScrolling = false; } else { _autoScrollDistance += step; } scrollPages(-step); if (!_isAutoScrolling) { pageTurningEvent(); } break; } break; case 1: { float step = _autoScrollSpeed*dt; if (_autoScrollDistance - step <= 0.0f) { step = _autoScrollDistance; _autoScrollDistance = 0.0f; _isAutoScrolling = false; } else { _autoScrollDistance -= step; } scrollPages(step); if (!_isAutoScrolling) { pageTurningEvent(); } break; } default: break; } } }
void PageView::autoScroll(float dt) { switch (_autoScrollDirection) { case AutoScrollDirection::LEFT: { float step = _autoScrollSpeed*dt; if (_autoScrollDistance + step >= 0.0f) { step = -_autoScrollDistance; _autoScrollDistance = 0.0f; _isAutoScrolling = false; } else { _autoScrollDistance += step; } scrollPages(-step); if (!_isAutoScrolling) { pageTurningEvent(); } break; } break; case AutoScrollDirection::RIGHT: { float step = _autoScrollSpeed*dt; if (_autoScrollDistance - step <= 0.0f) { step = _autoScrollDistance; _autoScrollDistance = 0.0f; _isAutoScrolling = false; } else { _autoScrollDistance -= step; } scrollPages(step); if (!_isAutoScrolling) { pageTurningEvent(); } break; } default: break; } }
void UIPageView::update(float dt) { if (m_bIsAutoScrolling) { switch (m_nAutoScrollDir) { case 0: { float step = m_fAutoScrollSpeed*dt; if (m_fAutoScrollDistance + step >= 0.0f) { step = -m_fAutoScrollDistance; m_fAutoScrollDistance = 0.0f; m_bIsAutoScrolling = false; pageTurningEvent(); } else { m_fAutoScrollDistance += step; } scrollPages(-step); break; } break; case 1: { float step = m_fAutoScrollSpeed*dt; if (m_fAutoScrollDistance - step <= 0.0f) { step = m_fAutoScrollDistance; m_fAutoScrollDistance = 0.0f; m_bIsAutoScrolling = false; pageTurningEvent(); } else { m_fAutoScrollDistance -= step; } scrollPages(step); break; } default: break; } } }
void PageView::handleReleaseLogic(Touch *touch) { if (this->getPageCount() <= 0) { return; } Widget* curPage = dynamic_cast<Widget*>(this->getPages().at(_curPageIdx)); if (curPage) { Vec2 curPagePos = curPage->getPosition(); ssize_t pageCount = this->getPageCount(); float curPageLocation = curPagePos.x; float pageWidth = getContentSize().width; if (!_usingCustomScrollThreshold) { _customScrollThreshold = pageWidth / 2.0; } float boundary = _customScrollThreshold; if (curPageLocation <= -boundary) { if (_curPageIdx >= pageCount-1) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx+1); } } else if (curPageLocation >= boundary) { if (_curPageIdx <= 0) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx-1); } } else { scrollToPage(_curPageIdx); } } }
void PageView::handleReleaseLogic(const Vec2 &touchPoint) { if (this->getPageCount() <= 0) { return; } Widget* curPage = dynamic_cast<Widget*>(this->getPages().at(_curPageIdx)); if (curPage) { Vec2 curPagePos = curPage->getPosition(); ssize_t pageCount = this->getPageCount(); float curPageLocation = curPagePos.x; float pageWidth = getSize().width; float boundary = pageWidth/2.0f; if (curPageLocation <= -boundary) { if (_curPageIdx >= pageCount-1) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx+1); } } else if (curPageLocation >= boundary) { if (_curPageIdx <= 0) { scrollPages(-curPageLocation); } else { scrollToPage(_curPageIdx-1); } } else { scrollToPage(_curPageIdx); } } }
void UIPageView::handleReleaseLogic(const CCPoint &touchPoint) { UIWidget* curPage = dynamic_cast<UIWidget*>(m_pages->objectAtIndex(m_nCurPageIdx)); if (curPage) { CCPoint curPagePos = curPage->getPosition(); int pageCount = m_pages->count(); float curPageLocation = curPagePos.x; float pageWidth = getSize().width; float boundary = pageWidth/2.0f; if (curPageLocation <= -boundary) { if (m_nCurPageIdx >= pageCount-1) { scrollPages(-curPageLocation); } else { scrollToPage(m_nCurPageIdx+1); } } else if (curPageLocation >= boundary) { if (m_nCurPageIdx <= 0) { scrollPages(-curPageLocation); } else { scrollToPage(m_nCurPageIdx-1); } } else { scrollToPage(m_nCurPageIdx); } } }
void PageView::handleMoveLogic(Touch *touch) { Vec2 touchPoint = touch->getLocation(); float offset = 0.0; offset = touchPoint.x - touch->getPreviousLocation().x; if (offset < 0) { _touchMoveDirection = TouchDirection::LEFT; } else if (offset > 0) { _touchMoveDirection = TouchDirection::RIGHT; } scrollPages(offset); }
void PageView::handleMoveLogic(const Vec2 &touchPoint) { Vec2 nsp = convertToNodeSpace(touchPoint); float offset = 0.0; float moveX = nsp.x; offset = moveX - _touchMoveStartLocation; _touchMoveStartLocation = moveX; if (offset < 0) { _touchMoveDirection = TouchDirection::LEFT; } else if (offset > 0) { _touchMoveDirection = TouchDirection::RIGHT; } scrollPages(offset); }
void PageView::handleMoveLogic(const Point &touchPoint) { Point nsp = convertToNodeSpace(touchPoint); float offset = 0.0; float moveX = nsp.x; offset = moveX - _touchMoveStartLocation; _touchMoveStartLocation = moveX; if (offset < 0) { _touchMoveDir = PAGEVIEW_TOUCHLEFT; } else if (offset > 0) { _touchMoveDir = PAGEVIEW_TOUCHRIGHT; } scrollPages(offset); }
void UIPageView::handleMoveLogic(const CCPoint &touchPoint) { CCPoint nsp = m_pRenderer->convertToNodeSpace(touchPoint); float offset = 0.0; float moveX = nsp.x; offset = moveX - m_fTouchMoveStartLocation; m_fTouchMoveStartLocation = moveX; if (offset < 0) { m_touchMoveDir = PAGEVIEW_TOUCHLEFT; } else if (offset > 0) { m_touchMoveDir = PAGEVIEW_TOUCHRIGHT; } scrollPages(offset); }