/************************************************************************* Remove the given TreeItem from this item's list. *************************************************************************/ void TreeItem::removeItem(const TreeItem* item) { if (item) { Tree* parentWindow = (Tree*)getOwnerWindow(); LBItemList::iterator pos = std::find(d_listItems.begin(), d_listItems.end(), item); if (pos != d_listItems.end()) { (*pos)->setOwnerWindow(0); d_listItems.erase(pos); if (item == parentWindow->d_lastSelected) parentWindow->d_lastSelected = 0; if (item->isAutoDeleted()) delete item; WindowEventArgs args(parentWindow); parentWindow->onListContentsChanged(args); } } }
/************************************************************************* Add the given TreeItem to this item's list. *************************************************************************/ void TreeItem::addItem(TreeItem* item) { if (item != 0) { Tree* parentWindow = (Tree*)getOwnerWindow(); // establish ownership item->setOwnerWindow(parentWindow); // if sorting is enabled, re-sort the tree if (parentWindow->isSortEnabled()) { d_listItems.insert( std::upper_bound(d_listItems.begin(), d_listItems.end(), item, &lbi_less), item); } // not sorted, just stick it on the end. else { d_listItems.push_back(item); } WindowEventArgs args(parentWindow); parentWindow->onListContentsChanged(args); } }
void ListboxTextItem::draw(RenderCache& cache,const Rect& targetRect, float zBase, float alpha, const Rect* clipper) const { if (d_selected && d_selectBrush != 0) { cache.cacheImage(*d_selectBrush, targetRect, zBase, getModulateAlphaColourRect(d_selectCols, alpha), clipper); } const FontBase* font = getFont(); if (font) { Rect finalPos(targetRect); finalPos.d_top += PixelAligned( FontBase::LineSpace * 0.5f); cache.cacheText( getOwnerWindow(), d_itemText, font, d_horzFormateing, finalPos, zBase, getModulateAlphaColourRect(d_textCols, alpha), clipper); } }
/************************************************************************* Draw the list box item in its current state. *************************************************************************/ void ListboxTextItem::draw(const Vector3& position, float alpha, const Rect& clipper) const { if (d_selected && (d_selectBrush != NULL)) { d_selectBrush->draw(clipper, position.d_z, clipper, getModulateAlphaColourRect(d_selectCols, alpha)); } const FontBase* fnt = getFont(); if (fnt != NULL) { Vector3 finalPos(position); finalPos.d_y -= PixelAligned((fnt->getLineSpacing() - fnt->getBaseline()) * 0.5f); fnt->drawText( getOwnerWindow(), d_itemText, finalPos, clipper, getModulateAlphaColourRect(d_textCols, alpha)); } }