2012-08-15 14:33:56 +08:00
|
|
|
//
|
2013-06-20 14:17:10 +08:00
|
|
|
// EditBoxTest.cpp
|
2012-08-15 14:33:56 +08:00
|
|
|
// TestCpp
|
|
|
|
//
|
|
|
|
// Created by James on 8/14/12.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "EditBoxTest.h"
|
|
|
|
#include "../ExtensionsTest.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
|
|
|
|
EditBoxTest::EditBoxTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Point visibleOrigin = EGLView::sharedOpenGLView()->getVisibleOrigin();
|
|
|
|
Size visibleSize = EGLView::sharedOpenGLView()->getVisibleSize();
|
2012-08-15 14:33:56 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* pBg = Sprite::create("Images/HelloWorld.png");
|
2012-08-15 14:33:56 +08:00
|
|
|
pBg->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2));
|
|
|
|
addChild(pBg);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_TTFShowEditReturn = LabelTTF::create("No edit control return!", "", 30);
|
2013-06-15 14:03:30 +08:00
|
|
|
_TTFShowEditReturn->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y + visibleSize.height - 50));
|
|
|
|
addChild(_TTFShowEditReturn);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// Back Menu
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(EditBoxTest::toExtensionsMainLayer, this));
|
2012-08-15 14:33:56 +08:00
|
|
|
itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25));
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menuBack = Menu::create(itemBack, NULL);
|
|
|
|
menuBack->setPosition(PointZero);
|
2012-08-15 14:33:56 +08:00
|
|
|
addChild(menuBack);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size editBoxSize = CCSizeMake(visibleSize.width - 100, 60);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// top
|
2013-06-20 14:17:10 +08:00
|
|
|
_editName = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/green_edit.png"));
|
2013-06-15 14:03:30 +08:00
|
|
|
_editName->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-06-15 14:03:30 +08:00
|
|
|
_editName->setFontName("Paint Boy");
|
2013-02-20 21:41:08 +08:00
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
_editName->setFontName("fonts/Paint Boy.ttf");
|
2013-02-20 21:41:08 +08:00
|
|
|
#endif
|
2013-06-15 14:03:30 +08:00
|
|
|
_editName->setFontSize(25);
|
|
|
|
_editName->setFontColor(ccRED);
|
|
|
|
_editName->setPlaceHolder("Name:");
|
|
|
|
_editName->setPlaceholderFontColor(ccWHITE);
|
|
|
|
_editName->setMaxLength(8);
|
|
|
|
_editName->setReturnType(kKeyboardReturnTypeDone);
|
|
|
|
_editName->setDelegate(this);
|
|
|
|
addChild(_editName);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// middle
|
2013-06-20 14:17:10 +08:00
|
|
|
_editPassword = EditBox::create(editBoxSize, Scale9Sprite::create("extensions/orange_edit.png"));
|
2013-06-15 14:03:30 +08:00
|
|
|
_editPassword->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-06-15 14:03:30 +08:00
|
|
|
_editPassword->setFont("American Typewriter", 30);
|
2013-02-20 21:41:08 +08:00
|
|
|
#else
|
2013-06-15 14:03:30 +08:00
|
|
|
_editPassword->setFont("fonts/American Typewriter.ttf", 30);
|
2013-02-20 21:41:08 +08:00
|
|
|
#endif
|
2013-06-15 14:03:30 +08:00
|
|
|
_editPassword->setFontColor(ccGREEN);
|
|
|
|
_editPassword->setPlaceHolder("Password:");
|
|
|
|
_editPassword->setMaxLength(6);
|
|
|
|
_editPassword->setInputFlag(kEditBoxInputFlagPassword);
|
|
|
|
_editPassword->setInputMode(kEditBoxInputModeSingleLine);
|
|
|
|
_editPassword->setDelegate(this);
|
|
|
|
addChild(_editPassword);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
// bottom
|
2013-06-20 14:17:10 +08:00
|
|
|
_editEmail = EditBox::create(CCSizeMake(editBoxSize.width, editBoxSize.height), Scale9Sprite::create("extensions/yellow_edit.png"));
|
2013-06-15 14:03:30 +08:00
|
|
|
_editEmail->setPosition(ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/4));
|
|
|
|
_editEmail->setAnchorPoint(ccp(0.5, 1.0f));
|
|
|
|
_editEmail->setPlaceHolder("Email:");
|
|
|
|
_editEmail->setInputMode(kEditBoxInputModeEmailAddr);
|
|
|
|
_editEmail->setDelegate(this);
|
|
|
|
addChild(_editEmail);
|
2013-02-26 11:16:26 +08:00
|
|
|
|
|
|
|
this->setPosition(ccp(10, 20));
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EditBoxTest::~EditBoxTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void EditBoxTest::toExtensionsMainLayer(cocos2d::Object *sender)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
|
|
|
ExtensionsTestScene *pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void EditBoxTest::editBoxEditingDidBegin(cocos2d::extension::EditBox* editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
|
|
|
CCLog("editBox %p DidBegin !", editBox);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void EditBoxTest::editBoxEditingDidEnd(cocos2d::extension::EditBox* editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
|
|
|
CCLog("editBox %p DidEnd !", editBox);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void EditBoxTest::editBoxTextChanged(cocos2d::extension::EditBox* editBox, const std::string& text)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
|
|
|
CCLog("editBox %p TextChanged, text: %s ", editBox, text.c_str());
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void EditBoxTest::editBoxReturn(EditBox* editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
2013-05-24 11:42:27 +08:00
|
|
|
CCLog("editBox %p was returned !",editBox);
|
2012-08-17 14:29:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editName == editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_TTFShowEditReturn->setString("Name EditBox return !");
|
2012-08-17 14:29:07 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
else if (_editPassword == editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_TTFShowEditReturn->setString("Password EditBox return !");
|
2012-08-17 14:29:07 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
else if (_editEmail == editBox)
|
2012-08-17 14:29:07 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_TTFShowEditReturn->setString("Email EditBox return !");
|
2012-08-17 14:29:07 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
void runEditBoxTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene *pScene = Scene::create();
|
2012-08-15 14:33:56 +08:00
|
|
|
EditBoxTest *pLayer = new EditBoxTest();
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene);
|
2012-08-15 14:33:56 +08:00
|
|
|
pLayer->release();
|
2013-04-03 22:20:01 +08:00
|
|
|
}
|