예제 #1
0
CCTableGridCell* CCTableGridBackPackTest::tableviewDataSource(CCTableGrid* pTable, CCTableGridCell* pCell, unsigned int idx)
{
	CCButton* pIconButton = NULL;

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

		CC9Sprite* pBg = CC9Sprite::create("sprite9_btn1.png");
		pBg->setContentSize(CCSize(70, 70));
		pBg->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2));
		pCell->addChild(pBg);

		pIconButton = CCButton::create("icon.png");
		pIconButton->setLongClickSelector(this, longclick_selector(CCTableGridBackPackTest::onItemLongClick));
		pIconButton->getTextTTF()->setFontSize(25);
		pIconButton->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2));
		pIconButton->setTextOffset(ccp(-15, -15));
		pIconButton->setTag(1);
		pCell->addChild(pIconButton);
	}
	else
	{
		pIconButton = (CCButton*) pCell->getChildByTag(1);
	}

	if( idx != CC_INVALID_INDEX )
	{
		pIconButton->setVisible(true);

		pIconButton->getTextTTF()->setString(m_vData[idx].c_str());
		pIconButton->setUserTag(idx);
	}
	else
	{
		pIconButton->setVisible(false);
	}

	return pCell;
}
예제 #2
0
bool CCTableGridBackPackTest::onItemLongClick(CCObject* pSender)
{
	CCButton* pIconButton = (CCButton*) pSender;
	pIconButton->setVisible(false);

	CCPoint tPoint = pIconButton->getParent()->convertToWorldSpace(pIconButton->getPosition());

	m_pSelectedSprite->setVisible(true);
	m_pSelectedSprite->setPosition(tPoint);

	return true;
}
예제 #3
0
CCTableGridCell* CCTableGridBasicTest::tableviewDataSource(CCTableGrid* pTable, CCTableGridCell* pCell, unsigned int idx)
{
	CCButton* pButton = NULL;

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

		pButton = CCButton::createWith9Sprite(CCSizeMake(70, 70), "sprite9_btn1.png", "sprite9_btn2.png");
		pButton->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2));
		pButton->getTextTTF()->setFontSize(25.0f);
		pButton->setTag(1);
		pCell->addChild(pButton);
	}
	else
	{
		pButton = (CCButton*) pCell->getChildByTag(1);
	}

	if( idx != CC_INVALID_INDEX )
	{
		pButton->setVisible(true);

		char buff[64];
		sprintf(buff, "%u", idx);
		pButton->getTextTTF()->setString(buff);
		pButton->setUserTag(idx);
	}
	else
	{
		pButton->setVisible(false);
	}

	return pCell;
}
예제 #4
0
void CCTableGridBackPackTest::onLayoutTouchEndedAfterLongClick(CCObject* pSender, CCTouch* pTouch, float fDuration)
{
	CCButton* pIconButton = (CCButton*) pSender;
	
	m_pSelectedSprite->setPosition(pTouch->getLocation());

	CCPoint tLayoutPoint = m_pLayout->convertTouchToNodeSpace(pTouch);
	if( m_pToggleImage->boundingBox().containsPoint(tLayoutPoint) )
	{
		m_vData.erase(m_vData.begin() + pIconButton->getUserTag());
		pTable->setCountOfCell(m_vData.size());
		pTable->reloadData();
	}

	pIconButton->setVisible(true); //back to the same as before drag
	m_pSelectedSprite->setVisible(false);
	m_pToggleImage->setChecked(false);
}