From 8ad7236ca2a7d66cca0b79749311e46ea0c1cc1d Mon Sep 17 00:00:00 2001 From: natural-law Date: Wed, 13 Jul 2011 16:17:50 +0800 Subject: [PATCH] fixed #599, Resolve the wrong orientation when exit the TouchesTest. --- tests/tests/DirectorTest/DirectorTest.cpp | 6 +++ tests/tests/DirectorTest/DirectorTest.h | 2 + tests/tests/HiResTest/HiResTest.cpp | 34 +++---------- tests/tests/HiResTest/HiResTest.h | 4 +- tests/tests/TouchesTest/TouchesTest.cpp | 5 +- tests/tests/TouchesTest/TouchesTest.h | 3 +- tests/tests/controller.cpp | 3 +- tests/tests/controller.h | 1 - tests/tests/testBasic.cpp | 59 +++++++++++------------ tests/tests/testBasic.h | 13 ++--- 10 files changed, 55 insertions(+), 75 deletions(-) diff --git a/tests/tests/DirectorTest/DirectorTest.cpp b/tests/tests/DirectorTest/DirectorTest.cpp index 5e0a83b449..2137052e84 100644 --- a/tests/tests/DirectorTest/DirectorTest.cpp +++ b/tests/tests/DirectorTest/DirectorTest.cpp @@ -218,3 +218,9 @@ void DirectorTestScene::runThisTest() CCDirector::sharedDirector()->replaceScene(this); } + +void DirectorTestScene::MainMenuCallback(CCObject* pSender) +{ + CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait); + TestScene::MainMenuCallback(pSender); +} diff --git a/tests/tests/DirectorTest/DirectorTest.h b/tests/tests/DirectorTest/DirectorTest.h index ee058c025f..e5d0ad1f6c 100644 --- a/tests/tests/DirectorTest/DirectorTest.h +++ b/tests/tests/DirectorTest/DirectorTest.h @@ -33,6 +33,8 @@ class DirectorTestScene : public TestScene { public: virtual void runThisTest(); + + virtual void MainMenuCallback(CCObject* pSender); }; #endif diff --git a/tests/tests/HiResTest/HiResTest.cpp b/tests/tests/HiResTest/HiResTest.cpp index 8224b98192..f0adfb77c2 100644 --- a/tests/tests/HiResTest/HiResTest.cpp +++ b/tests/tests/HiResTest/HiResTest.cpp @@ -52,25 +52,6 @@ CCLayer* backHiResAction() return pLayer; } -////////////////////////////////////////////////////////////////////////// -// HiResTestBackToMainMenuLayer -////////////////////////////////////////////////////////////////////////// -class HiResTestBackToainMenuLayer : public BackToMainMenuLayer -{ -public: - HiResTestBackToainMenuLayer() {} - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(CCObject* pSender) - { - CCDirector::sharedDirector()->enableRetinaDisplay(sm_bRitinaDisplay); - BackToMainMenuLayer::MainMenuCallback(pSender); - } - - static bool sm_bRitinaDisplay; -}; -bool HiResTestBackToainMenuLayer::sm_bRitinaDisplay = false; - //////////////////////////////////// // // HiResDemo @@ -222,9 +203,11 @@ std::string HiResTest2::subtitle() // HiResTestScene // /////////////////////////////////// +bool HiResTestScene::sm_bRitinaDisplay = false; + void HiResTestScene::runThisTest() { - HiResTestBackToainMenuLayer::sm_bRitinaDisplay = CCDirector::sharedDirector()->isRetinaDisplay(); + sm_bRitinaDisplay = CCDirector::sharedDirector()->isRetinaDisplay(); CCLayer* pLayer = nextHiResAction(); addChild(pLayer); @@ -233,13 +216,8 @@ void HiResTestScene::runThisTest() CCDirector::sharedDirector()->replaceScene(this); } -void HiResTestScene::onEnter() +void HiResTestScene::MainMenuCallback(CCObject* pSender) { - TestScene::onEnter(); - - CCLayer* pLayer = (CCLayer*)getChildByTag(54321); - removeChild(pLayer, true); - pLayer = new HiResTestBackToainMenuLayer; - addChild(pLayer, 1000, 54321); - pLayer->release(); + CCDirector::sharedDirector()->enableRetinaDisplay(sm_bRitinaDisplay); + TestScene::MainMenuCallback(pSender); } diff --git a/tests/tests/HiResTest/HiResTest.h b/tests/tests/HiResTest/HiResTest.h index 41b3c7818e..b77bbf1493 100644 --- a/tests/tests/HiResTest/HiResTest.h +++ b/tests/tests/HiResTest/HiResTest.h @@ -37,7 +37,9 @@ class HiResTestScene : public TestScene { public: virtual void runThisTest(); - virtual void onEnter(); + virtual void MainMenuCallback(CCObject* pSender); + + static bool sm_bRitinaDisplay; }; #endif diff --git a/tests/tests/TouchesTest/TouchesTest.cpp b/tests/tests/TouchesTest/TouchesTest.cpp index 5d44c13240..d62b43f6f9 100644 --- a/tests/tests/TouchesTest/TouchesTest.cpp +++ b/tests/tests/TouchesTest/TouchesTest.cpp @@ -31,9 +31,10 @@ PongScene::PongScene() pongLayer->release(); } -void PongScene::onExit() +void PongScene::MainMenuCallback(CCObject* pSender) { - TestScene::onExit(); + CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait); + TestScene::MainMenuCallback(pSender); } //------------------------------------------------------------------ diff --git a/tests/tests/TouchesTest/TouchesTest.h b/tests/tests/TouchesTest/TouchesTest.h index 6791fff38d..0db8ad3cbf 100644 --- a/tests/tests/TouchesTest/TouchesTest.h +++ b/tests/tests/TouchesTest/TouchesTest.h @@ -11,8 +11,9 @@ class PongScene : public TestScene public: PongScene(); - virtual void onExit(); virtual void runThisTest(); + + virtual void MainMenuCallback(CCObject* pSender); }; class Ball; diff --git a/tests/tests/controller.cpp b/tests/tests/controller.cpp index 5b80d238b6..7fa8bf8c45 100644 --- a/tests/tests/controller.cpp +++ b/tests/tests/controller.cpp @@ -1,5 +1,6 @@ #include "controller.h" #include "testResource.h" +#include "tests.h" #define LINE_SPACE 40 @@ -113,8 +114,6 @@ static TestScene* CreateTestScene(int nIdx) TestController::TestController() : m_tBeginPos(CCPointZero) { - CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationPortrait); - // add close menu CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) ); CCMenu* pMenu =CCMenu::menuWithItems(pCloseItem, NULL); diff --git a/tests/tests/controller.h b/tests/tests/controller.h index 450e1626cc..ea8f7ad697 100644 --- a/tests/tests/controller.h +++ b/tests/tests/controller.h @@ -2,7 +2,6 @@ #define _CONTROLLER_H_ #include "cocos2d.h" -#include "tests.h" using namespace cocos2d; diff --git a/tests/tests/testBasic.cpp b/tests/tests/testBasic.cpp index a0847d6539..e21b7d25c0 100644 --- a/tests/tests/testBasic.cpp +++ b/tests/tests/testBasic.cpp @@ -1,34 +1,6 @@ #include "testBasic.h" #include "controller.h" -BackToMainMenuLayer::BackToMainMenuLayer() -{ - //add the menu item for back to main menu -#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY) - CCLabelBMFont* label = CCLabelBMFont::bitmapFontAtlasWithString("MainMenu", "fonts/arial16.fnt"); -#else - CCLabelTTF* label = CCLabelTTF::labelWithString("MainMenu", "Arial", 20); -#endif - CCMenuItemLabel* pMenuItem = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(BackToMainMenuLayer::MainMenuCallback)); - - CCMenu* pMenu =CCMenu::menuWithItems(pMenuItem, NULL); - CCSize s = CCDirector::sharedDirector()->getWinSize(); - pMenu->setPosition( CCPointZero ); - pMenuItem->setPosition( CCPointMake( s.width - 50, 25) ); - - addChild(pMenu, 1); -} - -void BackToMainMenuLayer::MainMenuCallback(CCObject* pSender) -{ - CCScene* pScene = CCScene::node(); - CCLayer* pLayer = new TestController(); - pLayer->autorelease(); - - pScene->addChild(pLayer); - CCDirector::sharedDirector()->replaceScene(pScene); -} - TestScene::TestScene(bool bPortrait) :m_bPortrait(bPortrait) { @@ -38,9 +10,34 @@ TestScene::TestScene(bool bPortrait) } CCScene::init(); - CCLayer* pLayer = new BackToMainMenuLayer(); +} + +void TestScene::onEnter() +{ + CCScene::onEnter(); + + //add the menu item for back to main menu +#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY) + CCLabelBMFont* label = CCLabelBMFont::bitmapFontAtlasWithString("MainMenu", "fonts/arial16.fnt"); +#else + CCLabelTTF* label = CCLabelTTF::labelWithString("MainMenu", "Arial", 20); +#endif + CCMenuItemLabel* pMenuItem = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(TestScene::MainMenuCallback)); + + CCMenu* pMenu =CCMenu::menuWithItems(pMenuItem, NULL); + CCSize s = CCDirector::sharedDirector()->getWinSize(); + pMenu->setPosition( CCPointZero ); + pMenuItem->setPosition( CCPointMake( s.width - 50, 25) ); + + addChild(pMenu, 1); +} + +void TestScene::MainMenuCallback(CCObject* pSender) +{ + CCScene* pScene = CCScene::node(); + CCLayer* pLayer = new TestController(); pLayer->autorelease(); - // 54321 is the tag of BackToMainMenuLayer - addChild(pLayer, 1000, 54321); + pScene->addChild(pLayer); + CCDirector::sharedDirector()->replaceScene(pScene); } diff --git a/tests/tests/testBasic.h b/tests/tests/testBasic.h index 42fad5f01e..5a0b285932 100644 --- a/tests/tests/testBasic.h +++ b/tests/tests/testBasic.h @@ -5,22 +5,17 @@ using namespace cocos2d; -class BackToMainMenuLayer : public CCLayer -{ -public: - BackToMainMenuLayer(); - - // The CallBack for back to the main menu scene - virtual void MainMenuCallback(CCObject* pSender); -}; - class TestScene : public CCScene { public: TestScene(bool bPortrait = false); + virtual void onEnter(); virtual void runThisTest() = 0; + // The CallBack for back to the main menu scene + virtual void MainMenuCallback(CCObject* pSender); + protected: bool m_bPortrait; // indicate if this test case requires portrait mode };