Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / super-blur-view / super-blur-view-example.cpp
1 /*
2  * Copyright (c) 2020 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-toolkit/dali-toolkit.h>
19 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
20 #include <dali/dali.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 const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-4.jpg");
30
31 const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry
32
33 } // namespace
34
35 /**
36  * This example shows a background image which is "super blurred" while the push-button control is pressed.
37  */
38 class SuperBlurViewExample : public ConnectionTracker
39 {
40 public:
41   SuperBlurViewExample(Application& application)
42   : mApplication(application)
43   {
44     mApplication.InitSignal().Connect(this, &SuperBlurViewExample::Create);
45   }
46
47   ~SuperBlurViewExample() = default;
48
49 private:
50   void Create(Application& application)
51   {
52     Window window = application.GetWindow();
53     window.KeyEventSignal().Connect(this, &SuperBlurViewExample::OnKeyEvent);
54
55     mSuperBlurView = SuperBlurView::New(DEFAULT_BLUR_LEVEL);
56     mSuperBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
57     mSuperBlurView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
58     mSuperBlurView.SetProperty(Actor::Property::SIZE, Vector2(800, 1280));
59     mSuperBlurView.SetProperty(SuperBlurView::Property::IMAGE_URL, BACKGROUND_IMAGE);
60     window.Add(mSuperBlurView);
61
62     mBlurAnimation = Animation::New(1.0f);
63     mBlurAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f);
64
65     mClearAnimation = Animation::New(1.0f);
66     mClearAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f);
67
68     mPushButton = PushButton::New();
69     mPushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER);
70     mPushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
71     mPushButton.SetProperty(Button::Property::LABEL, "Blur");
72     mPushButton.PressedSignal().Connect(this, &SuperBlurViewExample::OnButtonPressed);
73     mPushButton.ReleasedSignal().Connect(this, &SuperBlurViewExample::OnButtonReleased);
74     window.Add(mPushButton);
75   }
76
77   bool OnButtonPressed(Button button)
78   {
79     mBlurAnimation.Play();
80     return true;
81   }
82
83   bool OnButtonReleased(Button button)
84   {
85     mClearAnimation.Play();
86     return true;
87   }
88
89   void OnKeyEvent(const KeyEvent& event)
90   {
91     if(event.GetState() == KeyEvent::DOWN)
92     {
93       if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
94       {
95         mApplication.Quit();
96       }
97     }
98   }
99
100 private:
101   Application& mApplication;
102
103   SuperBlurView mSuperBlurView;
104
105   PushButton mPushButton;
106
107   Animation mBlurAnimation;
108   Animation mClearAnimation;
109 };
110
111 int DALI_EXPORT_API main(int argc, char** argv)
112 {
113   Application application = Application::New(&argc, &argv);
114
115   SuperBlurViewExample test(application);
116
117   application.MainLoop();
118
119   return 0;
120 }