Merge "Removing unused variables" into devel/master
[platform/core/uifw/dali-demo.git] / examples / animated-vector-images / animated-vector-images-example.cpp
index 21419bc..b7bbd1d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
+#include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-signals-devel.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -48,14 +51,14 @@ enum CellPlacement
   NUMBER_OF_ROWS
 };
 
-unsigned int GetButtonIndex( Button button )
+unsigned int GetControlIndex( Control control )
 {
-  std::string buttonName = button.GetName();
+  std::string controlName = control.GetProperty< std::string >( Dali::Actor::Property::NAME );
   unsigned int index = 0;
 
-  if ( buttonName != "")
+  if ( controlName != "")
   {
-    index = std::stoul( buttonName );
+    index = std::stoul( controlName );
   }
 
   return index;
@@ -81,7 +84,7 @@ class AnimatedVectorImageViewController: public ConnectionTracker
     // The Init signal is received once (only) during the Application lifetime
 
     // Creates a default view with a default tool bar.
-    // The view is added to the stage.
+    // The view is added to the window.
     mContentLayer = DemoHelper::CreateView( application,
                                             mView,
                                             mToolBar,
@@ -92,11 +95,11 @@ class AnimatedVectorImageViewController: public ConnectionTracker
 
     // Create a table view to show a pair of buttons above each image.
     mTable = TableView::New( CellPlacement::NUMBER_OF_ROWS, NUMBER_OF_IMAGES );
-    mTable.SetAnchorPoint( AnchorPoint::CENTER );
-    mTable.SetParentOrigin( ParentOrigin::CENTER );
+    mTable.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mTable.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mTable.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
     Vector3 offset( 0.9f, 0.70f, 0.0f );
-    mTable.SetSizeModeFactor( offset );
+    mTable.SetProperty( Actor::Property::SIZE_MODE_FACTOR, offset );
     mTable.SetFitHeight(CellPlacement::TOP_BUTTON);
     mTable.SetFitHeight(CellPlacement::LOWER_BUTTON);
     mContentLayer.Add( mTable );
@@ -105,91 +108,92 @@ class AnimatedVectorImageViewController: public ConnectionTracker
     {
       mPlayButtons[x] = PushButton::New();
       mPlayButtons[x].SetProperty( Button::Property::LABEL, "Play" );
-      mPlayButtons[x].SetParentOrigin( ParentOrigin::TOP_CENTER );
-      mPlayButtons[x].SetAnchorPoint( AnchorPoint::TOP_CENTER );
+      mPlayButtons[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+      mPlayButtons[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
       mPlayButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnPlayButtonClicked );
       mPlayButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
       mPlayButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
       std::string s = std::to_string(x);
-      mPlayButtons[x].SetName( s );
+      mPlayButtons[x].SetProperty( Dali::Actor::Property::NAME, s );
       mTable.AddChild( mPlayButtons[x], TableView::CellPosition( CellPlacement::TOP_BUTTON, x )  );
 
-      mPauseButtons[x] = PushButton::New();
-      mPauseButtons[x].SetProperty( Button::Property::LABEL, "Pause" );
-      mPauseButtons[x].SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-      mPauseButtons[x].SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-      mPauseButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnPauseButtonClicked );
-      mPauseButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-      mPauseButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-      mPauseButtons[x].SetName( s );
-      mTable.AddChild( mPauseButtons[x], TableView::CellPosition( CellPlacement::LOWER_BUTTON, x )  );
+      mStopButtons[x] = PushButton::New();
+      mStopButtons[x].SetProperty( Button::Property::LABEL, "Stop" );
+      mStopButtons[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
+      mStopButtons[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
+      mStopButtons[x].ClickedSignal().Connect( this, &AnimatedVectorImageViewController::OnStopButtonClicked );
+      mStopButtons[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+      mStopButtons[x].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+      mStopButtons[x].SetProperty( Dali::Actor::Property::NAME, s );
+      mTable.AddChild( mStopButtons[x], TableView::CellPosition( CellPlacement::LOWER_BUTTON, x )  );
 
       mImageViews[x] = ImageView::New( );
       Property::Map imagePropertyMap;
-      imagePropertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
-      imagePropertyMap.Insert( ImageVisual::Property::URL,  IMAGE_PATH[ x ]  );
-      mImageViews[x].SetProperty( ImageView::Property::IMAGE , imagePropertyMap );
+      imagePropertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
+      imagePropertyMap.Insert( ImageVisual::Property::URL, IMAGE_PATH[ x ] );
+      imagePropertyMap.Insert( DevelImageVisual::Property::LOOP_COUNT, 3 );
+      mImageViews[x].SetProperty( ImageView::Property::IMAGE, imagePropertyMap );
 
-      mImageViews[x].SetParentOrigin( ParentOrigin::CENTER );
-      mImageViews[x].SetAnchorPoint( AnchorPoint::CENTER );
+      mImageViews[x].SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+      mImageViews[x].SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
       mImageViews[x].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+      mImageViews[x].SetProperty( Dali::Actor::Property::NAME, s );
 
-      mTable.AddChild( mImageViews[x], TableView::CellPosition( CellPlacement::IMAGE, x ) );
+      DevelControl::VisualEventSignal( mImageViews[x] ).Connect( this, &AnimatedVectorImageViewController::OnVisualEvent );
 
-      // Set changeable counter and toggle for each ImageView
-      mImageViewPlayStatus[x] = false;
-      mImageViewPauseStatus[x] = false;
+      mTable.AddChild( mImageViews[x], TableView::CellPosition( CellPlacement::IMAGE, x ) );
     }
 
-    Stage::GetCurrent().KeyEventSignal().Connect(this, &AnimatedVectorImageViewController::OnKeyEvent);
+    application.GetWindow().KeyEventSignal().Connect(this, &AnimatedVectorImageViewController::OnKeyEvent);
   }
 
 private:
 
   bool OnPlayButtonClicked( Button button )
   {
-    unsigned int buttonIndex = GetButtonIndex( button );
+    unsigned int controlIndex = GetControlIndex( button );
 
-    ImageView imageView =  mImageViews[buttonIndex];
-    if( !mImageViewPlayStatus[buttonIndex] )
-    {
-      mPlayButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Stop" );
+    ImageView imageView =  mImageViews[controlIndex];
 
-      DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value() );
-    }
-    else
+    Property::Map map = imageView.GetProperty< Property::Map >( ImageView::Property::IMAGE );
+    Property::Value* value = map.Find( DevelImageVisual::Property::PLAY_STATE );
+
+    if( value )
     {
-      mPlayButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Play" );
+      if( value->Get< int >() != static_cast< int >( DevelImageVisual::PlayState::PLAYING ) )
+      {
+        mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Pause" );
 
-      DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value() );
-    }
+        DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PLAY, Property::Value() );
+      }
+      else
+      {
+        mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" );
 
-    mImageViewPlayStatus[buttonIndex] = !mImageViewPlayStatus[buttonIndex];
+        DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value() );
+      }
+    }
 
     return true;
   }
 
-  bool OnPauseButtonClicked( Button button )
+  bool OnStopButtonClicked( Button button )
   {
-    unsigned int buttonIndex = GetButtonIndex( button );
+    unsigned int controlIndex = GetControlIndex( button );
+    ImageView imageView =  mImageViews[controlIndex];
+    DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::STOP, Property::Value() );
 
-    ImageView imageView =  mImageViews[buttonIndex];
-    if( !mImageViewPauseStatus[buttonIndex] )
-    {
-      mPauseButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Resume" );
+    return true;
+  }
 
-      DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::PAUSE, Property::Value() );
-    }
-    else
-    {
-      mPauseButtons[buttonIndex].SetProperty( Button::Property::LABEL, "Pause" );
+  void OnVisualEvent( Control control, Dali::Property::Index visualIndex, Dali::Property::Index signalId )
+  {
+    unsigned int controlIndex = GetControlIndex( control );
 
-      DevelControl::DoAction( imageView, ImageView::Property::IMAGE, DevelAnimatedVectorImageVisual::Action::RESUME, Property::Value() );
+    if( visualIndex == ImageView::Property::IMAGE && signalId == DevelAnimatedVectorImageVisual::Signal::ANIMATION_FINISHED )
+    {
+      mPlayButtons[controlIndex].SetProperty( Button::Property::LABEL, "Play" );
     }
-
-    mImageViewPauseStatus[buttonIndex] = !mImageViewPauseStatus[buttonIndex];
-
-    return true;
   }
 
   /**
@@ -197,7 +201,7 @@ private:
    */
   void OnKeyEvent( const KeyEvent& event )
   {
-    if( event.state == KeyEvent::Down )
+    if( event.GetState() == KeyEvent::DOWN )
     {
       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
       {
@@ -215,9 +219,7 @@ private:
   TableView         mTable;
   ImageView         mImageViews[ NUMBER_OF_IMAGES ];
   PushButton        mPlayButtons[ NUMBER_OF_IMAGES ];
-  PushButton        mPauseButtons[ NUMBER_OF_IMAGES ];
-  bool              mImageViewPlayStatus[ NUMBER_OF_IMAGES ];
-  bool              mImageViewPauseStatus[ NUMBER_OF_IMAGES ];
+  PushButton        mStopButtons[ NUMBER_OF_IMAGES ];
 
 };