From f023ada6f685e734f41a9b9006c1f8ed0ebf5b5b Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 2 Jan 2014 14:25:28 -0800 Subject: [PATCH] Improves transitions test Unifies functions with trantions name --- .../TransitionsTest/TransitionsTest.cpp | 168 +++++++----------- 1 file changed, 62 insertions(+), 106 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/TransitionsTest/TransitionsTest.cpp b/samples/Cpp/TestCpp/Classes/TransitionsTest/TransitionsTest.cpp index aaa8915438..0c81fa9373 100644 --- a/samples/Cpp/TestCpp/Classes/TransitionsTest/TransitionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/TransitionsTest/TransitionsTest.cpp @@ -142,127 +142,83 @@ public: } }; -#define MAX_LAYER 41 +#define STRINGIFY(x) #x -static std::string transitions[MAX_LAYER] = { - "CCTransitionJumpZoom", +#define TRANS(__className__) { \ + { [](float t, Scene* s){ return __className__::create(t,s);} }, \ + STRINGIFY(__className__), \ + } - "CCTransitionProgressRadialCCW", - "CCTransitionProgressRadialCW", - "CCTransitionProgressHorizontal", - "CCTransitionProgressVertical", - "CCTransitionProgressInOut", - "CCTransitionProgressOutIn", +struct _transitions { + std::function function; + const char * name; +} transitions[] { + TRANS(TransitionJumpZoom), + TRANS(TransitionProgressRadialCCW), + TRANS(TransitionProgressRadialCW), + TRANS(TransitionProgressHorizontal), + TRANS(TransitionProgressVertical), + TRANS(TransitionProgressInOut), + TRANS(TransitionProgressOutIn), - "CCTransitionCrossFade", - "TransitionPageForward", - "TransitionPageBackward", - "CCTransitionFadeTR", - "CCTransitionFadeBL", - "CCTransitionFadeUp", - "CCTransitionFadeDown", - "CCTransitionTurnOffTiles", - "CCTransitionSplitRows", - "CCTransitionSplitCols", + TRANS(TransitionCrossFade), - "CCTransitionFade", - "FadeWhiteTransition", + TRANS(PageTransitionForward), + TRANS(PageTransitionBackward), + TRANS(TransitionFadeTR), + TRANS(TransitionFadeBL), + TRANS(TransitionFadeUp), + TRANS(TransitionFadeDown), - "FlipXLeftOver", - "FlipXRightOver", - "FlipYUpOver", - "FlipYDownOver", - "FlipAngularLeftOver", - "FlipAngularRightOver", + TRANS(TransitionTurnOffTiles), - "ZoomFlipXLeftOver", - "ZoomFlipXRightOver", - "ZoomFlipYUpOver", - "ZoomFlipYDownOver", - "ZoomFlipAngularLeftOver", - "ZoomFlipAngularRightOver", + TRANS(TransitionSplitRows), + TRANS(TransitionSplitCols), - "CCTransitionShrinkGrow", - "CCTransitionRotoZoom", + TRANS(TransitionFade), + TRANS(FadeWhiteTransition), - "CCTransitionMoveInL", - "CCTransitionMoveInR", - "CCTransitionMoveInT", - "CCTransitionMoveInB", - "CCTransitionSlideInL", - "CCTransitionSlideInR", - "CCTransitionSlideInT", - "CCTransitionSlideInB", + TRANS(FlipXLeftOver), + TRANS(FlipXRightOver), + TRANS(FlipYUpOver), + TRANS(FlipYDownOver), + TRANS(FlipAngularLeftOver), + TRANS(FlipAngularRightOver), + TRANS(ZoomFlipXLeftOver), + TRANS(ZoomFlipXRightOver), + TRANS(ZoomFlipYUpOver), + TRANS(ZoomFlipYDownOver), + TRANS(ZoomFlipAngularLeftOver), + TRANS(ZoomFlipAngularRightOver), + TRANS(TransitionShrinkGrow), + TRANS(TransitionRotoZoom), + + TRANS(TransitionMoveInL), + TRANS(TransitionMoveInR), + TRANS(TransitionMoveInT), + TRANS(TransitionMoveInB), + + TRANS(TransitionSlideInL), + TRANS(TransitionSlideInR), + TRANS(TransitionSlideInT), + TRANS(TransitionSlideInB), }; + + +#define MAX_LAYER (sizeof(transitions) / sizeof(transitions[0])) + + static int s_nSceneIdx = 0; -TransitionScene* createTransition(int nIndex, float t, Scene* s) +TransitionScene* createTransition(int index, float t, Scene* s) { // fix bug #486, without setDepthTest(false), FlipX,Y will flickers Director::getInstance()->setDepthTest(false); - switch(nIndex) - { - case 0: return TransitionJumpZoom::create(t, s); - - case 1: return TransitionProgressRadialCCW::create(t, s); - case 2: return TransitionProgressRadialCW::create(t, s); - case 3: return TransitionProgressHorizontal::create(t, s); - case 4: return TransitionProgressVertical::create(t, s); - case 5: return TransitionProgressInOut::create(t, s); - case 6: return TransitionProgressOutIn::create(t, s); - - case 7: return TransitionCrossFade::create(t,s); - - case 8: return PageTransitionForward::create(t, s); - case 9: return PageTransitionBackward::create(t, s); - case 10: return TransitionFadeTR::create(t, s); - case 11: return TransitionFadeBL::create(t, s); - case 12: return TransitionFadeUp::create(t, s); - case 13: return TransitionFadeDown::create(t, s); - - case 14: return TransitionTurnOffTiles::create(t, s); - - case 15: return TransitionSplitRows::create(t, s); - case 16: return TransitionSplitCols::create(t, s); - - case 17: return TransitionFade::create(t, s); - case 18: return FadeWhiteTransition::create(t, s); - - case 19: return FlipXLeftOver::create(t, s); - case 20: return FlipXRightOver::create(t, s); - case 21: return FlipYUpOver::create(t, s); - case 22: return FlipYDownOver::create(t, s); - case 23: return FlipAngularLeftOver::create(t, s); - case 24: return FlipAngularRightOver::create(t, s); - - case 25: return ZoomFlipXLeftOver::create(t, s); - case 26: return ZoomFlipXRightOver::create(t, s); - case 27: return ZoomFlipYUpOver::create(t, s); - case 28: return ZoomFlipYDownOver::create(t, s); - case 29: return ZoomFlipAngularLeftOver::create(t, s); - case 30: return ZoomFlipAngularRightOver::create(t, s); - - case 31: return TransitionShrinkGrow::create(t, s); - case 32: return TransitionRotoZoom::create(t, s); - - case 33: return TransitionMoveInL::create(t, s); - case 34: return TransitionMoveInR::create(t, s); - case 35: return TransitionMoveInT::create(t, s); - case 36: return TransitionMoveInB::create(t, s); - - case 37: return TransitionSlideInL::create(t, s); - case 38: return TransitionSlideInR::create(t, s); - case 39: return TransitionSlideInT::create(t, s); - case 40: return TransitionSlideInB::create(t, s); - - default: break; - } - - return NULL; -} + return transitions[index].function(t,s); +} void TransitionsTestScene::runThisTest() @@ -286,7 +242,7 @@ TestLayer1::TestLayer1(void) bg1->setPosition( Point(size.width/2, size.height/2) ); addChild(bg1, -1); - auto title = LabelTTF::create( (transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 ); + auto title = LabelTTF::create( (transitions[s_nSceneIdx]).name, "Thonburi", 32 ); addChild(title); title->setColor( Color3B(255,32,32) ); title->setPosition( Point(x/2, y-100) ); @@ -415,7 +371,7 @@ TestLayer2::TestLayer2() bg1->setPosition( Point(size.width/2, size.height/2) ); addChild(bg1, -1); - auto title = LabelTTF::create((transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 ); + auto title = LabelTTF::create((transitions[s_nSceneIdx]).name, "Thonburi", 32 ); addChild(title); title->setColor( Color3B(255,32,32) ); title->setPosition( Point(x/2, y-100) );