Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-demo.git] / examples / dissolve-effect / dissolve-effect-example.cpp
index 53d54df..37e8d6b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
 
 using namespace Dali;
 
@@ -77,19 +78,15 @@ const float INITIAL_DEPTH = -10.0f;
 /**
  * @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
@@ -156,7 +153,7 @@ private:
 
 private:
   Application&                    mApplication;
-  Toolkit::View                   mView;
+  Toolkit::Control                mView;
   Toolkit::ToolBar                mToolBar;
   Layer                           mContent;
   Toolkit::TextLabel              mTitleActor;
@@ -165,10 +162,9 @@ private:
   ImageActor                      mCurrentImage;
   ImageActor                      mNextImage;
   unsigned int                    mIndex;
-  Constraint                      mSizeConstraint;
 
-  Toolkit::DissolveEffect         mCurrentImageEffect;
-  Toolkit::DissolveEffect         mNextImageEffect;
+  ShaderEffect                    mCurrentImageEffect;
+  ShaderEffect                    mNextImageEffect;
   bool                            mUseHighPrecision;
   Animation                       mAnimation;
 
@@ -208,8 +204,6 @@ DissolveEffectApp::~DissolveEffectApp()
 
 void DissolveEffectApp::OnInit( Application& application )
 {
-  DemoHelper::RequestThemeChange();
-
   Stage::GetCurrent().KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent);
 
   // Creates a default view with a default tool bar, the view is added to the stage.
@@ -240,8 +234,8 @@ void DissolveEffectApp::OnInit( Application& application )
   mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture );
 
   // create the dissolve effect object
-  mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision);
-  mNextImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision);
+  mCurrentImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision);
+  mNextImageEffect = Toolkit::CreateDissolveEffect(mUseHighPrecision);
 
   mViewTimer = Timer::New( VIEWINGTIME );
   mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick );
@@ -253,12 +247,11 @@ void DissolveEffectApp::OnInit( Application& application )
   mParent.SetPositionInheritanceMode( USE_PARENT_POSITION );
   mContent.Add( mParent );
 
-  mSizeConstraint= Constraint::New<Vector3>( Actor::Property::SCALE, LocalSource( Actor::Property::SIZE ), ParentSource( Actor::Property::SIZE ), ScaleToFitKeepAspectRatioConstraint() );
-
   // show the first image
   mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) );
   mCurrentImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION);
-  mCurrentImage.ApplyConstraint( mSizeConstraint );
+  mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+  mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
   mParent.Add( mCurrentImage );
 
   mPanGestureDetector.Attach( mCurrentImage );
@@ -287,7 +280,8 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture )
     Image image = LoadStageFillingImage( IMAGES[ mIndex ] );
     mNextImage = ImageActor::New( image );
     mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION);
-    mNextImage.ApplyConstraint( mSizeConstraint );
+    mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
     mNextImage.SetZ(INITIAL_DEPTH);
     mParent.Add( mNextImage );
     Vector2 size = Vector2( mCurrentImage.GetCurrentSize() );
@@ -299,24 +293,24 @@ void DissolveEffectApp::StartTransition(Vector2 position, Vector2 displacement)
 {
   mAnimation = Animation::New(TRANSITION_DURATION);
 
-  mCurrentImageEffect.SetCentralLine(position,displacement);
-  mCurrentImageEffect.SetDistortion(0.0f);
+  Dali::Toolkit::DissolveEffectSetCentralLine( mCurrentImageEffect, position, displacement );
+  mCurrentImageEffect.SetUniform("uPercentage", 0.0f);
   mCurrentImage.SetShaderEffect(mCurrentImageEffect);
-  mAnimation.AnimateTo( Property(mCurrentImageEffect, mCurrentImageEffect.GetDistortionPropertyName()), 1.0f, AlphaFunctions::Linear );
+  mAnimation.AnimateTo( Property(mCurrentImageEffect, "uPercentage"), 1.0f, AlphaFunction::LINEAR );
 
   mNextImage.SetOpacity(0.0f);
-  mAnimation.OpacityTo( mNextImage, 1.0, AlphaFunctions::Linear );
+  mAnimation.AnimateTo( Property( mNextImage, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::LINEAR );
 
   if(mUseHighPrecision)
   {
-    mNextImageEffect.SetCentralLine(position,-displacement);
-    mNextImageEffect.SetDistortion(1.0f);
+    Dali::Toolkit::DissolveEffectSetCentralLine( mNextImageEffect, position, displacement );
+    mNextImageEffect.SetUniform("uPercentage", 1.0f);
     mNextImage.SetShaderEffect(mNextImageEffect);
-    mAnimation.AnimateTo( Property(mNextImageEffect, mNextImageEffect.GetDistortionPropertyName()), 0.0f, AlphaFunctions::Linear );
+    mAnimation.AnimateTo( Property(mNextImageEffect, "uPercentage"), 0.0f, AlphaFunction::LINEAR );
   }
   else
   {
-    mAnimation.MoveTo(mNextImage, Vector3(0.0f, 0.0f, 0.0f), AlphaFunctions::Linear);
+    mAnimation.AnimateTo( Property( mNextImage, Actor::Property::POSITION ), Vector3( 0.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
   }
 
   mAnimation.FinishedSignal().Connect( this, &DissolveEffectApp::OnTransitionCompleted );
@@ -338,7 +332,7 @@ void DissolveEffectApp::OnKeyEvent(const KeyEvent& event)
 bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button )
 {
   mUseHighPrecision = !mUseHighPrecision;
-  mCurrentImageEffect = Toolkit::DissolveEffect::New(mUseHighPrecision);
+  mCurrentImageEffect = Dali::Toolkit::CreateDissolveEffect(mUseHighPrecision);
   if(mUseHighPrecision)
   {
     mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_HIGHP) );
@@ -346,6 +340,7 @@ bool DissolveEffectApp::OnEffectButtonClicked( Toolkit::Button button )
   }
   else
   {
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_MEDIUMP) );
     mEffectChangeButton.SetBackgroundImage(mIconMediumP);
   }
 
@@ -397,7 +392,8 @@ bool DissolveEffectApp::OnTimerTick()
     Image image = LoadStageFillingImage( IMAGES[ mIndex ] );
     mNextImage = ImageActor::New( image );
     mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION);
-    mNextImage.ApplyConstraint( mSizeConstraint );
+    mNextImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    mNextImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
     mNextImage.SetZ(INITIAL_DEPTH);
     mParent.Add( mNextImage );
     switch( mCentralLineIndex%4 )
@@ -432,7 +428,7 @@ bool DissolveEffectApp::OnTimerTick()
 // 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 );
   DissolveEffectApp test( application );
   application.MainLoop();