text: #include "EffectsTest.h"
  #include "../testResource.h"
  
  enum {
      kTagTextLayer = 1,
  
      kTagBackground = 1,
      kTagLabel = 2,
  };
  
  static int actionIdx=0; 
  static std::string effectsList[] =
  {
      "Shaky3D",
      "Waves3D",
      "FlipX3D",
      "FlipY3D",
      "Lens3D",
      "Ripple3D",
      "Liquid",
      "Waves",
      "Twirl",
      "ShakyTiles3D",
      "ShatteredTiles3D",
      "ShuffleTiles",
      "FadeOutTRTiles",
      "FadeOutBLTiles",
      "FadeOutUpTiles",
      "FadeOutDownTiles",
      "TurnOffTiles",
      "WavesTiles3D",
      "JumpTiles3D",
      "SplitRows",
      "SplitCols",
      "PageTurn3D",
  }; 
  
  
  class Shaky3DDemo : public CCShaky3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCShaky3D::create(5, false, ccg(15,10), t);
      }
  };
  
  class Waves3DDemo : public CCWaves3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCWaves3D::create(5, 40, ccg(15,10), t);
      }
  };
  
  class FlipX3DDemo : public CCFlipX3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFlipX3D* flipx  = CCFlipX3D::create(t);
          CCActionInterval* flipx_back = flipx->reverse();
          CCDelayTime* delay = CCDelayTime::create(2);
          
          return (CCActionInterval*)(CCSequence::create(flipx, delay, flipx_back, NULL));
      }
  };
  
  class FlipY3DDemo : public CCFlipY3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFlipY3D* flipy  = CCFlipY3D::create(t);
          CCActionInterval* flipy_back = flipy->reverse();
          CCDelayTime* delay = CCDelayTime::create(2);
          
          return (CCActionInterval*)(CCSequence::create(flipy, delay, flipy_back, NULL));
      }
  };
  
  class Lens3DDemo : public CCLens3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCSize size = CCDirector::sharedDirector()->getWinSize();
          return CCLens3D::create(CCPointMake(size.width/2,size.height/2), 240, ccg(15,10), t); 
      }
  };
  
  
  class Ripple3DDemo : public CCRipple3D 
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCSize size = CCDirector::sharedDirector()->getWinSize();
          return CCRipple3D::create(CCPointMake(size.width/2,size.height/2), 240, 4, 160, ccg(32,24), t);
      }
  };
  
  
  class LiquidDemo : public CCLiquid
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCLiquid::create(4, 20, ccg(16,12), t); 
      }
  };
  
  
  class WavesDemo : public CCWaves 
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCWaves::create(4, 20, true, true, ccg(16,12), t);  
      }
  };
  
  
  class TwirlDemo : public CCTwirl 
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCSize size = CCDirector::sharedDirector()->getWinSize();
          return CCTwirl::create(CCPointMake(size.width/2, size.height/2), 1, 2.5f, ccg(12,8), t); 
      }
  };
  
  
  class ShakyTiles3DDemo : public CCShakyTiles3D
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCShakyTiles3D::create(5, false, ccg(16,12), t) ;
      }
  };
  
  
  class ShatteredTiles3DDemo : public CCShatteredTiles3D
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCShatteredTiles3D::create(5, false, ccg(16,12), t); 
      }
  };
  
  
  class ShuffleTilesDemo : public CCShuffleTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCShuffleTiles* shuffle = CCShuffleTiles::create(25, ccg(16,12), t);
          CCActionInterval* shuffle_back = shuffle->reverse();
          CCDelayTime* delay = CCDelayTime::create(2);
  
          return (CCActionInterval*)(CCSequence::create(shuffle, delay, shuffle_back, NULL));
      }
  };
  
  
  class FadeOutTRTilesDemo : public CCFadeOutTRTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFadeOutTRTiles* fadeout = CCFadeOutTRTiles::create(ccg(16,12), t);
          CCActionInterval* back = fadeout->reverse();
          CCDelayTime* delay = CCDelayTime::create(0.5f);
  
          return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
      }
  };
  
  
  class FadeOutBLTilesDemo : public CCFadeOutBLTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFadeOutBLTiles* fadeout = CCFadeOutBLTiles::create(ccg(16,12), t);
          CCActionInterval* back = fadeout->reverse();
          CCDelayTime* delay = CCDelayTime::create(0.5f);
  
          return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
      }
  };
  
  
  class FadeOutUpTilesDemo : public CCFadeOutUpTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFadeOutUpTiles* fadeout = CCFadeOutUpTiles::create(ccg(16,12), t);
          CCActionInterval* back = fadeout->reverse();
          CCDelayTime* delay = CCDelayTime::create(0.5f);
  
          return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
      }
  };
  
  class FadeOutDownTilesDemo : public CCFadeOutDownTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCFadeOutDownTiles* fadeout = CCFadeOutDownTiles::create(ccg(16,12), t);
          CCActionInterval* back = fadeout->reverse();
          CCDelayTime* delay = CCDelayTime::create(0.5f);
  
          return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
      }
  };
  
  class TurnOffTilesDemo : public CCTurnOffTiles
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCTurnOffTiles* fadeout = CCTurnOffTiles::create(25, ccg(48,32) , t);
          CCActionInterval* back = fadeout->reverse();
          CCDelayTime* delay = CCDelayTime::create(0.5f);
  
          return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
      }
  };
  
  class WavesTiles3DDemo : public CCWavesTiles3D
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCWavesTiles3D::create(4, 120, ccg(15,10), t); 
      }
  };
  
  class JumpTiles3DDemo : public CCJumpTiles3D
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCSize size = CCDirector::sharedDirector()->getWinSize();
          return CCJumpTiles3D::create(2, 30, ccg(15,10), t); 
      }
  };
  
  class SplitRowsDemo : public CCSplitRows
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCSplitRows::create(9, t); 
      }
  };
  
  class SplitColsDemo : public CCSplitCols
  {
  public:
      static CCActionInterval* create(float t)
      {
          return CCSplitCols::create(9, t); 
      }
  };
  
  class PageTurn3DDemo : public CCPageTurn3D
  {
  public:
      static CCActionInterval* create(float t)
      {
          CCDirector::sharedDirector()->setDepthTest(true);
          return CCPageTurn3D::create(ccg(15,10), t); 
      }
  };
  
  //------------------------------------------------------------------
  //
  // TextLayer
  //
  //------------------------------------------------------------------
  #define MAX_LAYER    22
  
  CCActionInterval* createEffect(int nIndex, float t)
  {
  
      CCDirector::sharedDirector()->setDepthTest(false);
  
      switch(nIndex)
      {
          case 0: return Shaky3DDemo::create(t);
          case 1: return Waves3DDemo::create(t);
          case 2: return FlipX3DDemo::create(t);
          case 3: return FlipY3DDemo::create(t);
          case 4: return Lens3DDemo::create(t);
          case 5: return Ripple3DDemo::create(t);
          case 6: return LiquidDemo::create(t);
          case 7: return WavesDemo::create(t);
          case 8: return TwirlDemo::create(t);
          case 9: return ShakyTiles3DDemo::create(t);
          case 10: return ShatteredTiles3DDemo::create(t);
          case 11: return ShuffleTilesDemo::create(t);
          case 12: return FadeOutTRTilesDemo::create(t);
          case 13: return FadeOutBLTilesDemo::create(t);
          case 14: return FadeOutUpTilesDemo::create(t);
          case 15: return FadeOutDownTilesDemo::create(t);
          case 16: return TurnOffTilesDemo::create(t);
          case 17: return WavesTiles3DDemo::create(t);
          case 18: return JumpTiles3DDemo::create(t);
          case 19: return SplitRowsDemo::create(t);
          case 20: return SplitColsDemo::create(t);
          case 21: return PageTurn3DDemo::create(t);
      }
  
      return NULL;
  }
  
  CCActionInterval* getAction()
  {
      CCActionInterval* pEffect = createEffect(actionIdx, 3);
  
      return pEffect;
  } 
  
  void EffectTestScene::runThisTest()
  {
      addChild(TextLayer::create());
      CCDirector::sharedDirector()->replaceScene(this);
  }
  
  #define SID_RESTART        1
  
  TextLayer::TextLayer(void)
  {
      initWithColor( ccc4(32,128,32,255) );
          
      float x,y;
      
      CCSize s = CCDirector::sharedDirector()->getWinSize();
      x = s.width;
      y = s.height;
      
      CCNode* node = CCNode::create();
      CCActionInterval* effect = getAction();
      node->runAction(effect);
      addChild(node, 0, kTagBackground);
      
      CCSprite *bg = CCSprite::create(s_back3);
      node->addChild(bg, 0);
  //  bg->setAnchorPoint( CCPointZero );
      bg->setPosition(ccp(s.width/2, s.height/2));
  
      CCSprite* grossini = CCSprite::create(s_pPathSister2);
      node->addChild(grossini, 1);
      grossini->setPosition( CCPointMake(x/3,y/2) );
      CCActionInterval* sc = CCScaleBy::create(2, 5);
      CCActionInterval* sc_back = sc->reverse();
      grossini->runAction( CCRepeatForever::create((CCActionInterval*)(CCSequence::create(sc, sc_back, NULL)) ) );
  
      CCSprite* tamara = CCSprite::create(s_pPathSister1);
      node->addChild(tamara, 1);
      tamara->setPosition( CCPointMake(2*x/3,y/2) );
      CCActionInterval* sc2 = CCScaleBy::create(2, 5);
      CCActionInterval* sc2_back = sc2->reverse();
      tamara->runAction( CCRepeatForever::create((CCActionInterval*)(CCSequence::create(sc2, sc2_back, NULL))) );
      
      CCLabelTTF* label = CCLabelTTF::create((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
      
      label->setPosition( CCPointMake(x/2,y-80) );
      addChild(label);
      label->setTag( kTagLabel );
  
      CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) );
      CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) );
      CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) );
  
      CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
  
      menu->setPosition(CCPointZero);
      item1->setPosition(CCPointMake( s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2));
      item2->setPosition(CCPointMake( s.width/2, item2->getContentSize().height/2));
      item3->setPosition(CCPointMake( s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2));
      
      addChild(menu, 1);    
  
      schedule( schedule_selector(TextLayer::checkAnim) );
  }
  
  void TextLayer::checkAnim(float dt)
  {
      CCNode* s2 = getChildByTag(kTagBackground);
      if ( s2->numberOfRunningActions() == 0 && s2->getGrid() != NULL)
          s2->setGrid(NULL);;
  }
  
  
  TextLayer::~TextLayer(void)
  {
  }
  
  // TextLayer* TextLayer::node()
  // {
  //     return TextLayer::create();
  // }
  
  TextLayer* TextLayer::create()
  {
      TextLayer* pLayer = new TextLayer();
      pLayer->autorelease();
      
      return pLayer;
  }
  
  void TextLayer::onEnter()
  {
      CCLayer::onEnter();
  }
  
  void TextLayer::newScene()
  {
      CCScene* s = new EffectTestScene();
      CCNode* child = TextLayer::create();
      s->addChild(child);
      CCDirector::sharedDirector()->replaceScene(s);
      s->release();
  }
  
  void TextLayer::restartCallback(CCObject* pSender)
  {
      newScene();
  }
  
  void TextLayer::nextCallback(CCObject* pSender)
  {
      // update the action index
      actionIdx++;
      actionIdx = actionIdx % MAX_LAYER;
  
      newScene();
  }
  
  void TextLayer::backCallback(CCObject* pSender)
  {
      // update the action index
      actionIdx--;
      int total = MAX_LAYER;
      if( actionIdx < 0 )
          actionIdx += total;    
  
      newScene();
  } 
  