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.
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
24 using Dali::Toolkit::TextLabel;
25 using Dali::Toolkit::GaussianBlurView;
30 const char* const BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
31 const float BACKGROUND_IMAGE_WIDTH = 2048.0f;
36 * This example shows a scrolling background image which can be blurred (on/off) by tapping the screen
38 class GaussianBlurViewExample : public ConnectionTracker
42 GaussianBlurViewExample( Application& application )
43 : mApplication( application ),
48 mApplication.InitSignal().Connect( this, &GaussianBlurViewExample::Create );
51 ~GaussianBlurViewExample() = default;
55 void Create( Application& application )
57 auto window = application.GetWindow();
58 Vector2 windowSize = window.GetSize();
59 window.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent);
61 mImageView = Toolkit::ImageView::New( BACKGROUND_IMAGE );
62 mImageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
63 mImageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
65 float excessWidth = std::max( 0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f );
67 if( excessWidth > 0.0f )
69 // Move background image to show GaussianBlurView activity
71 float pixelsPerSecond = 10.0f;
72 float duration = excessWidth / pixelsPerSecond;
73 float qDuration = duration * 0.25f;
75 mAnimation = Animation::New( duration );
76 mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f , qDuration) );
77 mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration , qDuration) );
78 mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f*qDuration, qDuration) );
79 mAnimation.AnimateTo( Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f*qDuration, qDuration) );
81 mAnimation.SetLooping( true );
85 Layer onTop = Layer::New();
86 onTop.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
87 onTop.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
88 onTop.SetProperty( Actor::Property::SIZE, windowSize );
92 mOnLabel = TextLabel::New( "Blur ON" );
93 mOnLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
94 mOnLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::GREEN );
95 mOnLabel.SetProperty( Actor::Property::VISIBLE, false );
96 onTop.Add( mOnLabel );
98 mOffLabel = TextLabel::New( "Blur OFF" );
99 mOffLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
100 mOffLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
101 mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
102 onTop.Add( mOffLabel );
104 mGaussianBlurView = GaussianBlurView::New( 30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false );
105 mGaussianBlurView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
106 mGaussianBlurView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
107 mGaussianBlurView.SetProperty( Actor::Property::SIZE, windowSize );
108 window.Add( mGaussianBlurView );
110 mGaussianBlurView.Add( mImageView );
111 mGaussianBlurView.SetProperty( mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength );
113 window.GetRootLayer().TouchSignal().Connect( this, &GaussianBlurViewExample::OnTouch );
116 bool OnTouch( Actor actor, const TouchEvent& touch )
118 const PointState::Type state = touch.GetState( 0 );
120 if( PointState::DOWN == state )
125 mGaussianBlurView.Activate();
127 mOnLabel.SetProperty( Actor::Property::VISIBLE, true );
128 mOffLabel.SetProperty( Actor::Property::VISIBLE, false );
133 mGaussianBlurView.Deactivate();
135 mOnLabel.SetProperty( Actor::Property::VISIBLE, false );
136 mOffLabel.SetProperty( Actor::Property::VISIBLE, true );
143 void OnKeyEvent(const KeyEvent& event)
145 if(event.GetState() == KeyEvent::Down)
147 if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
156 Application& mApplication;
158 Toolkit::ImageView mImageView;
160 Animation mAnimation;
165 GaussianBlurView mGaussianBlurView;
173 int DALI_EXPORT_API main( int argc, char **argv )
175 Application application = Application::New( &argc, &argv );
177 GaussianBlurViewExample test( application );
179 application.MainLoop();