Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-demo.git] / examples / dissolve-effect / dissolve-effect-example.cpp
old mode 100644 (file)
new mode 100755 (executable)
index e9b9493..6e7aaec
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -22,6 +22,7 @@
 #include "shared/view.h"
 
 #include <dali/dali.h>
+#include <dali/devel-api/actors/actor-devel.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
 
@@ -80,17 +81,26 @@ const float TRANSITION_DURATION = 2.5f; //2.5 second
 const float INITIAL_DEPTH = 10.0f;
 
 /**
- * @brief Load an image, scaled-down to no more than the stage dimensions.
+ * @brief Create an image view with an image which would be scaled-down to no more than the window dimensions.
  *
  * 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 BOX_THEN_LINEAR to sample the image with
- * maximum quality.
+ * load time to cover the entire window with pixels with no borders,
+ * and filter mode BOX_THEN_LINEAR to sample the image with maximum quality.
  */
-ResourceImage LoadStageFillingImage( const char * const imagePath )
+Toolkit::ImageView CreateWindowFillingImageView( const Vector2& windowSize, const char * const imagePath )
 {
-  Size stageSize = Stage::GetCurrent().GetSize();
-  return ResourceImage::New( imagePath, ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
+  Toolkit::ImageView imageView = Toolkit::ImageView::New();
+  Property::Map map;
+  map[Toolkit::Visual::Property::TYPE] = Toolkit::Visual::IMAGE;
+  map[Toolkit::ImageVisual::Property::URL] = imagePath;
+  map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = windowSize.x;
+  map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = windowSize.y;
+  map[Toolkit::ImageVisual::Property::FITTING_MODE] = FittingMode::SCALE_TO_FILL;
+  map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = SamplingMode::BOX_THEN_LINEAR;
+  map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = true;
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
+
+  return imageView;
 }
 
 } // namespace
@@ -181,16 +191,7 @@ private:
   bool                            mTimerReady;
   unsigned int                    mCentralLineIndex;
 
-  Image                           mIconPlay;
-  Image                           mIconPlaySelected;
-  Image                           mIconStop;
-  Image                           mIconStopSelected;
   Toolkit::PushButton             mPlayStopButton;
-
-  Image                           mIconHighP;
-  Image                           mIconHighPSelected;
-  Image                           mIconMediumP;
-  Image                           mIconMediumPSelected;
   Toolkit::PushButton             mEffectChangeButton;
 };
 
@@ -213,36 +214,30 @@ DissolveEffectApp::~DissolveEffectApp()
 
 void DissolveEffectApp::OnInit( Application& application )
 {
-  Stage::GetCurrent().KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent);
+  auto window = application.GetWindow();
+  Vector2 windowSize = window.GetSize();
+  window.KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent);
 
-  // Creates a default view with a default tool bar, the view is added to the stage.
+  // Creates a default view with a default tool bar, the view is added to the window.
   mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" );
 
   // Add an effect-changing button on the right of the tool bar.
-  mIconHighP = ResourceImage::New( EFFECT_HIGHP_IMAGE );
-  mIconHighPSelected = ResourceImage::New( EFFECT_HIGHP_IMAGE_SELECTED );
-  mIconMediumP = ResourceImage::New( EFFECT_MEDIUMP_IMAGE );
-  mIconMediumPSelected = ResourceImage::New( EFFECT_MEDIUMP_IMAGE_SELECTED );
   mEffectChangeButton = Toolkit::PushButton::New();
-  mEffectChangeButton.SetButtonImage( mIconHighP );
-  mEffectChangeButton.SetSelectedImage( mIconHighPSelected );
+  mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE );
+  mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED );
   mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked );
-  mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
+  mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_RIGHT, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
 
   // Add title to the tool bar.
   mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_HIGHP );
-  mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
+  mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HORIZONTAL_CENTER );
 
   // Add an slide-show button on the right of the title
-  mIconPlay = ResourceImage::New( PLAY_ICON );
-  mIconPlaySelected = ResourceImage::New( PLAY_ICON_SELECTED );
-  mIconStop = ResourceImage::New( STOP_ICON );
-  mIconStopSelected = ResourceImage::New( STOP_ICON_SELECTED );
   mPlayStopButton = Toolkit::PushButton::New();
-  mPlayStopButton.SetButtonImage( mIconPlay );
-  mPlayStopButton.SetSelectedImage( mIconPlaySelected );
+  mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON );
+  mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED );
   mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked );
-  mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING );
+  mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HORIZONTAL_CENTER, DemoHelper::DEFAULT_PLAY_PADDING );
 
   // use pan gesture to detect the cursor or finger movement
   mPanGestureDetector = PanGestureDetector::New();
@@ -252,23 +247,24 @@ void DissolveEffectApp::OnInit( Application& application )
   mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick );
   mTimerReady = true;
 
-  // Set size to stage size to avoid seeing a black border on transition
+  // Set size to window size to avoid seeing a black border on transition
   mParent = Actor::New();
-  mParent.SetSize( Stage::GetCurrent().GetSize() );
-  mParent.SetParentOrigin( ParentOrigin::CENTER );
+  mParent.SetProperty( Actor::Property::SIZE, windowSize );
+  mParent.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mContent.Add( mParent );
 
   // show the first image
-  mCurrentImage = Toolkit::ImageView::New( LoadStageFillingImage( IMAGES[mIndex] ) );
-  mCurrentImage.SetParentOrigin( ParentOrigin::CENTER );
+  mCurrentImage = CreateWindowFillingImageView( windowSize, IMAGES[mIndex] );
+  mCurrentImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
   mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-  mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+  mCurrentImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
   mParent.Add( mCurrentImage );
 
   mPanGestureDetector.Attach( mCurrentImage );
 
   mDissolveEffect = Dali::Toolkit::CreateDissolveEffect( mUseHighPrecision );
-  mEmptyEffect.Insert( "shader", Property::Value() );
+  Property::Map emptyShaderMap;
+  mEmptyEffect.Insert( "shader", emptyShaderMap );
 }
 
 // signal handler, called when the pan gesture is detected
@@ -280,9 +276,10 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture )
     return;
   }
 
-  if( gesture.state == Gesture::Continuing )
+  if( gesture.GetState() == GestureState::CONTINUING )
   {
-    if( gesture.displacement.x < 0)
+    const Vector2& displacement = gesture.GetDisplacement();
+    if( displacement.x < 0)
     {
       mIndex = (mIndex + 1)%NUM_IMAGES;
     }
@@ -291,15 +288,14 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture )
       mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES;
     }
 
-    Image image = LoadStageFillingImage( IMAGES[ mIndex ] );
-    mNextImage = Toolkit::ImageView::New( image );
-    mNextImage.SetParentOrigin( ParentOrigin::CENTER );
+    mNextImage = CreateWindowFillingImageView( mApplication.GetWindow().GetSize(), IMAGES[ mIndex ] );
+    mNextImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
-    mNextImage.SetZ(INITIAL_DEPTH);
+    mNextImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+    mNextImage.SetProperty( Actor::Property::POSITION_Z, INITIAL_DEPTH);
     mParent.Add( mNextImage );
-    Vector2 size = Vector2( mCurrentImage.GetCurrentSize() );
-    StartTransition( gesture.position / size, gesture.displacement * Vector2(1.0, size.x/size.y));
+    Vector2 size = Vector2( mCurrentImage.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) );
+    StartTransition( gesture.GetPosition() / size, displacement * Vector2(1.0, size.x/size.y));
   }
 }
 
@@ -311,7 +307,7 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement)
   mCurrentImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mDissolveEffect );
   mAnimation.AnimateTo( Property( mCurrentImage, "uPercentage" ), 1.0f, AlphaFunction::LINEAR );
 
-  mNextImage.SetOpacity(0.0f);
+  mNextImage.SetProperty( Actor::Property::OPACITY,0.0f);
   mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR );
 
   if(mUseHighPrecision)
@@ -332,7 +328,7 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement)
 
 void DissolveEffectApp::OnKeyEvent(const KeyEvent& event)
 {
-  if(event.state == KeyEvent::Down)
+  if(event.GetState() == KeyEvent::DOWN)
   {
     if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
     {
@@ -348,14 +344,14 @@ bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button )
   if(mUseHighPrecision)
   {
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) );
-    mEffectChangeButton.SetButtonImage( mIconHighP );
-    mEffectChangeButton.SetSelectedImage( mIconHighPSelected );
+    mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE );
+    mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_HIGHP_IMAGE_SELECTED );
   }
   else
   {
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_MEDIUMP) );
-    mEffectChangeButton.SetButtonImage( mIconMediumP );
-    mEffectChangeButton.SetSelectedImage( mIconMediumPSelected );
+    mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE );
+    mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EFFECT_MEDIUMP_IMAGE_SELECTED );
   }
 
   return true;
@@ -366,16 +362,16 @@ bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button )
   mSlideshow = !mSlideshow;
   if( mSlideshow )
   {
-    mPlayStopButton.SetButtonImage( mIconStop );
-    mPlayStopButton.SetSelectedImage( mIconStopSelected );
+    mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, STOP_ICON );
+    mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, STOP_ICON_SELECTED );
     mPanGestureDetector.Detach( mParent );
     mViewTimer.Start();
     mTimerReady = false;
   }
   else
   {
-    mPlayStopButton.SetButtonImage( mIconPlay );
-    mPlayStopButton.SetSelectedImage( mIconPlaySelected );
+    mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_ICON );
+    mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_ICON_SELECTED );
     mTimerReady = true;
     mPanGestureDetector.Attach( mParent );
   }
@@ -384,7 +380,10 @@ bool DissolveEffectApp::OnSildeshowButtonClicked( Toolkit::Button button )
 
 void DissolveEffectApp::OnTransitionCompleted( Animation& source )
 {
-  mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect );
+  if(mUseHighPrecision)
+  {
+    mNextImage.SetProperty( Toolkit::ImageView::Property::IMAGE, mEmptyEffect );
+  }
   mParent.Remove( mCurrentImage );
   mPanGestureDetector.Detach( mCurrentImage );
   mCurrentImage = mNextImage;
@@ -404,12 +403,11 @@ bool DissolveEffectApp::OnTimerTick()
   if(mSlideshow)
   {
     mIndex = (mIndex + 1)%NUM_IMAGES;
-    Image image = LoadStageFillingImage( IMAGES[ mIndex ] );
-    mNextImage = Toolkit::ImageView::New( image );
-    mNextImage.SetParentOrigin( ParentOrigin::CENTER );
+    mNextImage = CreateWindowFillingImageView( mApplication.GetWindow().GetSize(), IMAGES[ mIndex ] );
+    mNextImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
-    mNextImage.SetZ(INITIAL_DEPTH);
+    mNextImage.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
+    mNextImage.SetProperty( Actor::Property::POSITION_Z, INITIAL_DEPTH);
     mParent.Add( mNextImage );
     switch( mCentralLineIndex%4 )
     {
@@ -440,8 +438,7 @@ bool DissolveEffectApp::OnTimerTick()
   return false;   //return false to stop the timer
 }
 
-// Entry point for Linux & Tizen applications
-int main( int argc, char **argv )
+int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
   DissolveEffectApp test( application );