2 * Copyright (c) 2022 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/controls/text-controls/text-label-devel.h>
21 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
22 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
23 #include <dali/integration-api/debug.h>
25 #include <dali/devel-api/adaptor-framework/performance-logger.h>
32 using namespace Dali::Toolkit;
38 // This example shows the blur radius property of the color visual and animates it.
40 class ColorVisualExample : public ConnectionTracker
43 ColorVisualExample(Application& application)
44 : mApplication(application)
46 // Connect to the Application's Init signal
47 mApplication.InitSignal().Connect(this, &ColorVisualExample::Create);
52 // Nothing to do here;
57 std::list<Control> list;
60 const int duration = 100; // miliseconds.
62 PerformanceLogger customLoopLogger;
63 PerformanceLogger customNew1Logger;
64 PerformanceLogger customColorLogger;
66 // The Init signal is received once (only) during the Application lifetime
67 void Create(Application& application)
69 StyleManager instance = StyleManager::Get();
70 window = application.GetWindow();
71 window.SetBackgroundColor(Color::WHITE);
73 timer = Timer::New(duration);
74 timer.TickSignal().Connect(this, &ColorVisualExample::OnTick);
77 customLoopLogger = PerformanceLogger::New("20Controls");
78 customNew1Logger = PerformanceLogger::New("1_New");
79 customColorLogger = PerformanceLogger::New("2_SetBG");
81 customLoopLogger.EnableLogging(true);
82 customNew1Logger.EnableLogging(true);
83 customColorLogger.EnableLogging(true);
85 // Respond to key events
86 window.KeyEventSignal().Connect(this, &ColorVisualExample::OnKeyEvent);
91 float width = (float)window.GetSize().GetWidth() / m;
92 float height = (float)window.GetSize().GetHeight() / n;
96 customLoopLogger.AddMarker(PerformanceLogger::Marker::START_EVENT);
97 customNew1Logger.AddMarker(PerformanceLogger::Marker::START_EVENT);
98 Control rawView = Control::New(Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS);
99 customNew1Logger.AddMarker(PerformanceLogger::Marker::END_EVENT);
101 customColorLogger.AddMarker(PerformanceLogger::Marker::START_EVENT);
102 rawView.SetBackgroundColor(Color::BLUE);
103 customColorLogger.AddMarker(PerformanceLogger::Marker::END_EVENT);
104 rawView[Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
105 rawView[Actor::Property::ANCHOR_POINT] = AnchorPoint::TOP_LEFT;
106 rawView[Actor::Property::SIZE] = Vector2((float)window.GetSize().GetWidth(), height);
107 rawView[Actor::Property::POSITION] = Vector2(0.0f, height * i);
109 for(int j = 0; j < m; j++)
112 customNew1Logger.AddMarker(PerformanceLogger::Marker::START_EVENT);
114 bgView = ImageView::New(Control::ControlBehaviour::DISABLE_STYLE_CHANGE_SIGNALS, DEMO_IMAGE_DIR "gallery-small-23.jpg");
116 customNew1Logger.AddMarker(PerformanceLogger::Marker::END_EVENT);
118 customColorLogger.AddMarker(PerformanceLogger::Marker::START_EVENT);
119 bgView.SetBackgroundColor(Color::CRIMSON);
120 customColorLogger.AddMarker(PerformanceLogger::Marker::END_EVENT);
121 bgView[Actor::Property::PARENT_ORIGIN] = ParentOrigin::TOP_LEFT;
122 bgView[Actor::Property::ANCHOR_POINT] = AnchorPoint::TOP_LEFT;
123 bgView[Actor::Property::SIZE] = Vector2(width * 0.9f, height * 0.9f);
124 bgView[Actor::Property::POSITION] = Vector2(width * j + width * 0.05f, height * 0.05f);
127 customLoopLogger.AddMarker(PerformanceLogger::Marker::END_EVENT);
129 window.GetRootLayer().Add(rawView);
130 list.push_back(rawView);
132 Animation animation = Animation::New(duration * 0.001f * n);
133 animation.AnimateTo(Property(rawView, Actor::Property::POSITION_Y), -height);
136 while((int)list.size() > n)
138 list.front().Unparent();
146 void OnKeyEvent(const KeyEvent& event)
148 if(event.GetState() == KeyEvent::DOWN)
150 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
160 Application& mApplication;
163 int DALI_EXPORT_API main(int argc, char** argv)
165 Application application = Application::New(&argc, &argv);
166 ColorVisualExample test(application);
167 application.MainLoop();