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-07-23 08:25:44 +08:00
|
|
|
Scene* scene = Scene::create(); \
|
|
|
|
Bug##__bug__##Layer* layer = new Bug##__bug__##Layer(); \
|
|
|
|
layer->init(); \
|
|
|
|
scene->addChild(layer); \
|
|
|
|
Director::getInstance()->replaceScene(scene); \
|
|
|
|
layer->autorelease(); \
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 5432,
|
|
|
|
};
|
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
static Point s_tCurPos = Point::ZERO;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-08 08:21:11 +08:00
|
|
|
struct {
|
|
|
|
const char *test_name;
|
2014-02-20 10:53:49 +08:00
|
|
|
std::function<void(Ref*)> callback;
|
2013-06-08 08:21:11 +08:00
|
|
|
} g_bugs[] = {
|
2014-02-20 10:53:49 +08:00
|
|
|
{ "Bug-350", [](Ref* sender){ TEST_BUG(350)} },
|
|
|
|
{ "Bug-422", [](Ref* sender){ TEST_BUG(422)} },
|
|
|
|
{ "Bug-458", [](Ref* sender){ TEST_BUG(458)} },
|
|
|
|
{ "Bug-624", [](Ref* sender){ TEST_BUG(624)} },
|
|
|
|
{ "Bug-886", [](Ref* sender){ TEST_BUG(886)} },
|
|
|
|
{ "Bug-899", [](Ref* sender){ TEST_BUG(899)} },
|
|
|
|
{ "Bug-914", [](Ref* sender){ TEST_BUG(914)} },
|
|
|
|
{ "Bug-1159", [](Ref* sender){ TEST_BUG(1159)} },
|
|
|
|
{ "Bug-1174", [](Ref* 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-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-06-20 14:17:10 +08:00
|
|
|
_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-08-16 16:05:27 +08:00
|
|
|
auto pItem = MenuItemFont::create(g_bugs[i].test_name, g_bugs[i].callback);
|
2013-07-12 14:11:55 +08:00
|
|
|
pItem->setPosition(Point(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);
|
2013-10-23 16:14:03 +08:00
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(BugsTestMainLayer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(BugsTestMainLayer::onTouchesMoved, this);
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void BugsTestMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
_beginPos = touches[0]->getLocation();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void BugsTestMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touchLocation = touches[0]->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 = _itmeMenu->getPosition();
|
|
|
|
auto nextPos = Point(curPos.x, curPos.y + nMoveY);
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2013-07-12 14:47:36 +08:00
|
|
|
_itmeMenu->setPosition(Point::ZERO);
|
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-07-12 14:11:55 +08:00
|
|
|
_itmeMenu->setPosition(Point(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);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pMainItem = MenuItemFont::create("Back", CC_CALLBACK_1(BugsTestBaseLayer::backCallback, this));
|
2013-07-12 14:11:55 +08:00
|
|
|
pMainItem->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(pMainItem, NULL);
|
2013-07-24 06:20:22 +08:00
|
|
|
menu->setPosition( Point::ZERO );
|
|
|
|
addChild(menu);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void BugsTestBaseLayer::backCallback(Ref* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
// Director::getInstance()->enableRetinaDisplay(false);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = new BugsTestScene();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->runThisTest();
|
|
|
|
scene->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// BugsTestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void BugsTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new BugsTestMainLayer();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|