Ejemplo n.º 1
0
void CGridView::reloadData()
{
#if USING_LUA
	CCAssert(
		(m_nDataSourceAdapterScriptHandler != 0) || 
		(m_pDataSourceAdapterListener && m_pDataSourceAdapterHandler), "reloadData");
#else
	CCAssert(m_pDataSourceAdapterListener && m_pDataSourceAdapterHandler , "reloadData");
#endif
	CCAssert((int)m_tCellsSize.width != 0 && (int)m_tCellsSize.height != 0, "reloadData");
    CCAssert(m_eDirection == eScrollViewDirectionVertical, "reloadData");
	CCAssert(m_uColumns != 0, "reloadData");

	list<CGridViewCell*>::iterator iter = m_lCellsUsed.begin();
	while(iter != m_lCellsUsed.end())
	{
		CGridViewCell* pCell = (*iter);
		m_lCellsFreed.push_back(pCell);
		iter = m_lCellsUsed.erase(iter);
		m_pContainer->removeChild(pCell, true);
		pCell->reset();
	}

	m_sIndices.clear();
    m_vPositions.clear();
	this->updatePositions();
	this->setContentOffsetToTop();
    this->onScrolling();
	
	relocateContainer();
}
Ejemplo n.º 2
0
void CGridView::onScrolling()
{
	unsigned uBeginRow = 0, uEndRow = 0;

	uBeginRow = cellBeginRowFromOffset( getContentOffset() );
	uEndRow = cellEndRowFromOffset( getContentOffset() );
	
#if 0
	CCLOG("row begin %u  end %u", uBeginRow, uEndRow);
#endif

	while( !m_lCellsUsed.empty() )
    {
        CGridViewCell* pCell = m_lCellsUsed.front();
		unsigned int uRow = pCell->getRow();
		unsigned int uIdx = pCell->getIdx();

        if( uRow < uBeginRow )
        {
			m_sIndices.erase(uIdx);
			m_lCellsUsed.pop_front();
            m_lCellsFreed.push_back(pCell);
            pCell->reset();
            m_pContainer->removeChild(pCell, true);
        }
        else
        {
            break;
        }
    }

	while( !m_lCellsUsed.empty() )
    {
        CGridViewCell* pCell = m_lCellsUsed.back();
		unsigned int uRow = pCell->getRow();
		unsigned int uIdx = pCell->getIdx();

        if( uRow > uEndRow && uRow < m_uRows )
        {
			m_sIndices.erase(uIdx);
			m_lCellsUsed.pop_back();
            m_lCellsFreed.push_back(pCell);
            pCell->reset();
            m_pContainer->removeChild(pCell, true);
        }
        else
        {
            break;
        }
    }

	for( unsigned int row = uBeginRow; row <= uEndRow && row < m_uRows; ++row )
    {
		unsigned int nCellBeginIndex = cellFirstIndexFromRow(row);
		unsigned int nCellEndIndx = nCellBeginIndex + m_uColumns;
		unsigned int idx = nCellBeginIndex;

		for(; idx < nCellEndIndx && idx < m_uCellsCount; ++idx)
		{
			if( m_sIndices.find(idx) != m_sIndices.end() )
			{
				continue;
			}
			updateCellAtIndex(idx, row);
		}
    }
}