2 * Copyright (c) 2023 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>
22 using namespace Dali::Toolkit;
26 constexpr Vector2 PARENT_VIEW_SIZE_LIST[] = {
27 Vector2(100.0f, 150.0f),
28 Vector2(200.0f, 100.0f),
29 Vector2(100.0f, 200.0f),
30 Vector2(100.0f, 100.0f),
32 constexpr int PARENT_VIEW_SIZE_LIST_COUNT = sizeof(PARENT_VIEW_SIZE_LIST) / sizeof(PARENT_VIEW_SIZE_LIST[0]);
34 constexpr Vector2 PARENT_VIEW_SCALE_LIST[] = {
39 constexpr int PARENT_VIEW_SCALE_LIST_COUNT = sizeof(PARENT_VIEW_SCALE_LIST) / sizeof(PARENT_VIEW_SCALE_LIST[0]);
41 constexpr Vector2 CURRENT_VIEW_SIZE_LIST[] = {
42 Vector2(200.0f, 250.0f),
43 Vector2(200.0f, 100.0f),
44 Vector2(100.0f, 200.0f),
45 Vector2(10.0f, 10.0f),
47 constexpr int CURRENT_VIEW_SIZE_LIST_COUNT = sizeof(CURRENT_VIEW_SIZE_LIST) / sizeof(CURRENT_VIEW_SIZE_LIST[0]);
49 constexpr Vector2 CURRENT_VIEW_POSITION_LIST[] = {
50 Vector2(100.0f, 120.0f),
52 Vector2(100.0f, 100.0f),
53 Vector2(-100.0f, -200.0f),
55 constexpr int CURRENT_VIEW_POSITION_LIST_COUNT = sizeof(CURRENT_VIEW_POSITION_LIST) / sizeof(CURRENT_VIEW_POSITION_LIST[0]);
57 constexpr Vector2 CURRENT_VIEW_SCALE_LIST[] = {
62 constexpr int CURRENT_VIEW_SCALE_LIST_COUNT = sizeof(CURRENT_VIEW_SCALE_LIST) / sizeof(CURRENT_VIEW_SCALE_LIST[0]);
64 constexpr Vector3 PARENT_ORIGIN_LIST[] = {
65 ParentOrigin::TOP_LEFT,
66 ParentOrigin::TOP_CENTER,
67 ParentOrigin::TOP_RIGHT,
68 ParentOrigin::CENTER_LEFT,
70 ParentOrigin::CENTER_RIGHT,
71 ParentOrigin::BOTTOM_LEFT,
72 ParentOrigin::BOTTOM_CENTER,
73 ParentOrigin::BOTTOM_RIGHT,
75 constexpr int PARENT_ORIGIN_LIST_COUNT = sizeof(PARENT_ORIGIN_LIST) / sizeof(PARENT_ORIGIN_LIST[0]);
77 constexpr Vector3 ANCHOR_POINT_LIST[] = {
78 AnchorPoint::TOP_LEFT,
79 AnchorPoint::TOP_CENTER,
80 AnchorPoint::TOP_RIGHT,
81 AnchorPoint::CENTER_LEFT,
83 AnchorPoint::CENTER_RIGHT,
84 AnchorPoint::BOTTOM_LEFT,
85 AnchorPoint::BOTTOM_CENTER,
86 AnchorPoint::BOTTOM_RIGHT,
88 constexpr int ANCHOR_POINT_LIST_COUNT = sizeof(ANCHOR_POINT_LIST) / sizeof(ANCHOR_POINT_LIST[0]);
91 // This example shows how to create and display Hello World! using a simple TextActor
93 class InheritTestController : public ConnectionTracker
96 InheritTestController(Application& application)
97 : mApplication(application)
99 // Connect to the Application's Init signal
100 mApplication.InitSignal().Connect(this, &InheritTestController::Create);
103 ~InheritTestController() = default; // Nothing to do in destructor
105 // The Init signal is received once (only) during the Application lifetime
106 void Create(Application& application)
108 // Get a handle to the window
109 mWindow = application.GetWindow();
110 mWindow.SetBackgroundColor(Color::WHITE);
112 Vector2 windowSize(1280, 800);
113 if(mWindow.GetSize().GetWidth() < 1280)
115 mWindow.SetSize(Uint16Pair(windowSize.x, windowSize.y));
119 windowSize.x = mWindow.GetSize().GetWidth();
120 windowSize.y = mWindow.GetSize().GetHeight();
123 mTitle = TextLabel::New();
124 mTitle.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
125 mTitle.SetProperty(TextLabel::Property::MULTI_LINE, true);
130 // Respond to a touch anywhere on the window
131 mWindow.GetRootLayer().TouchedSignal().Connect(this, &InheritTestController::OnTouch);
133 // Respond to key events
134 mWindow.KeyEventSignal().Connect(this, &InheritTestController::OnKeyEvent);
137 bool OnTouch(Actor actor, const TouchEvent& touch)
139 // quit the application
144 void OnKeyEvent(const KeyEvent& event)
146 if(event.GetState() == KeyEvent::DOWN)
148 bool needUpdate = false;
149 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
153 if(event.GetKeyName() == "1") // Inherit flag
155 mInheritFlag = (mInheritFlag + 1) % 8;
158 else if(event.GetKeyName() == "2") // ParentView Size
160 mParentSizeIndex = (mParentSizeIndex + 1) % PARENT_VIEW_SIZE_LIST_COUNT;
163 else if(event.GetKeyName() == "3") // ParentView Scale
165 mParentScaleIndex = (mParentScaleIndex + 1) % PARENT_VIEW_SCALE_LIST_COUNT;
168 else if(event.GetKeyName() == "4") // ParentOrigin
170 mParentOriginIndex = (mParentOriginIndex + 1) % PARENT_ORIGIN_LIST_COUNT;
173 else if(event.GetKeyName() == "5") // AnchorPoint
175 mAnchorPointIndex = (mAnchorPointIndex + 1) % ANCHOR_POINT_LIST_COUNT;
178 else if(event.GetKeyName() == "6") // Size
180 mCurrentSizeIndex = (mCurrentSizeIndex + 1) % CURRENT_VIEW_SIZE_LIST_COUNT;
183 else if(event.GetKeyName() == "7") // Position
185 mCurrentPositionIndex = (mCurrentPositionIndex + 1) % CURRENT_VIEW_POSITION_LIST_COUNT;
188 else if(event.GetKeyName() == "8") // Scale
190 mCurrentScaleIndex = (mCurrentScaleIndex + 1) % CURRENT_VIEW_SCALE_LIST_COUNT;
212 Vector2 parentViewSize = PARENT_VIEW_SIZE_LIST[mParentSizeIndex];
213 Vector2 parentViewScale = PARENT_VIEW_SCALE_LIST[mParentScaleIndex];
215 mParent = Control::New();
216 mParent.SetBackgroundColor(Color::BLUE);
217 mParent.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
218 mParent.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
219 mParent.SetProperty(Actor::Property::SIZE, parentViewSize);
220 mParent.SetProperty(Actor::Property::POSITION, Vector3::ZERO);
221 mParent.SetProperty(Actor::Property::SCALE, parentViewScale);
223 Vector3 parentOrigin = PARENT_ORIGIN_LIST[mParentOriginIndex];
224 Vector3 anchorPoint = ANCHOR_POINT_LIST[mAnchorPointIndex];
225 Vector2 currentViewSize = CURRENT_VIEW_SIZE_LIST[mCurrentSizeIndex];
226 Vector2 currentViewPosition = CURRENT_VIEW_POSITION_LIST[mCurrentPositionIndex];
227 Vector2 currentViewScale = CURRENT_VIEW_SCALE_LIST[mCurrentScaleIndex];
229 bool inheritPosition = mInheritFlag & 1;
230 bool inheritScale = mInheritFlag & 2;
231 bool inheritOrientation = mInheritFlag & 4;
233 mCurrent = Control::New();
234 mCurrent.SetBackgroundColor(Color::RED);
235 mCurrent.SetProperty(Actor::Property::PARENT_ORIGIN, parentOrigin);
236 mCurrent.SetProperty(Actor::Property::ANCHOR_POINT, anchorPoint);
237 mCurrent.SetProperty(Actor::Property::SIZE, currentViewSize);
238 mCurrent.SetProperty(Actor::Property::POSITION, currentViewPosition);
239 mCurrent.SetProperty(Actor::Property::SCALE, currentViewScale);
241 mCurrent.SetProperty(Actor::Property::INHERIT_POSITION, inheritPosition);
242 mCurrent.SetProperty(Actor::Property::INHERIT_SCALE, inheritScale);
243 mCurrent.SetProperty(Actor::Property::INHERIT_ORIENTATION, inheritOrientation);
245 mParent.Add(mCurrent);
246 mWindow.Add(mParent);
248 mAnimation = Animation::New(5.0f);
249 mAnimation.AnimateBy(Property(mParent, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS));
250 mAnimation.AnimateBy(Property(mCurrent, Actor::Property::ORIENTATION), Quaternion(Radian(Degree(360.0f)), Vector3::ZAXIS));
251 mAnimation.SetLooping(true);
252 mAnimation.PlayAfter(1.0f); // Play animation after world value printed
254 mTimer = Timer::New(32);
255 mTimer.TickSignal().Connect(this, &InheritTestController::OnTickLableUpdate);
259 bool OnTickLableUpdate()
265 void UpdateLabelInfo()
267 std::ostringstream oss;
269 Vector2 parentViewSize = PARENT_VIEW_SIZE_LIST[mParentSizeIndex];
270 Vector2 parentViewScale = PARENT_VIEW_SCALE_LIST[mParentScaleIndex];
272 Vector3 parentOrigin = PARENT_ORIGIN_LIST[mParentOriginIndex];
273 Vector3 anchorPoint = ANCHOR_POINT_LIST[mAnchorPointIndex];
274 Vector2 currentViewSize = CURRENT_VIEW_SIZE_LIST[mCurrentSizeIndex];
275 Vector2 currentViewPosition = CURRENT_VIEW_POSITION_LIST[mCurrentPositionIndex];
276 Vector2 currentViewScale = CURRENT_VIEW_SCALE_LIST[mCurrentScaleIndex];
278 Vector2 screenPositon = mCurrent.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
279 Vector3 worldPosition = mCurrent.GetProperty<Vector3>(Actor::Property::WORLD_POSITION);
280 Vector3 worldScale = mCurrent.GetProperty<Vector3>(Actor::Property::WORLD_SCALE);
281 Quaternion worldOrientation = mCurrent.GetProperty<Quaternion>(Actor::Property::WORLD_ORIENTATION);
283 bool inheritPosition = mInheritFlag & 1;
284 bool inheritScale = mInheritFlag & 2;
285 bool inheritOrientation = mInheritFlag & 4;
287 oss << "Inherit P S O : " << inheritPosition << " " << inheritScale << " " << inheritOrientation << "\n";
288 oss << "screenPosition : " << screenPositon << "\n";
290 oss << "parentViewSize : " << parentViewSize << "\n";
291 oss << "parentViewScale : " << parentViewScale << "\n";
293 oss << "parentOrigin : " << parentOrigin << "\n";
294 oss << "anchorPoint : " << anchorPoint << "\n";
295 oss << "currentViewSize : " << currentViewSize << "\n";
296 oss << "currentViewPosition : " << currentViewPosition << "\n";
297 oss << "currentViewScale : " << currentViewScale << "\n";
299 oss << "worldPosition : " << worldPosition << "\n";
300 oss << "worldScale : " << worldScale << "\n";
301 oss << "worldOrientation : " << worldOrientation << "\n";
303 oss << "Key 1 : Change flag\n";
304 oss << "Key 2 : Change ParentView's Size\n";
305 oss << "Key 3 : Change ParentView's Scale\n";
306 oss << "Key 4 : Change CurrentView's ParentOrigin\n";
307 oss << "Key 5 : Change CurrentView's AnchorPoint\n";
308 oss << "Key 6 : Change CurrentView's Size\n";
309 oss << "Key 7 : Change CurrentView's Position\n";
310 oss << "Key 8 : Change CurrentView's Scale\n";
312 mTitle.SetProperty(TextLabel::Property::TEXT, oss.str());
316 Application& mApplication;
324 Animation mAnimation;
326 int mInheritFlag = 0;
328 int mParentSizeIndex = 0;
329 int mParentScaleIndex = 0;
330 int mCurrentSizeIndex = 0;
331 int mCurrentPositionIndex = 0;
332 int mCurrentScaleIndex = 0;
333 int mParentOriginIndex = 0;
334 int mAnchorPointIndex = 0;
337 int DALI_EXPORT_API main(int argc, char** argv)
339 Application application = Application::New(&argc, &argv);
340 InheritTestController test(application);
341 application.MainLoop();