2012-08-15 14:33:56 +08:00
|
|
|
//
|
|
|
|
// CCEditBoxTest.cpp
|
|
|
|
// TestCpp
|
|
|
|
//
|
|
|
|
// Created by James on 8/14/12.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "EditBoxTest.h"
|
|
|
|
#include "../ExtensionsTest.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
|
|
|
|
EditBoxTest::EditBoxTest()
|
|
|
|
{
|
2012-08-21 14:58:31 +08:00
|
|
|
CCPoint visibleOrigin = CCEGLView::sharedOpenGLView()->getVisibleOrigin();
|
|
|
|
CCSize visibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize();
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
CCSprite* pBg = CCSprite::create("Images/HelloWorld.png");
|
|
|
|
pBg->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
|
|
|
|
addChild(pBg);
|
|
|
|
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pTTFShowEditReturn = CCLabelTTF::create("No edit control return!", "", 30);
|
|
|
|
m_pTTFShowEditReturn->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y + visibleSize.height - 50));
|
|
|
|
addChild(m_pTTFShowEditReturn);
|
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// Back Menu
|
2013-06-08 08:21:11 +08:00
|
|
|
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", std::bind( &EditBoxTest::toExtensionsMainLayer, this, std::placeholders::_1));
|
2012-08-15 14:33:56 +08:00
|
|
|
itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25));
|
|
|
|
CCMenu *menuBack = CCMenu::create(itemBack, NULL);
|
|
|
|
menuBack->setPosition(CCPointZero);
|
|
|
|
addChild(menuBack);
|
|
|
|
|
2012-08-23 15:34:57 +08:00
|
|
|
CCSize editBoxSize = CCSizeMake(visibleSize.width - 100, 60);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// top
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("extensions/green_edit.png"));
|
|
|
|
m_pEditName->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height*3/4));
|
2013-02-25 14:44:38 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
2013-04-03 22:20:01 +08:00
|
|
|
m_pEditName->setFontName("Paint Boy");
|
2013-02-20 21:41:08 +08:00
|
|
|
#else
|
2013-04-03 22:20:01 +08:00
|
|
|
m_pEditName->setFontName("fonts/Paint Boy.ttf");
|
2013-02-20 21:41:08 +08:00
|
|
|
#endif
|
2013-04-03 22:20:01 +08:00
|
|
|
m_pEditName->setFontSize(25);
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditName->setFontColor(ccRED);
|
|
|
|
m_pEditName->setPlaceHolder("Name:");
|
2013-02-20 21:41:08 +08:00
|
|
|
m_pEditName->setPlaceholderFontColor(ccWHITE);
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditName->setMaxLength(8);
|
|
|
|
m_pEditName->setReturnType(kKeyboardReturnTypeDone);
|
|
|
|
m_pEditName->setDelegate(this);
|
|
|
|
addChild(m_pEditName);
|
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// middle
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("extensions/orange_edit.png"));
|
|
|
|
m_pEditPassword->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
|
2013-02-25 14:44:38 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
2013-02-25 22:50:15 +08:00
|
|
|
m_pEditPassword->setFont("American Typewriter", 30);
|
2013-02-20 21:41:08 +08:00
|
|
|
#else
|
2013-02-25 22:50:15 +08:00
|
|
|
m_pEditPassword->setFont("fonts/American Typewriter.ttf", 30);
|
2013-02-20 21:41:08 +08:00
|
|
|
#endif
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditPassword->setFontColor(ccGREEN);
|
|
|
|
m_pEditPassword->setPlaceHolder("Password:");
|
|
|
|
m_pEditPassword->setMaxLength(6);
|
|
|
|
m_pEditPassword->setInputFlag(kEditBoxInputFlagPassword);
|
|
|
|
m_pEditPassword->setInputMode(kEditBoxInputModeSingleLine);
|
|
|
|
m_pEditPassword->setDelegate(this);
|
|
|
|
addChild(m_pEditPassword);
|
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// bottom
|
2012-08-23 15:34:57 +08:00
|
|
|
m_pEditEmail = CCEditBox::create(CCSizeMake(editBoxSize.width, editBoxSize.height), CCScale9Sprite::create("extensions/yellow_edit.png"));
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditEmail->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
|
2013-02-20 21:41:08 +08:00
|
|
|
m_pEditEmail->setAnchorPoint(ccp(0.5, 1.0f));
|
2012-08-17 14:29:07 +08:00
|
|
|
m_pEditEmail->setPlaceHolder("Email:");
|
|
|
|
m_pEditEmail->setInputMode(kEditBoxInputModeEmailAddr);
|
|
|
|
m_pEditEmail->setDelegate(this);
|
|
|
|
addChild(m_pEditEmail);
|
2013-02-26 11:16:26 +08:00
|
|
|
|
|
|
|
this->setPosition(ccp(10, 20));
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EditBoxTest::~EditBoxTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBoxTest::toExtensionsMainLayer(cocos2d::CCObject *sender)
|
|
|
|
{
|
|
|
|
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
|
2012-08-17 14:29:07 +08:00
|
|
|
void EditBoxTest::editBoxEditingDidBegin(cocos2d::extension::CCEditBox* editBox)
|
|
|
|
{
|
|
|
|
CCLog("editBox %p DidBegin !", editBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBoxTest::editBoxEditingDidEnd(cocos2d::extension::CCEditBox* editBox)
|
|
|
|
{
|
|
|
|
CCLog("editBox %p DidEnd !", editBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBoxTest::editBoxTextChanged(cocos2d::extension::CCEditBox* editBox, const std::string& text)
|
|
|
|
{
|
|
|
|
CCLog("editBox %p TextChanged, text: %s ", editBox, text.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditBoxTest::editBoxReturn(CCEditBox* editBox)
|
|
|
|
{
|
2013-05-24 11:42:27 +08:00
|
|
|
CCLog("editBox %p was returned !",editBox);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
|
|
|
if (m_pEditName == editBox)
|
|
|
|
{
|
|
|
|
m_pTTFShowEditReturn->setString("Name EditBox return !");
|
|
|
|
}
|
|
|
|
else if (m_pEditPassword == editBox)
|
|
|
|
{
|
|
|
|
m_pTTFShowEditReturn->setString("Password EditBox return !");
|
|
|
|
}
|
|
|
|
else if (m_pEditEmail == editBox)
|
|
|
|
{
|
|
|
|
m_pTTFShowEditReturn->setString("Email EditBox return !");
|
|
|
|
}
|
|
|
|
}
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
void runEditBoxTest()
|
|
|
|
{
|
|
|
|
CCScene *pScene = CCScene::create();
|
|
|
|
EditBoxTest *pLayer = new EditBoxTest();
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
pLayer->release();
|
2013-04-03 22:20:01 +08:00
|
|
|
}
|