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"
27 const char * const TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
28 const char * const TITLE_SUPER_BLUR( "Super Blur" );
29 const char * const TITLE_BLOOM( "Bloom" );
30 const char * const CHANGE_BACKGROUND_ICON( DEMO_IMAGE_DIR "icon-change.png" );
31 const char * const CHANGE_BACKGROUND_ICON_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
32 const char * const CHANGE_BLUR_ICON( DEMO_IMAGE_DIR "icon-replace.png" );
33 const char * const CHANGE_BLUR_ICON_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
35 const char* BACKGROUND_IMAGES[]=
37 DEMO_IMAGE_DIR "background-1.jpg",
38 DEMO_IMAGE_DIR "background-2.jpg",
39 DEMO_IMAGE_DIR "background-3.jpg",
40 DEMO_IMAGE_DIR "background-4.jpg",
41 DEMO_IMAGE_DIR "background-5.jpg",
42 DEMO_IMAGE_DIR "background-magnifier.jpg",
44 const unsigned int NUM_BACKGROUND_IMAGES( sizeof( BACKGROUND_IMAGES ) / sizeof( BACKGROUND_IMAGES[0] ) );
48 * @brief Load an image, scaled-down to no more than the stage dimensions.
50 * Uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at
51 * load time to cover the entire stage with pixels with no borders,
52 * and filter mode BOX_THEN_LINEAR to sample the image with
55 ResourceImage LoadStageFillingImage( const char * const imagePath )
57 Size stageSize = Stage::GetCurrent().GetSize();
58 return ResourceImage::New( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
61 class BlurExample : public ConnectionTracker
64 BlurExample(Application &app)
69 // Connect to the Application's Init signal
70 app.InitSignal().Connect(this, &BlurExample::Create);
77 // The Init signal is received once (only) during the Application lifetime
78 void Create(Application& app)
80 Stage stage = Stage::GetCurrent();
81 Vector2 stageSize = stage.GetSize();
83 stage.KeyEventSignal().Connect(this, &BlurExample::OnKeyEvent);
85 // Creates a default view with a default tool bar.
86 // The view is added to the stage.
87 Layer content = DemoHelper::CreateView( app,
94 // Add a button to change background. (right of toolbar)
95 Toolkit::PushButton changeBackgroundButton = Toolkit::PushButton::New();
96 changeBackgroundButton.SetUnselectedImage( CHANGE_BACKGROUND_ICON );
97 changeBackgroundButton.SetSelectedImage( CHANGE_BACKGROUND_ICON_SELECTED );
98 changeBackgroundButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBackgroundIconClicked );
99 mToolBar.AddControl( changeBackgroundButton,
100 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
101 Toolkit::Alignment::HorizontalRight,
102 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
104 // Add a button to change the blur view. (left of toolbar)
105 Toolkit::PushButton changeBlurButton = Toolkit::PushButton::New();
106 changeBlurButton.SetUnselectedImage( CHANGE_BLUR_ICON );
107 changeBlurButton.SetSelectedImage( CHANGE_BLUR_ICON_SELECTED );
108 changeBlurButton.ClickedSignal().Connect( this, &BlurExample::OnChangeBlurIconClicked );
109 mToolBar.AddControl( changeBlurButton,
110 DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage,
111 Toolkit::Alignment::HorizontalLeft,
112 DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
114 mSuperBlurView = Toolkit::SuperBlurView::New( 5 );
115 mSuperBlurView.SetSize( stageSize );
116 mSuperBlurView.SetParentOrigin( ParentOrigin::CENTER );
117 mSuperBlurView.SetAnchorPoint( AnchorPoint::CENTER );
118 mSuperBlurView.BlurFinishedSignal().Connect(this, &BlurExample::OnBlurFinished);
119 mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
120 mSuperBlurView.SetImage( mCurrentImage );
121 mBackground.Add( mSuperBlurView );
123 SetTitle( TITLE_SUPER_BLUR );
125 mBloomView = Toolkit::BloomView::New();
126 mBloomView.SetParentOrigin(ParentOrigin::CENTER);
127 mBloomView.SetSize(stageSize);
128 mBloomActor = Toolkit::ImageView::New(mCurrentImage);
129 mBloomActor.SetParentOrigin( ParentOrigin::CENTER );
130 mBloomView.Add( mBloomActor );
132 // Connect the callback to the touch signal on the background
133 mSuperBlurView.TouchSignal().Connect( this, &BlurExample::OnTouch );
134 mBloomView.TouchSignal().Connect( this, &BlurExample::OnTouch );
137 // Callback function of the touch signal on the background
138 bool OnTouch(Dali::Actor actor, const Dali::TouchData& event)
140 switch( event.GetState( 0 ) )
142 case PointState::DOWN:
149 mAnimation = Animation::New( 2.f );
150 if( mSuperBlurView.OnStage() )
152 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 1.f );
156 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 3.f );
162 case PointState::LEAVE:
163 case PointState::INTERRUPTED:
170 mAnimation = Animation::New( 2.f );
171 if( mSuperBlurView.OnStage() )
173 mAnimation.AnimateTo( Property( mSuperBlurView, mSuperBlurView.GetBlurStrengthPropertyIndex() ), 0.f );
177 mAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBloomIntensityPropertyIndex() ), 0.f );
182 case PointState::MOTION:
183 case PointState::STATIONARY:
192 * Main key event handler
194 void OnKeyEvent(const KeyEvent& event)
196 if(event.state == KeyEvent::Down)
198 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
205 bool OnChangeBackgroundIconClicked( Toolkit::Button button )
217 mImageIndex = (mImageIndex+1u)%NUM_BACKGROUND_IMAGES;
218 mCurrentImage = LoadStageFillingImage( BACKGROUND_IMAGES[mImageIndex] );
220 if( mSuperBlurView.OnStage() )
224 mSuperBlurView.SetBlurStrength( 0.f );
225 mSuperBlurView.SetImage( mCurrentImage );
229 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
230 mBloomActor.SetImage( mCurrentImage );
236 bool OnChangeBlurIconClicked( Toolkit::Button button )
238 if( mSuperBlurView.OnStage() )
240 SetTitle( TITLE_BLOOM );
241 mBackground.Remove( mSuperBlurView );
243 mBloomActor.SetImage( mCurrentImage );
244 mBloomView.SetProperty( mBloomView.GetBloomIntensityPropertyIndex(), 0.f );
245 mBackground.Add( mBloomView );
246 mBloomView.Activate();
251 SetTitle( TITLE_SUPER_BLUR );
252 mBackground.Remove( mBloomView );
253 mBloomView.Deactivate();
255 mBackground.Add( mSuperBlurView );
256 mSuperBlurView.SetBlurStrength( 0.f );
257 mSuperBlurView.SetImage( mCurrentImage );
264 void OnBlurFinished( Toolkit::SuperBlurView blurView )
270 * Sets/Updates the title of the View
271 * @param[in] title The new title for the view.
273 void SetTitle(const std::string& title)
277 mTitleActor = DemoHelper::CreateToolBarLabel( title );
278 // Add title to the tool bar.
279 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter );
282 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, title );
288 Toolkit::ToolBar mToolBar;
289 Toolkit::TextLabel mTitleActor; ///< The Toolbar's Title.
290 Toolkit::Control mBackground;
291 Toolkit::SuperBlurView mSuperBlurView;
292 Toolkit::BloomView mBloomView;
293 Animation mAnimation;
294 Toolkit::ImageView mBloomActor;
296 unsigned int mImageIndex;
300 /*****************************************************************************/
303 RunTest(Application& app)
305 BlurExample theApp(app);
309 /*****************************************************************************/
311 int DALI_EXPORT_API main(int argc, char **argv)
313 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);