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::GaussianBlurView;
25 using Dali::Toolkit::TextLabel;
29 const char* const BACKGROUND_IMAGE(DEMO_IMAGE_DIR "lake_front.jpg");
30 const float BACKGROUND_IMAGE_WIDTH = 2048.0f;
35 * This example shows a scrolling background image which can be blurred (on/off) by tapping the screen
37 class GaussianBlurViewExample : public ConnectionTracker
40 GaussianBlurViewExample(Application& application)
41 : mApplication(application),
46 mApplication.InitSignal().Connect(this, &GaussianBlurViewExample::Create);
49 ~GaussianBlurViewExample() = default;
52 void Create(Application& application)
54 auto window = application.GetWindow();
55 Vector2 windowSize = window.GetSize();
56 window.KeyEventSignal().Connect(this, &GaussianBlurViewExample::OnKeyEvent);
58 mImageView = Toolkit::ImageView::New(BACKGROUND_IMAGE);
59 mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
60 mImageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
62 float excessWidth = std::max(0.0f, (BACKGROUND_IMAGE_WIDTH - windowSize.width) * 0.5f);
64 if(excessWidth > 0.0f)
66 // Move background image to show GaussianBlurView activity
68 float pixelsPerSecond = 10.0f;
69 float duration = excessWidth / pixelsPerSecond;
70 float qDuration = duration * 0.25f;
72 mAnimation = Animation::New(duration);
73 mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), excessWidth, TimePeriod(0.0f, qDuration));
74 mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(qDuration, qDuration));
75 mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), -excessWidth, TimePeriod(2.0f * qDuration, qDuration));
76 mAnimation.AnimateTo(Property(mImageView, Actor::Property::POSITION_X), 0.0f, TimePeriod(3.0f * qDuration, qDuration));
78 mAnimation.SetLooping(true);
82 Layer onTop = Layer::New();
83 onTop.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
84 onTop.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
85 onTop.SetProperty(Actor::Property::SIZE, windowSize);
89 mOnLabel = TextLabel::New("Blur ON");
90 mOnLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
91 mOnLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::GREEN);
92 mOnLabel.SetProperty(Actor::Property::VISIBLE, false);
95 mOffLabel = TextLabel::New("Blur OFF");
96 mOffLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
97 mOffLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE);
98 mOffLabel.SetProperty(Actor::Property::VISIBLE, true);
101 mGaussianBlurView = GaussianBlurView::New(30, 8.0f, Pixel::RGBA8888, 0.5f, 0.5f, false);
102 mGaussianBlurView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
103 mGaussianBlurView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
104 mGaussianBlurView.SetProperty(Actor::Property::SIZE, windowSize);
105 window.Add(mGaussianBlurView);
107 mGaussianBlurView.Add(mImageView);
108 mGaussianBlurView.SetProperty(mGaussianBlurView.GetBlurStrengthPropertyIndex(), mStrength);
110 window.GetRootLayer().TouchedSignal().Connect(this, &GaussianBlurViewExample::OnTouch);
113 bool OnTouch(Actor actor, const TouchEvent& touch)
115 const PointState::Type state = touch.GetState(0);
117 if(PointState::DOWN == state)
122 mGaussianBlurView.Activate();
124 mOnLabel.SetProperty(Actor::Property::VISIBLE, true);
125 mOffLabel.SetProperty(Actor::Property::VISIBLE, false);
130 mGaussianBlurView.Deactivate();
132 mOnLabel.SetProperty(Actor::Property::VISIBLE, false);
133 mOffLabel.SetProperty(Actor::Property::VISIBLE, true);
140 void OnKeyEvent(const KeyEvent& event)
142 if(event.GetState() == KeyEvent::DOWN)
144 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
152 Application& mApplication;
154 Toolkit::ImageView mImageView;
156 Animation mAnimation;
161 GaussianBlurView mGaussianBlurView;
169 int DALI_EXPORT_API main(int argc, char** argv)
171 Application application = Application::New(&argc, &argv);
173 GaussianBlurViewExample test(application);
175 application.MainLoop();