Esempio n. 1
0
Ref* CGridViewBasicTest::gridviewDataSource(Ref* pConvertView, unsigned int idx)
{
	CGridViewCell* pCell = (CGridViewCell*) pConvertView;
	CButton* pButton = NULL;

	if(!pCell)
	{
		pCell = new CGridViewCell();
		pCell->autorelease();

		pButton = CButton::createWith9Sprite(Size(70, 70), "sprite9_btn1.png", "sprite9_btn2.png");
		pButton->setPosition(Point(480 / 5 / 2, 320 / 4 / 2));
//		pButton->getLabel()->setFontSize(25.0f);
		pButton->setTag(1);
		pCell->addChild(pButton);
	}
	else
	{
		pButton = (CButton*) pCell->getChildByTag(1);
	}

	char buff[64];
	sprintf(buff, "%u", idx);
	pButton->getLabel()->setString(buff);
	pButton->setUserTag(idx);

	return pCell;
}
Esempio n. 2
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();
}
Esempio n. 3
0
CCObject* CChangeHeadImg::gridviewDataSource(CCObject* pConvertCell, unsigned int uIdx)
{ 
	CGridViewCell* pCell = (CGridViewCell*)pConvertCell;
	if (uIdx<m_headIconList.size())
	{
		pCell = new CGridViewCell();
		pCell->autorelease();
		pCell->setTag(uIdx);
		addGridCell(uIdx,pCell);
	}
	return pCell;
}
Esempio n. 4
0
CGridViewCell* CGridView::dequeueCell()
{
	CGridViewCell* pCell = NULL;
    if( m_lCellsFreed.empty() )
    {
        return NULL;
    }
    else
    {
        pCell = m_lCellsFreed.front();
        m_lCellsFreed.pop_front();
        pCell->autorelease();
    }
    return pCell;
}
Esempio n. 5
0
CCObject* CSignLayer::gridviewDataSource(CCObject* pConvertCell, unsigned int uIdx)
{ 
	CGridViewCell* pCell = (CGridViewCell*)pConvertCell;
	if (!pCell)
	{
		pCell = new CGridViewCell();
		pCell->autorelease();
		pCell->setTag(uIdx);
	}
	else
	{
		pCell->removeAllChildren();
	}
	
	addGridCell(uIdx,pCell);

	return pCell;
}
Esempio n. 6
0
Ref* Bagui::event_adapt_gvBag(Ref* pConvertCell, unsigned int uIdx)
{
	CGridViewCell* pCell = (CGridViewCell*)pConvertCell;
	CButton *btn = nullptr;
	if (!pCell)
	{
		pCell = new CGridViewCell();
		pCell->autorelease();

		TuiManager::getInstance()->parseCell(pCell, "cell_grid", PATH_BAG);

		btn = (CButton*)pCell->getChildByTag(BTN_GRID);
		btn->setOnClickListener(this, ccw_click_selector(Bagui::event_btn_gv));
	}else{
		btn = (CButton*)pCell->getChildByTag(BTN_GRID);
	}
	btn->setUserTag(uIdx);
	return pCell;
}
Esempio n. 7
0
void CGridView::updateCellAtIndex(unsigned int idx, unsigned int row)
{
	if( m_uCellsCount == 0 )
		return;

	CGridViewCell* pCell = (CGridViewCell*) executeDataSourceAdapterHandler(dequeueCell(), idx);
#if 1
    CCAssert(pCell != NULL, "cell can not be nil");
#endif

	pCell->setIdx(idx);
	pCell->setRow(row);
	pCell->setAnchorPoint(Point(0, 1));
	pCell->setContentSize(m_tCellsSize);
	pCell->setPosition(cellPositionFromIndex(idx));

    m_pContainer->addChild(pCell);
	insertSortableCell(pCell, idx);
    pCell->retain();

	m_sIndices.insert(idx);
}
Esempio n. 8
0
CCObject* ViewScene::gridViewDataSource(CCObject* pContentView, unsigned int idx){
	CGridViewCell* pCell = (CGridViewCell*) pContentView;
	CButton* pButton = NULL;
	CCheckBox* pCheckbox = NULL;
	Notes = SQLiteData::getNote(unit_id,zi_id);
	vector<string> oneNote = Notes.at(idx);			//oneNote 中第一个元素为ID,第二个元素为笔画序列

	if (!pCell)
	{
		pCell = new CGridViewCell();
		pCell->autorelease();

		pButton = CButton::create("strangedesign/Dlg_cancel_button.png","strangedesign/Dlg_cancel_button_down.png");
		pButton->setPosition(CCPoint(360/2, 350-pButton->getContentSize().height/2));

		pCheckbox = CCheckBox::create();
		pCheckbox->setNormalImage("ckb_normal_01.png");
		pCheckbox->setNormalPressImage("ckb_normal_02.png");
		pCheckbox->setCheckedImage("ckb_selected_01.png");
		pCheckbox->setCheckedPressImage("ckb_selected_02.png");
		pCheckbox->setDisabledNormalImage("ckb_disable_01.png");
		pCheckbox->setDisabledCheckedImage("ckb_disable_02.png");
		pCheckbox->setPosition(CCPoint(360-pCheckbox->getContentSize().width, 350-pButton->getContentSize().height/2));

		pCell->addChild(pCheckbox,10);
		//pCell->addChild(pButton,10);

		HcharacterDrawnode* handwritingHz = HcharacterDrawnode::create();
		
		vector< vector<CCPoint> > strokesvec = DataTool::spliteString(oneNote.at(1));
		for (unsigned int i = 0; i < strokesvec.size(); i++)
		{
			vector<CCPoint> oneStrokeVec = strokesvec[i];
			Stroke stroke(oneStrokeVec);
			handwritingHz->addStroke(stroke);
		}
		
		handwritingHz->setContentSize(CCSize(320,320));
		CCPoint position = ccp(360/2- handwritingHz->getContentSize().width/2, 350/2- handwritingHz->getContentSize().height/2);
		handwritingHz->setPosition(position);
		pCell->addChild(handwritingHz,1);



	}else
	{
		pButton = CButton::create("strangedesign/Dlg_cancel_button.png","strangedesign/Dlg_cancel_button_down.png");
		pButton->setPosition(CCPoint(360/2, 350-pButton->getContentSize().height/2));

		pCheckbox = CCheckBox::create();
		pCheckbox->setNormalImage("ckb_normal_01.png");
		pCheckbox->setNormalPressImage("ckb_normal_02.png");
		pCheckbox->setCheckedImage("ckb_selected_01.png");
		pCheckbox->setCheckedPressImage("ckb_selected_02.png");
		pCheckbox->setDisabledNormalImage("ckb_disable_01.png");
		pCheckbox->setDisabledCheckedImage("ckb_disable_02.png");
		pCheckbox->setPosition(CCPoint(360-pCheckbox->getContentSize().width, 350-pButton->getContentSize().height/2));

		pCell->addChild(pCheckbox,10);

		//pCell->addChild(pButton,10);

		HcharacterDrawnode* handwritingHz = HcharacterDrawnode::create();
		vector<string> oneNote = Notes.at(idx);			//oneNote 中第一个元素为ID,第二个元素为笔画序列
		vector< vector<CCPoint> > strokesvec = DataTool::spliteString(oneNote.at(1));
		for (unsigned int i = 0; i < strokesvec.size(); i++)
		{
			vector<CCPoint> oneStrokeVec = strokesvec[i];
			Stroke stroke(oneStrokeVec);
			handwritingHz->addStroke(stroke);
		}

 		handwritingHz->setContentSize(CCSize(320,320));
		CCPoint position = ccp(360/2- handwritingHz->getContentSize().width/2, 350/2- handwritingHz->getContentSize().height/2);
		handwritingHz->setPosition(position);
		pCell->addChild(handwritingHz,1);
	}

	char buff[64];
	sprintf(buff, "%u", idx);
	pButton->getLabel()->setString(buff);
	int userTag = DataTool::stringToInt(oneNote.at(0));
	pButton->setUserTag(userTag);
	pCheckbox->setUserTag(userTag);

	pButton->setOnClickListener(this,ccw_click_selector(ViewScene::buttonClick));
	pCheckbox->setOnClickListener(this,ccw_click_selector(ViewScene::checkBoxClick));

	return pCell;
}
Esempio n. 9
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);
		}
    }
}
Esempio n. 10
0
CCObject* MainScene::gridviewDataSource(CCObject* pConvertView, unsigned int idx){
	CGridViewCell* pCell = (CGridViewCell*) pConvertView;
	CButton* pButton = NULL;
	CCLog("idx %d",idx);
	if(!pCell)
	{
		pCell = new CGridViewCell();
		pCell->autorelease();

		pButton = CButton::create("strangedesign/main_clincher.png","strangedesign/main_clincher_down.png");
		pButton->setPosition(CCPoint(360/2, 350-pButton->getContentSize().height/2));
		pButton->getLabel()->setFontSize(40.0f);
		pButton->setTag(1);

		pCell->addChild(pButton,10);

		CCSprite* sprite = CCSprite::create("strangedesign/table4mul4.png");
		sprite->setContentSize(CCSize(320,320));
		sprite->setPosition(CCPoint(360/2,350/2));
		pCell->addChild(sprite,1);
		
		CCLog("idx %d",idx);
		vector<vector<string> > groupCharacter = SQLiteData::getUnit(unit_ids.at(idx));

		CCPoint positions[16] = {ccp(40,280),ccp(120,280),ccp(200,280),ccp(280,280),
			ccp(40,200),ccp(120,200),ccp(200,200),ccp(280,200),
			ccp(40,120),ccp(120,120),ccp(200,120),ccp(280,120),
			ccp(40,40),ccp(120,40),ccp(200,40),ccp(280,40)
		};
		for (unsigned int i = 0; i < groupCharacter.size(); i++)
		{
			string hanzi = groupCharacter.at(i).at(0);
			CCLabelTTF* clabel = CCLabelTTF::create(hanzi.c_str(),"Arial",40);
			clabel->setPosition(positions[i]);
			clabel->setColor(ccc3(0,0,0));
			sprite->addChild(clabel);
		}
	}
	else
	{
		pButton = CButton::create("strangedesign/main_clincher.png","strangedesign/main_clincher_down.png");
		pButton->setPosition(CCPoint(360/2, 350-pButton->getContentSize().height/2));
		pButton->getLabel()->setFontSize(40.0f);
		pButton->setTag(1);

		pCell->addChild(pButton,10);

		CCSprite* sprite = CCSprite::create("strangedesign/table4mul4.png");
		sprite->setContentSize(CCSize(320,320));
		sprite->setPosition(CCPoint(360/2,350/2));
		pCell->addChild(sprite,1);

		CCLog("idx %d",idx);
		vector<vector<string> > groupCharacter = SQLiteData::getUnit(unit_ids.at(idx));

		CCPoint positions[16] = {ccp(40,280),ccp(120,280),ccp(200,280),ccp(280,280),
			ccp(40,200),ccp(120,200),ccp(200,200),ccp(280,200),
			ccp(40,120),ccp(120,120),ccp(200,120),ccp(280,120),
			ccp(40,40),ccp(120,40),ccp(200,40),ccp(280,40)
		};
		for (unsigned int i = 0; i < groupCharacter.size(); i++)
		{
			string hanzi = groupCharacter.at(i).at(0);
			CCLabelTTF* clabel = CCLabelTTF::create(hanzi.c_str(),"Arial",40);
			clabel->setPosition(positions[i]);
			clabel->setColor(ccc3(0,0,0));
			sprite->addChild(clabel);
		}
	}

	char buff[64];
	unsigned int labelidx = idx+1;
	sprintf(buff, "%u", labelidx);
	pButton->getLabel()->setString(buff);
	pButton->setUserTag(idx);

	pButton->setOnClickListener(this,ccw_click_selector(MainScene::buttonClick));
	pButton->setOnLongClickListener(this,ccw_longclick_selector(MainScene::buttonLongClick));
	return pCell;
}