2012-04-19 14:35:52 +08:00
|
|
|
#include "BugsTest.h"
|
|
|
|
#include "Bug-350.h"
|
|
|
|
#include "Bug-422.h"
|
|
|
|
#include "Bug-458/Bug-458.h"
|
|
|
|
#include "Bug-624.h"
|
|
|
|
#include "Bug-886.h"
|
|
|
|
#include "Bug-899.h"
|
|
|
|
#include "Bug-914.h"
|
|
|
|
#include "Bug-1159.h"
|
|
|
|
#include "Bug-1174.h"
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
#define TEST_BUG(__bug__) \
|
|
|
|
{ \
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* pScene = Scene::create(); \
|
2013-06-08 08:21:11 +08:00
|
|
|
Bug##__bug__##Layer* pLayer = new Bug##__bug__##Layer(); \
|
|
|
|
pLayer->init(); \
|
|
|
|
pScene->addChild(pLayer); \
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(pScene); \
|
2013-06-08 08:21:11 +08:00
|
|
|
pLayer->autorelease(); \
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 5432,
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Point s_tCurPos = PointZero;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
struct {
|
|
|
|
const char *test_name;
|
2013-06-20 14:17:10 +08:00
|
|
|
std::function<void(Object*)> callback;
|
2013-06-08 08:21:11 +08:00
|
|
|
} g_bugs[] = {
|
2013-06-20 14:17:10 +08:00
|
|
|
{ "Bug-350", [](Object* sender){ TEST_BUG(350)} },
|
|
|
|
{ "Bug-422", [](Object* sender){ TEST_BUG(422)} },
|
|
|
|
{ "Bug-458", [](Object* sender){ TEST_BUG(458)} },
|
|
|
|
{ "Bug-624", [](Object* sender){ TEST_BUG(624)} },
|
|
|
|
{ "Bug-886", [](Object* sender){ TEST_BUG(886)} },
|
|
|
|
{ "Bug-899", [](Object* sender){ TEST_BUG(899)} },
|
|
|
|
{ "Bug-914", [](Object* sender){ TEST_BUG(914)} },
|
|
|
|
{ "Bug-1159", [](Object* sender){ TEST_BUG(1159)} },
|
|
|
|
{ "Bug-1174", [](Object* sender){ TEST_BUG(1174)} },
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
static const int g_maxitems = sizeof(g_bugs) / sizeof(g_bugs[0]);
|
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// BugsTestMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void BugsTestMainLayer::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size s = Director::sharedDirector()->getWinSize();
|
|
|
|
_itmeMenu = Menu::create();
|
|
|
|
MenuItemFont::setFontName("Arial");
|
|
|
|
MenuItemFont::setFontSize(24);
|
2013-06-08 08:21:11 +08:00
|
|
|
for (int i = 0; i < g_maxitems; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont* pItem = MenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback);
|
2012-04-19 14:35:52 +08:00
|
|
|
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2013-06-15 14:03:30 +08:00
|
|
|
_itmeMenu->addChild(pItem, kItemTagBasic + i);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_itmeMenu->setPosition(s_tCurPos);
|
|
|
|
addChild(_itmeMenu);
|
2012-06-15 15:10:40 +08:00
|
|
|
setTouchEnabled(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void BugsTestMainLayer::ccTouchesBegan(Set *pTouches, Event *pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 11:02:43 +08:00
|
|
|
Touch* touch = (Touch*) pTouches->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-06-20 14:17:10 +08:00
|
|
|
void BugsTestMainLayer::ccTouchesMoved(Set *pTouches, Event *pEvent)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 11:02:43 +08:00
|
|
|
Touch* touch = (Touch*) pTouches->anyObject();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Point 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-06-20 14:17:10 +08:00
|
|
|
Point curPos = _itmeMenu->getPosition();
|
|
|
|
Point nextPos = ccp(curPos.x, curPos.y + nMoveY);
|
|
|
|
Size winSize = Director::sharedDirector()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
_itmeMenu->setPosition(PointZero);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
if (nextPos.y > ((g_maxitems + 1)* LINE_SPACE - winSize.height))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_itmeMenu->setPosition(ccp(0, ((g_maxitems + 1)* LINE_SPACE - winSize.height)));
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_itmeMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
2012-04-19 14:35:52 +08:00
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// BugsTestBaseLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void BugsTestBaseLayer::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
MenuItemFont::setFontName("Arial");
|
|
|
|
MenuItemFont::setFontSize(24);
|
|
|
|
MenuItemFont* pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(BugsTestBaseLayer::backCallback, this));
|
2012-10-23 17:48:50 +08:00
|
|
|
pMainItem->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu* pMenu = Menu::create(pMainItem, NULL);
|
|
|
|
pMenu->setPosition( PointZero );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(pMenu);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void BugsTestBaseLayer::backCallback(Object* pSender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
// Director::sharedDirector()->enableRetinaDisplay(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
BugsTestScene* pScene = new BugsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->autorelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// BugsTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void BugsTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* pLayer = new BugsTestMainLayer();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Director::sharedDirector()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|