extern "C" int GUI_CreateItem(lua_State *L)
{
	CUserInterface *pUI = CGUIManager::GetInstance()->GetCurrentUI();
	if(pUI)
	{
		cLua *lua = CGUIManager::GetInstance()->GetLuaContext();

		unsigned int id = (unsigned int) lua->GetNumberArgument(1);
		const char *type = lua->GetStringArgument(2);

		CGUIObject *pObject = NULL;

		if(strcmp(type, kpSpriteName) == 0)
		{
			//create a sprite
			CGUISprite *pSprite = new CGUISprite;
			pSprite->SetTexture((char *) lua->GetStringArgument(3));
			pObject = pSprite;
		}

		if(strcmp(type, kpTextFieldName) == 0)
		{
			//create a Text Field
			CTextField  *pTextField = new CTextField;
			pTextField->SetTexture((char *) lua->GetStringArgument(3, NULL));
			pObject = pTextField;
		}

		if(strcmp(type, kpButtonName) == 0)
		{
			//create a button
			CButton *pButton = new CButton;
			char *norm	= (char *) lua->GetStringArgument(3, NULL);
			char *hover = (char *) lua->GetStringArgument(4, NULL);
			char *sel	= (char *) lua->GetStringArgument(5, NULL);
			char *dis	= (char *) lua->GetStringArgument(6, NULL);

			pButton->SetButtonTextures(norm, hover, sel, dis);
			pObject = pButton;
		}

		if(pObject)
		{
			pUI->DeleteGUIObject(id);
			pObject->SetID(id);
			pUI->AddGUIObject(id, pObject);
		}
	}
	return 0;
}
void CUIManager::CreateGUIItem(const UINT nID, const tstring strType, const vector<tstring>& strTexture)
{
	if ( strTexture[0].empty() )
	{
		return;
	}
	CUserInterface* pUI = GetCurrentUI();;
	if (nullptr == pUI)
	{
		throw tstring(_T("Get current UI field."));
	}

	CObject* pObject = nullptr;

	if (strSpriteName == strType)
	{
		// Create Sprite
		CSprite* pSprite = new CSprite(m_pDDraw);
		pSprite->SetTexture(strTexture);
		pObject = pSprite;
	}
	else if (strTextFieldName == strType)
	{
		// Create Text field
		CTextField* pText = new CTextField(m_pDDraw);
		pText->SetTexture(strTexture);
		pObject = pText;
	}
	else if (strButtonName == strType)
	{
		// Create Button
		CButton* pButton = new CButton(m_pDDraw);
		pButton->SetTexture(strTexture);
		pObject = pButton;
	}
	else
	{
		throw tstring(_T("Type error"));
	}

	if (pObject)
	{
		pUI->DeleteObject(nID);
		pObject->SetID(nID);
		pUI->AddObject(nID, pObject);
	}
}
Beispiel #3
0
 CTextField * CTextField::create(const char *placeholder, const char *fontName, float fontSize)
 {
     CTextField *pRet = new CTextField();
     
     if(pRet && pRet->initWithString("", fontName, fontSize))
     {
         pRet->autorelease();
         if (placeholder)
         {
             pRet->setPlaceHolder(placeholder);
         }
         
         pRet->initCursorSprite(fontSize);
         
         return pRet;
     }
     
     CC_SAFE_DELETE(pRet);
     
     return NULL;
 }