1 #include "test-custom-actor.h"
5 std::vector<std::string> MasterCallStack;
6 bool gOnRelayout = false;
12 struct TestCustomActor;
15 TestCustomActor TestCustomActor::New()
17 Impl::TestCustomActor* impl = new Impl::TestCustomActor;
18 TestCustomActor custom(*impl); // takes ownership
25 TestCustomActor TestCustomActor::NewNegoSize()
27 Impl::TestCustomActor* impl = new Impl::TestCustomActor(true);
28 TestCustomActor custom(*impl); // takes ownership
29 custom.SetProperty(Dali::Actor::Property::NAME, "SizeNegotiationActor");
36 TestCustomActor TestCustomActor::NewVariant1(Actor childToAdd)
38 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1(childToAdd);
39 TestCustomActor custom(*impl); // takes ownership
46 TestCustomActor TestCustomActor::NewVariant2()
48 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant2();
49 TestCustomActor custom(*impl); // takes ownership
56 TestCustomActor TestCustomActor::NewVariant3(Actor childToAdd)
58 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant3(childToAdd);
59 TestCustomActor custom(*impl); // takes ownership
66 TestCustomActor TestCustomActor::NewVariant4()
68 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant4();
69 TestCustomActor custom(*impl); // takes ownership
76 TestCustomActor TestCustomActor::NewVariant5(Integration::Scene scene)
78 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant5(scene);
79 TestCustomActor custom(*impl); // takes ownership
86 TestCustomActor TestCustomActor::NewVariant6(Integration::Scene scene)
88 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant6(scene);
89 TestCustomActor custom(*impl); // takes ownership
96 TestCustomActor TestCustomActor::NewVariant7(const char* name)
98 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant7();
99 TestCustomActor custom(*impl); // takes ownership
101 impl->Initialize(name);
106 TestCustomActor TestCustomActor::NewVariant8(Actor rival)
108 Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant8(rival);
109 TestCustomActor custom(*impl); // takes ownership
116 TestCustomActor::~TestCustomActor()
120 Impl::TestCustomActor& TestCustomActor::GetImpl()
122 return static_cast<Impl::TestCustomActor&>(GetImplementation());
125 std::vector<std::string>& TestCustomActor::GetMethodsCalled()
127 return GetImpl().mMethodsCalled;
130 void TestCustomActor::ResetCallStack()
132 GetImpl().ResetCallStack();
135 void TestCustomActor::SetDaliProperty(std::string s)
137 GetImpl().SetDaliProperty(s);
140 Vector3 TestCustomActor::GetSize()
142 return GetImpl().mSizeSet;
145 Vector3 TestCustomActor::GetTargetSize()
147 return GetImpl().mTargetSize;
150 Vector3 TestCustomActor::GetNaturalSize()
152 return Vector3(0.0f, 0.0f, 0.0f);
155 float TestCustomActor::GetHeightForWidth(float width)
160 float TestCustomActor::GetWidthForHeight(float height)
165 void TestCustomActor::OnRelayout(const Vector2& size, RelayoutContainer& container)
169 void TestCustomActor::OnLayoutNegotiated(float size, Dimension::Type dimension)
173 void TestCustomActor::OnCalculateRelayoutSize(Dimension::Type dimension)
177 void TestCustomActor::TestRelayoutRequest()
179 GetImpl().TestRelayoutRequest();
182 float TestCustomActor::TestGetHeightForWidthBase(float width)
184 return GetImpl().TestGetHeightForWidthBase(width);
187 float TestCustomActor::TestGetWidthForHeightBase(float height)
189 return GetImpl().TestGetWidthForHeightBase(height);
192 float TestCustomActor::TestCalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension)
194 return GetImpl().TestCalculateChildSizeBase(child, dimension);
197 bool TestCustomActor::TestRelayoutDependentOnChildrenBase(Dimension::Type dimension)
199 return GetImpl().TestRelayoutDependentOnChildrenBase(dimension);
202 uint32_t TestCustomActor::GetDepth()
204 return GetImpl().mDepth;
207 TestCustomActor::TestCustomActor()
211 TestCustomActor::TestCustomActor(Impl::TestCustomActor& impl)
216 TestCustomActor::TestCustomActor(Dali::Internal::CustomActor* internal)
217 : CustomActor(internal)
221 TestCustomActor TestCustomActor::DownCast(BaseHandle handle)
223 TestCustomActor actor;
224 CustomActor custom = Dali::CustomActor::DownCast(handle);
227 CustomActorImpl& customImpl = custom.GetImplementation();
229 Test::Impl::TestCustomActor* impl = dynamic_cast<Test::Impl::TestCustomActor*>(&customImpl);
232 actor = TestCustomActor(customImpl.GetOwner());
240 TestCustomActor::TestCustomActor()
241 : CustomActorImpl(ActorFlags(DISABLE_SIZE_NEGOTIATION)),
242 mDaliProperty(Property::INVALID_INDEX),
243 mSizeSet(Vector3::ZERO),
244 mTargetSize(Vector3::ZERO),
251 TestCustomActor::TestCustomActor(bool nego)
252 : CustomActorImpl(ActorFlags()),
253 mDaliProperty(Property::INVALID_INDEX),
254 mSizeSet(Vector3::ZERO),
255 mTargetSize(Vector3::ZERO),
263 TestCustomActor::~TestCustomActor()
267 void TestCustomActor::Initialize(const char* name)
269 mDaliProperty = Self().RegisterProperty("Dali", std::string("no"), Property::READ_WRITE);
274 void TestCustomActor::OnInitialize(const char* name)
279 * Resets the call stack
281 void TestCustomActor::ResetCallStack()
283 mSizeSet = Vector3();
284 mTargetSize = Vector3();
285 mMethodsCalled.clear();
288 void TestCustomActor::AddToCallStacks(const char* method)
290 mMethodsCalled.push_back(method);
292 // Combine Actor name with method string
293 std::string nameAndMethod(Self().GetProperty<std::string>(Dali::Actor::Property::NAME));
294 if(0 == nameAndMethod.size())
296 nameAndMethod = "Unknown: ";
300 nameAndMethod += ": ";
302 nameAndMethod += method;
304 MasterCallStack.push_back(nameAndMethod);
307 // From CustomActorImpl
308 void TestCustomActor::OnSceneConnection(int depth)
310 AddToCallStacks("OnSceneConnection");
313 void TestCustomActor::OnSceneDisconnection()
315 AddToCallStacks("OnSceneDisconnection");
317 void TestCustomActor::OnChildAdd(Actor& child)
319 AddToCallStacks("OnChildAdd");
321 void TestCustomActor::OnChildRemove(Actor& child)
323 AddToCallStacks("OnChildRemove");
325 void TestCustomActor::OnPropertySet(Property::Index index, const Property::Value& propertyValue)
327 AddToCallStacks("OnPropertySet");
329 void TestCustomActor::OnSizeSet(const Vector3& targetSize)
331 mSizeSet = targetSize;
332 AddToCallStacks("OnSizeSet");
334 void TestCustomActor::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
336 mTargetSize = targetSize;
337 AddToCallStacks("OnSizeAnimation");
339 void TestCustomActor::OnKeyInputFocusGained()
341 AddToCallStacks("OnKeyInputFocusGained");
343 void TestCustomActor::OnKeyInputFocusLost()
345 AddToCallStacks("OnKeyInputFocusLost");
347 Vector3 TestCustomActor::GetNaturalSize()
349 return Vector3(0.0f, 0.0f, 0.0f);
352 float TestCustomActor::GetHeightForWidth(float width)
357 float TestCustomActor::GetWidthForHeight(float height)
362 void TestCustomActor::OnRelayout(const Vector2& size, RelayoutContainer& container)
367 void TestCustomActor::OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
371 void TestCustomActor::OnCalculateRelayoutSize(Dimension::Type dimension)
375 float TestCustomActor::CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension)
380 void TestCustomActor::OnLayoutNegotiated(float size, Dimension::Type dimension)
384 bool TestCustomActor::RelayoutDependentOnChildren(Dimension::Type dimension)
389 void TestCustomActor::SetDaliProperty(std::string s)
391 Self().SetProperty(mDaliProperty, s);
393 void TestCustomActor::TestRelayoutRequest()
398 float TestCustomActor::TestGetHeightForWidthBase(float width)
400 return GetHeightForWidthBase(width);
403 float TestCustomActor::TestGetWidthForHeightBase(float height)
405 return GetWidthForHeightBase(height);
408 float TestCustomActor::TestCalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension)
410 return CalculateChildSizeBase(child, dimension);
413 bool TestCustomActor::TestRelayoutDependentOnChildrenBase(Dimension::Type dimension)
415 return RelayoutDependentOnChildrenBase(dimension);
418 void TestCustomActor::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
420 Test::TestCustomActor actor = Test::TestCustomActor::DownCast(Dali::BaseHandle(object));
424 TestCustomActor& actorImpl = GetImpl(actor);
427 case Test::TestCustomActor::Property::TEST_PROPERTY1:
429 actorImpl.prop1 = value.Get<float>();
432 case Test::TestCustomActor::Property::TEST_PROPERTY2:
434 actorImpl.prop2 = value.Get<Vector4>();
437 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
439 actorImpl.develProp3 = value.Get<Vector4>();
442 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
444 actorImpl.develProp4 = value.Get<int>();
447 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
449 actorImpl.develProp5 = value.Get<float>();
456 Property::Value TestCustomActor::GetProperty(BaseObject* object, Property::Index index)
458 Test::TestCustomActor actor = Test::TestCustomActor::DownCast(Dali::BaseHandle(object));
462 TestCustomActor& actorImpl = GetImpl(actor);
465 case Test::TestCustomActor::Property::TEST_PROPERTY1:
467 return Property::Value(actorImpl.prop1);
469 case Test::TestCustomActor::Property::TEST_PROPERTY2:
471 return Property::Value(actorImpl.prop2);
473 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY3:
475 return Property::Value(actorImpl.develProp3);
477 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY4:
479 return Property::Value(actorImpl.develProp4);
481 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5:
483 return Property::Value(actorImpl.develProp5);
485 case Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6:
487 return Property::Value(actorImpl.develProp6);
491 return Property::Value();
494 BaseHandle CreateActor()
496 return Test::TestCustomActor::New();
499 DALI_TYPE_REGISTRATION_BEGIN(Test::TestCustomActor, Dali::CustomActor, CreateActor);
501 DALI_PROPERTY_REGISTRATION(Test, TestCustomActor, "testProperty1", FLOAT, TEST_PROPERTY1)
502 DALI_PROPERTY_REGISTRATION(Test, TestCustomActor, "testProperty2", VECTOR4, TEST_PROPERTY2)
503 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty3", VECTOR4, DEVEL_TEST_PROPERTY3)
504 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty4", INTEGER, DEVEL_TEST_PROPERTY4)
505 DALI_DEVEL_PROPERTY_REGISTRATION(Test, TestCustomActor, "develTestProperty5", FLOAT, DEVEL_TEST_PROPERTY5)
506 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY(Test, TestCustomActor, "develTestProperty6", FLOAT, DEVEL_TEST_PROPERTY6)
508 DALI_TYPE_REGISTRATION_END()