Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / cube-transition-effect / cube-transition-effect-example.cpp
index b50c3b0..fd4ce0a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/buttons/toggle-button.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>
@@ -191,8 +192,6 @@ private:
 
   Vector2                         mPanPosition;
   Vector2                         mPanDisplacement;
-
-  Toolkit::PushButton             mEffectChangeButton;
 };
 
 CubeTransitionApp::CubeTransitionApp( Application& application )
@@ -217,12 +216,18 @@ void CubeTransitionApp::OnInit( Application& application )
   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.
-  mEffectChangeButton = Toolkit::PushButton::New();
-  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 an effect changing toggle button
+  Toolkit::ToggleButton effectChangeToggleButton = Toolkit::ToggleButton::ToggleButton::New();
+
+  effectChangeToggleButton.SetProperty( Toolkit::ToggleButton::Property::STATE_VISUALS,
+                                        Property::Array{ EFFECT_WAVE_IMAGE,
+                                                         EFFECT_CROSS_IMAGE,
+                                                         EFFECT_FOLD_IMAGE }
+                                      );
+
+  effectChangeToggleButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked );
+  mToolBar.AddControl( effectChangeToggleButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
 
   // Add title to the tool bar.
   mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE );
@@ -230,8 +235,8 @@ void CubeTransitionApp::OnInit( Application& application )
 
   //Add an slideshow icon on the right of the title
   mSlideshowButton = Toolkit::PushButton::New();
-  mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON );
-  mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED );
+  mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON );
+  mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, 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 );
 
@@ -247,8 +252,8 @@ void CubeTransitionApp::OnInit( Application& application )
   mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE );
   mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
 
-  mCubeWaveEffect.SetSize( mViewSize );
-  mCubeWaveEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeWaveEffect.SetProperty( Actor::Property::SIZE, mViewSize );
+  mCubeWaveEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mCubeWaveEffect.SetCurrentTexture( mCurrentTexture );
 
   // use big cubes
@@ -257,16 +262,16 @@ void CubeTransitionApp::OnInit( Application& application )
   mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS );
   mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
 
-  mCubeCrossEffect.SetSize( mViewSize );
-  mCubeCrossEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeCrossEffect.SetProperty( Actor::Property::SIZE, mViewSize );
+  mCubeCrossEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mCubeCrossEffect.SetCurrentTexture( mCurrentTexture );
 
   mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD );
   mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD );
   mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted);
 
-  mCubeFoldEffect.SetSize( mViewSize );
-  mCubeFoldEffect.SetParentOrigin( ParentOrigin::CENTER );
+  mCubeFoldEffect.SetProperty( Actor::Property::SIZE, mViewSize );
+  mCubeFoldEffect.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mCubeFoldEffect.SetCurrentTexture( mCurrentTexture );
 
   mViewTimer = Timer::New( VIEWINGTIME );
@@ -324,23 +329,16 @@ bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button )
   {
     mCurrentEffect = mCubeCrossEffect;
     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;
     mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) );
-    mEffectChangeButton.SetUnselectedImage( EFFECT_FOLD_IMAGE );
-    mEffectChangeButton.SetSelectedImage( EFFECT_FOLD_IMAGE_SELECTED );
   }
   else
   {
     mCurrentEffect = mCubeWaveEffect;
     mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) );
-    mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE );
-    mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED );
   }
   mContent.Add( mCurrentEffect );
 
@@ -356,8 +354,8 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button )
   if( mSlideshow )
   {
     mPanGestureDetector.Detach( mContent );
-    mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_STOP_ICON );
-    mSlideshowButton.SetSelectedImage( SLIDE_SHOW_STOP_ICON_SELECTED );
+    mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON );
+    mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_STOP_ICON_SELECTED );
     mPanPosition = Vector2( mViewSize.width, mViewSize.height*0.5f );
     mPanDisplacement = Vector2( -10.f, 0.f );
     mViewTimer.Start();
@@ -365,8 +363,8 @@ bool CubeTransitionApp::OnSildeshowButtonClicked( Toolkit::Button button )
   else
   {
     mPanGestureDetector.Attach( mContent );
-    mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON );
-    mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED );
+    mSlideshowButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON );
+    mSlideshowButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SLIDE_SHOW_START_ICON_SELECTED );
     mViewTimer.Stop();
   }
   return true;
@@ -395,9 +393,9 @@ bool CubeTransitionApp::OnTimerTick()
 Texture CubeTransitionApp::LoadStageFillingTexture( const char* filepath )
 {
   ImageDimensions dimensions( Stage::GetCurrent().GetSize().x, Stage::GetCurrent().GetSize().y );
-  BitmapLoader loader = BitmapLoader::New( filepath, dimensions, FittingMode::SCALE_TO_FILL );
-  loader.Load();
-  PixelData pixelData = loader.GetPixelData();
+  Devel::PixelBuffer pixelBuffer = LoadImageFromFile( filepath, dimensions, FittingMode::SCALE_TO_FILL );
+  PixelData pixelData = Devel::PixelBuffer::Convert(pixelBuffer);
+
   Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() );
   texture.Upload( pixelData );
   return texture;
@@ -414,7 +412,6 @@ void CubeTransitionApp::OnKeyEvent(const KeyEvent& event)
   }
 }
 
-// Entry point for Linux & Tizen applications
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );