2012-04-19 14:35:52 +08:00
|
|
|
#include "controller.h"
|
|
|
|
#include "testResource.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
#define LINE_SPACE 40
|
|
|
|
|
|
|
|
static CCPoint s_tCurPos = CCPointZero;
|
|
|
|
|
|
|
|
static TestScene* CreateTestScene(int nIdx)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->purgeCachedData();
|
|
|
|
|
|
|
|
TestScene* pScene = NULL;
|
|
|
|
|
|
|
|
switch (nIdx)
|
|
|
|
{
|
|
|
|
case TEST_ACTIONS:
|
|
|
|
pScene = new ActionsTestScene(); break;
|
|
|
|
case TEST_TRANSITIONS:
|
|
|
|
pScene = new TransitionsTestScene(); break;
|
|
|
|
case TEST_PROGRESS_ACTIONS:
|
|
|
|
pScene = new ProgressActionsTestScene(); break;
|
|
|
|
case TEST_EFFECTS:
|
|
|
|
pScene = new EffectTestScene(); break;
|
|
|
|
case TEST_CLICK_AND_MOVE:
|
|
|
|
pScene = new ClickAndMoveTestScene(); break;
|
|
|
|
case TEST_ROTATE_WORLD:
|
|
|
|
pScene = new RotateWorldTestScene(); break;
|
|
|
|
case TEST_PARTICLE:
|
|
|
|
pScene = new ParticleTestScene(); break;
|
|
|
|
case TEST_EASE_ACTIONS:
|
|
|
|
pScene = new ActionsEaseTestScene(); break;
|
|
|
|
case TEST_MOTION_STREAK:
|
|
|
|
pScene = new MotionStreakTestScene(); break;
|
|
|
|
case TEST_DRAW_PRIMITIVES:
|
|
|
|
pScene = new DrawPrimitivesTestScene(); break;
|
|
|
|
case TEST_COCOSNODE:
|
|
|
|
pScene = new CocosNodeTestScene(); break;
|
|
|
|
case TEST_TOUCHES:
|
|
|
|
pScene = new PongScene(); break;
|
|
|
|
case TEST_MENU:
|
|
|
|
pScene = new MenuTestScene(); break;
|
|
|
|
case TEST_ACTION_MANAGER:
|
|
|
|
pScene = new ActionManagerTestScene(); break;
|
|
|
|
case TEST_LAYER:
|
|
|
|
pScene = new LayerTestScene(); break;
|
|
|
|
case TEST_SCENE:
|
|
|
|
pScene = new SceneTestScene(); break;
|
|
|
|
case TEST_PARALLAX:
|
|
|
|
pScene = new ParallaxTestScene(); break;
|
|
|
|
case TEST_TILE_MAP:
|
|
|
|
pScene = new TileMapTestScene(); break;
|
|
|
|
case TEST_INTERVAL:
|
|
|
|
pScene = new IntervalTestScene(); break;
|
|
|
|
case TEST_LABEL:
|
|
|
|
pScene = new AtlasTestScene(); break;
|
|
|
|
case TEST_TEXT_INPUT:
|
|
|
|
pScene = new TextInputTestScene(); break;
|
|
|
|
case TEST_SPRITE:
|
|
|
|
pScene = new SpriteTestScene(); break;
|
|
|
|
case TEST_SCHEDULER:
|
|
|
|
pScene = new SchedulerTestScene(); break;
|
|
|
|
case TEST_RENDERTEXTURE:
|
|
|
|
pScene = new RenderTextureScene(); break;
|
|
|
|
case TEST_TEXTURE2D:
|
|
|
|
pScene = new TextureTestScene(); break;
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2012-11-21 12:02:29 +08:00
|
|
|
case TEST_CHIPMUNK:
|
|
|
|
pScene = new ChipmunkAccelTouchTestScene(); break;
|
2012-11-25 03:14:01 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
case TEST_BOX2D:
|
|
|
|
pScene = new Box2DTestScene(); break;
|
|
|
|
case TEST_BOX2DBED:
|
|
|
|
pScene = new Box2dTestBedScene(); break;
|
|
|
|
case TEST_EFFECT_ADVANCE:
|
|
|
|
pScene = new EffectAdvanceScene(); break;
|
|
|
|
case TEST_ACCELEROMRTER:
|
|
|
|
pScene = new AccelerometerTestScene(); break;
|
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
|
|
|
case TEST_KEYPAD:
|
|
|
|
pScene = new KeypadTestScene(); break;
|
2013-05-31 20:29:32 +08:00
|
|
|
case TEST_KEYBOARD:
|
|
|
|
pScene = new KeyboardTestScene(); break;
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif
|
|
|
|
case TEST_COCOSDENSHION:
|
|
|
|
pScene = new CocosDenshionTestScene(); break;
|
|
|
|
case TEST_PERFORMANCE:
|
|
|
|
pScene = new PerformanceTestScene(); break;
|
|
|
|
case TEST_ZWOPTEX:
|
|
|
|
pScene = new ZwoptexTestScene(); break;
|
|
|
|
// bada don't support libcurl
|
2013-04-09 10:13:22 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA && CC_TARGET_PLATFORM != CC_PLATFORM_NACL && CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE && CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
|
2012-04-19 14:35:52 +08:00
|
|
|
case TEST_CURL:
|
|
|
|
pScene = new CurlTestScene(); break;
|
|
|
|
#endif
|
|
|
|
case TEST_USERDEFAULT:
|
|
|
|
pScene = new UserDefaultTestScene(); break;
|
|
|
|
case TEST_BUGS:
|
|
|
|
pScene = new BugsTestScene(); break;
|
|
|
|
case TEST_FONTS:
|
|
|
|
pScene = new FontTestScene(); break;
|
|
|
|
case TEST_CURRENT_LANGUAGE:
|
|
|
|
pScene = new CurrentLanguageTestScene(); break;
|
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
|
|
|
case TEST_TEXTURECACHE: pScene = new TextureCacheTestScene(); break;
|
|
|
|
#endif
|
|
|
|
case TEST_EXTENSIONS:
|
2013-03-02 01:09:58 +08:00
|
|
|
pScene = new ExtensionsTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
case TEST_SHADER:
|
|
|
|
pScene = new ShaderTestScene();
|
|
|
|
break;
|
2012-04-23 14:30:38 +08:00
|
|
|
case TEST_MUTITOUCH:
|
|
|
|
pScene = new MutiTouchTestScene();
|
|
|
|
break;
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2012-11-21 15:22:54 +08:00
|
|
|
case TEST_CLIPPINGNODE:
|
|
|
|
pScene = new ClippingNodeTestScene();
|
|
|
|
break;
|
2012-11-25 03:14:01 +08:00
|
|
|
#endif
|
2013-01-28 15:17:20 +08:00
|
|
|
case TEST_FILEUTILS:
|
|
|
|
pScene = new FileUtilsTestScene();
|
|
|
|
break;
|
2013-04-24 13:57:34 +08:00
|
|
|
case TEST_SPINE:
|
|
|
|
pScene = new SpineTestScene();
|
|
|
|
break;
|
2013-04-26 01:40:49 +08:00
|
|
|
case TEST_TEXTUREPACKER_ENCRYPTION:
|
|
|
|
pScene = new TextureAtlasEncryptionTestScene();
|
|
|
|
break;
|
2013-05-10 15:07:05 +08:00
|
|
|
case TEST_DATAVISTOR:
|
|
|
|
pScene = new DataVisitorTestScene();
|
|
|
|
break;
|
2013-05-23 08:56:05 +08:00
|
|
|
case TEST_CONFIGURATION:
|
|
|
|
pScene = new ConfigurationTestScene();
|
|
|
|
break;
|
|
|
|
default:
|
2012-04-19 14:35:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pScene;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestController::TestController()
|
|
|
|
: m_tBeginPos(CCPointZero)
|
|
|
|
{
|
|
|
|
// add close menu
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) );
|
|
|
|
CCMenu* pMenu =CCMenu::create(pCloseItem, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
pMenu->setPosition( CCPointZero );
|
2012-10-23 17:48:50 +08:00
|
|
|
pCloseItem->setPosition(ccp( VisibleRect::right().x - 30, VisibleRect::top().y - 30));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add menu items for tests
|
2012-06-14 15:13:16 +08:00
|
|
|
m_pItemMenu = CCMenu::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
for (int i = 0; i < TESTS_COUNT; ++i)
|
|
|
|
{
|
|
|
|
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
2012-06-14 15:13:16 +08:00
|
|
|
// CCLabelBMFont* label = CCLabelBMFont::create(g_aTestNames[i].c_str(), "fonts/arial16.fnt");
|
2012-04-19 14:35:52 +08:00
|
|
|
// #else
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF* label = CCLabelTTF::create(g_aTestNames[i].c_str(), "Arial", 24);
|
2012-04-19 14:35:52 +08:00
|
|
|
// #endif
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestController::menuCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
m_pItemMenu->addChild(pMenuItem, i + 10000);
|
2012-10-23 17:48:50 +08:00
|
|
|
pMenuItem->setPosition( ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
m_pItemMenu->setContentSize(CCSizeMake(VisibleRect::getVisibleRect().size.width, (TESTS_COUNT + 1) * (LINE_SPACE)));
|
2012-04-19 14:35:52 +08:00
|
|
|
m_pItemMenu->setPosition(s_tCurPos);
|
|
|
|
addChild(m_pItemMenu);
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(pMenu, 1);
|
2012-04-27 18:47:49 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestController::~TestController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::menuCallback(CCObject * pSender)
|
|
|
|
{
|
|
|
|
// get the userdata, it's the index of the menu item clicked
|
|
|
|
CCMenuItem* pMenuItem = (CCMenuItem *)(pSender);
|
|
|
|
int nIdx = pMenuItem->getZOrder() - 10000;
|
|
|
|
|
|
|
|
// create the test scene and run it
|
|
|
|
TestScene* pScene = CreateTestScene(nIdx);
|
|
|
|
if (pScene)
|
|
|
|
{
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::closeCallback(CCObject * pSender)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->end();
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
exit(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
|
|
|
{
|
|
|
|
CCSetIterator it = pTouches->begin();
|
|
|
|
CCTouch* touch = (CCTouch*)(*it);
|
|
|
|
|
2012-07-31 17:41:53 +08:00
|
|
|
m_tBeginPos = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
|
|
|
|
{
|
|
|
|
CCSetIterator it = pTouches->begin();
|
|
|
|
CCTouch* touch = (CCTouch*)(*it);
|
|
|
|
|
2012-07-31 17:41:53 +08:00
|
|
|
CCPoint touchLocation = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
float nMoveY = touchLocation.y - m_tBeginPos.y;
|
|
|
|
|
|
|
|
CCPoint curPos = m_pItemMenu->getPosition();
|
|
|
|
CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
|
2012-10-23 17:48:50 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
|
|
|
m_pItemMenu->setPosition(CCPointZero);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
if (nextPos.y > ((TESTS_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-10-23 17:48:50 +08:00
|
|
|
m_pItemMenu->setPosition(ccp(0, ((TESTS_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pItemMenu->setPosition(nextPos);
|
|
|
|
m_tBeginPos = touchLocation;
|
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|