CPP Tests migrated to the new C++11 API

Many tests were converted to the C++11 API
and some tests were also simplified by using the "CL" macro
instead of the "CF" macro.
This commit is contained in:
Ricardo Quesada 2013-06-07 17:21:11 -07:00
parent 06fc79ac3b
commit 022dfc0acc
43 changed files with 237 additions and 521 deletions

View File

@ -115,7 +115,14 @@ void Box2DTestLayer::initPhysics()
void Box2DTestLayer::createResetButton() void Box2DTestLayer::createResetButton()
{ {
CCMenuItemImage *reset = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(Box2DTestLayer::reset)); CCMenuItemImage *reset = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", [](CCObject *sender) {
CCScene* s = new Box2DTestScene();
Box2DTestLayer* child = new Box2DTestLayer();
s->addChild(child);
child->release();
CCDirector::sharedDirector()->replaceScene(s);
s->release();
});
CCMenu *menu = CCMenu::create(reset, NULL); CCMenu *menu = CCMenu::create(reset, NULL);
@ -124,16 +131,6 @@ void Box2DTestLayer::createResetButton()
} }
void Box2DTestLayer::reset(CCObject* sender)
{
CCScene* s = new Box2DTestScene();
Box2DTestLayer* child = new Box2DTestLayer();
s->addChild(child);
child->release();
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void Box2DTestLayer::draw() void Box2DTestLayer::draw()
{ {
// //

View File

@ -28,7 +28,6 @@ public:
void initPhysics(); void initPhysics();
void createResetButton(); void createResetButton();
void reset(CCObject* sender);
virtual void draw(); virtual void draw();
void addNewSpriteAtPosition(CCPoint p); void addNewSpriteAtPosition(CCPoint p);

View File

@ -67,9 +67,9 @@ bool MenuLayer::initWithEntryID(int entryId)
addChild(label, 1); addChild(label, 1);
label->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50) ); label->setPosition( ccp(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height-50) );
CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(MenuLayer::backCallback) ); CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", std::bind( &MenuLayer::backCallback, this, std::placeholders::_1) );
CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(MenuLayer::restartCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", std::bind( &MenuLayer::restartCallback, this, std::placeholders::_1) );
CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(MenuLayer::nextCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", std::bind( &MenuLayer::nextCallback, this, std::placeholders::_1) );
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);

View File

@ -45,7 +45,7 @@ bool Bug1159Layer::init()
sprite_b->setPosition(ccp(s.width/2, s.height/2)); sprite_b->setPosition(ccp(s.width/2, s.height/2));
addChild(sprite_b); addChild(sprite_b);
CCMenuItemLabel *label = CCMenuItemLabel::create(CCLabelTTF::create("Flip Me", "Helvetica", 24), this, menu_selector(Bug1159Layer::callBack)); CCMenuItemLabel *label = CCMenuItemLabel::create(CCLabelTTF::create("Flip Me", "Helvetica", 24), std::bind( &Bug1159Layer::callBack, this, std::placeholders::_1) );
CCMenu *menu = CCMenu::create(label, NULL); CCMenu *menu = CCMenu::create(label, NULL);
menu->setPosition(ccp(s.width - 200.0f, 50.0f)); menu->setPosition(ccp(s.width - 200.0f, 50.0f));
addChild(menu); addChild(menu);

View File

@ -31,9 +31,9 @@ void Bug422Layer::reset()
removeChild(node, false); removeChild(node, false);
// [self removeChildByTag:localtag-1 cleanup:NO]; // [self removeChildByTag:localtag-1 cleanup:NO];
CCMenuItem *item1 = CCMenuItemFont::create("One", this, menu_selector(Bug422Layer::menuCallback)); CCMenuItem *item1 = CCMenuItemFont::create("One", std::bind( &Bug422Layer::menuCallback, this, std::placeholders::_1) );
CCLog("MenuItemFont: %p", item1); CCLog("MenuItemFont: %p", item1);
CCMenuItem *item2 = CCMenuItemFont::create("Two", this, menu_selector(Bug422Layer::menuCallback)); CCMenuItem *item2 = CCMenuItemFont::create("Two", std::bind( &Bug422Layer::menuCallback, this, std::placeholders::_1) );
CCMenu *menu = CCMenu::create(item1, item2, NULL); CCMenu *menu = CCMenu::create(item1, item2, NULL);
menu->alignItemsVertically(); menu->alignItemsVertically();

View File

@ -21,13 +21,13 @@ bool Bug458Layer::init()
// [question setContentSize:CGSizeMake(50,50)]; // [question setContentSize:CGSizeMake(50,50)];
// [question2 setContentSize:CGSizeMake(50,50)]; // [question2 setContentSize:CGSizeMake(50,50)];
CCMenuItemSprite* sprite = CCMenuItemSprite::create(question2, question, (CCObject*)this, menu_selector(Bug458Layer::selectAnswer)); CCMenuItemSprite* sprite = CCMenuItemSprite::create(question2, question, std::bind( &Bug458Layer::selectAnswer, this, std::placeholders::_1) );
CCLayerColor* layer = CCLayerColor::create(ccc4(0,0,255,255), 100, 100); CCLayerColor* layer = CCLayerColor::create(ccc4(0,0,255,255), 100, 100);
question->release(); question->release();
question2->release(); question2->release();
CCLayerColor* layer2 = CCLayerColor::create(ccc4(255,0,0,255), 100, 100); CCLayerColor* layer2 = CCLayerColor::create(ccc4(255,0,0,255), 100, 100);
CCMenuItemSprite* sprite2 = CCMenuItemSprite::create(layer, layer2, (CCObject*)this, menu_selector(Bug458Layer::selectAnswer)); CCMenuItemSprite* sprite2 = CCMenuItemSprite::create(layer, layer2, std::bind( &Bug458Layer::selectAnswer, this, std::placeholders::_1) );
CCMenu* menu = CCMenu::create(sprite, sprite2, NULL); CCMenu* menu = CCMenu::create(sprite, sprite2, NULL);
menu->alignItemsVerticallyWithPadding(100); menu->alignItemsVerticallyWithPadding(100);
menu->setPosition(ccp(size.width / 2, size.height / 2)); menu->setPosition(ccp(size.width / 2, size.height / 2));

View File

@ -46,7 +46,7 @@ bool Bug914Layer::init()
// create and initialize a Label // create and initialize a Label
CCLabelTTF *label = CCLabelTTF::create("Hello World", "Marker Felt", 64); CCLabelTTF *label = CCLabelTTF::create("Hello World", "Marker Felt", 64);
CCMenuItem *item1 = CCMenuItemFont::create("restart", this, menu_selector(Bug914Layer::restart)); CCMenuItem *item1 = CCMenuItemFont::create("restart", std::bind( &Bug914Layer::restart, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item1, NULL); CCMenu *menu = CCMenu::create(item1, NULL);
menu->alignItemsVertically(); menu->alignItemsVertically();

View File

@ -9,38 +9,42 @@
#include "Bug-1159.h" #include "Bug-1159.h"
#include "Bug-1174.h" #include "Bug-1174.h"
#define TEST_BUG(bugNO) \ #define TEST_BUG(__bug__) \
{ \ { \
CCScene* pScene = CCScene::create(); \ CCScene* pScene = CCScene::create(); \
Bug##bugNO##Layer* pLayer = new Bug##bugNO##Layer(); \ Bug##__bug__##Layer* pLayer = new Bug##__bug__##Layer(); \
pLayer->init(); \ pLayer->init(); \
pScene->addChild(pLayer); \ pScene->addChild(pLayer); \
CCDirector::sharedDirector()->replaceScene(pScene); \ CCDirector::sharedDirector()->replaceScene(pScene); \
pLayer->autorelease(); \ pLayer->autorelease(); \
} }
enum enum
{ {
MAX_COUNT = 9,
LINE_SPACE = 40, LINE_SPACE = 40,
kItemTagBasic = 5432, kItemTagBasic = 5432,
}; };
static CCPoint s_tCurPos = CCPointZero; static CCPoint s_tCurPos = CCPointZero;
const std::string testsName[MAX_COUNT] = struct {
{ const char *test_name;
"Bug-350", std::function<void(CCObject*)> callback;
"Bug-422", } g_bugs[] = {
"Bug-458", { "Bug-350", [](CCObject* sender){ TEST_BUG(350)} },
"Bug-624", { "Bug-422", [](CCObject* sender){ TEST_BUG(422)} },
"Bug-886", { "Bug-458", [](CCObject* sender){ TEST_BUG(458)} },
"Bug-899", { "Bug-624", [](CCObject* sender){ TEST_BUG(624)} },
"Bug-914", { "Bug-886", [](CCObject* sender){ TEST_BUG(886)} },
"Bug-1159", { "Bug-899", [](CCObject* sender){ TEST_BUG(899)} },
"Bug-1174" { "Bug-914", [](CCObject* sender){ TEST_BUG(914)} },
{ "Bug-1159", [](CCObject* sender){ TEST_BUG(1159)} },
{ "Bug-1174", [](CCObject* sender){ TEST_BUG(1174)} },
}; };
static const int g_maxitems = sizeof(g_bugs) / sizeof(g_bugs[0]);
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// BugsTestMainLayer // BugsTestMainLayer
@ -54,10 +58,9 @@ void BugsTestMainLayer::onEnter()
m_pItmeMenu = CCMenu::create(); m_pItmeMenu = CCMenu::create();
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
for (int i = 0; i < MAX_COUNT; ++i) for (int i = 0; i < g_maxitems; ++i)
{ {
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this, CCMenuItemFont* pItem = CCMenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback);
menu_selector(BugsTestMainLayer::menuCallback));
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
m_pItmeMenu->addChild(pItem, kItemTagBasic + i); m_pItmeMenu->addChild(pItem, kItemTagBasic + i);
} }
@ -67,45 +70,6 @@ void BugsTestMainLayer::onEnter()
setTouchEnabled(true); setTouchEnabled(true);
} }
void BugsTestMainLayer::menuCallback(CCObject* pSender)
{
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
int nIndex = pItem->getZOrder() - kItemTagBasic;
switch (nIndex)
{
case 0:
TEST_BUG(350);
break;
case 1:
TEST_BUG(422);
break;
case 2:
TEST_BUG(458);
break;
case 3:
TEST_BUG(624);
break;
case 4:
TEST_BUG(886);
break;
case 5:
TEST_BUG(899);
break;
case 6:
TEST_BUG(914);
break;
case 7:
TEST_BUG(1159);
break;
case 8:
TEST_BUG(1174);
break;
default:
break;
}
}
void BugsTestMainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) void BugsTestMainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{ {
CCSetIterator it = pTouches->begin(); CCSetIterator it = pTouches->begin();
@ -131,9 +95,9 @@ void BugsTestMainLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
return; return;
} }
if (nextPos.y > ((MAX_COUNT + 1)* LINE_SPACE - winSize.height)) if (nextPos.y > ((g_maxitems + 1)* LINE_SPACE - winSize.height))
{ {
m_pItmeMenu->setPosition(ccp(0, ((MAX_COUNT + 1)* LINE_SPACE - winSize.height))); m_pItmeMenu->setPosition(ccp(0, ((g_maxitems + 1)* LINE_SPACE - winSize.height)));
return; return;
} }
@ -153,8 +117,7 @@ void BugsTestBaseLayer::onEnter()
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", this, CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", std::bind( &BugsTestBaseLayer::backCallback, this, std::placeholders::_1));
menu_selector(BugsTestBaseLayer::backCallback));
pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pMenu = CCMenu::create(pMainItem, NULL); CCMenu* pMenu = CCMenu::create(pMainItem, NULL);
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );

View File

@ -7,7 +7,6 @@ class BugsTestMainLayer : public CCLayer
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
void menuCallback(CCObject* pSender);
virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent); virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent); virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);

View File

@ -50,7 +50,7 @@ ChipmunkTestLayer::ChipmunkTestLayer()
// menu for debug layer // menu for debug layer
CCMenuItemFont::setFontSize(18); CCMenuItemFont::setFontSize(18);
CCMenuItemFont *item = CCMenuItemFont::create("Toggle debug", this, menu_selector(ChipmunkTestLayer::toggleDebugCallback)); CCMenuItemFont *item = CCMenuItemFont::create("Toggle debug", std::bind( &ChipmunkTestLayer::toggleDebugCallback, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
this->addChild(menu); this->addChild(menu);
@ -147,7 +147,7 @@ void ChipmunkTestLayer::update(float delta)
void ChipmunkTestLayer::createResetButton() void ChipmunkTestLayer::createResetButton()
{ {
CCMenuItemImage *reset = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(ChipmunkTestLayer::reset)); CCMenuItemImage *reset = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", std::bind( &ChipmunkTestLayer::reset, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(reset, NULL); CCMenu *menu = CCMenu::create(reset, NULL);

View File

@ -63,7 +63,7 @@ m_nSoundId(0)
//#else //#else
CCLabelTTF* label = CCLabelTTF::create(testItems[i].c_str(), "Arial", 24); CCLabelTTF* label = CCLabelTTF::create(testItems[i].c_str(), "Arial", 24);
//#endif //#endif
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(CocosDenshionTest::menuCallback)); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, std::bind( &CocosDenshionTest::menuCallback, this, std::placeholders::_1));
m_pItmeMenu->addChild(pMenuItem, i + 10000); m_pItmeMenu->addChild(pMenuItem, i + 10000);
pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) )); pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));

View File

@ -42,8 +42,7 @@ bool CCControlScene::init()
{ {
if (CCLayer::init()) if (CCLayer::init())
{ {
CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this, CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", std::bind( &CCControlScene::toExtensionsMainLayer, this, std::placeholders::_1));
menu_selector(CCControlScene::toExtensionsMainLayer));
pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL); CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL);
pBackMenu->setPosition( CCPointZero ); pBackMenu->setPosition( CCPointZero );
@ -66,9 +65,9 @@ bool CCControlScene::init()
addChild(m_pSceneTitleLabel, 1); addChild(m_pSceneTitleLabel, 1);
// Add the menu // Add the menu
CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(CCControlScene::previousCallback)); CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", std::bind( &CCControlScene::previousCallback, this, std::placeholders::_1));
CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(CCControlScene::restartCallback)); CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", std::bind( &CCControlScene::restartCallback, this, std::placeholders::_1));
CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(CCControlScene::nextCallback)); CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", std::bind( &CCControlScene::nextCallback, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item1, item3, item2, NULL); CCMenu *menu = CCMenu::create(item1, item3, item2, NULL);
menu->setPosition(CCPointZero); menu->setPosition(CCPointZero);

View File

@ -27,7 +27,7 @@ EditBoxTest::EditBoxTest()
addChild(m_pTTFShowEditReturn); addChild(m_pTTFShowEditReturn);
// Back Menu // Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(EditBoxTest::toExtensionsMainLayer)); CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", std::bind( &EditBoxTest::toExtensionsMainLayer, this, std::placeholders::_1));
itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25)); itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL); CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero); menuBack->setPosition(CCPointZero);

View File

@ -22,38 +22,42 @@ enum
kItemTagBasic = 1000, kItemTagBasic = 1000,
}; };
enum static struct {
{ const char *name;
TEST_NOTIFICATIONCENTER = 0, std::function<void(CCObject* sender)> callback;
TEST_CCCONTROLBUTTON, } g_extensionsTests[] = {
TEST_COCOSBUILDER, { "NotificationCenterTest", [](CCObject* sender) { runNotificationCenterTest(); }
TEST_HTTPCLIENT, },
{ "CCControlButtonTest", [](CCObject *sender){
CCControlSceneManager* pManager = CCControlSceneManager::sharedControlSceneManager();
CCScene* pScene = pManager->currentControlScene();
CCDirector::sharedDirector()->replaceScene(pScene);
}},
{ "CocosBuilderTest", [](CCObject *sender) {
TestScene* pScene = new CocosBuilderTestScene();
if (pScene)
{
pScene->runThisTest();
pScene->release();
}
}},
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
{ "HttpClientTest", [](CCObject *sender){ runHttpClientTest();}
},
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
TEST_WEBSOCKET, { "WebSocketTest", [](CCObject *sender){ runWebSocketTest();}
},
#endif #endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
TEST_EDITBOX, { "EditBoxTest", [](CCObject *sender){ runEditBoxTest();}
},
#endif #endif
TEST_TABLEVIEW, { "TableViewTest", [](CCObject *sender){ runTableViewTest();}
TEST_MAX_COUNT, },
}; };
static const std::string testsName[TEST_MAX_COUNT] = static const int g_maxTests = sizeof(g_extensionsTests) / sizeof(g_extensionsTests[0]);
{
"NotificationCenterTest",
"CCControlButtonTest",
"CocosBuilderTest",
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
"HttpClientTest",
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
"WebSocketTest",
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
"EditBoxTest",
#endif
"TableViewTest"
};
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
@ -70,10 +74,9 @@ void ExtensionsMainLayer::onEnter()
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
for (int i = 0; i < TEST_MAX_COUNT; ++i) for (int i = 0; i < g_maxTests; ++i)
{ {
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this, CCMenuItemFont* pItem = CCMenuItemFont::create(g_extensionsTests[i].name, g_extensionsTests[i].callback);
menu_selector(ExtensionsMainLayer::menuCallback));
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
pMenu->addChild(pItem, kItemTagBasic + i); pMenu->addChild(pItem, kItemTagBasic + i);
} }
@ -81,68 +84,6 @@ void ExtensionsMainLayer::onEnter()
addChild(pMenu); addChild(pMenu);
} }
void ExtensionsMainLayer::menuCallback(CCObject* pSender)
{
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
int nIndex = pItem->getZOrder() - kItemTagBasic;
switch (nIndex)
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) // MARMALADE CHANGE: Not yet avaiable on Marmalade
case TEST_NOTIFICATIONCENTER:
{
runNotificationCenterTest();
}
break;
#endif
case TEST_CCCONTROLBUTTON:
{
CCControlSceneManager* pManager = CCControlSceneManager::sharedControlSceneManager();
CCScene* pScene = pManager->currentControlScene();
CCDirector::sharedDirector()->replaceScene(pScene);
}
break;
case TEST_COCOSBUILDER:
{
TestScene* pScene = new CocosBuilderTestScene();
if (pScene)
{
pScene->runThisTest();
pScene->release();
}
}
break;
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE && CC_TARGET_PLATFORM != CC_PLATFORM_NACL && CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
case TEST_HTTPCLIENT:
{
runHttpClientTest();
}
break;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
case TEST_WEBSOCKET:
{
runWebSocketTest();
}
break;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
case TEST_EDITBOX:
{
runEditBoxTest();
}
break;
#endif
case TEST_TABLEVIEW:
{
runTableViewTest();
}
break;
default:
break;
}
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// ExtensionsTestScene // ExtensionsTestScene

View File

@ -7,7 +7,6 @@ class ExtensionsMainLayer : public CCLayer
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
void menuCallback(CCObject* pSender);
}; };
class ExtensionsTestScene : public TestScene class ExtensionsTestScene : public TestScene

View File

@ -23,31 +23,31 @@ HttpClientTest::HttpClientTest()
// Get // Get
CCLabelTTF *labelGet = CCLabelTTF::create("Test Get", "Arial", 22); CCLabelTTF *labelGet = CCLabelTTF::create("Test Get", "Arial", 22);
CCMenuItemLabel *itemGet = CCMenuItemLabel::create(labelGet, this, menu_selector(HttpClientTest::onMenuGetTestClicked)); CCMenuItemLabel *itemGet = CCMenuItemLabel::create(labelGet, std::bind( &HttpClientTest::onMenuGetTestClicked, this, std::placeholders::_1));
itemGet->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - SPACE)); itemGet->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - SPACE));
menuRequest->addChild(itemGet); menuRequest->addChild(itemGet);
// Post // Post
CCLabelTTF *labelPost = CCLabelTTF::create("Test Post", "Arial", 22); CCLabelTTF *labelPost = CCLabelTTF::create("Test Post", "Arial", 22);
CCMenuItemLabel *itemPost = CCMenuItemLabel::create(labelPost, this, menu_selector(HttpClientTest::onMenuPostTestClicked)); CCMenuItemLabel *itemPost = CCMenuItemLabel::create(labelPost, std::bind( &HttpClientTest::onMenuPostTestClicked, this, std::placeholders::_1));
itemPost->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 2 * SPACE)); itemPost->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 2 * SPACE));
menuRequest->addChild(itemPost); menuRequest->addChild(itemPost);
// Post Binary // Post Binary
CCLabelTTF *labelPostBinary = CCLabelTTF::create("Test Post Binary", "Arial", 22); CCLabelTTF *labelPostBinary = CCLabelTTF::create("Test Post Binary", "Arial", 22);
CCMenuItemLabel *itemPostBinary = CCMenuItemLabel::create(labelPostBinary, this, menu_selector(HttpClientTest::onMenuPostBinaryTestClicked)); CCMenuItemLabel *itemPostBinary = CCMenuItemLabel::create(labelPostBinary, std::bind( &HttpClientTest::onMenuPostBinaryTestClicked, this, std::placeholders::_1));
itemPostBinary->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 3 * SPACE)); itemPostBinary->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 3 * SPACE));
menuRequest->addChild(itemPostBinary); menuRequest->addChild(itemPostBinary);
// Put // Put
CCLabelTTF *labelPut = CCLabelTTF::create("Test Put", "Arial", 22); CCLabelTTF *labelPut = CCLabelTTF::create("Test Put", "Arial", 22);
CCMenuItemLabel *itemPut = CCMenuItemLabel::create(labelPut, this, menu_selector(HttpClientTest::onMenuPutTestClicked)); CCMenuItemLabel *itemPut = CCMenuItemLabel::create(labelPut, std::bind( &HttpClientTest::onMenuPutTestClicked, this, std::placeholders::_1));
itemPut->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 4 * SPACE)); itemPut->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 4 * SPACE));
menuRequest->addChild(itemPut); menuRequest->addChild(itemPut);
// Delete // Delete
CCLabelTTF *labelDelete = CCLabelTTF::create("Test Delete", "Arial", 22); CCLabelTTF *labelDelete = CCLabelTTF::create("Test Delete", "Arial", 22);
CCMenuItemLabel *itemDelete = CCMenuItemLabel::create(labelDelete, this, menu_selector(HttpClientTest::onMenuDeleteTestClicked)); CCMenuItemLabel *itemDelete = CCMenuItemLabel::create(labelDelete, std::bind( &HttpClientTest::onMenuDeleteTestClicked, this, std::placeholders::_1));
itemDelete->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 5 * SPACE)); itemDelete->setPosition(ccp(winSize.width / 2, winSize.height - MARGIN - 5 * SPACE));
menuRequest->addChild(itemDelete); menuRequest->addChild(itemDelete);
@ -57,7 +57,7 @@ HttpClientTest::HttpClientTest()
addChild(m_labelStatusCode); addChild(m_labelStatusCode);
// Back Menu // Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(HttpClientTest::toExtensionsMainLayer)); CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", std::bind( &HttpClientTest::toExtensionsMainLayer, this, std::placeholders::_1));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL); CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero); menuBack->setPosition(CCPointZero);

View File

@ -82,8 +82,7 @@ NotificationCenterTest::NotificationCenterTest()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this, CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", std::bind( &NotificationCenterTest::toExtensionsMainLayer, this, std::placeholders::_1));
menu_selector(NotificationCenterTest::toExtensionsMainLayer));
pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL); CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL);
pBackMenu->setPosition( CCPointZero ); pBackMenu->setPosition( CCPointZero );
@ -93,7 +92,7 @@ NotificationCenterTest::NotificationCenterTest()
CCLabelTTF *label2 = CCLabelTTF::create("switch on", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::create("switch on", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2); CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::toggleSwitch), item1, item2, NULL); CCMenuItemToggle *item = CCMenuItemToggle::createWithCallback( std::bind( &NotificationCenterTest::toggleSwitch, this, std::placeholders::_1), item1, item2, NULL);
// turn on // turn on
item->setSelectedIndex(1); item->setSelectedIndex(1);
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
@ -115,7 +114,7 @@ NotificationCenterTest::NotificationCenterTest()
CCLabelTTF *label2 = CCLabelTTF::create("connected", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::create("connected", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2); CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(NotificationCenterTest::connectToSwitch), item1, item2, NULL); CCMenuItemToggle *item = CCMenuItemToggle::createWithCallback( std::bind( &NotificationCenterTest::connectToSwitch, this, std::placeholders::_1), item1, item2, NULL);
item->setTag(kTagConnect+i); item->setTag(kTagConnect+i);
item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50)); item->setPosition(ccp(light->getPosition().x, light->getPosition().y+50));
menuConnect->addChild(item, 0); menuConnect->addChild(item, 0);

View File

@ -39,7 +39,7 @@ bool TableViewTestLayer::init()
tableView->reloadData(); tableView->reloadData();
// Back Menu // Back Menu
CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(TableViewTestLayer::toExtensionsMainLayer)); CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", std::bind( &TableViewTestLayer::toExtensionsMainLayer, this, std::placeholders::_1));
itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu *menuBack = CCMenu::create(itemBack, NULL); CCMenu *menuBack = CCMenu::create(itemBack, NULL);
menuBack->setPosition(CCPointZero); menuBack->setPosition(CCPointZero);

View File

@ -57,7 +57,12 @@ IntervalLayer::IntervalLayer()
addChild(sprite); addChild(sprite);
sprite->runAction( CCRepeatForever::create(CCSequence::create(jump, jump->reverse(), NULL) )); sprite->runAction( CCRepeatForever::create(CCSequence::create(jump, jump->reverse(), NULL) ));
// pause button // pause button
CCMenuItem* item1 = CCMenuItemFont::create("Pause", this, menu_selector(IntervalLayer::onPause) ); CCMenuItem* item1 = CCMenuItemFont::create("Pause", [&](CCObject* sender) {
if(CCDirector::sharedDirector()->isPaused())
CCDirector::sharedDirector()->resume();
else
CCDirector::sharedDirector()->pause();
});
CCMenu* menu = CCMenu::create(item1, NULL); CCMenu* menu = CCMenu::create(item1, NULL);
menu->setPosition( ccp(s.width/2, s.height-50) ); menu->setPosition( ccp(s.width/2, s.height-50) );
@ -80,15 +85,6 @@ void IntervalLayer::update(float dt)
m_label0->setString(time); m_label0->setString(time);
} }
void IntervalLayer::onPause(CCObject* pSender)
{
if(CCDirector::sharedDirector()->isPaused())
CCDirector::sharedDirector()->resume();
else
CCDirector::sharedDirector()->pause();
}
void IntervalLayer::step1(float dt) void IntervalLayer::step1(float dt)
{ {
m_time1 +=dt; m_time1 +=dt;

View File

@ -18,7 +18,6 @@ public:
IntervalLayer(void); IntervalLayer(void);
virtual ~IntervalLayer(); virtual ~IntervalLayer();
public: public:
void onPause(CCObject* pSender);
void step1(float dt); void step1(float dt);
void step2(float dt); void step2(float dt);

View File

@ -940,19 +940,19 @@ LabelTTFTest::LabelTTFTest()
CCMenuItemFont::setFontSize(30); CCMenuItemFont::setFontSize(30);
CCMenu *menu = CCMenu::create( CCMenu *menu = CCMenu::create(
CCMenuItemFont::create("Left", this, menu_selector(LabelTTFTest::setAlignmentLeft)), CCMenuItemFont::create("Left", std::bind( &LabelTTFTest::setAlignmentLeft, this, std::placeholders::_1)),
CCMenuItemFont::create("Center", this, menu_selector(LabelTTFTest::setAlignmentCenter)), CCMenuItemFont::create("Center", std::bind( &LabelTTFTest::setAlignmentCenter, this, std::placeholders::_1)),
CCMenuItemFont::create("Right", this, menu_selector(LabelTTFTest::setAlignmentRight)), CCMenuItemFont::create("Right", std::bind( &LabelTTFTest::setAlignmentRight, this, std::placeholders::_1)),
NULL); NULL);
menu->alignItemsVerticallyWithPadding(4); menu->alignItemsVerticallyWithPadding(4);
menu->setPosition(ccp(50, s.height / 2 - 20)); menu->setPosition(ccp(50, s.height / 2 - 20));
this->addChild(menu); this->addChild(menu);
menu = CCMenu::create( menu = CCMenu::create(
CCMenuItemFont::create("Top", this, menu_selector(LabelTTFTest::setAlignmentTop)), CCMenuItemFont::create("Top", std::bind( &LabelTTFTest::setAlignmentTop, this, std::placeholders::_1)),
CCMenuItemFont::create("Middle", this, menu_selector(LabelTTFTest::setAlignmentMiddle)), CCMenuItemFont::create("Middle", std::bind( &LabelTTFTest::setAlignmentMiddle, this, std::placeholders::_1)),
CCMenuItemFont::create("Bottom", this, menu_selector(LabelTTFTest::setAlignmentBottom)), CCMenuItemFont::create("Bottom", std::bind( &LabelTTFTest::setAlignmentBottom, this, std::placeholders::_1)),
NULL); NULL);
menu->alignItemsVerticallyWithPadding(4); menu->alignItemsVerticallyWithPadding(4);
menu->setPosition(ccp(s.width - 50, s.height / 2 - 20)); menu->setPosition(ccp(s.width - 50, s.height / 2 - 20));
this->addChild(menu); this->addChild(menu);
@ -1155,9 +1155,9 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment()
this->m_pArrowsShouldRetain->retain(); this->m_pArrowsShouldRetain->retain();
CCMenuItemFont::setFontSize(20); CCMenuItemFont::setFontSize(20);
CCMenuItemFont *longSentences = CCMenuItemFont::create("Long Flowing Sentences", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenuItemFont *longSentences = CCMenuItemFont::create("Long Flowing Sentences", std::bind( &BitmapFontMultiLineAlignment::stringChanged, this, std::placeholders::_1));
CCMenuItemFont *lineBreaks = CCMenuItemFont::create("Short Sentences With Intentional Line Breaks", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenuItemFont *lineBreaks = CCMenuItemFont::create("Short Sentences With Intentional Line Breaks", std::bind( &BitmapFontMultiLineAlignment::stringChanged, this, std::placeholders::_1));
CCMenuItemFont *mixed = CCMenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenuItemFont *mixed = CCMenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", std::bind( &BitmapFontMultiLineAlignment::stringChanged, this, std::placeholders::_1));
CCMenu *stringMenu = CCMenu::create(longSentences, lineBreaks, mixed, NULL); CCMenu *stringMenu = CCMenu::create(longSentences, lineBreaks, mixed, NULL);
stringMenu->alignItemsVertically(); stringMenu->alignItemsVertically();
@ -1169,9 +1169,9 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment()
CCMenuItemFont::setFontSize(30); CCMenuItemFont::setFontSize(30);
CCMenuItemFont *left = CCMenuItemFont::create("Left", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenuItemFont *left = CCMenuItemFont::create("Left", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1));
CCMenuItemFont *center = CCMenuItemFont::create("Center", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenuItemFont *center = CCMenuItemFont::create("Center", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1));
CCMenuItemFont *right = CCMenuItemFont::create("Right", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenuItemFont *right = CCMenuItemFont::create("Right", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1));
CCMenu *alignmentMenu = CCMenu::create(left, center, right, NULL); CCMenu *alignmentMenu = CCMenu::create(left, center, right, NULL);
alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding); alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding);

View File

@ -6,36 +6,21 @@ enum
kTagLayer = 1, kTagLayer = 1,
}; };
TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityA); static std::function<CCLayer*()> createFunctions[] = {
TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityB); CL(LayerTestCascadingOpacityA),
TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityC); CL(LayerTestCascadingOpacityB),
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorA); CL(LayerTestCascadingOpacityC),
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorB); CL(LayerTestCascadingColorA),
TESTLAYER_CREATE_FUNC(LayerTestCascadingColorC); CL(LayerTestCascadingColorB),
TESTLAYER_CREATE_FUNC(LayerTest1); CL(LayerTestCascadingColorC),
TESTLAYER_CREATE_FUNC(LayerTest2); CL(LayerTest1),
TESTLAYER_CREATE_FUNC(LayerTestBlend); CL(LayerTest2),
TESTLAYER_CREATE_FUNC(LayerGradient); CL(LayerTestBlend),
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointPos); CL(LayerGradient),
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointRot); CL(LayerIgnoreAnchorPointPos),
TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointScale); CL(LayerIgnoreAnchorPointRot),
TESTLAYER_CREATE_FUNC(LayerExtendedBlendOpacityTest); CL(LayerIgnoreAnchorPointScale),
CL(LayerExtendedBlendOpacityTest)
static NEWTESTFUNC createFunctions[] = {
CF(LayerTestCascadingOpacityA),
CF(LayerTestCascadingOpacityB),
CF(LayerTestCascadingOpacityC),
CF(LayerTestCascadingColorA),
CF(LayerTestCascadingColorB),
CF(LayerTestCascadingColorC),
CF(LayerTest1),
CF(LayerTest2),
CF(LayerTestBlend),
CF(LayerGradient),
CF(LayerIgnoreAnchorPointPos),
CF(LayerIgnoreAnchorPointRot),
CF(LayerIgnoreAnchorPointScale),
CF(LayerExtendedBlendOpacityTest)
}; };
static int sceneIdx=-1; static int sceneIdx=-1;
@ -610,7 +595,7 @@ LayerGradient::LayerGradient()
CCLabelTTF *label2 = CCLabelTTF::create("Compressed Interpolation: Disabled", "Marker Felt", 26); CCLabelTTF *label2 = CCLabelTTF::create("Compressed Interpolation: Disabled", "Marker Felt", 26);
CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1);
CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2); CCMenuItemLabel *item2 = CCMenuItemLabel::create(label2);
CCMenuItemToggle *item = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerGradient::toggleItem), item1, item2, NULL); CCMenuItemToggle *item = CCMenuItemToggle::createWithCallback( std::bind(&LayerGradient::toggleItem, this, std::placeholders::_1), item1, item2, NULL);
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
addChild(menu); addChild(menu);
@ -675,7 +660,7 @@ void LayerIgnoreAnchorPointPos::onEnter()
CCSize lsize = l->getContentSize(); CCSize lsize = l->getContentSize();
child->setPosition(ccp(lsize.width/2, lsize.height/2)); child->setPosition(ccp(lsize.width/2, lsize.height/2));
CCMenuItemFont *item = CCMenuItemFont::create("Toggle ignore anchor point", this, menu_selector(LayerIgnoreAnchorPointPos::onToggle)); CCMenuItemFont *item = CCMenuItemFont::create("Toggle ignore anchor point", std::bind( &LayerIgnoreAnchorPointPos::onToggle, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
this->addChild(menu); this->addChild(menu);
@ -723,7 +708,7 @@ void LayerIgnoreAnchorPointRot::onEnter()
CCSize lsize = l->getContentSize(); CCSize lsize = l->getContentSize();
child->setPosition(ccp(lsize.width/2, lsize.height/2)); child->setPosition(ccp(lsize.width/2, lsize.height/2));
CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", this, menu_selector(LayerIgnoreAnchorPointRot::onToggle)); CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", std::bind( &LayerIgnoreAnchorPointRot::onToggle, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
this->addChild(menu); this->addChild(menu);
@ -774,7 +759,7 @@ void LayerIgnoreAnchorPointScale::onEnter()
CCSize lsize = l->getContentSize(); CCSize lsize = l->getContentSize();
child->setPosition(ccp(lsize.width/2, lsize.height/2)); child->setPosition(ccp(lsize.width/2, lsize.height/2));
CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", this, menu_selector(LayerIgnoreAnchorPointScale::onToggle)); CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", std::bind( &LayerIgnoreAnchorPointScale::onToggle, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
this->addChild(menu); this->addChild(menu);

View File

@ -518,9 +518,9 @@ void MenuLayerPriorityTest::menuCallback(CCObject* pSender)
// BugsTest // BugsTest
BugsTest::BugsTest() BugsTest::BugsTest()
{ {
CCMenuItemFont *issue1410 = CCMenuItemFont::create("Issue 1410", this, menu_selector(BugsTest::issue1410MenuCallback)); CCMenuItemFont *issue1410 = CCMenuItemFont::create("Issue 1410", std::bind( &BugsTest::issue1410MenuCallback, this, std::placeholders::_1));
CCMenuItemFont *issue1410_2 = CCMenuItemFont::create("Issue 1410 #2", this, menu_selector(BugsTest::issue1410v2MenuCallback)); CCMenuItemFont *issue1410_2 = CCMenuItemFont::create("Issue 1410 #2", std::bind( &BugsTest::issue1410v2MenuCallback, this, std::placeholders::_1));
CCMenuItemFont *back = CCMenuItemFont::create("Back", this, menu_selector(BugsTest::backMenuCallback)); CCMenuItemFont *back = CCMenuItemFont::create("Back", std::bind( &BugsTest::backMenuCallback, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(issue1410, issue1410_2, back, NULL); CCMenu *menu = CCMenu::create(issue1410, issue1410_2, back, NULL);
addChild(menu); addChild(menu);
@ -564,7 +564,7 @@ RemoveMenuItemWhenMove::RemoveMenuItemWhenMove()
item = CCMenuItemFont::create("item 1"); item = CCMenuItemFont::create("item 1");
item->retain(); item->retain();
CCMenuItemFont *back = CCMenuItemFont::create("go back", this, menu_selector(RemoveMenuItemWhenMove::goBack)); CCMenuItemFont *back = CCMenuItemFont::create("go back", std::bind( &RemoveMenuItemWhenMove::goBack, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, back, NULL); CCMenu *menu = CCMenu::create(item, back, NULL);
addChild(menu); addChild(menu);

View File

@ -92,9 +92,23 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
quantityOfNodes = nNodes; quantityOfNodes = nNodes;
CCMenuItemFont::setFontSize(65); CCMenuItemFont::setFontSize(65);
CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(NodeChildrenMainScene::onDecrease)); CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", [&](CCObject *sender) {
quantityOfNodes -= kNodesIncrease;
if( quantityOfNodes < 0 )
quantityOfNodes = 0;
updateQuantityLabel();
updateQuantityOfNodes();
});
decrease->setColor(ccc3(0,200,20)); decrease->setColor(ccc3(0,200,20));
CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(NodeChildrenMainScene::onIncrease)); CCMenuItemFont *increase = CCMenuItemFont::create(" + ", [&](CCObject *sender) {
quantityOfNodes += kNodesIncrease;
if( quantityOfNodes > kMaxNodes )
quantityOfNodes = kMaxNodes;
updateQuantityLabel();
updateQuantityOfNodes();
});
increase->setColor(ccc3(0,200,20)); increase->setColor(ccc3(0,200,20));
CCMenu *menu = CCMenu::create(decrease, increase, NULL); CCMenu *menu = CCMenu::create(decrease, increase, NULL);
@ -115,26 +129,6 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
updateQuantityOfNodes(); updateQuantityOfNodes();
} }
void NodeChildrenMainScene::onDecrease(CCObject* pSender)
{
quantityOfNodes -= kNodesIncrease;
if( quantityOfNodes < 0 )
quantityOfNodes = 0;
updateQuantityLabel();
updateQuantityOfNodes();
}
void NodeChildrenMainScene::onIncrease(CCObject* pSender)
{
quantityOfNodes += kNodesIncrease;
if( quantityOfNodes > kMaxNodes )
quantityOfNodes = kMaxNodes;
updateQuantityLabel();
updateQuantityOfNodes();
}
std::string NodeChildrenMainScene::title() std::string NodeChildrenMainScene::title()
{ {
return "No title"; return "No title";

View File

@ -19,8 +19,6 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
virtual void updateQuantityOfNodes() = 0; virtual void updateQuantityOfNodes() = 0;
void onDecrease(CCObject* pSender);
void onIncrease(CCObject* pSender);
void updateQuantityLabel(); void updateQuantityLabel();
int getQuantityOfNodes() { return quantityOfNodes; } int getQuantityOfNodes() { return quantityOfNodes; }

View File

@ -79,9 +79,23 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles)
quantityParticles = particles; quantityParticles = particles;
CCMenuItemFont::setFontSize(65); CCMenuItemFont::setFontSize(65);
CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(ParticleMainScene::onDecrease)); CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", [&](CCObject *sender) {
quantityParticles -= kNodesIncrease;
if( quantityParticles < 0 )
quantityParticles = 0;
updateQuantityLabel();
createParticleSystem();
});
decrease->setColor(ccc3(0,200,20)); decrease->setColor(ccc3(0,200,20));
CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(ParticleMainScene::onIncrease)); CCMenuItemFont *increase = CCMenuItemFont::create(" + ", [&](CCObject *sender) {
quantityParticles += kNodesIncrease;
if( quantityParticles > kMaxParticles )
quantityParticles = kMaxParticles;
updateQuantityLabel();
createParticleSystem();
});
increase->setColor(ccc3(0,200,20)); increase->setColor(ccc3(0,200,20));
CCMenu *menu = CCMenu::create(decrease, increase, NULL); CCMenu *menu = CCMenu::create(decrease, increase, NULL);
@ -111,7 +125,7 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles)
{ {
char str[10] = {0}; char str[10] = {0};
sprintf(str, "%d ", i); sprintf(str, "%d ", i);
CCMenuItemFont* itemFont = CCMenuItemFont::create(str, this, menu_selector(ParticleMainScene::testNCallback)); CCMenuItemFont* itemFont = CCMenuItemFont::create(str, std::bind( &ParticleMainScene::testNCallback, this, std::placeholders::_1));
itemFont->setTag(i); itemFont->setTag(i);
pSubMenu->addChild(itemFont, 10); pSubMenu->addChild(itemFont, 10);
@ -249,26 +263,6 @@ void ParticleMainScene::testNCallback(CCObject* pSender)
pMenu->restartCallback(pSender); pMenu->restartCallback(pSender);
} }
void ParticleMainScene::onIncrease(CCObject* pSender)
{
quantityParticles += kNodesIncrease;
if( quantityParticles > kMaxParticles )
quantityParticles = kMaxParticles;
updateQuantityLabel();
createParticleSystem();
}
void ParticleMainScene::onDecrease(CCObject* pSender)
{
quantityParticles -= kNodesIncrease;
if( quantityParticles < 0 )
quantityParticles = 0;
updateQuantityLabel();
createParticleSystem();
}
void ParticleMainScene::updateQuantityLabel() void ParticleMainScene::updateQuantityLabel()
{ {
if( quantityParticles != lastRenderedCount ) if( quantityParticles != lastRenderedCount )

View File

@ -18,8 +18,6 @@ public:
void step(float dt); void step(float dt);
void createParticleSystem(); void createParticleSystem();
void onDecrease(CCObject* pSender);
void onIncrease(CCObject* pSender);
void testNCallback(CCObject* pSender); void testNCallback(CCObject* pSender);
void updateQuantityLabel(); void updateQuantityLabel();
int getSubTestNum() { return subtestNumber; } int getSubTestNum() { return subtestNumber; }

View File

@ -287,9 +287,9 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
quantityNodes = 0; quantityNodes = 0;
CCMenuItemFont::setFontSize(65); CCMenuItemFont::setFontSize(65);
CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(SpriteMainScene::onDecrease)); CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", std::bind( &SpriteMainScene::onDecrease, this, std::placeholders::_1));
decrease->setColor(ccc3(0,200,20)); decrease->setColor(ccc3(0,200,20));
CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(SpriteMainScene::onIncrease)); CCMenuItemFont *increase = CCMenuItemFont::create(" + ", std::bind( &SpriteMainScene::onIncrease, this, std::placeholders::_1));
increase->setColor(ccc3(0,200,20)); increase->setColor(ccc3(0,200,20));
CCMenu *menu = CCMenu::create(decrease, increase, NULL); CCMenu *menu = CCMenu::create(decrease, increase, NULL);
@ -314,7 +314,7 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes)
{ {
char str[10] = {0}; char str[10] = {0};
sprintf(str, "%d ", i); sprintf(str, "%d ", i);
CCMenuItemFont* itemFont = CCMenuItemFont::create(str, this, menu_selector(SpriteMainScene::testNCallback)); CCMenuItemFont* itemFont = CCMenuItemFont::create(str, std::bind( &SpriteMainScene::testNCallback, this, std::placeholders::_1));
itemFont->setTag(i); itemFont->setTag(i);
pSubMenu->addChild(itemFont, 10); pSubMenu->addChild(itemFont, 10);

View File

@ -8,20 +8,24 @@
enum enum
{ {
MAX_COUNT = 5,
LINE_SPACE = 40, LINE_SPACE = 40,
kItemTagBasic = 1000, kItemTagBasic = 1000,
}; };
const std::string testsName[MAX_COUNT] = struct {
const char *name;
std::function<void(CCObject*)> callback;
} g_testsName[] =
{ {
"PerformanceNodeChildrenTest", { "PerformanceNodeChildrenTest", [](CCObject*sender){runNodeChildrenTest();} },
"PerformanceParticleTest", { "PerformanceParticleTest",[](CCObject*sender){runParticleTest();} },
"PerformanceSpriteTest", { "PerformanceSpriteTest",[](CCObject*sender){runSpriteTest();} },
"PerformanceTextureTest", { "PerformanceTextureTest",[](CCObject*sender){runTextureTest();} },
"PerformanceTouchesTest" { "PerformanceTouchesTest",[](CCObject*sender){runTouchesTest();} },
}; };
static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]);
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// PerformanceMainLayer // PerformanceMainLayer
@ -37,10 +41,9 @@ void PerformanceMainLayer::onEnter()
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
for (int i = 0; i < MAX_COUNT; ++i) for (int i = 0; i < g_testMax; ++i)
{ {
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this, CCMenuItemFont* pItem = CCMenuItemFont::create(g_testsName[i].name, g_testsName[i].callback);
menu_selector(PerformanceMainLayer::menuCallback));
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
pMenu->addChild(pItem, kItemTagBasic + i); pMenu->addChild(pItem, kItemTagBasic + i);
} }
@ -48,33 +51,6 @@ void PerformanceMainLayer::onEnter()
addChild(pMenu); addChild(pMenu);
} }
void PerformanceMainLayer::menuCallback(CCObject* pSender)
{
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
int nIndex = pItem->getZOrder() - kItemTagBasic;
switch (nIndex)
{
case 0:
runNodeChildrenTest();
break;
case 1:
runParticleTest();
break;
case 2:
runSpriteTest();
break;
case 3:
runTextureTest();
break;
case 4:
runTouchesTest();
break;
default:
break;
}
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// PerformBasicLayer // PerformBasicLayer
@ -94,17 +70,16 @@ void PerformBasicLayer::onEnter()
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", this, CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", std::bind( &PerformBasicLayer::toMainLayer, this, std::placeholders::_1));
menu_selector(PerformBasicLayer::toMainLayer));
pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
CCMenu* pMenu = CCMenu::create(pMainItem, NULL); CCMenu* pMenu = CCMenu::create(pMainItem, NULL);
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );
if (m_bControlMenuVisible) if (m_bControlMenuVisible)
{ {
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(PerformBasicLayer::backCallback) ); CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind( &PerformBasicLayer::backCallback, this, std::placeholders::_1));
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(PerformBasicLayer::restartCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind( &PerformBasicLayer::restartCallback, this, std::placeholders::_1));
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(PerformBasicLayer::nextCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, std::bind( &PerformBasicLayer::nextCallback, this, std::placeholders::_1));
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));

View File

@ -7,7 +7,6 @@ class PerformanceMainLayer : public CCLayer
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
void menuCallback(CCObject* pSender);
}; };
class PerformBasicLayer : public CCLayer class PerformBasicLayer : public CCLayer

View File

@ -6,21 +6,13 @@
// Test #3 by David Deaco (ddeaco) // Test #3 by David Deaco (ddeaco)
static std::function<CCLayer*()> createFunctions[] = {
TESTLAYER_CREATE_FUNC(RenderTextureSave); CL(RenderTextureSave),
TESTLAYER_CREATE_FUNC(RenderTextureIssue937); CL(RenderTextureIssue937),
TESTLAYER_CREATE_FUNC(RenderTextureZbuffer); CL(RenderTextureZbuffer),
TESTLAYER_CREATE_FUNC(RenderTextureTestDepthStencil); CL(RenderTextureTestDepthStencil),
TESTLAYER_CREATE_FUNC(RenderTextureTargetNode); CL(RenderTextureTargetNode),
TESTLAYER_CREATE_FUNC(SpriteRenderTextureBug); CL(SpriteRenderTextureBug),
static NEWTESTFUNC createFunctions[] = {
CF(RenderTextureSave),
CF(RenderTextureIssue937),
CF(RenderTextureZbuffer),
CF(RenderTextureTestDepthStencil),
CF(RenderTextureTargetNode),
CF(SpriteRenderTextureBug),
}; };
#define MAX_LAYER (sizeof(createFunctions)/sizeof(createFunctions[0])) #define MAX_LAYER (sizeof(createFunctions)/sizeof(createFunctions[0]))
@ -60,34 +52,7 @@ static CCLayer* restartTestCase()
void RenderTextureTest::onEnter() void RenderTextureTest::onEnter()
{ {
CCLayer::onEnter(); BaseTest::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 26);
addChild(label, 1);
label->setPosition( ccp(s.width/2, s.height-50) );
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
addChild(l, 1);
l->setPosition( ccp(s.width/2, s.height-80) );
}
CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(RenderTextureTest::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(RenderTextureTest::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(RenderTextureTest::nextCallback) );
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
menu->setPosition( CCPointZero );
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
addChild(menu, 1);
} }
void RenderTextureTest::restartCallback(CCObject* pSender) void RenderTextureTest::restartCallback(CCObject* pSender)
@ -150,8 +115,8 @@ RenderTextureSave::RenderTextureSave()
// Save Image menu // Save Image menu
CCMenuItemFont::setFontSize(16); CCMenuItemFont::setFontSize(16);
CCMenuItem *item1 = CCMenuItemFont::create("Save Image", this, menu_selector(RenderTextureSave::saveImage)); CCMenuItem *item1 = CCMenuItemFont::create("Save Image", std::bind( &RenderTextureSave::saveImage, this, std::placeholders::_1));
CCMenuItem *item2 = CCMenuItemFont::create("Clear", this, menu_selector(RenderTextureSave::clearImage)); CCMenuItem *item2 = CCMenuItemFont::create("Clear", std::bind( &RenderTextureSave::clearImage, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item1, item2, NULL); CCMenu *menu = CCMenu::create(item1, item2, NULL);
this->addChild(menu); this->addChild(menu);
menu->alignItemsVertically(); menu->alignItemsVertically();
@ -564,7 +529,7 @@ RenderTextureTargetNode::RenderTextureTargetNode()
scheduleUpdate(); scheduleUpdate();
// Toggle clear on / off // Toggle clear on / off
CCMenuItemFont *item = CCMenuItemFont::create("Clear On/Off", this, menu_selector(RenderTextureTargetNode::touched)); CCMenuItemFont *item = CCMenuItemFont::create("Clear On/Off", std::bind( &RenderTextureTargetNode::touched, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item, NULL); CCMenu *menu = CCMenu::create(item, NULL);
addChild(menu); addChild(menu);

View File

@ -3,8 +3,9 @@
#include "cocos2d.h" #include "cocos2d.h"
#include "../testBasic.h" #include "../testBasic.h"
#include "../BaseTest.h"
class RenderTextureTest : public CCLayer class RenderTextureTest : public BaseTest
{ {
public: public:
virtual void onEnter(); virtual void onEnter();

View File

@ -18,9 +18,9 @@ enum
SceneTestLayer1::SceneTestLayer1() SceneTestLayer1::SceneTestLayer1()
{ {
CCMenuItemFont* item1 = CCMenuItemFont::create( "Test pushScene", this, menu_selector(SceneTestLayer1::onPushScene) ); CCMenuItemFont* item1 = CCMenuItemFont::create( "Test pushScene", std::bind(&SceneTestLayer1::onPushScene, this, std::placeholders::_1));
CCMenuItemFont* item2 = CCMenuItemFont::create( "Test pushScene w/transition", this, menu_selector(SceneTestLayer1::onPushSceneTran) ); CCMenuItemFont* item2 = CCMenuItemFont::create( "Test pushScene w/transition", std::bind(&SceneTestLayer1::onPushSceneTran, this, std::placeholders::_1));
CCMenuItemFont* item3 = CCMenuItemFont::create( "Quit", this, menu_selector(SceneTestLayer1::onQuit) ); CCMenuItemFont* item3 = CCMenuItemFont::create( "Quit", std::bind(&SceneTestLayer1::onQuit, this, std::placeholders::_1));
CCMenu* menu = CCMenu::create( item1, item2, item3, NULL ); CCMenu* menu = CCMenu::create( item1, item2, item3, NULL );
menu->alignItemsVertically(); menu->alignItemsVertically();
@ -103,9 +103,9 @@ SceneTestLayer2::SceneTestLayer2()
{ {
m_timeCounter = 0; m_timeCounter = 0;
CCMenuItemFont* item1 = CCMenuItemFont::create( "replaceScene", this, menu_selector(SceneTestLayer2::onReplaceScene) ); CCMenuItemFont* item1 = CCMenuItemFont::create( "replaceScene", std::bind(&SceneTestLayer2::onReplaceScene, this, std::placeholders::_1));
CCMenuItemFont* item2 = CCMenuItemFont::create( "replaceScene w/transition", this, menu_selector(SceneTestLayer2::onReplaceSceneTran) ); CCMenuItemFont* item2 = CCMenuItemFont::create( "replaceScene w/transition", std::bind(&SceneTestLayer2::onReplaceSceneTran, this, std::placeholders::_1));
CCMenuItemFont* item3 = CCMenuItemFont::create( "Go Back", this, menu_selector(SceneTestLayer2::onGoBack) ); CCMenuItemFont* item3 = CCMenuItemFont::create( "Go Back", std::bind(&SceneTestLayer2::onGoBack, this, std::placeholders::_1));
CCMenu* menu = CCMenu::create( item1, item2, item3, NULL ); CCMenu* menu = CCMenu::create( item1, item2, item3, NULL );
menu->alignItemsVertically(); menu->alignItemsVertically();
@ -171,10 +171,10 @@ bool SceneTestLayer3::init()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemFont *item0 = CCMenuItemFont::create("Touch to pushScene (self)", this, menu_selector(SceneTestLayer3::item0Clicked)); CCMenuItemFont *item0 = CCMenuItemFont::create("Touch to pushScene (self)", std::bind(&SceneTestLayer3::item0Clicked, this, std::placeholders::_1));
CCMenuItemFont *item1 = CCMenuItemFont::create("Touch to popScene", this, menu_selector(SceneTestLayer3::item1Clicked)); CCMenuItemFont *item1 = CCMenuItemFont::create("Touch to popScene", std::bind(&SceneTestLayer3::item1Clicked, this, std::placeholders::_1));
CCMenuItemFont *item2 = CCMenuItemFont::create("Touch to popToRootScene", this, menu_selector(SceneTestLayer3::item2Clicked)); CCMenuItemFont *item2 = CCMenuItemFont::create("Touch to popToRootScene", std::bind(&SceneTestLayer3::item2Clicked, this, std::placeholders::_1));
CCMenuItemFont *item3 = CCMenuItemFont::create("Touch to popToSceneStackLevel(2)", this, menu_selector(SceneTestLayer3::item3Clicked)); CCMenuItemFont *item3 = CCMenuItemFont::create("Touch to popToSceneStackLevel(2)", std::bind(&SceneTestLayer3::item3Clicked, this, std::placeholders::_1));
CCMenu *menu = CCMenu::create(item0, item1, item2, item3, NULL); CCMenu *menu = CCMenu::create(item0, item1, item2, item3, NULL);
this->addChild(menu); this->addChild(menu);
@ -200,8 +200,8 @@ void SceneTestLayer3::testDealloc(float dt)
void SceneTestLayer3::item0Clicked(CCObject* pSender) void SceneTestLayer3::item0Clicked(CCObject* pSender)
{ {
CCScene *newScene = CCScene::create(); CCScene *newScene = CCScene::create();
newScene->addChild(SceneTestLayer3::create()); newScene->addChild(SceneTestLayer3::create());
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5, newScene, ccc3(0,255,255))); CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5, newScene, ccc3(0,255,255)));
} }

View File

@ -62,39 +62,6 @@ ShaderTestDemo::ShaderTestDemo()
} }
bool ShaderTestDemo::init()
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 26);
addChild(label, 1);
label->setPosition(ccp(s.width/2, s.height-50));
label->setColor(ccRED);
std::string subtitle = this->subtitle();
if (subtitle.length() > 0)
{
CCLabelTTF *l = CCLabelTTF::create(subtitle.c_str(), "Thonburi", 16);
addChild(l, 1);
l->setPosition(ccp(s.width/2, s.height-80));
}
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ShaderTestDemo::backCallback));
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ShaderTestDemo::restartCallback));
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ShaderTestDemo::nextCallback));
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
menu->setPosition(ccp(0, 0));
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
addChild(menu, 1);
return true;
}
void ShaderTestDemo::backCallback(CCObject* pSender) void ShaderTestDemo::backCallback(CCObject* pSender)
{ {
CCScene* s = new ShaderTestScene(); CCScene* s = new ShaderTestScene();

View File

@ -3,17 +3,17 @@
#include "../testBasic.h" #include "../testBasic.h"
#include "cocos-ext.h" #include "cocos-ext.h"
#include "../BaseTest.h"
USING_NS_CC_EXT; USING_NS_CC_EXT;
class ShaderTestDemo : public CCLayer class ShaderTestDemo : public BaseTest
{ {
public: public:
ShaderTestDemo(void); ShaderTestDemo(void);
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual bool init();
void restartCallback(CCObject* pSender); void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender); void nextCallback(CCObject* pSender);

View File

@ -1814,19 +1814,19 @@ void TextureMemoryAlloc::onEnter()
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
CCMenuItem *item1 = CCMenuItemFont::create("PNG", this, menu_selector(TextureMemoryAlloc::updateImage)); CCMenuItem *item1 = CCMenuItemFont::create("PNG", std::bind(&TextureMemoryAlloc::updateImage, this, std::placeholders::_1));
item1->setTag(0); item1->setTag(0);
CCMenuItem *item2 = CCMenuItemFont::create("RGBA8", this, menu_selector(TextureMemoryAlloc::updateImage)); CCMenuItem *item2 = CCMenuItemFont::create("RGBA8", std::bind(&TextureMemoryAlloc::updateImage, this, std::placeholders::_1));
item2->setTag(1); item2->setTag(1);
CCMenuItem *item3 = CCMenuItemFont::create("RGB8", this, menu_selector(TextureMemoryAlloc::updateImage)); CCMenuItem *item3 = CCMenuItemFont::create("RGB8", std::bind(&TextureMemoryAlloc::updateImage, this, std::placeholders::_1));
item3->setTag(2); item3->setTag(2);
CCMenuItem *item4 = CCMenuItemFont::create("RGBA4", this, menu_selector(TextureMemoryAlloc::updateImage)); CCMenuItem *item4 = CCMenuItemFont::create("RGBA4", std::bind(&TextureMemoryAlloc::updateImage, this, std::placeholders::_1));
item4->setTag(3); item4->setTag(3);
CCMenuItem *item5 = CCMenuItemFont::create("A8", this, menu_selector(TextureMemoryAlloc::updateImage)); CCMenuItem *item5 = CCMenuItemFont::create("A8", std::bind(&TextureMemoryAlloc::updateImage, this, std::placeholders::_1));
item5->setTag(4); item5->setTag(4);
CCMenu *menu = CCMenu::create(item1, item2, item3, item4, item5, NULL); CCMenu *menu = CCMenu::create(item1, item2, item3, item4, item5, NULL);
@ -1834,7 +1834,7 @@ void TextureMemoryAlloc::onEnter()
addChild(menu); addChild(menu);
CCMenuItemFont *warmup = CCMenuItemFont::create("warm up texture", this, menu_selector(TextureMemoryAlloc::changeBackgroundVisible)); CCMenuItemFont *warmup = CCMenuItemFont::create("warm up texture", std::bind(&TextureMemoryAlloc::changeBackgroundVisible, this, std::placeholders::_1));
CCMenu *menu2 = CCMenu::create(warmup, NULL); CCMenu *menu2 = CCMenu::create(warmup, NULL);

View File

@ -1428,45 +1428,13 @@ CCLayer* restartTileMapAction()
TileDemo::TileDemo(void) TileDemo::TileDemo(void)
: BaseTest()
{ {
setTouchEnabled( true ); setTouchEnabled( true );
CCSize s = CCDirector::sharedDirector()->getWinSize();
m_label = CCLabelTTF::create("", "Arial", 28);
addChild(m_label, 1);
m_label->setPosition( ccp(s.width/2, s.height-50) );
m_label->retain();
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
addChild(l, 1);
l->setPosition( ccp(s.width/2, s.height-80) );
m_subtitle = l;
m_subtitle->retain();
}
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TileDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TileDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TileDemo::nextCallback) );
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
menu->setPosition( CCPointZero );
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
addChild(menu, 1);
} }
TileDemo::~TileDemo(void) TileDemo::~TileDemo(void)
{ {
m_label->release();
m_subtitle->release();
} }
std::string TileDemo::title() std::string TileDemo::title()
@ -1481,10 +1449,7 @@ std::string TileDemo::subtitle()
void TileDemo::onEnter() void TileDemo::onEnter()
{ {
CCLayer::onEnter(); BaseTest::onEnter();
m_label->setString(title().c_str());
m_subtitle->setString(subtitle().c_str());
} }
void TileDemo::restartCallback(CCObject* pSender) void TileDemo::restartCallback(CCObject* pSender)

View File

@ -2,13 +2,10 @@
#define _TILEMAP_TEST_H_ #define _TILEMAP_TEST_H_
#include "../testBasic.h" #include "../testBasic.h"
#include "../BaseTest.h"
class TileDemo : public CCLayer class TileDemo : public BaseTest
{ {
protected:
CCLabelTTF* m_label;
CCLabelTTF* m_subtitle;
public: public:
TileDemo(void); TileDemo(void);
virtual ~TileDemo(void); virtual ~TileDemo(void);

View File

@ -30,11 +30,6 @@ PongScene::PongScene()
pongLayer->release(); pongLayer->release();
} }
void PongScene::MainMenuCallback(CCObject* pSender)
{
TestScene::MainMenuCallback(pSender);
}
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// PongLayer // PongLayer

View File

@ -12,8 +12,6 @@ public:
PongScene(); PongScene();
virtual void runThisTest(); virtual void runThisTest();
virtual void MainMenuCallback(CCObject* pSender);
}; };
class Ball; class Ball;

View File

@ -89,7 +89,7 @@ TestController::TestController()
: m_tBeginPos(CCPointZero) : m_tBeginPos(CCPointZero)
{ {
// add close menu // add close menu
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) ); CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pPathClose, s_pPathClose, std::bind( &TestController::closeCallback, this, std::placeholders::_1) );
CCMenu* pMenu =CCMenu::create(pCloseItem, NULL); CCMenu* pMenu =CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero ); pMenu->setPosition( CCPointZero );

View File

@ -17,7 +17,14 @@ void TestScene::onEnter()
//#else //#else
CCLabelTTF* label = CCLabelTTF::create("MainMenu", "Arial", 20); CCLabelTTF* label = CCLabelTTF::create("MainMenu", "Arial", 20);
//#endif //#endif
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestScene::MainMenuCallback)); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, [](CCObject *sender) {
CCScene* pScene = CCScene::create();
CCLayer* pLayer = new TestController();
pLayer->autorelease();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
});
CCMenu* pMenu =CCMenu::create(pMenuItem, NULL); CCMenu* pMenu =CCMenu::create(pMenuItem, NULL);
@ -26,13 +33,3 @@ void TestScene::onEnter()
addChild(pMenu, 1); addChild(pMenu, 1);
} }
void TestScene::MainMenuCallback(CCObject* pSender)
{
CCScene* pScene = CCScene::create();
CCLayer* pLayer = new TestController();
pLayer->autorelease();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
}

View File

@ -14,9 +14,6 @@ public:
virtual void onEnter(); virtual void onEnter();
virtual void runThisTest() = 0; virtual void runThisTest() = 0;
// The CallBack for back to the main menu scene
virtual void MainMenuCallback(CCObject* pSender);
}; };
typedef CCLayer* (*NEWTESTFUNC)(); typedef CCLayer* (*NEWTESTFUNC)();