bool
HelloWorld::init()
{
if
( !CCLayer::init() )
{
return
false
;
}
this
->m_size = CCDirector::sharedDirector()->getVisibleSize();
editBox = CCEditBox::create(CCSize(300,40),
CCScale9Sprite::create(
"9.9.png"
),
CCScale9Sprite::create(
"8.9.png"
));
editBox->setPosition(ccp(m_size.width/2,m_size.height/2));
this
->addChild(editBox);
editBox->setPlaceHolder(
"please input:"
);
editBox->setFontColor(ccc3(255,0,0));
editBox->setMaxLength(1);
editBox->setInputMode(kEditBoxInputModeAny);
editBox->setInputFlag(kEditBoxInputFlagPassword);
editBox->setReturnType(kKeyboardReturnTypeGo);
editBox->setDelegate(
this
);
return
true
;
}
void
HelloWorld::editBoxEditingDidBegin(CCEditBox * editBox)
{
CCLog(
"begin!"
);
CCLabelTTF * ttf = CCLabelTTF::create(
"begin"
,
""
,24);
ttf->setPosition(ccp(m_size.width/4,m_size.height*1/5));
this
->addChild(ttf);
}
void
HelloWorld::editBoxEditingDidEnd(CCEditBox * editBox)
{
CCLog(
"end!"
);
CCLabelTTF * ttf = CCLabelTTF::create(
"end"
,
""
,24);
ttf->setPosition(ccp(m_size.width/4,m_size.height*4/5));
this
->addChild(ttf);
}
void
HelloWorld::editBoxTextChanged(CCEditBox * editBox,
const
std::string & text)
{
CCLog(
"textChanged!"
);
CCLabelTTF * ttf = CCLabelTTF::create(
"textChanged!"
,
""
,24);
ttf->setPosition(ccp(m_size.width/4,m_size.height*3/5));
this
->addChild(ttf);
}
void
HelloWorld::editBoxReturn(CCEditBox * editBox)
{
CCLog(
"return"
);
CCLabelTTF * ttf = CCLabelTTF::create(
"return"
,
""
,24);
ttf->setPosition(ccp(m_size.width/4,m_size.height*2/5));
this
->addChild(ttf);
char
* str = (
char
*)
this
->editBox->getText();
CCLabelTTF * text = CCLabelTTF::create(str,
""
,24);
text->setPosition(ccp(m_size.width/2,m_size.height*2/5));
this
->addChild(text);
}