void UIScrollView::resetPositionWithAction() { using namespace cocos2d; CCPoint delta = CCPointZero; UIWidget* child = getCheckPositionChild(); switch (m_eDirection) { case SCROLLVIEW_DIR_VERTICAL: // vertical switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_UP: // up delta.y = m_fBottomBoundary + m_fDisBoundaryToChild_0 - child->getRelativeBottomPos();; break; case SCROLLVIEW_MOVE_DIR_DOWN: // down delta.y = m_fTopBoundary - m_fDisBoundaryToChild_0 - child->getRelativeTopPos(); break; default: break; } break; case SCROLLVIEW_DIR_HORIZONTAL: // horizontal switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_LEFT: // left delta.x = m_fRightBoundary - m_fDisBoundaryToChild_0 - child->getRelativeRightPos(); break; case SCROLLVIEW_MOVE_DIR_RIGHT: // right delta.x = m_fLeftBoundary + m_fDisBoundaryToChild_0 - child->getRelativeLeftPos(); break; default: break; } break; default: break; } // int times = m_children->count(); ccArray* arrayChildren = m_children->data; int times = arrayChildren->num; for (int i = 0; i < times - 1; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]); CCMoveBy* moveBy = CCMoveBy::create(0.25, delta); CCEaseOut* ease = CCEaseOut::create(moveBy, 0.5); child->runAction(ease); } UIWidget* child_last = dynamic_cast<UIWidget*>(m_children->lastObject()); CCMoveBy* moveBy = CCMoveBy::create(0.25, delta); CCEaseOut* ease = CCEaseOut::create(moveBy, 0.5); CCCallFunc* callFunc = CCCallFunc::create(this, callfunc_selector(UIScrollView::handleScrollActionEvent)); CCSequence* seq = CCSequence::create(ease, callFunc, NULL); child_last->runAction(seq); isRunningAction = true; }
void UIListView::collectOverLeftChild() { float scroll_left = m_fLeftBoundary; if (m_overLeftArray->count() > 0) { m_overLeftArray->removeAllObjects(); } ccArray* arrayChildren = m_children->data; int times = arrayChildren->num; for (int i = 0; i < times; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]); float child_right = child->getRelativeRightPos(); if (child_right <= scroll_left) { m_overLeftArray->addObject(child); } } }
void UIListView::setLoopPosition() { switch (m_eDirection) { case SCROLLVIEW_DIR_VERTICAL: // vertical switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_UP: // up if (m_overTopArray->count() == m_children->count()) { int count = m_overTopArray->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i)); if (i == 0) { float y = (count - 1); // float y = (0 - m_fDisBetweenChild) + m_fDisBetweenChild * (count - 1); child->setPosition(ccp(child->getPosition().x, y)); } else { UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i - 1)); child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y)); } } } else { float scroll_top = m_fTopBoundary; int count = m_children->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i)); float child_bottom = child->getRelativeBottomPos(); if (child_bottom >= scroll_top) { int index = (i == 0) ? (count - 1) : (i - 1); UIWidget* prev_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index)); child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y)); } } } break; case SCROLLVIEW_MOVE_DIR_DOWN: // down if (m_overBottomArray->count() == m_children->count()) { int count = m_overBottomArray->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i)); if (i == 0) { float y = (m_fTopBoundary) * (count - 1); // float y = (m_fTopBoundary) - m_fDisBetweenChild * (count - 1); child->setPosition(ccp(child->getPosition().x, y)); } else { UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i - 1)); child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y)); } } } else { float scroll_bottom = m_fBottomBoundary; int count = m_children->count(); for (int i = count - 1; i >= 0; --i) { UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i)); float child_top = child->getRelativeTopPos(); if (child_top <= scroll_bottom) { int index = (i == count - 1) ? 0 : (i + 1); UIWidget* next_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index)); child->setPosition(ccp(child->getPosition().x, next_child->getPosition().y)); } } } break; default: break; } break; case SCROLLVIEW_DIR_HORIZONTAL: // horizontal switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_LEFT: // left if (m_overLeftArray->count() == m_children->count()) { int count = m_overLeftArray->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i)); if (i == 0) { float x = m_fRightBoundary * (count - 1); // float x = (m_fRightBoundary + m_fDisBetweenChild) - m_fDisBetweenChild * (count - 1); child->setPosition(ccp(x, child->getPosition().y)); } else { UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i - 1)); child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y)); } } } else { float scroll_left = m_fLeftBoundary; int count = m_children->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i)); float child_right = child->getRelativeRightPos(); if (child_right <= scroll_left) { int index = (i == 0) ? (count - 1) : (i - 1); UIWidget* prev_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index)); child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y)); } } } break; case SCROLLVIEW_MOVE_DIR_RIGHT: // right if (m_overRightArray->count() == m_children->count()) { int count = m_overRightArray->count(); for (int i = 0; i < count; ++i) { UIWidget* child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i)); if (i == 0) { float x = (count - 1); // float x = (0 - m_fDisBetweenChild) + m_fDisBetweenChild * (count - 1); child->setPosition(ccp(x, child->getPosition().y)); } else { UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i - 1)); child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y)); } } } else { float scroll_right = m_fRightBoundary; int count = m_children->count(); for (int i = count - 1; i >= 0; --i) { UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i)); float child_left = child->getRelativeLeftPos(); if (child_left >= scroll_right) { int index = (i == count - 1) ? 0 : (i + 1); UIWidget* next_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index)); child->setPosition(ccp(next_child->getPosition().x, child->getPosition().y)); } } } break; default: break; } break; default: break; } }
float UIScrollView::calculateOffsetWithDragForce(float moveOffset) { float offset = moveOffset; UIWidget* child = getCheckPositionChild(); switch (m_eDirection) { case SCROLLVIEW_DIR_VERTICAL: // vertical switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_UP: // up { float scroll_bottom = m_fBottomBoundary; float child_bottom = child->getRelativeBottomPos(); if (child_bottom > scroll_bottom) { offset -= m_fDragForce * offset / m_fHeight; } } break; case SCROLLVIEW_MOVE_DIR_DOWN: // down { float scroll_top = m_fTopBoundary; float child_top = child->getRelativeTopPos(); if (child_top < scroll_top) { offset -= m_fDragForce * offset / m_fHeight; } } break; default: break; } break; case SCROLLVIEW_DIR_HORIZONTAL: // horizontal switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_LEFT: // left { float scroll_right = m_fRightBoundary; float child_right = child->getRelativeRightPos(); if (child_right < scroll_right) { offset -= m_fDragForce * offset / m_fWidth; } } break; case SCROLLVIEW_MOVE_DIR_RIGHT: // right { float scroll_left = m_fLeftBoundary; float child_left = child->getRelativeLeftPos(); if (child_left > scroll_left) { offset -= m_fDragForce * offset / m_fWidth; } } break; default: break; } break; default: break; } offset = MIN(offset, m_fDisBetweenChild); return offset; }