2 * Copyright (c) 2017 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.
17 #include <dali/dali.h>
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
20 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
21 #include <dali-toolkit/devel-api/controls/super-blur-view/super-blur-view.h>
22 #include "shared/view.h"
23 #include "shared/utility.h"
29 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
30 const char * const TITLE_SUPER_BLUR( "Super Blur" );
31 const char * const TITLE_BLOOM( "Bloom" );
32 const char * const CHANGE_BACKGROUND_ICON( DEMO_IMAGE_DIR "icon-change.png" );
33 const char * const CHANGE_BACKGROUND_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
34 const char * const CHANGE_BLUR_ICON( DEMO_IMAGE_DIR "icon-replace.png" );
35 const char * const CHANGE_BLUR_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
37 const char* BACKGROUND_IMAGES[]=
39 DEMO_IMAGE_DIR "background-1.jpg",
40 DEMO_IMAGE_DIR "background-2.jpg",
41 DEMO_IMAGE_DIR "background-3.jpg",
42 DEMO_IMAGE_DIR "background-4.jpg",
43 DEMO_IMAGE_DIR "background-5.jpg",
44 DEMO_IMAGE_DIR "background-magnifier.jpg",
46 const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) );
50 class BlurExample : public ConnectionTracker
53 BlurExample(Application &app)
58 // Connect to the Application's Init signal
59 app.InitSignal().Connect(this, &BlurExample::Create);
66 // The Init signal is received once (only) during the Application lifetime
67 void Create(Application& app)
69 Stage stage = Stage::GetCurrent();
70 Vector2 stageSize = stage.GetSize();
72 stage.KeyEventSignal().Connect(this, &BlurExample::OnKeyEvent);
74 // Creates a default view with a default tool bar.
75 // The view is added to the stage.
76 Layer content = DemoHelper::CreateView( app,
83 // Add a button to change background. (right of toolbar)
84 Toolkit::PushButton changeBackgroundButton = Toolkit::PushButton::New();
85 changeBackgroundButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON );
86 changeBackgroundButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BACKGROUND_ICON_SELECTED );
88 changeBackgroundButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBackgroundIconClicked );
89 mToolBar.AddControl( changeBackgroundButton,
90 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
91 Toolkit::Alignment::HorizontalRight,
92 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
94 // Add a button to change the blur view. (left of toolbar)
95 Toolkit::PushButton changeBlurButton = Toolkit::PushButton::New();
96 changeBlurButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_BLUR_ICON );
97 changeBlurButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_BLUR_ICON_SELECTED );
99 changeBlurButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBlurIconClicked );
100 mToolBar.AddControl( changeBlurButton,
101 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
102 Toolkit::Alignment::HorizontalLeft,
103 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
105 mSuperBlurView = Toolkit::SuperBlurView::New( 5 );
106 mSuperBlurView.SetSize( stageSize );
107 mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER );
108 mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER );
109 mSuperBlurView.BlurFinishedSignal().Connect(this, &BlurExample::OnBlurFinished);
110 mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
111 mSuperBlurView.SetImage( mCurrentImage );
112 mBackground.Add( mSuperBlurView );
114 SetTitle( TITLE_SUPER_BLUR );
116 mBloomView = Toolkit::BloomView::New();
117 mBloomView.SetParentOrigin(ParentOrigin::CENTER);
118 mBloomView.SetSize(stageSize);
119 mBloomActor = Toolkit::ImageView::New(mCurrentImage);
120 mBloomActor.SetParentOrigin( ParentOrigin::CENTER );
121 mBloomView.Add( mBloomActor );
123 // Connect the callback to the touch signal on the background
124 mSuperBlurView.TouchSignal().Connect( this, &BlurExample::OnTouch );
125 mBloomView.TouchSignal().Connect( this, &BlurExample::OnTouch );
128 // Callback function of the touch signal on the background
129 bool OnTouch(Dali::Actor actor, const Dali::TouchData& event)
131 switch( event.GetState( 0 ) )
133 case PointState::DOWN:
140 mAnimation = Animation::New( 2.f );
141 if( mSuperBlurView.OnStage() )
143 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 1.f );
147 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 3.f );
153 case PointState::LEAVE:
154 case PointState::INTERRUPTED:
161 mAnimation = Animation::New( 2.f );
162 if( mSuperBlurView.OnStage() )
164 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 0.f );
168 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 0.f );
173 case PointState::MOTION:
174 case PointState::STATIONARY:
183 * Main key event handler
185 void OnKeyEvent(const KeyEvent& event)
187 if(event.state == KeyEvent::Down)
189 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
196 bool OnChangeBackgroundIconClicked( Toolkit::Button button )
208 mImageIndex = (mImageIndex+1u)%NUM_BACKGROUND_IMAGES;
209 mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
211 if( mSuperBlurView.OnStage() )
215 mSuperBlurView.SetBlurStrength( 0.f );
216 mSuperBlurView.SetImage( mCurrentImage );
220 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
221 mBloomActor.SetImage( mCurrentImage );
227 bool OnChangeBlurIconClicked( Toolkit::Button button )
229 if( mSuperBlurView.OnStage() )
231 SetTitle( TITLE_BLOOM );
232 mBackground.Remove( mSuperBlurView );
234 mBloomActor.SetImage( mCurrentImage );
235 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
236 mBackground.Add( mBloomView );
237 mBloomView.Activate();
242 SetTitle( TITLE_SUPER_BLUR );
243 mBackground.Remove( mBloomView );
244 mBloomView.Deactivate();
246 mBackground.Add( mSuperBlurView );
247 mSuperBlurView.SetBlurStrength( 0.f );
248 mSuperBlurView.SetImage( mCurrentImage );
255 void OnBlurFinished( Toolkit::SuperBlurView blurView )
261 * Sets/Updates the title of the View
262 * @param[in] title The new title for the view.
264 void SetTitle(const std::string& title)
268 mTitleActor = DemoHelper::CreateToolBarLabel( title );
269 // Add title to the tool bar.
270 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
273 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, title );
279 Toolkit::ToolBar mToolBar;
280 Toolkit::TextLabel mTitleActor; ///< The Toolbar's Title.
281 Toolkit::Control mBackground;
282 Toolkit::SuperBlurView mSuperBlurView;
283 Toolkit::BloomView mBloomView;
284 Animation mAnimation;
285 Toolkit::ImageView mBloomActor;
287 unsigned int mImageIndex;
291 /*****************************************************************************/
294 RunTest(Application& app)
296 BlurExample theApp(app);
300 /*****************************************************************************/
302 int DALI_EXPORT_API main(int argc, char **argv)
304 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);