2 * Copyright (c) 2015 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/super-blur-view/super-blur-view.h>
20 #include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
21 #include "shared/view.h"
22 #include "shared/utility.h"
28 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
29 const char * const TITLE_SUPER_BLUR( "Super Blur" );
30 const char * const TITLE_BLOOM( "Bloom" );
31 const char * const CHANGE_BACKGROUND_ICON( DEMO_IMAGE_DIR "icon-change.png" );
32 const char * const CHANGE_BACKGROUND_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
33 const char * const CHANGE_BLUR_ICON( DEMO_IMAGE_DIR "icon-replace.png" );
34 const char * const CHANGE_BLUR_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
36 const char* BACKGROUND_IMAGES[]=
38 DEMO_IMAGE_DIR "background-1.jpg",
39 DEMO_IMAGE_DIR "background-2.jpg",
40 DEMO_IMAGE_DIR "background-3.jpg",
41 DEMO_IMAGE_DIR "background-4.jpg",
42 DEMO_IMAGE_DIR "background-5.jpg",
43 DEMO_IMAGE_DIR "background-magnifier.jpg",
45 const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) );
49 class BlurExample : public ConnectionTracker
52 BlurExample(Application &app)
57 // Connect to the Application's Init signal
58 app.InitSignal().Connect(this, &BlurExample::Create);
65 // The Init signal is received once (only) during the Application lifetime
66 void Create(Application& app)
68 Stage stage = Stage::GetCurrent();
69 Vector2 stageSize = stage.GetSize();
71 stage.KeyEventSignal().Connect(this, &BlurExample::OnKeyEvent);
73 // Creates a default view with a default tool bar.
74 // The view is added to the stage.
75 Layer content = DemoHelper::CreateView( app,
82 // Add a button to change background. (right of toolbar)
83 Toolkit::PushButton changeBackgroundButton = Toolkit::PushButton::New();
84 changeBackgroundButton.SetUnselectedImage( CHANGE_BACKGROUND_ICON );
85 changeBackgroundButton.SetSelectedImage( CHANGE_BACKGROUND_ICON_SELECTED );
86 changeBackgroundButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBackgroundIconClicked );
87 mToolBar.AddControl( changeBackgroundButton,
88 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
89 Toolkit::Alignment::HorizontalRight,
90 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
92 // Add a button to change the blur view. (left of toolbar)
93 Toolkit::PushButton changeBlurButton = Toolkit::PushButton::New();
94 changeBlurButton.SetUnselectedImage( CHANGE_BLUR_ICON );
95 changeBlurButton.SetSelectedImage( CHANGE_BLUR_ICON_SELECTED );
96 changeBlurButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBlurIconClicked );
97 mToolBar.AddControl( changeBlurButton,
98 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
99 Toolkit::Alignment::HorizontalLeft,
100 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
102 mSuperBlurView = Toolkit::SuperBlurView::New( 5 );
103 mSuperBlurView.SetSize( stageSize );
104 mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER );
105 mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER );
106 mSuperBlurView.BlurFinishedSignal().Connect(this, &BlurExample::OnBlurFinished);
107 mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
108 mSuperBlurView.SetImage( mCurrentImage );
109 mBackground.Add( mSuperBlurView );
111 SetTitle( TITLE_SUPER_BLUR );
113 mBloomView = Toolkit::BloomView::New();
114 mBloomView.SetParentOrigin(ParentOrigin::CENTER);
115 mBloomView.SetSize(stageSize);
116 mBloomActor = Toolkit::ImageView::New(mCurrentImage);
117 mBloomActor.SetParentOrigin( ParentOrigin::CENTER );
118 mBloomView.Add( mBloomActor );
120 // Connect the callback to the touch signal on the background
121 mSuperBlurView.TouchSignal().Connect( this, &BlurExample::OnTouch );
122 mBloomView.TouchSignal().Connect( this, &BlurExample::OnTouch );
125 // Callback function of the touch signal on the background
126 bool OnTouch(Dali::Actor actor, const Dali::TouchData& event)
128 switch( event.GetState( 0 ) )
130 case PointState::DOWN:
137 mAnimation = Animation::New( 2.f );
138 if( mSuperBlurView.OnStage() )
140 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 1.f );
144 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 3.f );
150 case PointState::LEAVE:
151 case PointState::INTERRUPTED:
158 mAnimation = Animation::New( 2.f );
159 if( mSuperBlurView.OnStage() )
161 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 0.f );
165 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 0.f );
170 case PointState::MOTION:
171 case PointState::STATIONARY:
180 * Main key event handler
182 void OnKeyEvent(const KeyEvent& event)
184 if(event.state == KeyEvent::Down)
186 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
193 bool OnChangeBackgroundIconClicked( Toolkit::Button button )
205 mImageIndex = (mImageIndex+1u)%NUM_BACKGROUND_IMAGES;
206 mCurrentImage = DemoHelper::LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
208 if( mSuperBlurView.OnStage() )
212 mSuperBlurView.SetBlurStrength( 0.f );
213 mSuperBlurView.SetImage( mCurrentImage );
217 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
218 mBloomActor.SetImage( mCurrentImage );
224 bool OnChangeBlurIconClicked( Toolkit::Button button )
226 if( mSuperBlurView.OnStage() )
228 SetTitle( TITLE_BLOOM );
229 mBackground.Remove( mSuperBlurView );
231 mBloomActor.SetImage( mCurrentImage );
232 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
233 mBackground.Add( mBloomView );
234 mBloomView.Activate();
239 SetTitle( TITLE_SUPER_BLUR );
240 mBackground.Remove( mBloomView );
241 mBloomView.Deactivate();
243 mBackground.Add( mSuperBlurView );
244 mSuperBlurView.SetBlurStrength( 0.f );
245 mSuperBlurView.SetImage( mCurrentImage );
252 void OnBlurFinished( Toolkit::SuperBlurView blurView )
258 * Sets/Updates the title of the View
259 * @param[in] title The new title for the view.
261 void SetTitle(const std::string& title)
265 mTitleActor = DemoHelper::CreateToolBarLabel( title );
266 // Add title to the tool bar.
267 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
270 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, title );
276 Toolkit::ToolBar mToolBar;
277 Toolkit::TextLabel mTitleActor; ///< The Toolbar's Title.
278 Toolkit::Control mBackground;
279 Toolkit::SuperBlurView mSuperBlurView;
280 Toolkit::BloomView mBloomView;
281 Animation mAnimation;
282 Toolkit::ImageView mBloomActor;
284 unsigned int mImageIndex;
288 /*****************************************************************************/
291 RunTest(Application& app)
293 BlurExample theApp(app);
297 /*****************************************************************************/
299 int DALI_EXPORT_API main(int argc, char **argv)
301 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);