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-toolkit/dali-toolkit.h>
19 #include <dali-toolkit/devel-api/controls/control-devel.h>
20 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
21 #include <dali-toolkit/devel-api/visuals/color-visual-properties-devel.h>
22 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
25 using namespace Dali::Toolkit;
29 const char* IMAGE_FILE(DEMO_IMAGE_DIR "gallery-medium-1.jpg");
31 const float BLUR_RADIUS_VALUE(10.0f);
32 const float NO_BLUR_VALUE(0.0f);
33 const float ANIMATION_DURATION(2.0f);
35 const Property::Value SHADOW{
36 {Visual::Property::TYPE, Visual::COLOR},
37 {Visual::Property::MIX_COLOR, Vector4(0.0f, 0.0f, 0.0f, 0.5f)},
38 {Visual::Property::TRANSFORM, Property::Map{{Visual::Transform::Property::OFFSET, Vector2(0.05f, 0.05f)}, {Visual::Transform::Property::SIZE, Vector2(1.05f, 1.05f)}, {Visual::Transform::Property::ORIGIN, Align::CENTER}, {Visual::Transform::Property::ANCHOR_POINT, Align::CENTER}}},
39 {DevelColorVisual::Property::BLUR_RADIUS, BLUR_RADIUS_VALUE}};
43 // This example shows the blur radius property of the color visual and animates it.
45 class ColorVisualExample : public ConnectionTracker
48 ColorVisualExample(Application& application)
49 : mApplication(application),
52 // Connect to the Application's Init signal
53 mApplication.InitSignal().Connect(this, &ColorVisualExample::Create);
58 // Nothing to do here;
61 // The Init signal is received once (only) during the Application lifetime
62 void Create(Application& application)
64 // Get a handle to the window
65 Window window = application.GetWindow();
66 window.SetBackgroundColor(Color::WHITE);
68 mImageView = ImageView::New(IMAGE_FILE);
69 mImageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
70 mImageView.SetProperty(Actor::Property::SIZE, Vector2(200.0f, 200.0f));
71 mImageView.SetProperty(DevelControl::Property::SHADOW, SHADOW);
73 window.Add(mImageView);
75 // Respond to a click anywhere on the window
76 window.GetRootLayer().TouchedSignal().Connect(this, &ColorVisualExample::OnTouch);
78 // Respond to key events
79 window.KeyEventSignal().Connect(this, &ColorVisualExample::OnKeyEvent);
82 bool OnTouch(Actor actor, const TouchEvent& touch)
84 if(touch.GetState(0) == PointState::UP)
86 float initialValue, targetValue;
89 initialValue = NO_BLUR_VALUE;
90 targetValue = BLUR_RADIUS_VALUE;
94 initialValue = BLUR_RADIUS_VALUE;
95 targetValue = NO_BLUR_VALUE;
98 mShadowVisible = !mShadowVisible;
100 TransitionData transitionData = TransitionData::New(Property::Map().Add("target", "shadow").Add("property", "blurRadius").Add("initialValue", initialValue).Add("targetValue", targetValue).Add("animator", Property::Map().Add("duration", ANIMATION_DURATION)));
101 Animation animation = DevelControl::CreateTransition(Toolkit::Internal::GetImplementation(mImageView), transitionData);
107 void OnKeyEvent(const KeyEvent& event)
109 if(event.GetState() == KeyEvent::DOWN)
111 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
119 Application& mApplication;
120 ImageView mImageView;
124 int DALI_EXPORT_API main(int argc, char** argv)
126 Application application = Application::New(&argc, &argv);
127 ColorVisualExample test(application);
128 application.MainLoop();