Modify gaussian-blur-view example 57/227757/6
authorSeungho, Baek <sbsh.baek@samsung.com>
Mon, 16 Mar 2020 07:50:07 +0000 (16:50 +0900)
committerSeungho, Baek <sbsh.baek@samsung.com>
Tue, 23 Jun 2020 03:09:15 +0000 (12:09 +0900)
 - Made not create new gaussian blur for every activation.

Change-Id: I8d5377d804760286188212923e95fb4737bae274
Signed-off-by: Seungho, Baek <sbsh.baek@samsung.com>
examples/gaussian-blur-view/gaussian-blur-view-example.cpp

index 87adb08..f0cc5a9 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 );
   }
@@ -61,8 +62,6 @@ private:
     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 );
 
     if( excessWidth > 0.0f )
@@ -102,46 +101,41 @@ private:
     mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
     onTop.Add( mOffLabel );
 
+    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.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength );
+
     stage.GetRootLayer().TouchSignal().Connect( this, &GaussianBlurViewExample::OnTouch );
   }
 
   bool OnTouch( Actor actor, const TouchData& 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;
   }
@@ -172,6 +166,8 @@ private:
 
   float mExcessWidth;
   float mStrength;
+
+  bool mActivate;
 };
 
 int DALI_EXPORT_API main( int argc, char **argv )