From ac6e26362189133c688dee008a86129ac6ad1877 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 16 Apr 2012 21:51:06 +0800 Subject: [PATCH] Updated CCControlExtension --- cocos2dx/include/CCString.h | 2 + .../CCControlButtonTest.cpp | 236 ++++++++++-------- .../CCControlButtonTest/CCControlButtonTest.h | 20 +- .../ControlExtensionTest/CCControlScene.cpp | 23 +- .../ControlExtensionTest/CCControlScene.h | 65 +++-- .../CCControlSceneManager.cpp | 7 +- .../CCControlSceneManager.h | 5 + tests/tests/ExtensionsTest/ExtensionsTest.cpp | 16 +- 8 files changed, 201 insertions(+), 173 deletions(-) diff --git a/cocos2dx/include/CCString.h b/cocos2dx/include/CCString.h index 8db2caaee5..763de0135c 100755 --- a/cocos2dx/include/CCString.h +++ b/cocos2dx/include/CCString.h @@ -106,6 +106,8 @@ public: }; #define CCStringMake(str) CCString::stringWithCString(str) +#define ccs CCStringMake + NS_CC_END diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp index dfabe1bb14..332d5a1110 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp @@ -25,47 +25,52 @@ #include "ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h" -CCControlButtonTest_HelloVariableSize::CCControlButtonTest_HelloVariableSize() +bool CCControlButtonTest_HelloVariableSize::init() { - CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); - - // Defines an array of title to create buttons dynamically - CCArray *stringArray = CCArray::arrayWithObjects( - CCStringMake("Hello"), - CCStringMake("Variable"), - CCStringMake("Size"), - CCStringMake("!"), - NULL); - - CCNode *layer = CCNode::node(); - addChild(layer, 1); - - double total_width = 0, height = 0; - - // For each title in the array - CCObject* pObj = NULL; - CCARRAY_FOREACH(stringArray, pObj) - { - CCString* title = (CCString*)pObj; - // Creates a button with this string as title - CCControlButton *button = standardButtonWithTitle(title->getCString()); - button->setPosition(ccp (total_width + button->getContentSize().width / 2, button->getContentSize().height / 2)); - layer->addChild(button); - - // Compute the size of the layer - height = button->getContentSize().height; - total_width += button->getContentSize().width; - } + if (CCControlScene::init()) + { + CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); + + // Defines an array of title to create buttons dynamically + CCArray *stringArray = CCArray::arrayWithObjects( + ccs("Hello"), + ccs("Variable"), + ccs("Size"), + ccs("!"), + NULL); + + CCNode *layer = CCNode::node(); + addChild(layer, 1); + + double total_width = 0, height = 0; + + // For each title in the array + CCObject* pObj = NULL; + CCARRAY_FOREACH(stringArray, pObj) + { + CCString* title = (CCString*)pObj; + // Creates a button with this string as title + CCControlButton *button = standardButtonWithTitle(title->getCString()); + button->setPosition(ccp (total_width + button->getContentSize().width / 2, button->getContentSize().height / 2)); + layer->addChild(button); + + // Compute the size of the layer + height = button->getContentSize().height; + total_width += button->getContentSize().width; + } - layer->setAnchorPoint(ccp (0.5, 0.5)); - layer->setContentSize(CCSizeMake(total_width, height)); - layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - - // Add the black background - CCScale9Sprite *background = CCScale9Sprite::spriteWithFile("buttonBackground.png"); - background->setContentSize(CCSizeMake(total_width + 14, height + 14)); - background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - addChild(background); + layer->setAnchorPoint(ccp (0.5, 0.5)); + layer->setContentSize(CCSizeMake(total_width, height)); + layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + + // Add the black background + CCScale9Sprite *background = CCScale9Sprite::spriteWithFile("buttonBackground.png"); + background->setContentSize(CCSizeMake(total_width + 14, height + 14)); + background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(background); + return true; + } + return false; } CCControlButton *CCControlButtonTest_HelloVariableSize::standardButtonWithTitle(const char * title) @@ -90,48 +95,52 @@ CCControlButtonTest_Event::~CCControlButtonTest_Event() CC_SAFE_RELEASE_NULL(m_pDisplayValueLabel); } -CCControlButtonTest_Event::CCControlButtonTest_Event() +bool CCControlButtonTest_Event::init() { - CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); + if (CCControlScene::init()) + { + CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); - // Add a label in which the button events will be displayed - setDisplayValueLabel(CCLabelTTF::labelWithString("No Event", "Marker Felt", 32)); - m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1)); - m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - addChild(m_pDisplayValueLabel, 1); - - // Add the button - CCScale9Sprite *backgroundButton = CCScale9Sprite::spriteWithFile("button.png"); - CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::spriteWithFile("buttonHighlighted.png"); - - CCLabelTTF *titleButton = CCLabelTTF::labelWithString("Touch Me!", "Marker Felt", 30); + // Add a label in which the button events will be displayed + setDisplayValueLabel(CCLabelTTF::labelWithString("No Event", "Marker Felt", 32)); + m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1)); + m_pDisplayValueLabel->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(m_pDisplayValueLabel, 1); + + // Add the button + CCScale9Sprite *backgroundButton = CCScale9Sprite::spriteWithFile("button.png"); + CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::spriteWithFile("buttonHighlighted.png"); + + CCLabelTTF *titleButton = CCLabelTTF::labelWithString("Touch Me!", "Marker Felt", 30); - titleButton->setColor(ccc3(159, 168, 176)); - - CCControlButton *controlButton = CCControlButton::buttonWithLabelAndBackgroundSprite(titleButton - backgroundButton); - controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted); - controlButton->setTitleColorForState(ccWHITE, CCControlStateHighlighted); - - controlButton->setAnchorPoint(ccp(0.5f, 1)); - controlButton->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - addChild(controlButton, 1); + titleButton->setColor(ccc3(159, 168, 176)); + + CCControlButton *controlButton = CCControlButton::buttonWithLabelAndBackgroundSprite(titleButton, backgroundButton); + controlButton->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted); + controlButton->setTitleColorForState(ccWHITE, CCControlStateHighlighted); + + controlButton->setAnchorPoint(ccp(0.5f, 1)); + controlButton->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(controlButton, 1); - // Add the black background - CCScale9Sprite *background = CCScale9Sprite::spriteWithFile("buttonBackground.png"); - background->setContentSize(CCSizeMake(300, 170)); - background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - addChild(background); - - // Sets up event handlers - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDownAction), CCControlEventTouchDown); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragInsideAction), CCControlEventTouchDragInside); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragOutsideAction), CCControlEventTouchDragOutside); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragEnterAction), CCControlEventTouchDragEnter); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragExitAction), CCControlEventTouchDragExit); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchUpInsideAction), CCControlEventTouchUpInside); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchUpOutsideAction), CCControlEventTouchUpOutside); - controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchCancelAction), CCControlEventTouchCancel); + // Add the black background + CCScale9Sprite *background = CCScale9Sprite::spriteWithFile("buttonBackground.png"); + background->setContentSize(CCSizeMake(300, 170)); + background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(background); + + // Sets up event handlers + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDownAction), CCControlEventTouchDown); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragInsideAction), CCControlEventTouchDragInside); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragOutsideAction), CCControlEventTouchDragOutside); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragEnterAction), CCControlEventTouchDragEnter); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchDragExitAction), CCControlEventTouchDragExit); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchUpInsideAction), CCControlEventTouchUpInside); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchUpOutsideAction), CCControlEventTouchUpOutside); + controlButton->addTargetWithActionForControlEvent(this, menu_selector(CCControlButtonTest_Event::touchCancelAction), CCControlEventTouchCancel); + return true; + } + return false; } void CCControlButtonTest_Event::touchDownAction(CCObject *sender) @@ -177,42 +186,47 @@ void CCControlButtonTest_Event::touchCancelAction(CCObject *sender) //CCControlButtonTest_Styling -CCControlButtonTest_Styling::CCControlButtonTest_Styling() +bool CCControlButtonTest_Styling::init() { - CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); + if (CCControlScene::init()) + { + CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); - CCNode *layer = CCNode::node(); - addChild(layer, 1); - - int space = 10; // px - - double max_w = 0, max_h = 0; - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { - // Add the buttons - CCControlButton *button = standardButtonWithTitle(CCString::stringWithFormat("%d",rand() % 30)->getCString()); - button->setAdjustBackgroundImage(false); // Tells the button that the background image must not be adjust - // It'll use the prefered size of the background image - button->setPosition(ccp (button->getContentSize().width / 2 + (button->getContentSize().width + space) * i, - button->getContentSize().height / 2 + (button->getContentSize().height + space) * j); - layer->addChild(button); - - max_w = MAX(button->getContentSize().width * (i + 1) + space * i, max_w); - max_h = MAX(button->getContentSize().height * (j + 1) + space * j, max_h); - } - } - - layer->setAnchorPoint(ccp (0.5, 0.5)); - layer->setContentSize(CCSizeMake(max_w, max_h)); - layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - - // Add the black background - CCScale9Sprite *backgroundButton = CCScale9Sprite::spriteWithFile("buttonBackground.png"); - backgroundButton->setContentSize(CCSizeMake(max_w + 14, max_h + 14)); - backgroundButton->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); - addChild(backgroundButton); + CCNode *layer = CCNode::node(); + addChild(layer, 1); + + int space = 10; // px + + double max_w = 0, max_h = 0; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + // Add the buttons + CCControlButton *button = standardButtonWithTitle(CCString::stringWithFormat("%d",rand() % 30)->getCString()); + button->setAdjustBackgroundImage(false); // Tells the button that the background image must not be adjust + // It'll use the prefered size of the background image + button->setPosition(ccp (button->getContentSize().width / 2 + (button->getContentSize().width + space) * i, + button->getContentSize().height / 2 + (button->getContentSize().height + space) * j)); + layer->addChild(button); + + max_w = MAX(button->getContentSize().width * (i + 1) + space * i, max_w); + max_h = MAX(button->getContentSize().height * (j + 1) + space * j, max_h); + } + } + + layer->setAnchorPoint(ccp (0.5, 0.5)); + layer->setContentSize(CCSizeMake(max_w, max_h)); + layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + + // Add the black background + CCScale9Sprite *backgroundButton = CCScale9Sprite::spriteWithFile("buttonBackground.png"); + backgroundButton->setContentSize(CCSizeMake(max_w + 14, max_h + 14)); + backgroundButton->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f)); + addChild(backgroundButton); + return true; + } + return false; } diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h index cf0000189c..508471367d 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.h @@ -23,22 +23,26 @@ * */ -#include "ExtensionsTest/ControlExtensionTest/CCControlScene.h" +#ifndef __CCCONTROLBUTTONTEST_H__ +#define __CCCONTROLBUTTONTEST_H__ + +#include "../CCControlScene.h" class CCControlButtonTest_HelloVariableSize : public CCControlScene { public: - CCControlButtonTest_HelloVariableSize(); + bool init(); /** Creates and return a button with a default background and title color. */ CCControlButton *standardButtonWithTitle(const char * title); - SCENE_NODE_FUNC(CCControlButtonTest_HelloVariableSize) + CONTROL_SCENE_NODE_FUNC(CCControlButtonTest_HelloVariableSize) }; class CCControlButtonTest_Event : public CCControlScene { public: - CCControlButtonTest_Event(); + ~CCControlButtonTest_Event(); + bool init(); void touchDownAction(CCObject *sender); void touchDragInsideAction(CCObject *sender); void touchDragOutsideAction(CCObject *sender); @@ -50,15 +54,17 @@ public: protected: CCLabelTTF *displayEvents; CC_SYNTHESIZE_RETAIN(CCLabelTTF *, m_pDisplayValueLabel, DisplayValueLabel) - SCENE_NODE_FUNC(CCControlButtonTest_Event) + CONTROL_SCENE_NODE_FUNC(CCControlButtonTest_Event) }; class CCControlButtonTest_Styling : public CCControlScene { public: - CCControlButtonTest_Styling(); + bool init(); CCControlButton *standardButtonWithTitle(const char *title); - SCENE_NODE_FUNC(CCControlButtonTest_Styling) + CONTROL_SCENE_NODE_FUNC(CCControlButtonTest_Styling) }; + +#endif /* __CCCONTROLBUTTONTEST_H__ */ diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp index cc059fb125..8b12c54a21 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp @@ -47,7 +47,7 @@ bool CCControlScene::init() CCSize screensize = CCDirector::sharedDirector()->getWinSize(); // Add the generated background - CCSprite *background = CCSprite spriteWithFile("background.png"); + CCSprite *background = CCSprite::spriteWithFile("background.png"); background->setPosition(ccp(screensize.width / 2, screensize.height / 2)); addChild(background); @@ -59,19 +59,19 @@ bool CCControlScene::init() // Add the title setSceneTitleLabel(CCLabelTTF::labelWithString("Title", "Arial", 12)); - m_pSceneTitleLabel->setPosition(ccp (screensize.width / 2, screensize.height - m_pSceneTitleLabel->getContentSize().height / 2 - 5)]; + m_pSceneTitleLabel->setPosition(ccp (screensize.width / 2, screensize.height - m_pSceneTitleLabel->getContentSize().height / 2 - 5)); addChild(m_pSceneTitleLabel, 1); // Add the menu - CCMenuItemImage *item1 = CCMenuItemImage::itemWithNormalImage("b1.png", "b2.png", this, menu_selector(CCControlScene::previousCallback))); - CCMenuItemImage *item2 = CCMenuItemImage::itemWithNormalImage("r1.png", "r2.png", this, menu_selector(CCControlScene::restartCallback))); - CCMenuItemImage *item3 = CCMenuItemImage::itemWithNormalImage("f1.png", "f2.png", this, menu_selector(CCControlScene::nextCallback))); + CCMenuItemImage *item1 = CCMenuItemImage::itemWithNormalImage("b1.png", "b2.png", this, menu_selector(CCControlScene::previousCallback)); + CCMenuItemImage *item2 = CCMenuItemImage::itemWithNormalImage("r1.png", "r2.png", this, menu_selector(CCControlScene::restartCallback)); + CCMenuItemImage *item3 = CCMenuItemImage::itemWithNormalImage("f1.png", "f2.png", this, menu_selector(CCControlScene::nextCallback)); CCMenu *menu = CCMenu::menuWithItems(item1, item3, item2, NULL); menu->setPosition(CCPointZero); - item1 setPosition(ccp(screensize.width / 2 - 100, 37)); - item2 setPosition(ccp(screensize.width / 2, 35)); - item3 setPosition(ccp(screensize.width / 2 + 100, 37)); + item1->setPosition(ccp(screensize.width / 2 - 100, 37)); + item2->setPosition(ccp(screensize.width / 2, 35)); + item3->setPosition(ccp(screensize.width / 2 + 100, 37)); addChild(menu ,1); return true; @@ -79,18 +79,17 @@ bool CCControlScene::init() return false; } -void CCControlScene::previousCallback(CCNode* sender) +void CCControlScene::previousCallback(CCObject* sender) { CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->previousControlScene()); } -void CCControlScene::restartCallback(CCNode* sender) +void CCControlScene::restartCallback(CCObject* sender) { CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->currentControlScene()); - } -void CCControlScene::nextCallback(CCNode* sender) +void CCControlScene::nextCallback(CCObject* sender) { CCDirector::sharedDirector()->replaceScene(CCControlSceneManager::sharedControlSceneManager()->nextControlScene()); } diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h index 65812ae0b3..7ca0ab5c98 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlScene.h @@ -23,56 +23,49 @@ * */ +#ifndef __CCCONTROLSCENE_H__ +#define __CCCONTROLSCENE_H__ + #include "cocos2d.h" -// 'scene' is an autorelease object. +USING_NS_CC; -// 'layer' is an autorelease object. -CCControlScene *controlLayer = CCControlScene::node(); -controlLayer->getSceneTitleLabel()->setString(title); - -// add layer as a child to scene -scene->addChild(controlLayer); - -// return the scene -return scene; - -#define CONTROL_SCENE_NODE_FUNC(scene) \ -static scene* sceneWithTitle(const char * title) \ +#define CONTROL_SCENE_NODE_FUNC(controlScene) \ +public: \ +static CCScene* sceneWithTitle(const char * title) \ { \ - scene *pRet = new scene(); \ - if (pRet && pRet->init()) \ - { \ - pRet->autorelease(); \ - } \ - else \ - { \ - CC_SAFE_DELETE(pRet); \ - } \ - return pRet; \ + CCScene* pScene = CCScene::node(); \ + controlScene* controlLayer = new controlScene(); \ + if (controlLayer && controlLayer->init()) \ + { \ + controlLayer->autorelease(); \ + controlLayer->getSceneTitleLabel()->setString(title); \ + pScene->addChild(controlLayer); \ + } \ + else \ + { \ + CC_SAFE_DELETE(controlLayer); \ + } \ + return pScene; \ } + class CCControlScene : public cocos2d::CCLayer { public: + CCControlScene(); ~CCControlScene(); - bool init(); - - /** - * Returns a CCScene that contains the CCControl example layer. - * - * @param title The title of the scene. - */ - static cocos2d::CCScene* sceneWithTitle(const char * title); - + bool init(); // Menu Callbacks - void previousCallback(cocos2d::CCNode* sender); - void restartCallback(cocos2d::CCNode* sender); - void nextCallback(cocos2d::CCNode* sender); + void previousCallback(cocos2d::CCObject* sender); + void restartCallback(cocos2d::CCObject* sender); + void nextCallback(cocos2d::CCObject* sender); /** Title label of the scene. */ CC_SYNTHESIZE_RETAIN(cocos2d::CCLabelTTF*, m_pSceneTitleLabel, SceneTitleLabel) - LAYER_NODE_FUNC(CCControlScene); + CONTROL_SCENE_NODE_FUNC(CCControlScene); }; + +#endif /* __CCCONTROLSCENE_H__ */ diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp index e0593f46be..46a58efddd 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp @@ -25,6 +25,7 @@ #include "CCControlSceneManager.h" #include "CCControlScene.h" +#include "CCControlButtonTest/CCControlButtonTest.h" USING_NS_CC; @@ -95,9 +96,9 @@ CCScene *CCControlSceneManager::currentControlScene() // case kCCControlSliderTest: // case kCCControlColourPickerTest: // case kCCControlSwitchTest: - case kCCControlButtonTest_HelloVariableSize:return CCControlButtonTest_HelloVariableSize::node(); - case kCCControlButtonTest_Event:return CCControlButtonTest_Event::node(); - case kCCControlButtonTest_Styling:return CCControlButtonTest_Styling::node(); + case kCCControlButtonTest_HelloVariableSize:return CCControlButtonTest_HelloVariableSize::sceneWithTitle(s_testArray[m_nCurrentControlSceneId]); + case kCCControlButtonTest_Event:return CCControlButtonTest_Event::sceneWithTitle(s_testArray[m_nCurrentControlSceneId]); + case kCCControlButtonTest_Styling:return CCControlButtonTest_Styling::sceneWithTitle(s_testArray[m_nCurrentControlSceneId]); } // return nextControlScene::sceneWithTitle(s_testArray[m_nCurrentControlSceneId]); diff --git a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h index 94ceec8082..8657e83b11 100644 --- a/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h +++ b/tests/tests/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.h @@ -22,9 +22,13 @@ * THE SOFTWARE. * */ +#ifndef __CCCONTROLSCENEMANAGER_H__ +#define __CCCONTROLSCENEMANAGER_H__ #include "cocos2d.h" +USING_NS_CC; + class CCControlSceneManager : public cocos2d::CCObject { public: @@ -46,3 +50,4 @@ public: CC_SYNTHESIZE(int, m_nCurrentControlSceneId, CurrentControlSceneId) }; +#endif /* __CCCONTROLSCENEMANAGER_H__ */ diff --git a/tests/tests/ExtensionsTest/ExtensionsTest.cpp b/tests/tests/ExtensionsTest/ExtensionsTest.cpp index 6cf615ec41..2d5e5ee103 100644 --- a/tests/tests/ExtensionsTest/ExtensionsTest.cpp +++ b/tests/tests/ExtensionsTest/ExtensionsTest.cpp @@ -1,18 +1,19 @@ #include "ExtensionsTest.h" #include "../testResource.h" -#include "NotificationCenterTest.h" - +#include "NotificationCenterTest/NotificationCenterTest.h" +#include "ControlExtensionTest/CCControlSceneManager.h" enum { - MAX_COUNT = 1, + MAX_COUNT = 2, LINE_SPACE = 40, kItemTagBasic = 1000, }; static const std::string testsName[MAX_COUNT] = { - "NotificationCenterTest" + "NotificationCenterTest", + "CCControlButtonTest" }; //////////////////////////////////////////////////////// @@ -51,6 +52,13 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender) case 0: runNotificationCenterTest(); break; + case 1: + { + CCControlSceneManager* pManager = sharedControlSceneManager(); + CCScene* pScene = pManager->currentControlScene(); + CCDirector::sharedDirector()->replaceScene(pScene); + } + break; default: break; }