UIListCell *MainScreen::CellAtIndex(UIList *list, int32 index) { UIListCell *c = list->GetReusableCell("UI info cell"); //try to get cell from the reusable cells store if(!c) { c = new UIListCell(Rect(0.0f, 0.0f, 2*buttonW, cellH), "UI info cell"); } c->RemoveAllControls(); WideString keyStr = (selectedControl ? selectedControl->GetSpecificInfoKeyText(index) : L""); WideString valueStr = (selectedControl ? selectedControl->GetSpecificInfoValueText(index) : L""); FTFont* font = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf"); font->SetSize(20.0f); font->SetColor(0.8f, 0.8f, 0.8f, 1.0f); c->SetStateFont(UIControl::STATE_NORMAL, font); UIStaticText* cellKeyText = new UIStaticText(Rect(0.0f, 0.0f, buttonW, cellH)); cellKeyText->SetFont(font); cellKeyText->SetText(keyStr); c->AddControl(cellKeyText); UIStaticText* cellValueText = new UIStaticText(Rect(buttonW, 0.0f, buttonW, cellH)); cellValueText->SetFont(font); cellValueText->SetText(valueStr); c->AddControl(cellValueText); SafeRelease(font); return c;//returns cell }
UIListCell *ComboBox::CellAtIndex(UIList *forList, int32 index) { UIListCell *c = forList->GetReusableCell("Combo cell"); if (!c) { c = new UIListCell(Rect(0, 0, listWidth, size.y), "Combo cell"); } ControlsFactory::CustomizeButton(c, StringToWString(items[index])); if (index == selectionIndex) { c->SetSelected(true); } else { c->SetSelected(false); } return c; }
UIControl* AutotestingSystemLua::FindControl(UIList* srcList, int32 index) { if(UIControlSystem::Instance()->GetLockInputCounter() > 0) return NULL; if(srcList) { const List<UIControl*> &cells = srcList->GetVisibleCells(); for(List<UIControl*>::const_iterator it = cells.begin(); it != cells.end(); ++it) { UIListCell* cell = dynamic_cast<UIListCell*>(*it); if(cell) { if(cell->GetIndex() == index && IsCenterInside(srcList, cell)) { return cell; } } } } return NULL; }
UIListCell *EditorListDelegate::CellAtIndex(UIList *forList, int32 index) { // Try to get cell from the reusable cells store UIListCell *cell = forList->GetReusableCell("Cell"); if (!cell) { cell = new UIListCell(Rect(0.0f, 0.0f, cellSize.x, cellSize.y), "Cell"); } else { cell->SetSize(Vector2(cellSize.x, cellSize.y)); // Reset reusable cells relative positions - new proper positions will be calculated at UIList::AddCellAtPost() method cell->SetPosition(Vector2(0.0f, 0.0f)); } cell->RemoveAllControls(); // Get aggregator control UIControl *aggregatorControl = GetCurrentAggregatorControl(); if (aggregatorControl) { UIAggregatorControl* control = new UIAggregatorControl(); control->CopyDataFrom(aggregatorControl); // DF-1770 - Reset aggregator's background draw type control->GetBackground()->SetDrawType(UIControlBackground::DRAW_ALIGNED); cell->AddControl(control); SafeRelease(control); } else { cell->SetStateFont(UIControl::STATE_NORMAL, EditorFontManager::Instance()->GetDefaultFont()); cell->SetStateText(UIControl::STATE_NORMAL, StringToWString(Format("Cell %d",index))); cell->SetSelected(true); } return cell; }
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(); } }
UIListCell *MaterialEditor::CellAtIndex(UIList *forList, int32 index) { UIListCell *c = forList->GetReusableCell("Material name cell"); if (!c) { c = new UIListCell(Rect(0, 0, forList->GetRect().dx, 20), "Material name cell"); float32 boxSize = 16; float32 y = (CellHeight(forList, index) - boxSize) / 2; float32 x = forList->GetRect().dx - boxSize; //Temporary fix for loading of UI Interface to avoid reloading of texrures to different formates. // 1. Reset default format before loading of UI // 2. Restore default format after loading of UI from stored settings. Texture::SetDefaultFileFormat(NOT_FILE); Rect r = Rect(x, y, boxSize, boxSize); UIControl *sceneFlagBox = new UIControl(r); sceneFlagBox->SetName("flagBox"); sceneFlagBox->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT); sceneFlagBox->SetSprite("~res:/Gfx/UI/marker", 1); sceneFlagBox->SetInputEnabled(false); c->AddControl(sceneFlagBox); SafeRelease(sceneFlagBox); Texture::SetDefaultFileFormat((ImageFileFormat)EditorSettings::Instance()->GetTextureViewFileFormat()); } Material *mat = GetMaterial(index); bool found = false; if(EDM_ALL == displayMode) { for (int32 i = 0; i < (int32)workingNodeMaterials.size(); ++i) { if(workingNodeMaterials[i] == mat) { found = true; break; } } } else { found = true; } ControlsFactory::CustomizeListCell(c, StringToWString(mat->GetName()), false); UIControl *sceneFlagBox = c->FindByName("flagBox"); sceneFlagBox->SetVisible(found, false); if (index == selectedMaterial) { c->SetSelected(true, false); lastSelection = c; } else { c->SetSelected(false, false); } return c; }
UIControl *UIListCell::Clone() { UIListCell *c = new UIListCell(GetRect(),identifier); c->CopyDataFrom(this); return c; }