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/bloom-view/bloom-view.h>
23 using namespace Dali::Toolkit;
28 const char* BACKGROUND_IMAGE_PATH( DEMO_IMAGE_DIR "desktop_background_1440x2560.png" );
29 const char* UI_DIFFUSE_IMAGE( DEMO_IMAGE_DIR "UI-Leather-DIFF.png" );
31 const Rect<int> UI_PIXEL_AREA( 0, 0, 720, 1280 );
33 const Rect<int> PANEL1_PIXEL_AREA( 0, 0, 720, 39 );
34 const Rect<int> PANEL2_PIXEL_AREA( 0, 39, 720, 100 );
36 const unsigned int NUM_MOVEMENT_ANIMATIONS = 2;
38 // for animating bloom intensity on tap gesture
39 const float PULSE_BLOOM_INCREASE_ANIM_TIME = 1.175;
40 const float PULSE_BLOOM_DECREASE_ANIM_TIME = 2.4;
41 const float PULSE_BLOOM_TOTAL_ANIM_TIME = PULSE_BLOOM_INCREASE_ANIM_TIME + PULSE_BLOOM_DECREASE_ANIM_TIME;
42 const float PULSE_BLOOM_INTENSITY_DEFAULT = 1.0f;
43 const float PULSE_BLOOM_INTENSITY_INCREASE = 3.0f;
45 // These values depend on the button background image
46 const Vector4 BUTTON_IMAGE_BORDER(16.0f, 16.0f, 16.0f, 20.0f);
48 const float UI_MARGIN = 4.0f; ///< Screen Margin for placement of UI buttons
49 const Vector3 BUTTON_SIZE_CONSTRAINT( 0.24f, 0.09f, 1.0f );
54 * This example demonstrates a bloom effect.
56 class BloomExample : public ConnectionTracker
60 BloomExample( Application &application )
61 : mApplication(application),
64 application.InitSignal().Connect( this, &BloomExample::Create );
73 void Create( Application& application )
75 Window window = application.GetWindow();
76 Vector2 windowSize = window.GetSize();
77 Vector2 viewSize( windowSize );
79 mRootActor = Actor::New();
80 mRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
81 mRootActor.SetProperty( Actor::Property::SIZE, windowSize );
82 window.Add( mRootActor );
84 // Create the object that will perform the blooming work
85 mBloomView = Dali::Toolkit::BloomView::New();
86 mBloomView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
87 mBloomView.SetProperty( Actor::Property::SIZE, viewSize );
88 mRootActor.Add( mBloomView );
89 mBloomView.Activate();
91 Layer backgroundLayer = Layer::New();
92 backgroundLayer.SetProperty( Actor::Property::SIZE, viewSize );
93 backgroundLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
94 mBloomView.Add( backgroundLayer );
96 // Create the background image
97 ImageView backgroundImage = ImageView::New( BACKGROUND_IMAGE_PATH );
98 backgroundImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
99 backgroundImage.SetProperty( Actor::Property::SIZE, viewSize );
100 backgroundLayer.Add( backgroundImage );
102 Layer foregroundLayer = Layer::New();
103 foregroundLayer.SetProperty( Actor::Property::SIZE, viewSize );
104 foregroundLayer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
105 mBloomView.Add( foregroundLayer );
107 // Create visible actors
108 mObjectRootActor = Actor::New();
109 mObjectRootActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
110 mObjectRootActor.SetProperty( Actor::Property::SIZE, viewSize );
111 foregroundLayer.Add( mObjectRootActor );
113 ImageView imageView = ImageView::New( UI_DIFFUSE_IMAGE );
114 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
115 imageView.SetProperty( Actor::Property::SIZE, viewSize );
116 mObjectRootActor.Add( imageView );
118 imageView = ImageView::New( UI_DIFFUSE_IMAGE );
119 imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
120 imageView.SetProperty( Actor::Property::SIZE, windowSize * 0.5f );
121 imageView.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 0.0f, 100.0f ) );
122 mObjectRootActor.Add( imageView );
125 PulseBloomIntensity();
127 // Respond to key events
128 window.KeyEventSignal().Connect( this, &BloomExample::OnKeyEvent );
131 void OnKeyEvent( const KeyEvent& event )
133 if( event.state == KeyEvent::Down )
135 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
142 void AnimateBloomView()
144 if(mRotationAnimation)
146 mRotationAnimation.Stop();
150 mResizeAnimation.Stop();
152 if(mTranslationAnimation)
154 mTranslationAnimation.Stop();
158 mBlurAnimation.Stop();
162 mRotationAnimation = Animation::New( 5.0f );
163 mRotationAnimation.AnimateBy( Property( mObjectRootActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT );
164 mRotationAnimation.SetEndAction( Animation::Discard );
165 mRotationAnimation.SetLooping( true );
166 mRotationAnimation.Play();
169 mTranslationAnimation = Animation::New( 7.5f );
170 mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(100.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f) );
171 mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(300.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(2.5f, 2.5f) );
172 mTranslationAnimation.AnimateBy( Property(mObjectRootActor, Actor::Property::POSITION), Vector3(0.0f, 0.0f, 0.0f), AlphaFunction::BOUNCE, TimePeriod(5.0f, 2.5f) );
173 mTranslationAnimation.SetEndAction( Animation::Discard );
174 mTranslationAnimation.SetLooping( true );
175 //mTranslationAnimation.Play();
178 mBlurAnimation = Animation::New( 4.0f );
179 mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 0.0f, AlphaFunction::LINEAR, TimePeriod(0.0f, 0.5f) );
180 mBlurAnimation.AnimateTo( Property( mBloomView, mBloomView.GetBlurStrengthPropertyIndex() ), 1.0f, AlphaFunction::LINEAR, TimePeriod(2.0f, 0.5f) );
181 mBlurAnimation.SetEndAction( Animation::Discard );
182 mBlurAnimation.SetLooping( true );
183 mBlurAnimation.Play();
186 void PulseBloomIntensity()
188 mPulseBloomIntensityAnim = Animation::New( 2.5f );
189 mPulseBloomIntensityAnim.AnimateTo( Property(mBloomView, mBloomView.GetBloomIntensityPropertyIndex()), 3.0f, AlphaFunction::BOUNCE, TimePeriod(2.5f) );
190 mPulseBloomIntensityAnim.SetEndAction( Animation::Discard );
191 mPulseBloomIntensityAnim.SetLooping( true );
192 mPulseBloomIntensityAnim.Play();
197 Application& mApplication;
201 Actor mObjectRootActor;
203 unsigned int mCurrentAnimation;
204 Animation mRotationAnimation;
205 Animation mResizeAnimation;
206 Animation mTranslationAnimation;
207 Animation mBlurAnimation;
208 Animation mPulseBloomIntensityAnim;
210 BloomView mBloomView;
213 int DALI_EXPORT_API main(int argc, char **argv)
215 Application application = Application::New( &argc, &argv );
217 BloomExample theApp( application );
218 application.MainLoop();