From 022dfc0acccafbf365987d49b2734b9eae12cc79 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 7 Jun 2013 17:21:11 -0700 Subject: [PATCH 1/2] 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. --- .../TestCpp/Classes/Box2DTest/Box2dTest.cpp | 19 ++- .../Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h | 1 - .../Classes/Box2DTestBed/Box2dView.cpp | 6 +- .../Cpp/TestCpp/Classes/BugsTest/Bug-1159.cpp | 2 +- .../Cpp/TestCpp/Classes/BugsTest/Bug-422.cpp | 4 +- .../Classes/BugsTest/Bug-458/Bug-458.cpp | 4 +- .../Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp | 2 +- .../Cpp/TestCpp/Classes/BugsTest/BugsTest.cpp | 95 +++++--------- .../Cpp/TestCpp/Classes/BugsTest/BugsTest.h | 1 - .../Classes/ChipmunkTest/ChipmunkTest.cpp | 4 +- .../CocosDenshionTest/CocosDenshionTest.cpp | 2 +- .../ControlExtensionTest/CCControlScene.cpp | 9 +- .../EditBoxTest/EditBoxTest.cpp | 2 +- .../Classes/ExtensionsTest/ExtensionsTest.cpp | 123 +++++------------- .../Classes/ExtensionsTest/ExtensionsTest.h | 1 - .../NetworkTest/HttpClientTest.cpp | 12 +- .../NotificationCenterTest.cpp | 7 +- .../TableViewTest/TableViewTestScene.cpp | 2 +- .../Classes/IntervalTest/IntervalTest.cpp | 16 +-- .../Classes/IntervalTest/IntervalTest.h | 1 - .../TestCpp/Classes/LabelTest/LabelTest.cpp | 26 ++-- .../TestCpp/Classes/LayerTest/LayerTest.cpp | 53 +++----- .../Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp | 8 +- .../PerformanceNodeChildrenTest.cpp | 38 +++--- .../PerformanceNodeChildrenTest.h | 2 - .../PerformanceParticleTest.cpp | 40 +++--- .../PerformanceTest/PerformanceParticleTest.h | 2 - .../PerformanceTest/PerformanceSpriteTest.cpp | 6 +- .../PerformanceTest/PerformanceTest.cpp | 59 +++------ .../Classes/PerformanceTest/PerformanceTest.h | 1 - .../RenderTextureTest/RenderTextureTest.cpp | 57 ++------ .../RenderTextureTest/RenderTextureTest.h | 3 +- .../TestCpp/Classes/SceneTest/SceneTest.cpp | 24 ++-- .../TestCpp/Classes/ShaderTest/ShaderTest.cpp | 33 ----- .../TestCpp/Classes/ShaderTest/ShaderTest.h | 4 +- .../Classes/Texture2dTest/Texture2dTest.cpp | 12 +- .../Classes/TileMapTest/TileMapTest.cpp | 39 +----- .../TestCpp/Classes/TileMapTest/TileMapTest.h | 7 +- .../Classes/TouchesTest/TouchesTest.cpp | 5 - .../TestCpp/Classes/TouchesTest/TouchesTest.h | 2 - samples/Cpp/TestCpp/Classes/controller.cpp | 2 +- samples/Cpp/TestCpp/Classes/testBasic.cpp | 19 ++- samples/Cpp/TestCpp/Classes/testBasic.h | 3 - 43 files changed, 237 insertions(+), 521 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp index dabefb806b..4e09fe1ee9 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -115,7 +115,14 @@ void Box2DTestLayer::initPhysics() 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); @@ -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() { // diff --git a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h index 0697f513a1..0103d66513 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Box2DTest/Box2dTest.h @@ -28,7 +28,6 @@ public: void initPhysics(); void createResetButton(); - void reset(CCObject* sender); virtual void draw(); void addNewSpriteAtPosition(CCPoint p); diff --git a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp index 1fd9198e4f..607977d016 100644 --- a/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp +++ b/samples/Cpp/TestCpp/Classes/Box2DTestBed/Box2dView.cpp @@ -67,9 +67,9 @@ bool MenuLayer::initWithEntryID(int entryId) addChild(label, 1); 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 *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(MenuLayer::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(MenuLayer::nextCallback) ); + 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", std::bind( &MenuLayer::restartCallback, this, std::placeholders::_1) ); + 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); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-1159.cpp b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-1159.cpp index 2f2a13412e..959f5f0c70 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-1159.cpp +++ b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-1159.cpp @@ -45,7 +45,7 @@ bool Bug1159Layer::init() sprite_b->setPosition(ccp(s.width/2, s.height/2)); 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); menu->setPosition(ccp(s.width - 200.0f, 50.0f)); addChild(menu); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-422.cpp b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-422.cpp index 317d06031e..955c6b647c 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-422.cpp +++ b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-422.cpp @@ -31,9 +31,9 @@ void Bug422Layer::reset() removeChild(node, false); // [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); - 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); menu->alignItemsVertically(); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-458/Bug-458.cpp b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-458/Bug-458.cpp index 6f1a177e5d..f0c1f90f86 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-458/Bug-458.cpp +++ b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-458/Bug-458.cpp @@ -21,13 +21,13 @@ bool Bug458Layer::init() // [question 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); question->release(); question2->release(); 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); menu->alignItemsVerticallyWithPadding(100); menu->setPosition(ccp(size.width / 2, size.height / 2)); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp index c06c4048b3..b5eea31647 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp +++ b/samples/Cpp/TestCpp/Classes/BugsTest/Bug-914.cpp @@ -46,7 +46,7 @@ bool Bug914Layer::init() // create and initialize a Label 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); menu->alignItemsVertically(); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.cpp b/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.cpp index 0ba5820b61..bbfab98236 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.cpp @@ -9,38 +9,42 @@ #include "Bug-1159.h" #include "Bug-1174.h" -#define TEST_BUG(bugNO) \ -{ \ -CCScene* pScene = CCScene::create(); \ -Bug##bugNO##Layer* pLayer = new Bug##bugNO##Layer(); \ -pLayer->init(); \ -pScene->addChild(pLayer); \ -CCDirector::sharedDirector()->replaceScene(pScene); \ -pLayer->autorelease(); \ +#define TEST_BUG(__bug__) \ +{ \ + CCScene* pScene = CCScene::create(); \ + Bug##__bug__##Layer* pLayer = new Bug##__bug__##Layer(); \ + pLayer->init(); \ + pScene->addChild(pLayer); \ + CCDirector::sharedDirector()->replaceScene(pScene); \ + pLayer->autorelease(); \ } enum { - MAX_COUNT = 9, LINE_SPACE = 40, kItemTagBasic = 5432, }; static CCPoint s_tCurPos = CCPointZero; -const std::string testsName[MAX_COUNT] = -{ - "Bug-350", - "Bug-422", - "Bug-458", - "Bug-624", - "Bug-886", - "Bug-899", - "Bug-914", - "Bug-1159", - "Bug-1174" +struct { + const char *test_name; + std::function callback; +} g_bugs[] = { + { "Bug-350", [](CCObject* sender){ TEST_BUG(350)} }, + { "Bug-422", [](CCObject* sender){ TEST_BUG(422)} }, + { "Bug-458", [](CCObject* sender){ TEST_BUG(458)} }, + { "Bug-624", [](CCObject* sender){ TEST_BUG(624)} }, + { "Bug-886", [](CCObject* sender){ TEST_BUG(886)} }, + { "Bug-899", [](CCObject* sender){ TEST_BUG(899)} }, + { "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 @@ -54,10 +58,9 @@ void BugsTestMainLayer::onEnter() m_pItmeMenu = CCMenu::create(); CCMenuItemFont::setFontName("Arial"); 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, - menu_selector(BugsTestMainLayer::menuCallback)); + CCMenuItemFont* pItem = CCMenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); m_pItmeMenu->addChild(pItem, kItemTagBasic + i); } @@ -67,45 +70,6 @@ void BugsTestMainLayer::onEnter() 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) { CCSetIterator it = pTouches->begin(); @@ -131,9 +95,9 @@ void BugsTestMainLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) 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; } @@ -153,8 +117,7 @@ void BugsTestBaseLayer::onEnter() CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontSize(24); - CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", this, - menu_selector(BugsTestBaseLayer::backCallback)); + CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", std::bind( &BugsTestBaseLayer::backCallback, this, std::placeholders::_1)); pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu* pMenu = CCMenu::create(pMainItem, NULL); pMenu->setPosition( CCPointZero ); diff --git a/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.h b/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.h index 3365571cd1..1a68a9aed3 100644 --- a/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.h +++ b/samples/Cpp/TestCpp/Classes/BugsTest/BugsTest.h @@ -7,7 +7,6 @@ class BugsTestMainLayer : public CCLayer { public: virtual void onEnter(); - void menuCallback(CCObject* pSender); virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent); virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent); diff --git a/samples/Cpp/TestCpp/Classes/ChipmunkTest/ChipmunkTest.cpp b/samples/Cpp/TestCpp/Classes/ChipmunkTest/ChipmunkTest.cpp index de60d254dd..4cacd23463 100644 --- a/samples/Cpp/TestCpp/Classes/ChipmunkTest/ChipmunkTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ChipmunkTest/ChipmunkTest.cpp @@ -50,7 +50,7 @@ ChipmunkTestLayer::ChipmunkTestLayer() // menu for debug layer 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); this->addChild(menu); @@ -147,7 +147,7 @@ void ChipmunkTestLayer::update(float delta) 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); diff --git a/samples/Cpp/TestCpp/Classes/CocosDenshionTest/CocosDenshionTest.cpp b/samples/Cpp/TestCpp/Classes/CocosDenshionTest/CocosDenshionTest.cpp index 1b5d4dfa13..fd7d235bcb 100644 --- a/samples/Cpp/TestCpp/Classes/CocosDenshionTest/CocosDenshionTest.cpp +++ b/samples/Cpp/TestCpp/Classes/CocosDenshionTest/CocosDenshionTest.cpp @@ -63,7 +63,7 @@ m_nSoundId(0) //#else CCLabelTTF* label = CCLabelTTF::create(testItems[i].c_str(), "Arial", 24); //#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); pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) )); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp index 549da85611..43aa67f697 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp @@ -42,8 +42,7 @@ bool CCControlScene::init() { if (CCLayer::init()) { - CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this, - menu_selector(CCControlScene::toExtensionsMainLayer)); + CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", std::bind( &CCControlScene::toExtensionsMainLayer, this, std::placeholders::_1)); pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL); pBackMenu->setPosition( CCPointZero ); @@ -66,9 +65,9 @@ bool CCControlScene::init() addChild(m_pSceneTitleLabel, 1); // Add the menu - CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(CCControlScene::previousCallback)); - CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(CCControlScene::restartCallback)); - CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(CCControlScene::nextCallback)); + 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", std::bind( &CCControlScene::restartCallback, this, std::placeholders::_1)); + 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); menu->setPosition(CCPointZero); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp index 35f98d7252..f1d759ae3c 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp @@ -27,7 +27,7 @@ EditBoxTest::EditBoxTest() addChild(m_pTTFShowEditReturn); // 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)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp index f1c3003bf3..0972e5b038 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp @@ -22,38 +22,42 @@ enum kItemTagBasic = 1000, }; -enum -{ - TEST_NOTIFICATIONCENTER = 0, - TEST_CCCONTROLBUTTON, - TEST_COCOSBUILDER, - TEST_HTTPCLIENT, +static struct { + const char *name; + std::function callback; +} g_extensionsTests[] = { + { "NotificationCenterTest", [](CCObject* sender) { runNotificationCenterTest(); } + }, + { "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) - TEST_WEBSOCKET, + { "WebSocketTest", [](CCObject *sender){ runWebSocketTest();} + }, #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) - TEST_EDITBOX, + { "EditBoxTest", [](CCObject *sender){ runEditBoxTest();} + }, #endif - TEST_TABLEVIEW, - TEST_MAX_COUNT, + { "TableViewTest", [](CCObject *sender){ runTableViewTest();} + }, }; -static const std::string testsName[TEST_MAX_COUNT] = -{ - "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" -}; +static const int g_maxTests = sizeof(g_extensionsTests) / sizeof(g_extensionsTests[0]); //////////////////////////////////////////////////////// // @@ -70,10 +74,9 @@ void ExtensionsMainLayer::onEnter() pMenu->setPosition( CCPointZero ); CCMenuItemFont::setFontName("Arial"); 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, - menu_selector(ExtensionsMainLayer::menuCallback)); + CCMenuItemFont* pItem = CCMenuItemFont::create(g_extensionsTests[i].name, g_extensionsTests[i].callback); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pMenu->addChild(pItem, kItemTagBasic + i); } @@ -81,68 +84,6 @@ void ExtensionsMainLayer::onEnter() 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 diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.h index 3ad27bf75e..4a1e0e6162 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.h @@ -7,7 +7,6 @@ class ExtensionsMainLayer : public CCLayer { public: virtual void onEnter(); - void menuCallback(CCObject* pSender); }; class ExtensionsTestScene : public TestScene diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp index ab366241a3..e66fa9ec57 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp @@ -23,31 +23,31 @@ HttpClientTest::HttpClientTest() // Get 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)); menuRequest->addChild(itemGet); // Post 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)); menuRequest->addChild(itemPost); // Post Binary 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)); menuRequest->addChild(itemPostBinary); // Put 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)); menuRequest->addChild(itemPut); // Delete 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)); menuRequest->addChild(itemDelete); @@ -57,7 +57,7 @@ HttpClientTest::HttpClientTest() addChild(m_labelStatusCode); // 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)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp index 9199d45f46..ec800ec849 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp @@ -82,8 +82,7 @@ NotificationCenterTest::NotificationCenterTest() { CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", this, - menu_selector(NotificationCenterTest::toExtensionsMainLayer)); + CCMenuItemFont* pBackItem = CCMenuItemFont::create("Back", std::bind( &NotificationCenterTest::toExtensionsMainLayer, this, std::placeholders::_1)); pBackItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu* pBackMenu = CCMenu::create(pBackItem, NULL); pBackMenu->setPosition( CCPointZero ); @@ -93,7 +92,7 @@ NotificationCenterTest::NotificationCenterTest() CCLabelTTF *label2 = CCLabelTTF::create("switch on", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); 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 item->setSelectedIndex(1); CCMenu *menu = CCMenu::create(item, NULL); @@ -115,7 +114,7 @@ NotificationCenterTest::NotificationCenterTest() CCLabelTTF *label2 = CCLabelTTF::create("connected", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); 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->setPosition(ccp(light->getPosition().x, light->getPosition().y+50)); menuConnect->addChild(item, 0); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp index 034155c8c1..e764bd4b91 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp @@ -39,7 +39,7 @@ bool TableViewTestLayer::init() tableView->reloadData(); // 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)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); diff --git a/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.cpp b/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.cpp index 49e06e766a..9c843a2387 100644 --- a/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.cpp +++ b/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.cpp @@ -57,7 +57,12 @@ IntervalLayer::IntervalLayer() addChild(sprite); sprite->runAction( CCRepeatForever::create(CCSequence::create(jump, jump->reverse(), NULL) )); // 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); menu->setPosition( ccp(s.width/2, s.height-50) ); @@ -80,15 +85,6 @@ void IntervalLayer::update(float dt) 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) { m_time1 +=dt; diff --git a/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.h b/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.h index 2cc6952eaf..5906225780 100644 --- a/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.h +++ b/samples/Cpp/TestCpp/Classes/IntervalTest/IntervalTest.h @@ -18,7 +18,6 @@ public: IntervalLayer(void); virtual ~IntervalLayer(); public: - void onPause(CCObject* pSender); void step1(float dt); void step2(float dt); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index d2f04a3e0b..fc0ea34a4c 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -940,19 +940,19 @@ LabelTTFTest::LabelTTFTest() CCMenuItemFont::setFontSize(30); CCMenu *menu = CCMenu::create( - CCMenuItemFont::create("Left", this, menu_selector(LabelTTFTest::setAlignmentLeft)), - CCMenuItemFont::create("Center", this, menu_selector(LabelTTFTest::setAlignmentCenter)), - CCMenuItemFont::create("Right", this, menu_selector(LabelTTFTest::setAlignmentRight)), + CCMenuItemFont::create("Left", std::bind( &LabelTTFTest::setAlignmentLeft, this, std::placeholders::_1)), + CCMenuItemFont::create("Center", std::bind( &LabelTTFTest::setAlignmentCenter, this, std::placeholders::_1)), + CCMenuItemFont::create("Right", std::bind( &LabelTTFTest::setAlignmentRight, this, std::placeholders::_1)), NULL); menu->alignItemsVerticallyWithPadding(4); menu->setPosition(ccp(50, s.height / 2 - 20)); this->addChild(menu); menu = CCMenu::create( - CCMenuItemFont::create("Top", this, menu_selector(LabelTTFTest::setAlignmentTop)), - CCMenuItemFont::create("Middle", this, menu_selector(LabelTTFTest::setAlignmentMiddle)), - CCMenuItemFont::create("Bottom", this, menu_selector(LabelTTFTest::setAlignmentBottom)), - NULL); + CCMenuItemFont::create("Top", std::bind( &LabelTTFTest::setAlignmentTop, this, std::placeholders::_1)), + CCMenuItemFont::create("Middle", std::bind( &LabelTTFTest::setAlignmentMiddle, this, std::placeholders::_1)), + CCMenuItemFont::create("Bottom", std::bind( &LabelTTFTest::setAlignmentBottom, this, std::placeholders::_1)), + NULL); menu->alignItemsVerticallyWithPadding(4); menu->setPosition(ccp(s.width - 50, s.height / 2 - 20)); this->addChild(menu); @@ -1155,9 +1155,9 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment() this->m_pArrowsShouldRetain->retain(); CCMenuItemFont::setFontSize(20); - CCMenuItemFont *longSentences = CCMenuItemFont::create("Long Flowing Sentences", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); - CCMenuItemFont *lineBreaks = CCMenuItemFont::create("Short Sentences With Intentional Line Breaks", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); - CCMenuItemFont *mixed = CCMenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", 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", std::bind( &BitmapFontMultiLineAlignment::stringChanged, this, std::placeholders::_1)); + 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); stringMenu->alignItemsVertically(); @@ -1169,9 +1169,9 @@ BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment() CCMenuItemFont::setFontSize(30); - CCMenuItemFont *left = CCMenuItemFont::create("Left", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); - CCMenuItemFont *center = CCMenuItemFont::create("Center", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); - CCMenuItemFont *right = CCMenuItemFont::create("Right", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); + CCMenuItemFont *left = CCMenuItemFont::create("Left", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1)); + CCMenuItemFont *center = CCMenuItemFont::create("Center", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1)); + CCMenuItemFont *right = CCMenuItemFont::create("Right", std::bind( &BitmapFontMultiLineAlignment::alignmentChanged, this, std::placeholders::_1)); CCMenu *alignmentMenu = CCMenu::create(left, center, right, NULL); alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding); diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp index fee44e279f..5eff037ce0 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp @@ -6,36 +6,21 @@ enum kTagLayer = 1, }; -TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityA); -TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityB); -TESTLAYER_CREATE_FUNC(LayerTestCascadingOpacityC); -TESTLAYER_CREATE_FUNC(LayerTestCascadingColorA); -TESTLAYER_CREATE_FUNC(LayerTestCascadingColorB); -TESTLAYER_CREATE_FUNC(LayerTestCascadingColorC); -TESTLAYER_CREATE_FUNC(LayerTest1); -TESTLAYER_CREATE_FUNC(LayerTest2); -TESTLAYER_CREATE_FUNC(LayerTestBlend); -TESTLAYER_CREATE_FUNC(LayerGradient); -TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointPos); -TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointRot); -TESTLAYER_CREATE_FUNC(LayerIgnoreAnchorPointScale); -TESTLAYER_CREATE_FUNC(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 std::function createFunctions[] = { + CL(LayerTestCascadingOpacityA), + CL(LayerTestCascadingOpacityB), + CL(LayerTestCascadingOpacityC), + CL(LayerTestCascadingColorA), + CL(LayerTestCascadingColorB), + CL(LayerTestCascadingColorC), + CL(LayerTest1), + CL(LayerTest2), + CL(LayerTestBlend), + CL(LayerGradient), + CL(LayerIgnoreAnchorPointPos), + CL(LayerIgnoreAnchorPointRot), + CL(LayerIgnoreAnchorPointScale), + CL(LayerExtendedBlendOpacityTest) }; static int sceneIdx=-1; @@ -610,7 +595,7 @@ LayerGradient::LayerGradient() CCLabelTTF *label2 = CCLabelTTF::create("Compressed Interpolation: Disabled", "Marker Felt", 26); CCMenuItemLabel *item1 = CCMenuItemLabel::create(label1); 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); addChild(menu); @@ -675,7 +660,7 @@ void LayerIgnoreAnchorPointPos::onEnter() CCSize lsize = l->getContentSize(); 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); this->addChild(menu); @@ -723,7 +708,7 @@ void LayerIgnoreAnchorPointRot::onEnter() CCSize lsize = l->getContentSize(); 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); this->addChild(menu); @@ -774,7 +759,7 @@ void LayerIgnoreAnchorPointScale::onEnter() CCSize lsize = l->getContentSize(); 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); this->addChild(menu); diff --git a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp index 3082d3dff1..5133647cc7 100644 --- a/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp +++ b/samples/Cpp/TestCpp/Classes/MenuTest/MenuTest.cpp @@ -518,9 +518,9 @@ void MenuLayerPriorityTest::menuCallback(CCObject* pSender) // BugsTest BugsTest::BugsTest() { - CCMenuItemFont *issue1410 = CCMenuItemFont::create("Issue 1410", this, menu_selector(BugsTest::issue1410MenuCallback)); - CCMenuItemFont *issue1410_2 = CCMenuItemFont::create("Issue 1410 #2", this, menu_selector(BugsTest::issue1410v2MenuCallback)); - CCMenuItemFont *back = CCMenuItemFont::create("Back", this, menu_selector(BugsTest::backMenuCallback)); + CCMenuItemFont *issue1410 = CCMenuItemFont::create("Issue 1410", std::bind( &BugsTest::issue1410MenuCallback, this, std::placeholders::_1)); + CCMenuItemFont *issue1410_2 = CCMenuItemFont::create("Issue 1410 #2", std::bind( &BugsTest::issue1410v2MenuCallback, this, std::placeholders::_1)); + CCMenuItemFont *back = CCMenuItemFont::create("Back", std::bind( &BugsTest::backMenuCallback, this, std::placeholders::_1)); CCMenu *menu = CCMenu::create(issue1410, issue1410_2, back, NULL); addChild(menu); @@ -564,7 +564,7 @@ RemoveMenuItemWhenMove::RemoveMenuItemWhenMove() item = CCMenuItemFont::create("item 1"); 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); addChild(menu); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp index c94dc277c3..5e3117b3b1 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.cpp @@ -92,9 +92,23 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes) quantityOfNodes = nNodes; 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)); - 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)); CCMenu *menu = CCMenu::create(decrease, increase, NULL); @@ -115,26 +129,6 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes) 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() { return "No title"; diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h index 479bde3e26..04f78eb323 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceNodeChildrenTest.h @@ -19,8 +19,6 @@ public: virtual std::string subtitle(); virtual void updateQuantityOfNodes() = 0; - void onDecrease(CCObject* pSender); - void onIncrease(CCObject* pSender); void updateQuantityLabel(); int getQuantityOfNodes() { return quantityOfNodes; } diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp index 758ea6a1f6..2d81199105 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.cpp @@ -79,9 +79,23 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles) quantityParticles = particles; 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)); - 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)); CCMenu *menu = CCMenu::create(decrease, increase, NULL); @@ -111,7 +125,7 @@ void ParticleMainScene::initWithSubTest(int asubtest, int particles) { char str[10] = {0}; 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); pSubMenu->addChild(itemFont, 10); @@ -249,26 +263,6 @@ void ParticleMainScene::testNCallback(CCObject* 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() { if( quantityParticles != lastRenderedCount ) diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.h index 636689a9cc..5d633cd8f3 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceParticleTest.h @@ -18,8 +18,6 @@ public: void step(float dt); void createParticleSystem(); - void onDecrease(CCObject* pSender); - void onIncrease(CCObject* pSender); void testNCallback(CCObject* pSender); void updateQuantityLabel(); int getSubTestNum() { return subtestNumber; } diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp index d6a7900689..4dbf18ac4c 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceSpriteTest.cpp @@ -287,9 +287,9 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) quantityNodes = 0; 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)); - 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)); CCMenu *menu = CCMenu::create(decrease, increase, NULL); @@ -314,7 +314,7 @@ void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) { char str[10] = {0}; 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); pSubMenu->addChild(itemFont, 10); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp index 950cc80cf2..fed8f3f710 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.cpp @@ -8,20 +8,24 @@ enum { - MAX_COUNT = 5, LINE_SPACE = 40, kItemTagBasic = 1000, }; -const std::string testsName[MAX_COUNT] = +struct { + const char *name; + std::function callback; +} g_testsName[] = { - "PerformanceNodeChildrenTest", - "PerformanceParticleTest", - "PerformanceSpriteTest", - "PerformanceTextureTest", - "PerformanceTouchesTest" + { "PerformanceNodeChildrenTest", [](CCObject*sender){runNodeChildrenTest();} }, + { "PerformanceParticleTest",[](CCObject*sender){runParticleTest();} }, + { "PerformanceSpriteTest",[](CCObject*sender){runSpriteTest();} }, + { "PerformanceTextureTest",[](CCObject*sender){runTextureTest();} }, + { "PerformanceTouchesTest",[](CCObject*sender){runTouchesTest();} }, }; +static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]); + //////////////////////////////////////////////////////// // // PerformanceMainLayer @@ -37,10 +41,9 @@ void PerformanceMainLayer::onEnter() pMenu->setPosition( CCPointZero ); CCMenuItemFont::setFontName("Arial"); 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, - menu_selector(PerformanceMainLayer::menuCallback)); + CCMenuItemFont* pItem = CCMenuItemFont::create(g_testsName[i].name, g_testsName[i].callback); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pMenu->addChild(pItem, kItemTagBasic + i); } @@ -48,33 +51,6 @@ void PerformanceMainLayer::onEnter() 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 @@ -94,17 +70,16 @@ void PerformBasicLayer::onEnter() CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontSize(24); - CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", this, - menu_selector(PerformBasicLayer::toMainLayer)); + CCMenuItemFont* pMainItem = CCMenuItemFont::create("Back", std::bind( &PerformBasicLayer::toMainLayer, this, std::placeholders::_1)); pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); CCMenu* pMenu = CCMenu::create(pMainItem, NULL); pMenu->setPosition( CCPointZero ); if (m_bControlMenuVisible) { - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(PerformBasicLayer::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(PerformBasicLayer::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(PerformBasicLayer::nextCallback) ); + CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind( &PerformBasicLayer::backCallback, this, std::placeholders::_1)); + CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind( &PerformBasicLayer::restartCallback, this, std::placeholders::_1)); + 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)); 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)); diff --git a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h index c85fb3b91e..ece8cacfc4 100644 --- a/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h +++ b/samples/Cpp/TestCpp/Classes/PerformanceTest/PerformanceTest.h @@ -7,7 +7,6 @@ class PerformanceMainLayer : public CCLayer { public: virtual void onEnter(); - void menuCallback(CCObject* pSender); }; class PerformBasicLayer : public CCLayer diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index c35aa26044..fbc9d344c5 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -6,21 +6,13 @@ // Test #3 by David Deaco (ddeaco) - -TESTLAYER_CREATE_FUNC(RenderTextureSave); -TESTLAYER_CREATE_FUNC(RenderTextureIssue937); -TESTLAYER_CREATE_FUNC(RenderTextureZbuffer); -TESTLAYER_CREATE_FUNC(RenderTextureTestDepthStencil); -TESTLAYER_CREATE_FUNC(RenderTextureTargetNode); -TESTLAYER_CREATE_FUNC(SpriteRenderTextureBug); - -static NEWTESTFUNC createFunctions[] = { - CF(RenderTextureSave), - CF(RenderTextureIssue937), - CF(RenderTextureZbuffer), - CF(RenderTextureTestDepthStencil), - CF(RenderTextureTargetNode), - CF(SpriteRenderTextureBug), +static std::function createFunctions[] = { + CL(RenderTextureSave), + CL(RenderTextureIssue937), + CL(RenderTextureZbuffer), + CL(RenderTextureTestDepthStencil), + CL(RenderTextureTargetNode), + CL(SpriteRenderTextureBug), }; #define MAX_LAYER (sizeof(createFunctions)/sizeof(createFunctions[0])) @@ -60,34 +52,7 @@ static CCLayer* restartTestCase() void RenderTextureTest::onEnter() { - CCLayer::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); + BaseTest::onEnter(); } void RenderTextureTest::restartCallback(CCObject* pSender) @@ -150,8 +115,8 @@ RenderTextureSave::RenderTextureSave() // Save Image menu CCMenuItemFont::setFontSize(16); - CCMenuItem *item1 = CCMenuItemFont::create("Save Image", this, menu_selector(RenderTextureSave::saveImage)); - CCMenuItem *item2 = CCMenuItemFont::create("Clear", this, menu_selector(RenderTextureSave::clearImage)); + CCMenuItem *item1 = CCMenuItemFont::create("Save Image", std::bind( &RenderTextureSave::saveImage, this, std::placeholders::_1)); + CCMenuItem *item2 = CCMenuItemFont::create("Clear", std::bind( &RenderTextureSave::clearImage, this, std::placeholders::_1)); CCMenu *menu = CCMenu::create(item1, item2, NULL); this->addChild(menu); menu->alignItemsVertically(); @@ -564,7 +529,7 @@ RenderTextureTargetNode::RenderTextureTargetNode() scheduleUpdate(); // 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); addChild(menu); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index de6d72ca99..cdfeb761bb 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -3,8 +3,9 @@ #include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" -class RenderTextureTest : public CCLayer +class RenderTextureTest : public BaseTest { public: virtual void onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/SceneTest/SceneTest.cpp b/samples/Cpp/TestCpp/Classes/SceneTest/SceneTest.cpp index 9f0b1bb3e1..4ae1549d4a 100644 --- a/samples/Cpp/TestCpp/Classes/SceneTest/SceneTest.cpp +++ b/samples/Cpp/TestCpp/Classes/SceneTest/SceneTest.cpp @@ -18,9 +18,9 @@ enum SceneTestLayer1::SceneTestLayer1() { - CCMenuItemFont* item1 = CCMenuItemFont::create( "Test pushScene", this, menu_selector(SceneTestLayer1::onPushScene) ); - CCMenuItemFont* item2 = CCMenuItemFont::create( "Test pushScene w/transition", this, menu_selector(SceneTestLayer1::onPushSceneTran) ); - CCMenuItemFont* item3 = CCMenuItemFont::create( "Quit", this, menu_selector(SceneTestLayer1::onQuit) ); + CCMenuItemFont* item1 = CCMenuItemFont::create( "Test pushScene", std::bind(&SceneTestLayer1::onPushScene, this, std::placeholders::_1)); + CCMenuItemFont* item2 = CCMenuItemFont::create( "Test pushScene w/transition", std::bind(&SceneTestLayer1::onPushSceneTran, this, std::placeholders::_1)); + CCMenuItemFont* item3 = CCMenuItemFont::create( "Quit", std::bind(&SceneTestLayer1::onQuit, this, std::placeholders::_1)); CCMenu* menu = CCMenu::create( item1, item2, item3, NULL ); menu->alignItemsVertically(); @@ -103,9 +103,9 @@ SceneTestLayer2::SceneTestLayer2() { m_timeCounter = 0; - CCMenuItemFont* item1 = CCMenuItemFont::create( "replaceScene", this, menu_selector(SceneTestLayer2::onReplaceScene) ); - CCMenuItemFont* item2 = CCMenuItemFont::create( "replaceScene w/transition", this, menu_selector(SceneTestLayer2::onReplaceSceneTran) ); - CCMenuItemFont* item3 = CCMenuItemFont::create( "Go Back", this, menu_selector(SceneTestLayer2::onGoBack) ); + CCMenuItemFont* item1 = CCMenuItemFont::create( "replaceScene", std::bind(&SceneTestLayer2::onReplaceScene, this, std::placeholders::_1)); + CCMenuItemFont* item2 = CCMenuItemFont::create( "replaceScene w/transition", std::bind(&SceneTestLayer2::onReplaceSceneTran, this, std::placeholders::_1)); + CCMenuItemFont* item3 = CCMenuItemFont::create( "Go Back", std::bind(&SceneTestLayer2::onGoBack, this, std::placeholders::_1)); CCMenu* menu = CCMenu::create( item1, item2, item3, NULL ); menu->alignItemsVertically(); @@ -171,10 +171,10 @@ bool SceneTestLayer3::init() { CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCMenuItemFont *item0 = CCMenuItemFont::create("Touch to pushScene (self)", this, menu_selector(SceneTestLayer3::item0Clicked)); - CCMenuItemFont *item1 = CCMenuItemFont::create("Touch to popScene", this, menu_selector(SceneTestLayer3::item1Clicked)); - CCMenuItemFont *item2 = CCMenuItemFont::create("Touch to popToRootScene", this, menu_selector(SceneTestLayer3::item2Clicked)); - CCMenuItemFont *item3 = CCMenuItemFont::create("Touch to popToSceneStackLevel(2)", this, menu_selector(SceneTestLayer3::item3Clicked)); + CCMenuItemFont *item0 = CCMenuItemFont::create("Touch to pushScene (self)", std::bind(&SceneTestLayer3::item0Clicked, this, std::placeholders::_1)); + CCMenuItemFont *item1 = CCMenuItemFont::create("Touch to popScene", std::bind(&SceneTestLayer3::item1Clicked, this, std::placeholders::_1)); + CCMenuItemFont *item2 = CCMenuItemFont::create("Touch to popToRootScene", std::bind(&SceneTestLayer3::item2Clicked, this, std::placeholders::_1)); + 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); this->addChild(menu); @@ -200,8 +200,8 @@ void SceneTestLayer3::testDealloc(float dt) void SceneTestLayer3::item0Clicked(CCObject* pSender) { - CCScene *newScene = CCScene::create(); - newScene->addChild(SceneTestLayer3::create()); + CCScene *newScene = CCScene::create(); + newScene->addChild(SceneTestLayer3::create()); CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5, newScene, ccc3(0,255,255))); } diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp index 164ffe2c07..7bacac30b2 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.cpp @@ -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) { CCScene* s = new ShaderTestScene(); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h index 28916a8f58..ade5192536 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest.h @@ -3,17 +3,17 @@ #include "../testBasic.h" #include "cocos-ext.h" +#include "../BaseTest.h" USING_NS_CC_EXT; -class ShaderTestDemo : public CCLayer +class ShaderTestDemo : public BaseTest { public: ShaderTestDemo(void); virtual std::string title(); virtual std::string subtitle(); - virtual bool init(); void restartCallback(CCObject* pSender); void nextCallback(CCObject* pSender); diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index 382fee3ceb..61de64941f 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -1814,19 +1814,19 @@ void TextureMemoryAlloc::onEnter() 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); - 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); - 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); - 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); - 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); CCMenu *menu = CCMenu::create(item1, item2, item3, item4, item5, NULL); @@ -1834,7 +1834,7 @@ void TextureMemoryAlloc::onEnter() 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); diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp index cada3db4ec..7d20a3e065 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.cpp @@ -1428,45 +1428,13 @@ CCLayer* restartTileMapAction() TileDemo::TileDemo(void) +: BaseTest() { 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) { - m_label->release(); - m_subtitle->release(); } std::string TileDemo::title() @@ -1481,10 +1449,7 @@ std::string TileDemo::subtitle() void TileDemo::onEnter() { - CCLayer::onEnter(); - - m_label->setString(title().c_str()); - m_subtitle->setString(subtitle().c_str()); + BaseTest::onEnter(); } void TileDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h index b42f09c4e1..4e6e368328 100644 --- a/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h +++ b/samples/Cpp/TestCpp/Classes/TileMapTest/TileMapTest.h @@ -2,13 +2,10 @@ #define _TILEMAP_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" -class TileDemo : public CCLayer +class TileDemo : public BaseTest { -protected: - CCLabelTTF* m_label; - CCLabelTTF* m_subtitle; - public: TileDemo(void); virtual ~TileDemo(void); diff --git a/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.cpp b/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.cpp index 9b74cf4314..95097af122 100644 --- a/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.cpp @@ -30,11 +30,6 @@ PongScene::PongScene() pongLayer->release(); } -void PongScene::MainMenuCallback(CCObject* pSender) -{ - TestScene::MainMenuCallback(pSender); -} - //------------------------------------------------------------------ // // PongLayer diff --git a/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.h b/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.h index 971199ef22..c3be6f69d1 100644 --- a/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.h +++ b/samples/Cpp/TestCpp/Classes/TouchesTest/TouchesTest.h @@ -12,8 +12,6 @@ public: PongScene(); virtual void runThisTest(); - - virtual void MainMenuCallback(CCObject* pSender); }; class Ball; diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 1c6294eb4c..d38f89c94f 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -89,7 +89,7 @@ TestController::TestController() : m_tBeginPos(CCPointZero) { // 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); pMenu->setPosition( CCPointZero ); diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index e0c900df00..fd2617fa71 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -17,7 +17,14 @@ void TestScene::onEnter() //#else CCLabelTTF* label = CCLabelTTF::create("MainMenu", "Arial", 20); //#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); @@ -26,13 +33,3 @@ void TestScene::onEnter() 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); -} diff --git a/samples/Cpp/TestCpp/Classes/testBasic.h b/samples/Cpp/TestCpp/Classes/testBasic.h index 693920bc84..860924459a 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.h +++ b/samples/Cpp/TestCpp/Classes/testBasic.h @@ -14,9 +14,6 @@ public: virtual void onEnter(); virtual void runThisTest() = 0; - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(CCObject* pSender); }; typedef CCLayer* (*NEWTESTFUNC)(); From ba5972ef79bf9f48ef3083615939f514f7a87032 Mon Sep 17 00:00:00 2001 From: James Chen Date: Sat, 8 Jun 2013 10:25:53 +0800 Subject: [PATCH 2/2] [C++ 11] Bug fix for the usage of lambda in testBasic.cpp while using GCC compiler. --- samples/Cpp/TestCpp/Classes/testBasic.cpp | 31 +++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/testBasic.cpp b/samples/Cpp/TestCpp/Classes/testBasic.cpp index fd2617fa71..6f929d6926 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.cpp +++ b/samples/Cpp/TestCpp/Classes/testBasic.cpp @@ -18,12 +18,33 @@ void TestScene::onEnter() CCLabelTTF* label = CCLabelTTF::create("MainMenu", "Arial", 20); //#endif CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, [](CCObject *sender) { - CCScene* pScene = CCScene::create(); - CCLayer* pLayer = new TestController(); - pLayer->autorelease(); + /* + ****** GCC Compiler issue on Android and Linux (CLANG compiler is ok) ****** + We couldn't use 'CCScene::create' directly since gcc will trigger + an error called "error: 'this' was not captured for this lambda function". + This is because 'CCScene' is the super class of TestScene, if we invoke 'CCScene::create' + directly in this lambda expression, gcc compiler found 'CCScene::create' and it think + that was the member function of 'TestScene' 's super class, but this lambda function doesn't + capture anything like 'this', so it has no access to invoke 'CCScene::create'. + + Solution (1): Passing 'this' to this lambda function. + Solution (2): Don't use 'CCScene::create' and don't pass 'this' to this lambda function, + instead, we just need to new the 'CCScene' and initialize the Scene. + + Semantically, I think in this lambda function, we shouldn't capture any varibles + outside the scope. So I choose the (2) solution. Commented by James Chen. + */ - pScene->addChild(pLayer); - CCDirector::sharedDirector()->replaceScene(pScene); +// CCScene *pScene = CCScene::create(); + CCScene *pScene = new CCScene(); + if (pScene && pScene->init()) + { + CCLayer* pLayer = new TestController(); + pScene->addChild(pLayer); + pLayer->release(); + CCDirector::sharedDirector()->replaceScene(pScene); + pScene->release(); + } }); CCMenu* pMenu =CCMenu::create(pMenuItem, NULL);