[3.0] add perf-scroll sample
[platform/core/uifw/dali-demo.git] / examples / cube-transition-effect / cube-transition-effect-example.cpp
index cd0e389..38dbd4a 100644 (file)
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/transition-effects/cube-transition-effect.h>
+#include <dali-toolkit/devel-api/transition-effects/cube-transition-cross-effect.h>
+#include <dali-toolkit/devel-api/transition-effects/cube-transition-fold-effect.h>
+#include <dali-toolkit/devel-api/transition-effects/cube-transition-wave-effect.h>
+
 
 using namespace Dali;
 
@@ -32,39 +37,44 @@ using Dali::Toolkit::TextLabel;
 namespace
 {
 
-const char * const TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
+const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
 const char * const APPLICATION_TITLE_WAVE( "Cube Transition: Wave" );
 const char * const APPLICATION_TITLE_CROSS( "Cube Transition: Cross" );
 const char * const APPLICATION_TITLE_FOLD( "Cube Transition: Fold" );
-const char * const EFFECT_WAVE_IMAGE( DALI_IMAGE_DIR "icon-effect-wave.png" );
-const char * const EFFECT_CROSS_IMAGE( DALI_IMAGE_DIR "icon-effect-cross.png" );
-const char * const EFFECT_FOLD_IMAGE( DALI_IMAGE_DIR "icon-effect-fold.png" );
-const char * const SLIDE_SHOW_START_ICON( DALI_IMAGE_DIR "icon-play.png" );
-const char * const SLIDE_SHOW_STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
+const char * const EFFECT_WAVE_IMAGE( DEMO_IMAGE_DIR "icon-effect-wave.png" );
+const char * const EFFECT_WAVE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-wave-selected.png" );
+const char * const EFFECT_CROSS_IMAGE( DEMO_IMAGE_DIR "icon-effect-cross.png" );
+const char * const EFFECT_CROSS_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-cross-selected.png" );
+const char * const EFFECT_FOLD_IMAGE( DEMO_IMAGE_DIR "icon-effect-fold.png" );
+const char * const EFFECT_FOLD_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-effect-fold-selected.png" );
+const char * const SLIDE_SHOW_START_ICON( DEMO_IMAGE_DIR "icon-play.png" );
+const char * const SLIDE_SHOW_START_ICON_SELECTED( DEMO_IMAGE_DIR "icon-play-selected.png" );
+const char * const SLIDE_SHOW_STOP_ICON( DEMO_IMAGE_DIR "icon-stop.png" );
+const char * const SLIDE_SHOW_STOP_ICON_SELECTED( DEMO_IMAGE_DIR "icon-stop-selected.png" );
 
 const char* IMAGES[] =
 {
-  DALI_IMAGE_DIR "gallery-large-1.jpg",
-  DALI_IMAGE_DIR "gallery-large-2.jpg",
-  DALI_IMAGE_DIR "gallery-large-3.jpg",
-  DALI_IMAGE_DIR "gallery-large-4.jpg",
-  DALI_IMAGE_DIR "gallery-large-5.jpg",
-  DALI_IMAGE_DIR "gallery-large-6.jpg",
-  DALI_IMAGE_DIR "gallery-large-7.jpg",
-  DALI_IMAGE_DIR "gallery-large-8.jpg",
-  DALI_IMAGE_DIR "gallery-large-9.jpg",
-  DALI_IMAGE_DIR "gallery-large-10.jpg",
-  DALI_IMAGE_DIR "gallery-large-11.jpg",
-  DALI_IMAGE_DIR "gallery-large-12.jpg",
-  DALI_IMAGE_DIR "gallery-large-13.jpg",
-  DALI_IMAGE_DIR "gallery-large-14.jpg",
-  DALI_IMAGE_DIR "gallery-large-15.jpg",
-  DALI_IMAGE_DIR "gallery-large-16.jpg",
-  DALI_IMAGE_DIR "gallery-large-17.jpg",
-  DALI_IMAGE_DIR "gallery-large-18.jpg",
-  DALI_IMAGE_DIR "gallery-large-19.jpg",
-  DALI_IMAGE_DIR "gallery-large-20.jpg",
-  DALI_IMAGE_DIR "gallery-large-21.jpg",
+  DEMO_IMAGE_DIR "gallery-large-1.jpg",
+  DEMO_IMAGE_DIR "gallery-large-2.jpg",
+  DEMO_IMAGE_DIR "gallery-large-3.jpg",
+  DEMO_IMAGE_DIR "gallery-large-4.jpg",
+  DEMO_IMAGE_DIR "gallery-large-5.jpg",
+  DEMO_IMAGE_DIR "gallery-large-6.jpg",
+  DEMO_IMAGE_DIR "gallery-large-7.jpg",
+  DEMO_IMAGE_DIR "gallery-large-8.jpg",
+  DEMO_IMAGE_DIR "gallery-large-9.jpg",
+  DEMO_IMAGE_DIR "gallery-large-10.jpg",
+  DEMO_IMAGE_DIR "gallery-large-11.jpg",
+  DEMO_IMAGE_DIR "gallery-large-12.jpg",
+  DEMO_IMAGE_DIR "gallery-large-13.jpg",
+  DEMO_IMAGE_DIR "gallery-large-14.jpg",
+  DEMO_IMAGE_DIR "gallery-large-15.jpg",
+  DEMO_IMAGE_DIR "gallery-large-16.jpg",
+  DEMO_IMAGE_DIR "gallery-large-17.jpg",
+  DEMO_IMAGE_DIR "gallery-large-18.jpg",
+  DEMO_IMAGE_DIR "gallery-large-19.jpg",
+  DEMO_IMAGE_DIR "gallery-large-20.jpg",
+  DEMO_IMAGE_DIR "gallery-large-21.jpg",
 };
 const int NUM_IMAGES( sizeof(IMAGES) / sizeof(IMAGES[0]) );
 
@@ -91,19 +101,15 @@ const int VIEWINGTIME = 2000; // 2 seconds
 /**
  * @brief Load an image, scaled-down to no more than the stage dimensions.
  *
- * Uses image scaling mode ImageAttributes::ScaleToFill to resize the image at
+ * Uses image scaling mode SCALE_TO_FILL to resize the image at
  * load time to cover the entire stage with pixels with no borders,
- * and filter mode ImageAttributes::BoxThenLinear to sample the image with
+ * and filter mode BOX_THEN_LINEAR to sample the image with
  * maximum quality.
  */
 ResourceImage LoadStageFillingImage( const char * const imagePath )
 {
   Size stageSize = Stage::GetCurrent().GetSize();
-  ImageAttributes attributes;
-  attributes.SetSize( stageSize.x, stageSize.y );
-  attributes.SetFilterMode( ImageAttributes::BoxThenLinear );
-  attributes.SetScalingMode( ImageAttributes::ScaleToFill );
-  return ResourceImage::New( imagePath, attributes );
+  return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
 }
 
 } // namespace
@@ -161,9 +167,9 @@ private:
   /**
    * Callback function of cube transition completed signal
    * @param[in] effect The cube effect used for the transition
-   * @param[in] imageActor The target imageActor of the completed transition
+   * @param[in] image The target Image of the completed transition
    */
-  void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor);
+  void OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image );
   /**
    * Callback function of timer tick
    * The timer is used to count the image display duration in slideshow,
@@ -172,16 +178,15 @@ private:
 
 private:
   Application&                    mApplication;
-  Toolkit::View                   mView;
+  Toolkit::Control                mView;
   Toolkit::ToolBar                mToolBar;
   Layer                           mContent;
-  Toolkit::TextLabel              mTitleActor;
-  Actor                           mParent;
+  Toolkit::TextLabel              mTitle;
 
   Vector2                         mViewSize;
 
-  ImageActor                      mCurrentImage;
-  ImageActor                      mNextImage;
+  ResourceImage                   mCurrentImage;
+  ResourceImage                   mNextImage;
   unsigned int                    mIndex;
   bool                            mIsImageLoading;
 
@@ -195,15 +200,10 @@ private:
   bool                            mSlideshow;
   Timer                           mViewTimer;
   Toolkit::PushButton             mSlideshowButton;
-  Image                           mIconSlideshowStart;
-  Image                           mIconSlideshowStop;
 
   Vector2                         mPanPosition;
   Vector2                         mPanDisplacement;
 
-  Image                           mImageWave;
-  Image                           mImageCross;
-  Image                           mImageFold;
   Toolkit::PushButton             mEffectChangeButton;
 };
 
@@ -223,84 +223,82 @@ CubeTransitionApp::~CubeTransitionApp()
 
 void CubeTransitionApp::OnInit( Application& application )
 {
-  DemoHelper::RequestThemeChange();
-
   Stage::GetCurrent().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent);
 
   // Creates a default view with a default tool bar, the view is added to the stage.
   mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" );
+  mContent.SetBehavior( Layer::LAYER_3D );
 
   // Add an effect-changing button on the right of the tool bar.
-  mImageWave = ResourceImage::New( EFFECT_WAVE_IMAGE );
-  mImageCross = ResourceImage::New( EFFECT_CROSS_IMAGE );
-  mImageFold = ResourceImage::New( EFFECT_FOLD_IMAGE );
   mEffectChangeButton = Toolkit::PushButton::New();
-  mEffectChangeButton.SetBackgroundImage(mImageWave);
+  mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE );
+  mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED );
   mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked );
   mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
 
   // Add title to the tool bar.
-  mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE );
-  mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
+  mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE );
+  mToolBar.AddControl( mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
 
   //Add an slideshow icon on the right of the title
-  mIconSlideshowStart = ResourceImage::New( SLIDE_SHOW_START_ICON );
-  mIconSlideshowStop = ResourceImage::New( SLIDE_SHOW_STOP_ICON );
   mSlideshowButton = Toolkit::PushButton::New();
-  mSlideshowButton.SetBackgroundImage( mIconSlideshowStart );
+  mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON );
+  mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED );
   mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked );
   mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING );
 
   // Set size to stage size to avoid seeing a black border on transition
   mViewSize = Stage::GetCurrent().GetSize();
 
-  mParent = Actor::New();
-  mParent.SetSize( mViewSize );
-  mParent.SetPositionInheritanceMode( USE_PARENT_POSITION );
-  mContent.Add( mParent );
-
-  // use pan gesture to detect the cursor or finger movement
-  mPanGestureDetector = PanGestureDetector::New();
-  mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture );
-  mPanGestureDetector.Attach( mParent );
+  // show the first image
+  mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] );
 
   //use small cubes
-  mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New(NUM_ROWS_WAVE, NUM_COLUMNS_WAVE, mViewSize);
+  mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE );
   mCubeWaveEffect.SetTransitionDuration( ANIMATION_DURATION_WAVE );
   mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE );
   mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
-  mParent.Add(mCubeWaveEffect.GetRoot());
+
+  mCubeWaveEffect.SetSize( mViewSize );
+  mCubeWaveEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeWaveEffect.SetCurrentImage( mCurrentImage );
+
   // use big cubes
-  mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS, mViewSize);
-  mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS);
+  mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS );
+  mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS );
   mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS );
   mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
-  mParent.Add(mCubeCrossEffect.GetRoot());
 
-  mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New(NUM_ROWS_FOLD, NUM_COLUMNS_FOLD, mViewSize);
-  mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD);
+  mCubeCrossEffect.SetSize( mViewSize );
+  mCubeCrossEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeCrossEffect.SetCurrentImage( mCurrentImage );
+
+  mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD );
+  mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD );
   mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
-  mParent.Add(mCubeFoldEffect.GetRoot());
+
+  mCubeFoldEffect.SetSize( mViewSize );
+  mCubeFoldEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeFoldEffect.SetCurrentImage( mCurrentImage );
 
   mViewTimer = Timer::New( VIEWINGTIME );
   mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick );
 
-  // show the first image
-  mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) );
-  mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION );
-  mCurrentImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
-  mCurrentImage.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO );
-  mParent.Add( mCurrentImage );
 
   mCurrentEffect = mCubeWaveEffect;
-  mCurrentEffect.SetCurrentImage( mCurrentImage );
+  mContent.Add( mCurrentEffect );
+
+  // use pan gesture to detect the cursor or finger movement
+  mPanGestureDetector = PanGestureDetector::New();
+  mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture );
+  mPanGestureDetector.Attach( mContent );
 }
 
 // signal handler, called when the pan gesture is detected
 void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture )
 {
   // does not response when the transition has not finished
-  if( mIsImageLoading || mCubeWaveEffect.IsTransiting() || mCubeCrossEffect.IsTransiting() || mCubeFoldEffect.IsTransiting() || mSlideshow )
+  if( mIsImageLoading || mCubeWaveEffect.IsTransitioning() || mCubeCrossEffect.IsTransitioning() || mCubeFoldEffect.IsTransitioning() || mSlideshow )
   {
     return;
   }
@@ -324,23 +322,17 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture )
 
 void CubeTransitionApp::GoToNextImage()
 {
-  ResourceImage image = LoadStageFillingImage( IMAGES[ mIndex ] );
-  mNextImage = ImageActor::New( image );
-
-  mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION);
-  mNextImage.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS );
-  mNextImage.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO );
-  mNextImage.SetRelayoutEnabled( false );
-  mCurrentEffect.SetTargetImage(mNextImage);
-  if( image.GetLoadingState() == ResourceLoadingSucceeded )
+  mNextImage = LoadStageFillingImage( IMAGES[ mIndex ] );
+  mCurrentEffect.SetTargetImage( mNextImage );
+  if( mNextImage.GetLoadingState() == ResourceLoadingSucceeded )
   {
     mIsImageLoading = false;
-    OnImageLoaded( image );
+    OnImageLoaded( mNextImage );
   }
   else
   {
     mIsImageLoading = true;
-    image.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded );
+    mNextImage.LoadingFinishedSignal().Connect( this, &CubeTransitionApp::OnImageLoaded );
   }
 }
 
@@ -348,36 +340,39 @@ void CubeTransitionApp::OnImageLoaded(ResourceImage image)
 {
    mIsImageLoading = false;
    mCurrentEffect.StartTransition( mPanPosition, mPanDisplacement );
-   mParent.Remove(mCurrentImage);
-   mParent.Add(mNextImage);
    mCurrentImage = mNextImage;
 }
 
 bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button )
 {
+  mContent.Remove( mCurrentEffect );
   if(mCurrentEffect == mCubeWaveEffect)
   {
     mCurrentEffect = mCubeCrossEffect;
-    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) );
-    mEffectChangeButton.SetBackgroundImage(mImageCross);
+    mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) );
+    mEffectChangeButton.SetUnselectedImage( EFFECT_CROSS_IMAGE );
+    mEffectChangeButton.SetSelectedImage( EFFECT_CROSS_IMAGE_SELECTED );
 
   }
   else if(mCurrentEffect == mCubeCrossEffect)
   {
     mCurrentEffect = mCubeFoldEffect;
-    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) );
-    mEffectChangeButton.SetBackgroundImage(mImageFold);
+    mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) );
+    mEffectChangeButton.SetUnselectedImage( EFFECT_FOLD_IMAGE );
+    mEffectChangeButton.SetSelectedImage( EFFECT_FOLD_IMAGE_SELECTED );
   }
   else
   {
     mCurrentEffect = mCubeWaveEffect;
-    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) );
-    mEffectChangeButton.SetBackgroundImage(mImageWave);
+    mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) );
+    mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE );
+    mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED );
   }
+  mContent.Add( mCurrentEffect );
 
   // Set the current image to cube transition effect
   // only need to set at beginning or change from another effect
-  mCurrentEffect.SetCurrentImage(mCurrentImage);
+  mCurrentEffect.SetCurrentImage( mCurrentImage );
   return true;
 }
 
@@ -386,22 +381,24 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button )
   mSlideshow = !mSlideshow;
   if( mSlideshow )
   {
-    mPanGestureDetector.Detach( mParent );
-    mSlideshowButton.SetBackgroundImage( mIconSlideshowStop );
+    mPanGestureDetector.Detach( mContent );
+    mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_STOP_ICON );
+    mSlideshowButton.SetSelectedImage( SLIDE_SHOW_STOP_ICON_SELECTED );
     mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f );
     mPanDisplacement = Vector2( -10.f, 0.f );
     mViewTimer.Start();
   }
   else
   {
-    mPanGestureDetector.Attach( mParent );
-    mSlideshowButton.SetBackgroundImage( mIconSlideshowStart );
+    mPanGestureDetector.Attach( mContent );
+    mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON );
+    mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED );
     mViewTimer.Stop();
   }
   return true;
 }
 
-void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, ImageActor imageActor)
+void CubeTransitionApp::OnTransitionCompleted(Toolkit::CubeTransitionEffect effect, Image image )
 {
   if( mSlideshow )
   {
@@ -435,7 +432,7 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event)
 // Entry point for Linux & Tizen applications
 int main( int argc, char **argv )
 {
-  Application application = Application::New( &argc, &argv );
+  Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
   CubeTransitionApp test( application );
   application.MainLoop();