Revert "Revert "Renamed KeyEvent enum values to comply with coding standards.""
[platform/core/uifw/dali-demo.git] / examples / video-view / video-view-example.cpp
index 8c46b8a..fb5b5a3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 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.
@@ -28,40 +28,13 @@ namespace
   const int INIT_HEIGHT( 400 );
   const int BUTTON_SIZE( 80 );
 
-  const char* const PLAY_FILE = DEMO_VIDEO_DIR "big_buck_bunny.mp4";
+  const char* const PLAY_FILE = DEMO_VIDEO_DIR "demoVideo.mp4";
   const char* const PLAY_IMAGE = DEMO_IMAGE_DIR "icon-play.png";
   const char* const PAUSE_IMAGE = DEMO_IMAGE_DIR "Pause.png";
-  const char* const STOP_IMAGE = DEMO_IMAGE_DIR "icon-stop.png";
-  const char* const RESET_IMAGE = DEMO_IMAGE_DIR "icon-reset.png";
+  const char* const CHANGE_IMAGE = DEMO_IMAGE_DIR "icon-change.png";
   const char* const FORWARD_IMAGE = DEMO_IMAGE_DIR "Forward.png";
   const char* const BACKWARD_IMAGE = DEMO_IMAGE_DIR "Backward.png";
 
-const char* DEFAULT_FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
-  }\n
-);
-
-const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
-  precision mediump float;
-  varying mediump vec2 vTexCoord;\n
-  uniform sampler2D sTexture;\n
-  uniform lowp vec4 uColor;\n
-  \n
-  void main()\n
-  {\n
-    vec2 st = vTexCoord.st;\n
-    vec3 irgb = texture2D( sTexture, st ).rgb;\n
-    vec3 negative = vec3( 1., 1., 1. ) - irgb;\n
-    gl_FragColor = vec4( mix( irgb, negative, 1.0), 1. ) * uColor;\n
-  }\n
-);
-
 }  // namespace
 
 class VideoViewController: public ConnectionTracker
@@ -71,10 +44,9 @@ class VideoViewController: public ConnectionTracker
   VideoViewController( Application& application )
     : mApplication( application ),
       mIsPlay( false ),
-      mIsStop( false ),
       mIsFullScreen( false ),
-      mSetCustomShader( false ),
-      mScale( 1.f )
+      mScale( 1.f ),
+      mPinchStartScale( 1.0f )
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect( this, &VideoViewController::Create );
@@ -87,109 +59,96 @@ class VideoViewController: public ConnectionTracker
 
   void Create( Application& application )
   {
-    mStageSize = Stage::GetCurrent().GetSize();
+    Window window = application.GetWindow();
+    mWindowSize = window.GetSize();
 
     mVideoView = Toolkit::VideoView::New();
-    Stage::GetCurrent().Add( mVideoView );
-    mVideoView.SetParentOrigin( ParentOrigin::CENTER );
-    mVideoView.SetAnchorPoint( AnchorPoint::CENTER );
+    window.Add( mVideoView );
+    mVideoView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mVideoView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
     mVideoView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
-    mVideoView.SetSize( INIT_WIDTH, INIT_HEIGHT );
+    mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) );
     mVideoView.SetProperty( VideoView::Property::LOOPING, true );
     mVideoView.SetProperty( VideoView::Property::MUTED, false );
     mVideoView.SetProperty( VideoView::Property::VIDEO, PLAY_FILE );
 
     mMenu = Layer::New();
-    mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
-    mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
+    mMenu.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
+    mMenu.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
     mMenu.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mMenu.SetSize( INIT_WIDTH, 120 );
+    mMenu.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, 120 ) );
     mVideoView.Add( mMenu );
 
     mPlayButton = PushButton::New();
-    mPlayButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mPlayButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mPlayButton.SetName( "Play" );
+    mPlayButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mPlayButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mPlayButton.SetProperty( Dali::Actor::Property::NAME, "Play" );
     mPlayButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mPlayButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mPlayButton.SetPosition( 40, 10 );
+    mPlayButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
+    mPlayButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 ));
     mPlayButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
 
     mPauseButton = PushButton::New();
-    mPauseButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mPauseButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mPauseButton.SetName( "Pause" );
+    mPauseButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mPauseButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mPauseButton.SetProperty( Dali::Actor::Property::NAME, "Pause" );
     mPauseButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mPauseButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mPauseButton.SetPosition( 40, 10 );
+    mPauseButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
+    mPauseButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 ));
     mPauseButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
 
-    mStopButton = PushButton::New();
-    mStopButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mStopButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mStopButton.SetName( "Stop" );
-    mStopButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mStopButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mStopButton.SetPosition( 140, 10 );
-    mStopButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
-
-    mResetButton = PushButton::New();
-    mResetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mResetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mResetButton.SetName( "Reset" );
-    mResetButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mResetButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mResetButton.SetPosition( 140, 10 );
-    mResetButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
+    mChangeButton = PushButton::New();
+    mChangeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mChangeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mChangeButton.SetProperty( Dali::Actor::Property::NAME, "Change" );
+    mChangeButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+    mChangeButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
+    mChangeButton.SetProperty( Actor::Property::POSITION, Vector2( 140, 10 ));
+    mChangeButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
 
     mBackwardButton = PushButton::New();
-    mBackwardButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mBackwardButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mBackwardButton.SetName( "Backward" );
+    mBackwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mBackwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mBackwardButton.SetProperty( Dali::Actor::Property::NAME, "Backward" );
     mBackwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mBackwardButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mBackwardButton.SetPosition( 240, 10 );
+    mBackwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
+    mBackwardButton.SetProperty( Actor::Property::POSITION, Vector2( 240, 10 ));
     mBackwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
 
     mForwardButton = PushButton::New();
-    mForwardButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
-    mForwardButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-    mForwardButton.SetName( "Forward" );
+    mForwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+    mForwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+    mForwardButton.SetProperty( Dali::Actor::Property::NAME, "Forward" );
     mForwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    mForwardButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
-    mForwardButton.SetPosition( 340, 10 );
+    mForwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
+    mForwardButton.SetProperty( Actor::Property::POSITION, Vector2( 340, 10 ));
     mForwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
 
     mMenu.Add( mPlayButton );
     mMenu.Add( mPauseButton );
-    mMenu.Add( mStopButton );
-    mMenu.Add( mResetButton );
+    mMenu.Add( mChangeButton );
     mMenu.Add( mBackwardButton );
     mMenu.Add( mForwardButton );
 
-    mPauseButton.SetVisible( false );
-    mPauseButton.SetDisabled( true );
-    mPlayButton.SetVisible( true );
-    mPlayButton.SetDisabled( false );
-    mStopButton.SetVisible( true );
-    mStopButton.SetDisabled( false );
-    mResetButton.SetVisible( false );
-    mResetButton.SetDisabled( true );
-
-    mPlayButton.SetUnselectedImage( PLAY_IMAGE );
-    mPlayButton.SetSelectedImage( PLAY_IMAGE );
-    mPauseButton.SetUnselectedImage( PAUSE_IMAGE );
-    mPauseButton.SetSelectedImage( PAUSE_IMAGE );
-
-    mStopButton.SetUnselectedImage( STOP_IMAGE );
-    mStopButton.SetSelectedImage( STOP_IMAGE );
-    mResetButton.SetUnselectedImage( RESET_IMAGE );
-    mResetButton.SetSelectedImage( RESET_IMAGE );
-
-    mBackwardButton.SetUnselectedImage( BACKWARD_IMAGE );
-    mBackwardButton.SetSelectedImage( BACKWARD_IMAGE );
-    mForwardButton.SetUnselectedImage( FORWARD_IMAGE );
-    mForwardButton.SetSelectedImage( FORWARD_IMAGE );
+    mPauseButton.SetProperty( Actor::Property::VISIBLE, false );
+    mPauseButton.SetProperty( Button::Property::DISABLED, true );
+    mPlayButton.SetProperty( Actor::Property::VISIBLE, true );
+    mPlayButton.SetProperty( Button::Property::DISABLED, false );
+    mChangeButton.SetProperty( Actor::Property::VISIBLE, true );
+    mChangeButton.SetProperty( Button::Property::DISABLED, false );
+
+    mPlayButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
+    mPlayButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
+    mPauseButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
+    mPauseButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
+
+    mChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
+    mChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
+
+    mBackwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
+    mBackwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
+    mForwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
+    mForwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
 
     mPanGestureDetector = PanGestureDetector::New();
     mPanGestureDetector.Attach( mVideoView );
@@ -207,93 +166,52 @@ class VideoViewController: public ConnectionTracker
     mRotationAnimation.AnimateBy( Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)) );
     mRotationAnimation.SetLooping(false);
 
-    Stage::GetCurrent().KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent );
-
-    Property::Map customShader;
-    customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
-    mCustomShader.Insert( "rendererType", "IMAGE" );
-    mCustomShader.Insert( "shader", customShader );
-
-    Property::Map defaultShader;
-    customShader.Insert( "fragmentShader", DEFAULT_FRAGMENT_SHADER );
-    mDefaultShader.Insert( "rendererType", "IMAGE" );
-    mDefaultShader.Insert( "shader", defaultShader );
-
-    mWindowSurfaceTarget.Insert( "RENDERING_TARGET", "windowSurfaceTarget" );
-    mNativeImageTarget.Insert( "RENDERING_TARGET", "nativeImageTarget" );
-
-    mVideoView.FinishedSignal().Connect( this, &VideoViewController::OnFinished );
+    window.KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent );
   }
 
   bool OnButtonClicked( Button button )
   {
-
-    if( mPauseButton.GetId() == button.GetId())
+    if( mPauseButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
     {
        if( mIsPlay )
       {
-        mPauseButton.SetVisible( false );
-        mPauseButton.SetDisabled( true );
-        mPlayButton.SetVisible( true );
-        mPlayButton.SetDisabled( false );
+        mPauseButton.SetProperty( Actor::Property::VISIBLE, false );
+        mPauseButton.SetProperty( Button::Property::DISABLED, true );
+        mPlayButton.SetProperty( Actor::Property::VISIBLE, true );
+        mPlayButton.SetProperty( Button::Property::DISABLED, false );
 
         mIsPlay = false;
         mVideoView.Pause();
       }
     }
-    else if( mPlayButton.GetId() == button.GetId())
+    else if( mPlayButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
     {
-      if( mIsStop )
-      {
-        return false;
-      }
-
-      mPauseButton.SetVisible( true );
-      mPauseButton.SetDisabled( false );
-      mPlayButton.SetVisible( false );
-      mPlayButton.SetDisabled( true );
+      mPauseButton.SetProperty( Actor::Property::VISIBLE, true );
+      mPauseButton.SetProperty( Button::Property::DISABLED, false );
+      mPlayButton.SetProperty( Actor::Property::VISIBLE, false );
+      mPlayButton.SetProperty( Button::Property::DISABLED, true );
 
       mIsPlay = true;
       mVideoView.Play();
     }
-    else if( mResetButton.GetId() == button.GetId())
+    else if( mChangeButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
     {
-      if( mIsStop )
+      bool underlay = false;
+      underlay = mVideoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
+      if( underlay )
       {
-        mPauseButton.SetVisible( true );
-        mPauseButton.SetDisabled( false );
-        mPlayButton.SetVisible( false );
-        mPlayButton.SetDisabled( true );
-        mResetButton.SetVisible( false );
-        mResetButton.SetDisabled( true );
-        mStopButton.SetVisible( true );
-        mStopButton.SetDisabled( false );
-
-        mIsStop = false;
-        mIsPlay = true;
-        mVideoView.SetProperty( VideoView::Property::VIDEO, PLAY_FILE );
-        mVideoView.Play();
+        mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
+      }
+      else
+      {
+        mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
       }
     }
-    else if( mStopButton.GetId() == button.GetId())
-    {
-      mPauseButton.SetVisible( false );
-      mPauseButton.SetDisabled( true );
-      mPlayButton.SetVisible( true );
-      mPlayButton.SetDisabled( false );
-      mResetButton.SetVisible( true );
-      mResetButton.SetDisabled( false );
-      mStopButton.SetVisible( false );
-      mStopButton.SetDisabled( true );
-
-      mIsStop = true;
-      mVideoView.Stop();
-    }
-    else if( mBackwardButton.GetId() == button.GetId())
+    else if( mBackwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
     {
       mVideoView.Backward( SEEK_POS );
     }
-    else if( mForwardButton.GetId() == button.GetId())
+    else if( mForwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
     {
       mVideoView.Forward( SEEK_POS );
     }
@@ -301,15 +219,6 @@ class VideoViewController: public ConnectionTracker
     return true;
   }
 
-  void OnFinished( VideoView& view )
-  {
-    if( !mIsFullScreen )
-    {
-      mRotationAnimation.Play();
-      mIsStop = true;
-    }
-  }
-
   void OnPan( Actor actor, const PanGesture& gesture )
   {
     if( !mIsFullScreen && gesture.state == Gesture::Continuing )
@@ -328,20 +237,7 @@ class VideoViewController: public ConnectionTracker
     if( gesture.state == Gesture::Finished )
     {
       mScale = mPinchStartScale * gesture.scale;
-      if( mScale > 1.f )
-      {
-        mVideoView.SetSize( mStageSize.x, mStageSize.y );
-        mVideoView.SetProperty( VideoView::Property::VIDEO, mWindowSurfaceTarget );
-        mMenu.SetSize( mStageSize.x, 120 );
-        mIsFullScreen = true;
-      }
-      else
-      {
-        mVideoView.SetSize( INIT_WIDTH, INIT_HEIGHT );
-        mVideoView.SetProperty( VideoView::Property::VIDEO, mNativeImageTarget );
-        mMenu.SetSize( INIT_WIDTH, 120 );
-        mIsFullScreen = false;
-      }
+      mVideoView.SetProperty( Actor::Property::SCALE, mScale );
     }
   }
 
@@ -349,18 +245,13 @@ class VideoViewController: public ConnectionTracker
   {
     if( !mIsFullScreen )
     {
-      mRotationAnimation.Play();
-
-      if( mSetCustomShader )
-      {
-        mSetCustomShader = false;
-        mVideoView.SetProperty( VideoView::Property::VIDEO, mDefaultShader );
-      }
-      else
-      {
-        mSetCustomShader = true;
-        mVideoView.SetProperty( VideoView::Property::VIDEO, mCustomShader );
-      }
+      mVideoView.SetProperty( Actor::Property::SIZE, mWindowSize );
+      mIsFullScreen = true;
+    }
+    else
+    {
+      mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) );
+      mIsFullScreen = false;
     }
   }
 
@@ -371,7 +262,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 ) )
       {
@@ -384,16 +275,14 @@ private:
   Application&  mApplication;
   VideoView mVideoView;
   Layer mMenu;
-  Vector2 mStageSize;
+  Vector2 mWindowSize;
 
   bool mIsPlay;
-  bool mIsStop;
   bool mIsFullScreen;
-  bool mSetCustomShader;
 
   PushButton mPlayButton;
   PushButton mPauseButton;
-  PushButton mStopButton;
+  PushButton mChangeButton;
   PushButton mResetButton;
   PushButton mBackwardButton;
   PushButton mForwardButton;
@@ -405,26 +294,12 @@ private:
   float mPinchStartScale;
 
   Animation mRotationAnimation;
-  Property::Map mCustomShader;
-  Property::Map mDefaultShader;
-  Property::Map mWindowSurfaceTarget;
-  Property::Map mNativeImageTarget;
 };
 
-void RunTest( Application& application )
-{
-  VideoViewController test( application );
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications
-//
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
-
-  RunTest( application );
-
+  VideoViewController test( application );
+  application.MainLoop();
   return 0;
 }