2013-06-04 13:33:52 +08:00
|
|
|
|
|
|
|
// C++ includes
|
|
|
|
#include <map>
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
// test inclues
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "controller.h"
|
|
|
|
#include "testResource.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
|
|
|
|
2013-06-05 01:03:32 +08:00
|
|
|
struct {
|
|
|
|
const char *test_name;
|
|
|
|
std::function<TestScene*()> callback;
|
|
|
|
} g_aTestNames[] = {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "Accelerometer", []() { return new AccelerometerTestScene(); } },
|
|
|
|
{ "ActionManagerTest", [](){return new ActionManagerTestScene(); } },
|
|
|
|
{ "ActionsEaseTest", [](){return new ActionsEaseTestScene();} },
|
|
|
|
{ "ActionsProgressTest", [](){return new ProgressActionsTestScene(); } },
|
|
|
|
{ "ActionsTest", [](){ return new ActionsTestScene(); } },
|
|
|
|
{ "Box2dTest", []() { return new Box2DTestScene(); } },
|
|
|
|
{ "Box2dTestBed", []() { return new Box2dTestBedScene(); } },
|
|
|
|
{ "BugsTest", []() { return new BugsTestScene(); } },
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "ChipmunkTest", []() { return new ChipmunkAccelTouchTestScene(); } },
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "ClickAndMoveTest", [](){return new ClickAndMoveTestScene(); } },
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "ClippingNodeTest", []() { return new ClippingNodeTestScene(); } },
|
2012-11-25 03:14:01 +08:00
|
|
|
#endif
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "CocosDenshionTest", []() { return new CocosDenshionTestScene(); } },
|
|
|
|
{ "ConfigurationTest", []() { return new ConfigurationTestScene(); } },
|
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
|
2013-06-21 03:15:42 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_NACL)
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2012-04-19 14:35:52 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "CurlTest", []() { return new CurlTestScene(); } },
|
2013-06-02 10:28:46 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif
|
2013-06-21 03:15:42 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "CurrentLanguageTest", []() { return new CurrentLanguageTestScene(); } },
|
|
|
|
{ "DrawPrimitivesTest", [](){return new DrawPrimitivesTestScene();} },
|
|
|
|
{ "EffectAdvancedTest", []() { return new EffectAdvanceScene(); } },
|
|
|
|
{ "EffectsTest", [](){return new EffectTestScene();} },
|
|
|
|
{ "ExtensionsTest", []() { return new ExtensionsTestScene(); } },
|
|
|
|
{ "FileUtilsTest", []() { return new FileUtilsTestScene(); } },
|
|
|
|
{ "FontTest", []() { return new FontTestScene(); } },
|
|
|
|
{ "IntervalTest", [](){return new IntervalTestScene(); } },
|
2013-06-29 10:02:10 +08:00
|
|
|
#ifdef CC_KEYBOARD_SUPPORT
|
2013-06-06 15:42:18 +08:00
|
|
|
{ "KeyboardTest", []() { return new KeyboardTestScene(); } },
|
|
|
|
#endif
|
2013-06-04 13:47:28 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA)
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "KeypadTest", []() { return new KeypadTestScene(); } },
|
2012-04-19 14:35:52 +08:00
|
|
|
#endif
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "LabelTest", [](){return new AtlasTestScene(); } },
|
2013-08-13 04:29:54 +08:00
|
|
|
{ "LabelTestNew", [](){return new AtlasTestSceneNew(); } },
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "LayerTest", [](){return new LayerTestScene();} },
|
|
|
|
{ "MenuTest", [](){return new MenuTestScene();} },
|
|
|
|
{ "MotionStreakTest", [](){return new MotionStreakTestScene();} },
|
2013-06-04 13:47:28 +08:00
|
|
|
{ "MutiTouchTest", []() { return new MutiTouchTestScene(); } },
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "NodeTest", [](){return new CocosNodeTestScene();} },
|
|
|
|
{ "ParallaxTest", [](){return new ParallaxTestScene(); } },
|
|
|
|
{ "ParticleTest", [](){return new ParticleTestScene(); } },
|
|
|
|
{ "PerformanceTest", []() { return new PerformanceTestScene(); } },
|
|
|
|
{ "RenderTextureTest", [](){return new RenderTextureScene(); } },
|
|
|
|
{ "RotateWorldTest", [](){return new RotateWorldTestScene(); } },
|
|
|
|
{ "SceneTest", [](){return new SceneTestScene();} },
|
|
|
|
{ "SchedulerTest", [](){return new SchedulerTestScene(); } },
|
|
|
|
{ "ShaderTest", []() { return new ShaderTestScene(); } },
|
2013-09-09 21:33:01 +08:00
|
|
|
{ "ShaderTestSprite", []() { return new ShaderTestScene2(); } },
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "SpineTest", []() { return new SpineTestScene(); } },
|
|
|
|
{ "SpriteTest", [](){return new SpriteTestScene(); } },
|
|
|
|
{ "TextInputTest", [](){return new TextInputTestScene(); } },
|
|
|
|
{ "Texture2DTest", [](){return new TextureTestScene(); } },
|
2012-11-25 03:14:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "TextureCacheTest", []() { return new TextureCacheTestScene(); } },
|
2012-11-25 03:14:01 +08:00
|
|
|
#endif
|
2013-06-04 13:47:28 +08:00
|
|
|
{ "TexturePackerEncryption", []() { return new TextureAtlasEncryptionTestScene(); } },
|
2013-06-04 13:33:52 +08:00
|
|
|
{ "TileMapTest", [](){return new TileMapTestScene(); } },
|
|
|
|
{ "TouchesTest", [](){return new PongScene();} },
|
|
|
|
{ "TransitionsTest", [](){return new TransitionsTestScene();} },
|
|
|
|
{ "UserDefaultTest", []() { return new UserDefaultTestScene(); } },
|
|
|
|
{ "ZwoptexTest", []() { return new ZwoptexTestScene(); } },
|
|
|
|
};
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-05 01:03:32 +08:00
|
|
|
static int g_testCount = sizeof(g_aTestNames) / sizeof(g_aTestNames[0]);
|
2013-06-04 13:33:52 +08:00
|
|
|
|
|
|
|
#define LINE_SPACE 40
|
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
static Point s_tCurPos = Point::ZERO;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
TestController::TestController()
|
2013-07-12 14:47:36 +08:00
|
|
|
: _beginPos(Point::ZERO)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// add close menu
|
2013-08-16 16:05:27 +08:00
|
|
|
auto closeItem = MenuItemImage::create(s_pathClose, s_pathClose, CC_CALLBACK_1(TestController::closeCallback, this) );
|
|
|
|
auto menu =Menu::create(closeItem, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
menu->setPosition( Point::ZERO );
|
|
|
|
closeItem->setPosition(Point( VisibleRect::right().x - 30, VisibleRect::top().y - 30));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add menu items for tests
|
2013-06-20 14:17:10 +08:00
|
|
|
_itemMenu = Menu::create();
|
2013-06-04 13:33:52 +08:00
|
|
|
for (int i = 0; i < g_testCount; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
2013-08-16 16:05:27 +08:00
|
|
|
// auto label = LabelBMFont::create(g_aTestNames[i].c_str(), "fonts/arial16.fnt");
|
2012-04-19 14:35:52 +08:00
|
|
|
// #else
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create( g_aTestNames[i].test_name, "Arial", 24);
|
2012-04-19 14:35:52 +08:00
|
|
|
// #endif
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menuItem = MenuItemLabel::create(label, CC_CALLBACK_1(TestController::menuCallback, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
_itemMenu->addChild(menuItem, i + 10000);
|
|
|
|
menuItem->setPosition( Point( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
_itemMenu->setContentSize(Size(VisibleRect::getVisibleRect().size.width, (g_testCount + 1) * (LINE_SPACE)));
|
2013-06-15 14:03:30 +08:00
|
|
|
_itemMenu->setPosition(s_tCurPos);
|
|
|
|
addChild(_itemMenu);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
addChild(menu, 1);
|
2012-04-27 18:47:49 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestController::~TestController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestController::menuCallback(Object * sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-04 13:47:28 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->purgeCachedData();
|
2013-06-04 13:47:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// get the userdata, it's the index of the menu item clicked
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menuItem = static_cast<MenuItem *>(sender);
|
2013-07-24 06:20:22 +08:00
|
|
|
int idx = menuItem->getZOrder() - 10000;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create the test scene and run it
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = g_aTestNames[idx].callback();
|
2013-06-04 13:47:28 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
if (scene)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestController::closeCallback(Object * sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->end();
|
2012-04-19 14:35:52 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
exit(0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestController::ccTouchesBegan(Set *touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touch = static_cast<Touch*>(touches->anyObject());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_beginPos = touch->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestController::ccTouchesMoved(Set *touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touch = static_cast<Touch*>(touches->anyObject());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto touchLocation = touch->getLocation();
|
2013-06-15 14:03:30 +08:00
|
|
|
float nMoveY = touchLocation.y - _beginPos.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto curPos = _itemMenu->getPosition();
|
|
|
|
auto nextPos = Point(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)
|
|
|
|
{
|
2013-07-12 14:47:36 +08:00
|
|
|
_itemMenu->setPosition(Point::ZERO);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-04 13:33:52 +08:00
|
|
|
if (nextPos.y > ((g_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
_itemMenu->setPosition(Point(0, ((g_testCount + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
2012-04-19 14:35:52 +08:00
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|