void UIHierarchy::AddBefore(UIHierarchyNode *forParent) { UIHierarchyNode *checkNode = NULL; if (!iheritanceQueue.empty()) { checkNode = *(iheritanceQueue.begin()); iheritanceQueue.pop_front(); } for (List<UIHierarchyNode *>::reverse_iterator it = forParent->children.rbegin(); it != forParent->children.rend(); it++) { if (checkNode) { if ((*it) == checkNode) { checkNode = NULL; if ((*it)->isOpen && !iheritanceQueue.empty()) { AddBefore((*it)); if(addPos + (int32)scrollContainer->relativePosition.y + cellHeight <= -size.y) { return; } if(addPos + (int32)scrollContainer->relativePosition.y <= size.y * 2) { AddCellAtPos(delegate->CellForNode(this, (*it)->userNode), addPos, cellHeight, (*it)); } addPos -= cellHeight; } } } else { if(addPos + (int32)scrollContainer->relativePosition.y + cellHeight <= -size.y) { return; } if ((*it)->isOpen) { AddBefore((*it)); if(addPos + (int32)scrollContainer->relativePosition.y + cellHeight <= -size.y) { return; } } if(addPos + (int32)scrollContainer->relativePosition.y <= size.y * 2) { AddCellAtPos(delegate->CellForNode(this, (*it)->userNode), addPos, cellHeight, (*it)); } addPos -= cellHeight; } } }
void UIList::Update(float32 timeElapsed) { if(!delegate) { return; } if(needRefresh) { FullRefresh(); } float d = newPos - oldPos; oldPos = newPos; Rect r = scrollContainer->GetRect(); if(orientation == ORIENTATION_HORIZONTAL) { r.x = scroll->GetPosition(d, SystemTimer::FrameDelta(), lockTouch); } else { r.y = scroll->GetPosition(d, SystemTimer::FrameDelta(), lockTouch); } scrollContainer->SetRect(r); List<UIControl*>::const_iterator it; Rect viewRect = GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); const List<UIControl*> &scrollList = scrollContainer->GetChildren(); List<UIControl*> removeList; //removing invisible elements for(it = scrollList.begin(); it != scrollList.end(); it++) { Rect crect = (*it)->GetGeometricData().GetUnrotatedRect();//GetRect(TRUE); if(orientation == ORIENTATION_HORIZONTAL) { if(crect.x + crect.dx < viewRect.x - viewRect.dx || crect.x > viewRect.x + viewRect.dx*2) { removeList.push_back(*it); } } else { if(crect.y + crect.dy < viewRect.y - viewRect.dy || crect.y > viewRect.y + viewRect.dy*2) { removeList.push_back(*it); } } } for(it = removeList.begin(); it != removeList.end(); it++) { scrollContainer->RemoveControl((*it)); } if (!scrollList.empty()) { //adding elements at the list end int32 ind = -1; UIListCell *fc = NULL; for(it = scrollList.begin(); it != scrollList.end(); it++) { UIListCell *lc = (UIListCell *)(*it); int32 i = lc->GetIndex(); if(i > ind) { ind = i; fc = lc; } } if(fc) { int32 borderPos; int32 rPos; int size = 0; int32 off; if(orientation == ORIENTATION_HORIZONTAL) { borderPos = (int32)(viewRect.dx + viewRect.dx / 2.0f); off = (int32)scrollContainer->GetRect().x; rPos = (int32)(fc->GetRect().x + fc->GetRect().dx + off); } else { borderPos = (int32)(viewRect.dy + viewRect.dy / 22.0f); off = (int32)scrollContainer->GetRect().y; rPos = (int32)(fc->GetRect().y + fc->GetRect().dy + off); } while(rPos < borderPos && fc->GetIndex() < delegate->ElementsCount(this) - 1) { int32 i = fc->GetIndex() + 1; fc = delegate->CellAtIndex(this, i); if(orientation == ORIENTATION_HORIZONTAL) { size = delegate->CellWidth(this, i); } else { size = delegate->CellHeight(this, i); } AddCellAtPos(fc, rPos - off, size, i); rPos += size; // scroll->SetElementSize((float32)(rPos - off)); } } //adding elements at the list begin ind = maximumElementsCount; fc = NULL; for(it = scrollList.begin(); it != scrollList.end(); it++) { UIListCell *lc = (UIListCell *)(*it); int32 i = lc->GetIndex(); if(i < ind) { ind = i; fc = lc; } } if(fc) { int32 borderPos; int32 rPos; int size = 0; int32 off; if(orientation == ORIENTATION_HORIZONTAL) { borderPos = (int32)(-viewRect.dx/2.0f); off = (int32)scrollContainer->GetRect().x; rPos = (int32)(fc->GetRect().x + off); } else { borderPos = (int32)(-viewRect.dy/2.0f); off = (int32)scrollContainer->GetRect().y; rPos = (int32)(fc->GetRect().y + off); } while(rPos > borderPos && fc->GetIndex() > 0) { int32 i = fc->GetIndex() - 1; fc = delegate->CellAtIndex(this, i); if(orientation == ORIENTATION_HORIZONTAL) { size = delegate->CellWidth(this, i); } else { size = delegate->CellHeight(this, i); } rPos -= size; AddCellAtPos(fc, rPos - off, size, i); } } } else { FullRefresh(); } }
void UIList::FullRefresh() { scrollContainer->RemoveAllControls(); if(!delegate) { return; } needRefresh = FALSE; addPos = 0; int32 scrollAdd; int32 maxSize; if(orientation == ORIENTATION_HORIZONTAL) { scrollAdd = (int32)scrollContainer->GetRect().x; maxSize = (int32)GetRect().dx; } else { scrollAdd = (int32)scrollContainer->GetRect().y; maxSize = (int32)GetRect().dy; } scroll->SetViewSize((float32)maxSize); int sz = 0; int32 elCnt = delegate->ElementsCount(this); int32 index = 0; for (; index < elCnt; index++) { int32 curPos = addPos + scrollAdd; int size = 0; if(orientation == ORIENTATION_HORIZONTAL) { size = delegate->CellWidth(this, index); } else { size = delegate->CellHeight(this, index); } sz += size; if(curPos + size > -maxSize) { AddCellAtPos(delegate->CellAtIndex(this, index), addPos, size, index); } addPos += size; if(addPos + scrollAdd > maxSize * 2) { break; } } index++; for (; index < elCnt; index++) { if(orientation == ORIENTATION_HORIZONTAL) { sz += delegate->CellWidth(this, index); } else { sz += delegate->CellHeight(this, index); } } scroll->SetElementSize((float32)sz); }