Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / gaussian-blur-view / gaussian-blur-view-example.cpp
index 87adb08..00aeb51 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 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.
@@ -42,7 +42,8 @@ public:
   GaussianBlurViewExample( Application& application )
   : mApplication( application ),
     mExcessWidth( 0.0f ),
-    mStrength( 1.0f )
+    mStrength( 1.0f ),
+    mActivate( false )
   {
     mApplication.InitSignal().Connect( this, &GaussianBlurViewExample::Create );
   }
@@ -53,17 +54,15 @@ private:
 
   void Create( Application& application )
   {
-    Stage stage = Stage::GetCurrent();
-    Vector2 stageSize = stage.GetSize();
-    stage.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent);
+    auto window = application.GetWindow();
+    Vector2 windowSize = window.GetSize();
+    window.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent);
 
     mImageView = Toolkit::ImageView::New( BACKGROUND_IMAGE );
     mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     mImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
 
-    stage.Add( mImageView );
-
-    float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - stageSize.width) * 0.5f );
+    float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f );
 
     if( excessWidth > 0.0f )
     {
@@ -86,8 +85,8 @@ private:
     Layer onTop = Layer::New();
     onTop.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
     onTop.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-    onTop.SetProperty( Actor::Property::SIZE, stageSize );
-    stage.Add( onTop );
+    onTop.SetProperty( Actor::Property::SIZE, windowSize );
+    window.Add( onTop );
     onTop.RaiseToTop();
 
     mOnLabel = TextLabel::New( "Blur ON" );
@@ -102,53 +101,48 @@ private:
     mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
     onTop.Add( mOffLabel );
 
-    stage.GetRootLayer().TouchSignal().Connect( this, &GaussianBlurViewExample::OnTouch );
+    mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false );
+    mGaussianBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mGaussianBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
+    mGaussianBlurView.SetProperty( Actor::Property::SIZE, windowSize );
+    window.Add( mGaussianBlurView );
+
+    mGaussianBlurView.Add( mImageView );
+    mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength );
+
+    window.GetRootLayer().TouchedSignal().Connect( this, &GaussianBlurViewExample::OnTouch );
   }
 
-  bool OnTouch( Actor actor, const TouchData& touch )
+  bool OnTouch( Actor actor, const TouchEvent& touch )
   {
-      const PointState::Type state = touch.GetState( 0 );
+    const PointState::Type state = touch.GetState( 0 );
 
-      if( PointState::DOWN == state )
+    if( PointState::DOWN == state )
+    {
+      if( !mActivate )
       {
-        Stage stage = Stage::GetCurrent();
-
-        // Enable/disable blur effect
-
-        if( !mGaussianBlurView )
-        {
-          mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false );
-          mGaussianBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-          mGaussianBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-          mGaussianBlurView.SetProperty( Actor::Property::SIZE, stage.GetSize() );
-          stage.Add( mGaussianBlurView );
-
-          mGaussianBlurView.Add( mImageView );
-          mGaussianBlurView.Activate();
+        mActivate = true;
+        mGaussianBlurView.Activate();
 
-          mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength );
-
-          mOnLabel.SetProperty( Actor::Property::VISIBLE, true );
-          mOffLabel.SetProperty( Actor::Property::VISIBLE, false );
-        }
-        else
-        {
-          stage.Add( mImageView );
-
-          UnparentAndReset( mGaussianBlurView );
-
-          mOnLabel.SetProperty( Actor::Property::VISIBLE, false );
-          mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
-        }
+        mOnLabel.SetProperty( Actor::Property::VISIBLE, true );
+        mOffLabel.SetProperty( Actor::Property::VISIBLE, false );
+      }
+      else
+      {
+        mActivate = false;
+        mGaussianBlurView.Deactivate();
 
+        mOnLabel.SetProperty( Actor::Property::VISIBLE, false );
+        mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
       }
+    }
 
     return true;
   }
 
   void 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) )
       {
@@ -172,6 +166,8 @@ private:
 
   float mExcessWidth;
   float mStrength;
+
+  bool mActivate;
 };
 
 int DALI_EXPORT_API main( int argc, char **argv )