Merge "DALi Version 1.0.47" into devel/master
[platform/core/uifw/dali-demo.git] / examples / cube-transition-effect / cube-transition-effect-example.cpp
index cd0e389..fcd3680 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;
 
@@ -37,10 +42,15 @@ 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_WAVE_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-wave-selected.png" );
 const char * const EFFECT_CROSS_IMAGE( DALI_IMAGE_DIR "icon-effect-cross.png" );
+const char * const EFFECT_CROSS_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-cross-selected.png" );
 const char * const EFFECT_FOLD_IMAGE( DALI_IMAGE_DIR "icon-effect-fold.png" );
+const char * const EFFECT_FOLD_IMAGE_SELECTED( DALI_IMAGE_DIR "icon-effect-fold-selected.png" );
 const char * const SLIDE_SHOW_START_ICON( DALI_IMAGE_DIR "icon-play.png" );
+const char * const SLIDE_SHOW_START_ICON_SELECTED( DALI_IMAGE_DIR "icon-play-selected.png" );
 const char * const SLIDE_SHOW_STOP_ICON( DALI_IMAGE_DIR "icon-stop.png" );
+const char * const SLIDE_SHOW_STOP_ICON_SELECTED( DALI_IMAGE_DIR "icon-stop-selected.png" );
 
 const char* IMAGES[] =
 {
@@ -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
@@ -172,7 +178,7 @@ private:
 
 private:
   Application&                    mApplication;
-  Toolkit::View                   mView;
+  Toolkit::Control                mView;
   Toolkit::ToolBar                mToolBar;
   Layer                           mContent;
   Toolkit::TextLabel              mTitleActor;
@@ -196,14 +202,19 @@ private:
   Timer                           mViewTimer;
   Toolkit::PushButton             mSlideshowButton;
   Image                           mIconSlideshowStart;
+  Image                           mIconSlideshowStartSelected;
   Image                           mIconSlideshowStop;
+  Image                           mIconSlideshowStopSelected;
 
   Vector2                         mPanPosition;
   Vector2                         mPanDisplacement;
 
   Image                           mImageWave;
+  Image                           mImageWaveSelected;
   Image                           mImageCross;
+  Image                           mImageCrossSelected;
   Image                           mImageFold;
+  Image                           mImageFoldSelected;
   Toolkit::PushButton             mEffectChangeButton;
 };
 
@@ -223,8 +234,6 @@ 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.
@@ -232,10 +241,14 @@ void CubeTransitionApp::OnInit( Application& application )
 
   // Add an effect-changing button on the right of the tool bar.
   mImageWave = ResourceImage::New( EFFECT_WAVE_IMAGE );
+  mImageWaveSelected = ResourceImage::New( EFFECT_WAVE_IMAGE_SELECTED );
   mImageCross = ResourceImage::New( EFFECT_CROSS_IMAGE );
+  mImageCrossSelected = ResourceImage::New( EFFECT_CROSS_IMAGE_SELECTED );
   mImageFold = ResourceImage::New( EFFECT_FOLD_IMAGE );
+  mImageFoldSelected = ResourceImage::New( EFFECT_FOLD_IMAGE_SELECTED );
   mEffectChangeButton = Toolkit::PushButton::New();
-  mEffectChangeButton.SetBackgroundImage(mImageWave);
+  mEffectChangeButton.SetButtonImage( mImageWave );
+  mEffectChangeButton.SetSelectedImage( mImageWaveSelected );
   mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked );
   mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
 
@@ -245,9 +258,12 @@ void CubeTransitionApp::OnInit( Application& application )
 
   //Add an slideshow icon on the right of the title
   mIconSlideshowStart = ResourceImage::New( SLIDE_SHOW_START_ICON );
+  mIconSlideshowStartSelected = ResourceImage::New( SLIDE_SHOW_START_ICON_SELECTED );
   mIconSlideshowStop = ResourceImage::New( SLIDE_SHOW_STOP_ICON );
+  mIconSlideshowStopSelected = ResourceImage::New( SLIDE_SHOW_STOP_ICON_SELECTED );
   mSlideshowButton = Toolkit::PushButton::New();
-  mSlideshowButton.SetBackgroundImage( mIconSlideshowStart );
+  mSlideshowButton.SetButtonImage( mIconSlideshowStart );
+  mSlideshowButton.SetSelectedImage( mIconSlideshowStartSelected );
   mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked );
   mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING );
 
@@ -288,8 +304,8 @@ void CubeTransitionApp::OnInit( Application& application )
   // 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 );
+  mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
   mParent.Add( mCurrentImage );
 
   mCurrentEffect = mCubeWaveEffect;
@@ -328,9 +344,8 @@ void CubeTransitionApp::GoToNextImage()
   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 );
+  mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
   mCurrentEffect.SetTargetImage(mNextImage);
   if( image.GetLoadingState() == ResourceLoadingSucceeded )
   {
@@ -359,20 +374,23 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button )
   {
     mCurrentEffect = mCubeCrossEffect;
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) );
-    mEffectChangeButton.SetBackgroundImage(mImageCross);
+    mEffectChangeButton.SetButtonImage( mImageCross );
+    mEffectChangeButton.SetSelectedImage( mImageCrossSelected );
 
   }
   else if(mCurrentEffect == mCubeCrossEffect)
   {
     mCurrentEffect = mCubeFoldEffect;
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) );
-    mEffectChangeButton.SetBackgroundImage(mImageFold);
+    mEffectChangeButton.SetButtonImage( mImageFold );
+    mEffectChangeButton.SetSelectedImage( mImageFoldSelected );
   }
   else
   {
     mCurrentEffect = mCubeWaveEffect;
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) );
-    mEffectChangeButton.SetBackgroundImage(mImageWave);
+    mEffectChangeButton.SetButtonImage( mImageWave );
+    mEffectChangeButton.SetSelectedImage( mImageWaveSelected );
   }
 
   // Set the current image to cube transition effect
@@ -387,7 +405,8 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button )
   if( mSlideshow )
   {
     mPanGestureDetector.Detach( mParent );
-    mSlideshowButton.SetBackgroundImage( mIconSlideshowStop );
+    mSlideshowButton.SetButtonImage( mIconSlideshowStop );
+    mSlideshowButton.SetSelectedImage( mIconSlideshowStopSelected );
     mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f );
     mPanDisplacement = Vector2( -10.f, 0.f );
     mViewTimer.Start();
@@ -395,7 +414,8 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button )
   else
   {
     mPanGestureDetector.Attach( mParent );
-    mSlideshowButton.SetBackgroundImage( mIconSlideshowStart );
+    mSlideshowButton.SetButtonImage( mIconSlideshowStart );
+    mSlideshowButton.SetSelectedImage( mIconSlideshowStartSelected );
     mViewTimer.Stop();
   }
   return true;
@@ -435,7 +455,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, DALI_DEMO_THEME_PATH );
   CubeTransitionApp test( application );
   application.MainLoop();