Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / super-blur-view / super-blur-view-example.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/dali.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
21
22 using namespace Dali;
23 using Dali::Toolkit::Button;
24 using Dali::Toolkit::PushButton;
25 using Dali::Toolkit::SuperBlurView;
26
27 namespace
28 {
29
30 const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-4.jpg" );
31
32 const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry
33
34 }
35
36 /**
37  * This example shows a background image which is "super blurred" while the push-button control is pressed.
38  */
39 class SuperBlurViewExample : public ConnectionTracker
40 {
41 public:
42
43   SuperBlurViewExample( Application& application )
44   : mApplication( application )
45   {
46     mApplication.InitSignal().Connect( this, &SuperBlurViewExample::Create );
47   }
48
49   ~SuperBlurViewExample() = default;
50
51 private:
52
53   void Create( Application& application )
54   {
55     Stage stage = Stage::GetCurrent();
56     stage.KeyEventSignal().Connect( this, &SuperBlurViewExample::OnKeyEvent );
57
58     mSuperBlurView = SuperBlurView::New( DEFAULT_BLUR_LEVEL );
59     mSuperBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
60     mSuperBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
61     mSuperBlurView.SetProperty( Actor::Property::SIZE, Vector2( 800, 1280 ) );
62     mSuperBlurView.SetProperty( SuperBlurView::Property::IMAGE_URL, BACKGROUND_IMAGE );
63     stage.Add( mSuperBlurView );
64
65     mBlurAnimation = Animation::New(1.0f);
66     mBlurAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f );
67
68     mClearAnimation = Animation::New(1.0f);
69     mClearAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f );
70
71     mPushButton = PushButton::New();
72     mPushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER );
73     mPushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
74     mPushButton.SetProperty( Button::Property::LABEL, "Blur" );
75     mPushButton.PressedSignal().Connect( this, &SuperBlurViewExample::OnButtonPressed );
76     mPushButton.ReleasedSignal().Connect( this, &SuperBlurViewExample::OnButtonReleased );
77     stage.Add( mPushButton );
78   }
79
80   bool OnButtonPressed( Button button )
81   {
82     mBlurAnimation.Play();
83     return true;
84   }
85
86   bool OnButtonReleased( Button button )
87   {
88     mClearAnimation.Play();
89     return true;
90   }
91
92   void OnKeyEvent( const KeyEvent& event )
93   {
94     if ( event.state == KeyEvent::Down )
95     {
96       if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
97       {
98         mApplication.Quit();
99       }
100     }
101   }
102
103 private:
104
105   Application&  mApplication;
106
107   SuperBlurView mSuperBlurView;
108
109   PushButton mPushButton;
110
111   Animation mBlurAnimation;
112   Animation mClearAnimation;
113 };
114
115 int DALI_EXPORT_API main( int argc, char **argv )
116 {
117   Application application = Application::New( &argc, &argv );
118
119   SuperBlurViewExample test( application );
120
121   application.MainLoop();
122
123   return 0;
124 }