void ScrollView::processInertiaScrolling(float dt) { _inertiaScrollElapsedTime += dt; if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom()) { // If the inner container is out of boundary, shorten the inertia time. _inertiaScrollElapsedTime += dt * (45000 / INERTIA_DEACCELERATION); } float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime; if(percentage >= 1) { _inertiaScrolling = false; startBounceBackIfNeeded(); return; } percentage = tweenfunc::quartEaseOut(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); }
void ViewController::setView(std::shared_ptr<View> view) { BaseView* parentView = nullptr; if(_parent) { parentView = &_parent->getView(); } else { parentView = &_root->getView(); } assert(parentView); // set new view pointer std::shared_ptr<View> oldView = _view; _view = view; if(oldView) { // move all the child controller views to the new view moveChildren(*oldView); // remove the old view from the parent controller view parentView->removeChild(*oldView); } // add the new view parentView->addChild(view); }
void TreeDiagram::moveChildren(DiagramItem *root,int dx) { DiagramItemList *dil=root->getChildren(); DiagramItem *di=dil->first(); while (di) { di->move(dx,0); moveChildren(di,dx); di=dil->next(); } }
void TreeDiagram::moveChildren(DiagramItem *root,int dx) { DiagramItemList *dil=root->getChildren(); QListIterator<DiagramItem> it(*dil); DiagramItem *di; for (;(di=it.current());++it) { di->move(dx,0); moveChildren(di,dx); } }
void GuiAnimation::update(int deltaTime) { float mult = deltaTime * 0.05f; if(mMoveX != 0 || mMoveY != 0) { int offsetx = (mMoveX > mMoveSpeed) ? mMoveSpeed : mMoveX; int offsety = (mMoveY > mMoveSpeed) ? mMoveSpeed : mMoveY; offsetx = (int)(offsetx * mult); offsety = (int)(offsety * mult); moveChildren(offsetx, offsety); mMoveX -= offsetx; mMoveY -= offsety; } if(mFadeRate != 0) { int opacity = (int)mOpacity + mFadeRate; if(opacity > 255) { mFadeRate = 0; opacity = 255; } if(opacity < 0) { mFadeRate = 0; opacity = 0; } mOpacity = (unsigned char)opacity; setChildrenOpacity((unsigned char)opacity); } }
bool UIListView::scrollChildren(float touchOffset) { float realOffset = touchOffset; switch (_direction) { case LISTVIEW_DIR_VERTICAL: // vertical switch (_moveDirection) { case LISTVIEW_MOVE_DIR_UP: // up { realOffset = MIN(realOffset, _disBetweenChild); UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject()); float child_last_bottom = child_last->getBottomInParent(); float scroll_bottom = _bottomBoundary; if (_end == _dataLength - 1) { if (realOffset > scroll_bottom + _disBoundaryToChild_0 - child_last_bottom) { realOffset = scroll_bottom + _disBoundaryToChild_0 - child_last_bottom; } moveChildren(realOffset); return false; } moveChildren(realOffset); if (_end < _dataLength - 1) { collectOverTopChild(); unsigned int count = _overTopArray->count(); if (count > 0) { updateChild(); setLoopPosition(); _overTopArray->removeAllObjects(); } } } break; case LISTVIEW_MOVE_DIR_DOWN: // down { realOffset = MAX(realOffset, -_disBetweenChild); UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0)); float child_0_top = child_0->getTopInParent(); float scroll_top = _topBoundary; if (_begin == 0) { if (realOffset < scroll_top - _disBoundaryToChild_0 - child_0_top) { realOffset = scroll_top - _disBoundaryToChild_0 - child_0_top; } moveChildren(realOffset); return false; } moveChildren(realOffset); if (_begin > 0) { collectOverBottomChild(); int count = _overBottomArray->count(); if (count > 0) { updateChild(); setLoopPosition(); _overBottomArray->removeAllObjects(); } } } break; default: break; } return true; break; case LISTVIEW_DIR_HORIZONTAL: // horizontal switch (_moveDirection) { case LISTVIEW_MOVE_DIR_LEFT: // left { realOffset = MAX(realOffset, -_disBetweenChild); UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject()); float child_last_right = child_last->getRightInParent(); float scroll_right = _rightBoundary; if (_end == _dataLength - 1) { if (realOffset < scroll_right - _disBoundaryToChild_0 - child_last_right) { realOffset = scroll_right - _disBoundaryToChild_0 - child_last_right; } moveChildren(realOffset); return false; } moveChildren(realOffset); if (_end < _dataLength - 1) { collectOverLeftChild(); int count = _overLeftArray->count(); if (count > 0) { updateChild(); setLoopPosition(); _overLeftArray->removeAllObjects(); } } } break; case LISTVIEW_MOVE_DIR_RIGHT: // right { realOffset = MIN(realOffset, _disBetweenChild); UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0)); float child_0_left = child_0->getLeftInParent(); float scroll_left = _leftBoundary; if (_begin == 0) { if (realOffset > scroll_left + _disBoundaryToChild_0 - child_0_left) { realOffset = scroll_left + _disBoundaryToChild_0 - child_0_left; } moveChildren(realOffset); return false; } moveChildren(realOffset); collectOverRightChild(); int count = _overRightArray->count(); if (count > 0) { updateChild(); setLoopPosition(); _overRightArray->removeAllObjects(); } } break; default: break; } return true; break; default: break; } return false; }
bool UIScrollViewP::scrollChildren(float touchOffset) { float realOffset = touchOffset; switch (m_eDirection) { case SCROLLVIEW_DIR_VERTICAL: // vertical switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_UP: // up { float icBottomPos = m_pInnerContainer->getBottomInParent(); if (icBottomPos + touchOffset >= m_fBottomBoundary) { realOffset = m_fBottomBoundary - icBottomPos; moveChildren(realOffset); m_bBottomEnd = true; scrollToBottomEvent(); return false; } break; } case SCROLLVIEW_MOVE_DIR_DOWN: // down { float icTopPos = m_pInnerContainer->getTopInParent(); if (icTopPos + touchOffset <= m_fTopBoundary) { realOffset = m_fTopBoundary - icTopPos; moveChildren(realOffset); m_bTopEnd = true; scrollToTopEvent(); return false; } break; } default: break; } moveChildren(realOffset); m_bTopEnd = false; m_bBottomEnd = false; return true; break; case SCROLLVIEW_DIR_HORIZONTAL: // horizontal switch (m_eMoveDirection) { case SCROLLVIEW_MOVE_DIR_LEFT: // left { float icRightPos = m_pInnerContainer->getRightInParent(); if (icRightPos + touchOffset <= m_fRightBoundary) { realOffset = m_fRightBoundary - icRightPos; moveChildren(realOffset); m_bRightEnd = true; scrollToRightEvent(); return false; } break; } case SCROLLVIEW_MOVE_DIR_RIGHT: // right { float icLeftPos = m_pInnerContainer->getLeftInParent(); if (icLeftPos + touchOffset >= m_fLeftBoundary) { realOffset = m_fLeftBoundary - icLeftPos; moveChildren(realOffset); m_bLeftEnd = true; scrollToLeftEvent(); return false; } break; } default: break; } moveChildren(realOffset); m_bLeftEnd = false; m_bRightEnd = false; return true; break; default: break; } return false; }
void RenderRubyBase::mergeChildrenWithBase(RenderRubyBase* toBlock) { moveChildren(toBlock); moveFloatsTo(toBlock); }
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) { 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 scrolledToLeft = false; bool scrolledToRight = false; bool scrolledToTop = false; bool scrolledToBottom = false; if (touchOffsetY > 0.0f) // up { float icBottomPos = _innerContainer->getBottomBoundary(); if (icBottomPos + touchOffsetY >= _bottomBoundary) { if(!_bounceEnabled) { realOffsetY = _bottomBoundary - icBottomPos; } scrolledToBottom = true; } } else if (touchOffsetY < 0.0f) // down { float icTopPos = _innerContainer->getTopBoundary(); if (icTopPos + touchOffsetY <= _topBoundary) { if(!_bounceEnabled) { realOffsetY = _topBoundary - icTopPos; } scrolledToTop = true; } } if (touchOffsetX < 0.0f) // left { float icRightPos = _innerContainer->getRightBoundary(); if (icRightPos + touchOffsetX <= _rightBoundary) { if(!_bounceEnabled) { realOffsetX = _rightBoundary - icRightPos; } scrolledToRight = true; } } else if (touchOffsetX > 0.0f) // right { float icLeftPos = _innerContainer->getLeftBoundary(); if (icLeftPos + touchOffsetX >= _leftBoundary) { if(!_bounceEnabled) { realOffsetX = _leftBoundary - icLeftPos; } scrolledToLeft = true; } } moveChildren(realOffsetX, realOffsetY); if(realOffsetX != 0 || realOffsetY != 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); } bool scrollEnabledUpDown = (!scrolledToBottom && !scrolledToTop); bool scrollEnabledLeftRight = (!scrolledToLeft && !scrolledToRight); return scrollEnabledUpDown || scrollEnabledLeftRight; }