2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
23 using Dali::Toolkit::Button;
24 using Dali::Toolkit::PushButton;
25 using Dali::Toolkit::SuperBlurView;
29 const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "background-4.jpg");
31 const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry
36 * This example shows a background image which is "super blurred" while the push-button control is pressed.
38 class SuperBlurViewExample : public ConnectionTracker
41 SuperBlurViewExample(Application& application)
42 : mApplication(application)
44 mApplication.InitSignal().Connect(this, &SuperBlurViewExample::Create);
47 ~SuperBlurViewExample() = default;
50 void Create(Application& application)
52 Window window = application.GetWindow();
53 window.KeyEventSignal().Connect(this, &SuperBlurViewExample::OnKeyEvent);
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);
62 mBlurAnimation = Animation::New(1.0f);
63 mBlurAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f);
65 mClearAnimation = Animation::New(1.0f);
66 mClearAnimation.AnimateTo(Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f);
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);
77 bool OnButtonPressed(Button button)
79 mBlurAnimation.Play();
83 bool OnButtonReleased(Button button)
85 mClearAnimation.Play();
89 void OnKeyEvent(const KeyEvent& event)
91 if(event.GetState() == KeyEvent::DOWN)
93 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
101 Application& mApplication;
103 SuperBlurView mSuperBlurView;
105 PushButton mPushButton;
107 Animation mBlurAnimation;
108 Animation mClearAnimation;
111 int DALI_EXPORT_API main(int argc, char** argv)
113 Application application = Application::New(&argc, &argv);
115 SuperBlurViewExample test(application);
117 application.MainLoop();