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/dali.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
23 using Dali::Toolkit::Button;
24 using Dali::Toolkit::PushButton;
25 using Dali::Toolkit::SuperBlurView;
30 const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "background-4.jpg" );
32 const unsigned int DEFAULT_BLUR_LEVEL(5u); ///< The default blur level when creating SuperBlurView from the type registry
37 * This example shows a background image which is "super blurred" while the push-button control is pressed.
39 class SuperBlurViewExample : public ConnectionTracker
43 SuperBlurViewExample( Application& application )
44 : mApplication( application )
46 mApplication.InitSignal().Connect( this, &SuperBlurViewExample::Create );
49 ~SuperBlurViewExample() = default;
53 void Create( Application& application )
55 Window window = application.GetWindow();
56 window.KeyEventSignal().Connect( this, &SuperBlurViewExample::OnKeyEvent );
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 window.Add( mSuperBlurView );
65 mBlurAnimation = Animation::New(1.0f);
66 mBlurAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 1.0f );
68 mClearAnimation = Animation::New(1.0f);
69 mClearAnimation.AnimateTo( Property(mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex()), 0.0f );
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 window.Add( mPushButton );
80 bool OnButtonPressed( Button button )
82 mBlurAnimation.Play();
86 bool OnButtonReleased( Button button )
88 mClearAnimation.Play();
92 void OnKeyEvent( const KeyEvent& event )
94 if ( event.state == KeyEvent::Down )
96 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
105 Application& mApplication;
107 SuperBlurView mSuperBlurView;
109 PushButton mPushButton;
111 Animation mBlurAnimation;
112 Animation mClearAnimation;
115 int DALI_EXPORT_API main( int argc, char **argv )
117 Application application = Application::New( &argc, &argv );
119 SuperBlurViewExample test( application );
121 application.MainLoop();