mirror of https://github.com/axmolengine/axmol.git
issue #574, Add DirectorTest for win32.
This commit is contained in:
parent
2bc8427b3c
commit
26513d6b7e
|
@ -963,6 +963,18 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="DirectorTest"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\DirectorTest\DirectorTest.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\tests\DirectorTest\DirectorTest.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
|
|
|
@ -0,0 +1,216 @@
|
||||||
|
#include "DirectorTest.h"
|
||||||
|
#include "../testResource.h"
|
||||||
|
|
||||||
|
#define MAX_LAYER 1
|
||||||
|
|
||||||
|
static int sceneIdx=-1;
|
||||||
|
static ccDeviceOrientation s_currentOrientation = CCDeviceOrientationPortrait;
|
||||||
|
|
||||||
|
CCLayer* createTestCaseLayer(int index)
|
||||||
|
{
|
||||||
|
switch (index)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
Director1* pRet = new Director1();
|
||||||
|
pRet->init();
|
||||||
|
pRet->autorelease();
|
||||||
|
return pRet;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLayer* nextDirectorTestCase()
|
||||||
|
{
|
||||||
|
sceneIdx++;
|
||||||
|
sceneIdx = sceneIdx % MAX_LAYER;
|
||||||
|
|
||||||
|
return createTestCaseLayer(sceneIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLayer* backDirectorTestCase()
|
||||||
|
{
|
||||||
|
sceneIdx--;
|
||||||
|
if( sceneIdx < 0 )
|
||||||
|
sceneIdx += MAX_LAYER;
|
||||||
|
|
||||||
|
return createTestCaseLayer(sceneIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
CCLayer* restartDirectorTestCase()
|
||||||
|
{
|
||||||
|
return createTestCaseLayer(sceneIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
///---------------------------------------
|
||||||
|
//
|
||||||
|
// DirectorTest
|
||||||
|
//
|
||||||
|
///---------------------------------------
|
||||||
|
bool DirectorTest::init()
|
||||||
|
{
|
||||||
|
bool bRet = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
CC_BREAK_IF(! CCLayer::init());
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
CCLabelTTF *label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 26);
|
||||||
|
addChild(label, 1);
|
||||||
|
label->setPosition(ccp(s.width/2, s.height-50));
|
||||||
|
|
||||||
|
std::string sSubtitle = subtitle();
|
||||||
|
if (sSubtitle.length())
|
||||||
|
{
|
||||||
|
CCLabelTTF *l = CCLabelTTF::labelWithString(sSubtitle.c_str(), "Thonburi", 16);
|
||||||
|
addChild(l, 1);
|
||||||
|
l->setPosition(ccp(s.width/2, s.height-80));
|
||||||
|
}
|
||||||
|
|
||||||
|
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(DirectorTest::backCallback));
|
||||||
|
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(DirectorTest::restartCallback));
|
||||||
|
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(DirectorTest::nextCallback));
|
||||||
|
|
||||||
|
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
|
||||||
|
menu->setPosition(CCPointZero);
|
||||||
|
item1->setPosition(ccp( s.width/2 - 100,30));
|
||||||
|
item2->setPosition(ccp( s.width/2, 30));
|
||||||
|
item3->setPosition(ccp( s.width/2 + 100,30));
|
||||||
|
|
||||||
|
bRet = true;
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectorTest::restartCallback(CCObject* pSender)
|
||||||
|
{
|
||||||
|
CCScene *s = new DirectorTestScene();
|
||||||
|
s->addChild(restartDirectorTestCase());
|
||||||
|
CCDirector::sharedDirector()->replaceScene(s);
|
||||||
|
s->autorelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectorTest::nextCallback(CCObject* pSender)
|
||||||
|
{
|
||||||
|
CCScene *s = new DirectorTestScene();
|
||||||
|
s->addChild(nextDirectorTestCase());
|
||||||
|
CCDirector::sharedDirector()->replaceScene(s);
|
||||||
|
s->autorelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectorTest::backCallback(CCObject* pSender)
|
||||||
|
{
|
||||||
|
CCScene *s = new DirectorTestScene();
|
||||||
|
s->addChild(backDirectorTestCase());
|
||||||
|
CCDirector::sharedDirector()->replaceScene(s);
|
||||||
|
s->autorelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DirectorTest::title()
|
||||||
|
{
|
||||||
|
return "No title";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DirectorTest::subtitle()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
///---------------------------------------
|
||||||
|
//
|
||||||
|
// Director1
|
||||||
|
//
|
||||||
|
///---------------------------------------
|
||||||
|
bool Director1::init()
|
||||||
|
{
|
||||||
|
bool bRet = false;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
CC_BREAK_IF(! DirectorTest::init());
|
||||||
|
|
||||||
|
setIsTouchEnabled(true);
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
CCMenuItem *item = CCMenuItemFont::itemFromString("Rotate Device", this, menu_selector(Director1::rotateDevice));
|
||||||
|
CCMenu *menu = CCMenu::menuWithItems(item, NULL);
|
||||||
|
menu->setPosition(ccp( s.width/2, s.height/2));
|
||||||
|
addChild(menu);
|
||||||
|
|
||||||
|
bRet = true;
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director1::newOrientation()
|
||||||
|
{
|
||||||
|
switch (s_currentOrientation)
|
||||||
|
{
|
||||||
|
case CCDeviceOrientationLandscapeLeft:
|
||||||
|
s_currentOrientation = CCDeviceOrientationPortrait;
|
||||||
|
break;
|
||||||
|
case CCDeviceOrientationPortrait:
|
||||||
|
s_currentOrientation = CCDeviceOrientationLandscapeRight;
|
||||||
|
break;
|
||||||
|
case CCDeviceOrientationLandscapeRight:
|
||||||
|
s_currentOrientation = CCDeviceOrientationPortraitUpsideDown;
|
||||||
|
break;
|
||||||
|
case CCDeviceOrientationPortraitUpsideDown:
|
||||||
|
s_currentOrientation = CCDeviceOrientationLandscapeLeft;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
CCDirector::sharedDirector()->setDeviceOrientation(s_currentOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director1::rotateDevice(CCObject* pSender)
|
||||||
|
{
|
||||||
|
newOrientation();
|
||||||
|
restartCallback(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Director1::ccTouchesEnded(CCSet * touches, CCEvent* event)
|
||||||
|
{
|
||||||
|
CCSetIterator it;
|
||||||
|
CCTouch* touch;
|
||||||
|
|
||||||
|
for( it = touches->begin(); it != touches->end(); it++)
|
||||||
|
{
|
||||||
|
touch = (CCTouch*)(*it);
|
||||||
|
|
||||||
|
if(!touch)
|
||||||
|
break;
|
||||||
|
CCPoint a = touch->locationInView(touch->view());
|
||||||
|
|
||||||
|
CCDirector *director = CCDirector::sharedDirector();
|
||||||
|
CCPoint b = director->convertToUI(director->convertToGL(a));
|
||||||
|
CCLog("(%d,%d) == (%d,%d)", (int) a.x, (int)a.y, (int)b.x, (int)b.y );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Director1::title()
|
||||||
|
{
|
||||||
|
return "Testing conversion";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Director1::subtitle()
|
||||||
|
{
|
||||||
|
return "Tap screen and see the debug console";
|
||||||
|
}
|
||||||
|
|
||||||
|
///---------------------------------------
|
||||||
|
//
|
||||||
|
// DirectorTestScene
|
||||||
|
//
|
||||||
|
///---------------------------------------
|
||||||
|
void DirectorTestScene::runThisTest()
|
||||||
|
{
|
||||||
|
s_currentOrientation = CCDeviceOrientationPortrait;
|
||||||
|
CCLayer* pLayer = nextDirectorTestCase();
|
||||||
|
addChild(pLayer);
|
||||||
|
|
||||||
|
CCDirector::sharedDirector()->replaceScene(this);
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef __DIRECTOR_TEST_H__
|
||||||
|
#define __DIRECTOR_TEST_H__
|
||||||
|
|
||||||
|
#include "../testBasic.h"
|
||||||
|
|
||||||
|
class DirectorTest: public CCLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool init();
|
||||||
|
|
||||||
|
void restartCallback(CCObject* pSender);
|
||||||
|
void nextCallback(CCObject* pSender);
|
||||||
|
void backCallback(CCObject* pSender);
|
||||||
|
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Director1 : public DirectorTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual bool init();
|
||||||
|
|
||||||
|
void newOrientation();
|
||||||
|
void rotateDevice(CCObject* pSender);
|
||||||
|
void ccTouchesEnded(CCSet * touches, CCEvent* event);
|
||||||
|
|
||||||
|
virtual std::string title();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
};
|
||||||
|
|
||||||
|
class DirectorTestScene : public TestScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void runThisTest();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -5,14 +5,9 @@
|
||||||
|
|
||||||
static CCPoint s_tCurPos = CCPointZero;
|
static CCPoint s_tCurPos = CCPointZero;
|
||||||
|
|
||||||
static ccDeviceOrientation s_eOrientation = CCDeviceOrientationPortrait;
|
|
||||||
static void ChangeOrientation(ccDeviceOrientation eOrientation)
|
static void ChangeOrientation(ccDeviceOrientation eOrientation)
|
||||||
{
|
{
|
||||||
if (s_eOrientation != eOrientation)
|
CCDirector::sharedDirector()->setDeviceOrientation(eOrientation);
|
||||||
{
|
|
||||||
s_eOrientation = eOrientation;
|
|
||||||
CCDirector::sharedDirector()->setDeviceOrientation(eOrientation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static TestScene* CreateTestScene(int nIdx)
|
static TestScene* CreateTestScene(int nIdx)
|
||||||
|
@ -110,6 +105,8 @@ static TestScene* CreateTestScene(int nIdx)
|
||||||
case TEST_USERDEFAULT:
|
case TEST_USERDEFAULT:
|
||||||
pScene = new UserDefaultTestScene(); break;
|
pScene = new UserDefaultTestScene(); break;
|
||||||
#endif
|
#endif
|
||||||
|
case TEST_DIRECTOR:
|
||||||
|
pScene = new DirectorTestScene(); break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "CocosDenshionTest/CocosDenshionTest.h"
|
#include "CocosDenshionTest/CocosDenshionTest.h"
|
||||||
#include "CurlTest/CurlTest.h"
|
#include "CurlTest/CurlTest.h"
|
||||||
#include "UserDefaultTest/UserDefaultTest.h"
|
#include "UserDefaultTest/UserDefaultTest.h"
|
||||||
|
#include "DirectorTest/DirectorTest.h"
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
|
||||||
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
|
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
|
||||||
|
@ -88,6 +89,7 @@ enum
|
||||||
TEST_ZWOPTEX,
|
TEST_ZWOPTEX,
|
||||||
TEST_CURL,
|
TEST_CURL,
|
||||||
TEST_USERDEFAULT,
|
TEST_USERDEFAULT,
|
||||||
|
TEST_DIRECTOR,
|
||||||
|
|
||||||
TESTS_COUNT,
|
TESTS_COUNT,
|
||||||
};
|
};
|
||||||
|
@ -128,7 +130,8 @@ const std::string g_aTestNames[TESTS_COUNT] = {
|
||||||
"PerformanceTest",
|
"PerformanceTest",
|
||||||
"ZwoptexTest",
|
"ZwoptexTest",
|
||||||
"CurlTest",
|
"CurlTest",
|
||||||
"UserDefaultTest"
|
"UserDefaultTest",
|
||||||
|
"DirectorTest"
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue