/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <stdlib.h>
#include <dali/public-api/dali-core.h>
+#include <dali/devel-api/actors/custom-actor-devel.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/integration-api/events/hover-event-integ.h>
#include <dali/integration-api/events/wheel-event-integ.h>
value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY5 );
DALI_TEST_EQUALS( value.Get<float>(), 40.0f, 0.001f, TEST_LOCATION );
+ // Get read-only property
+ value = actor.GetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6 );
+ DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
+
+ // Attempt to set read-only property and then ensure value hasn't changed
+ actor.SetProperty( Test::DevelTestCustomActor::Property::DEVEL_TEST_PROPERTY6, 40.0f );
+ DALI_TEST_EQUALS( value.Get<float>(), 10.0f, 0.001f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int utcDaliActorGetTypeInfo(void)
+{
+ TestApplication application;
+ tet_infoline( "Get the type info of a derived actor" );
+
+ Test::TestCustomActor customActor = Test::TestCustomActor::New();
+
+ Dali::TypeInfo typeInfo = Dali::DevelCustomActor::GetTypeInfo( customActor );
+
+ DALI_TEST_EQUALS( typeInfo.GetName(), std::string("TestCustomActor"), TEST_LOCATION );
+
END_TEST;
}
+
+namespace Impl
+{
+/**
+ * A custom actor that is not type registered on purpose
+ */
+struct UnregisteredCustomActor : public Dali::CustomActorImpl
+{
+ UnregisteredCustomActor() : CustomActorImpl( ACTOR_BEHAVIOUR_DEFAULT )
+ { }
+ virtual ~UnregisteredCustomActor()
+ { }
+ virtual void OnStageConnection( int32_t depth )
+ { }
+ virtual void OnStageDisconnection()
+ { }
+ virtual void OnChildAdd(Actor& child)
+ { }
+ virtual void OnChildRemove(Actor& child)
+ { }
+ virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
+ { }
+ virtual void OnSizeSet(const Vector3& targetSize)
+ { }
+ virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
+ { }
+ virtual bool OnTouchEvent(const TouchEvent& event) DALI_DEPRECATED_API
+ { return false; }
+ virtual bool OnHoverEvent(const HoverEvent& event)
+ { return false; }
+ virtual bool OnKeyEvent(const KeyEvent& event)
+ { return false; }
+ virtual bool OnWheelEvent(const WheelEvent& event)
+ { return false; }
+ virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
+ { }
+ virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
+ { }
+ virtual Vector3 GetNaturalSize()
+ { return Vector3(); }
+ virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension )
+ { return 0.f; }
+ virtual float GetHeightForWidth( float width )
+ { return 0.f; }
+ virtual float GetWidthForHeight( float height )
+ { return 0.f; }
+ virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS )
+ { return false; }
+ virtual void OnCalculateRelayoutSize( Dimension::Type dimension )
+ { }
+ virtual void OnLayoutNegotiated( float size, Dimension::Type dimension )
+ { }
+};
+}
+struct UnregisteredCustomActor : public Dali::CustomActor
+{
+ static UnregisteredCustomActor New()
+ {
+ Impl::UnregisteredCustomActor* impl = new Impl::UnregisteredCustomActor;
+ UnregisteredCustomActor custom( *impl ); // takes ownership
+ return custom;
+ }
+ UnregisteredCustomActor()
+ { }
+ ~UnregisteredCustomActor()
+ { }
+ UnregisteredCustomActor( Internal::CustomActor* impl )
+ : CustomActor( impl )
+ { }
+ UnregisteredCustomActor( Impl::UnregisteredCustomActor& impl )
+ : CustomActor( impl )
+ { }
+ static UnregisteredCustomActor DownCast( BaseHandle handle )
+ {
+ UnregisteredCustomActor hndl;
+ CustomActor custom = Dali::CustomActor::DownCast( handle );
+ if( custom )
+ {
+ CustomActorImpl& customImpl = custom.GetImplementation();
+
+ Impl::UnregisteredCustomActor* impl = dynamic_cast<Impl::UnregisteredCustomActor*>( &customImpl );
+
+ if( impl )
+ {
+ hndl = UnregisteredCustomActor( customImpl.GetOwner() );
+ }
+ }
+ return hndl;
+ }
+};
+
+int UtcDaliCustomActorSetGetActorPropertyActionSignal(void)
+{
+ TestApplication application; // Need the type registry
+
+ auto custom = UnregisteredCustomActor::New();
+ Stage::GetCurrent().Add( custom );
+
+ // should have all actor properties
+ DALI_TEST_EQUALS( custom.GetPropertyType( Actor::Property::COLOR ), Property::VECTOR4, TEST_LOCATION );
+ auto actorHandle = Actor::New();
+ DALI_TEST_EQUALS( custom.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
+
+ DALI_TEST_EQUALS( custom.IsVisible(), true, TEST_LOCATION );
+ custom.SetProperty( Actor::Property::VISIBLE, false );
+ application.SendNotification();
+ application.Render(); // IsVisible returns scene value
+ DALI_TEST_EQUALS( custom.IsVisible(), false, TEST_LOCATION );
+
+ // should have custom actor typename (as it has not registered itself)
+ DALI_TEST_EQUALS( "CustomActor", custom.GetTypeName(), TEST_LOCATION );
+
+ // should have actor actions
+ custom.DoAction( "show", Property::Map() );
+ DALI_TEST_EQUALS( custom.GetProperty( Actor::Property::VISIBLE ).Get<bool>(), true, TEST_LOCATION );
+
+ Animation animation = Animation::New(0.01f); // very short animation
+ // should be able to animate actor property
+ animation.AnimateTo( Property( custom, Actor::Property::POSITION ), Vector3( 100.0f, 150.0f, 200.0f ) );
+ animation.Play();
+
+ application.SendNotification();
+ application.Render(1000.f);
+
+ DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetProperty( Actor::Property::POSITION ).Get<Vector3>(), TEST_LOCATION );
+ DALI_TEST_EQUALS( Vector3( 100.0f, 150.0f, 200.0f ), custom.GetCurrentPosition(), TEST_LOCATION );
+
+ Dali::WeakHandle<UnregisteredCustomActor> weakRef( custom );
+ // should have actor signals
+ custom.ConnectSignal( &application, "offStage",
+ [weakRef]()
+ {
+ DALI_TEST_EQUALS( weakRef.GetHandle().OnStage(), false, TEST_LOCATION );
+ } );
+
+ Stage::GetCurrent().Remove( custom );
+ Stage::GetCurrent().Add( custom );
+
+ END_TEST;
+}
+
+namespace Impl
+{
+struct DerivedCustomActor : public UnregisteredCustomActor
+{ };
+}
+
+struct DerivedCustomActor : public UnregisteredCustomActor
+{
+ static DerivedCustomActor New()
+ {
+ Impl::DerivedCustomActor* impl = new Impl::DerivedCustomActor;
+ DerivedCustomActor custom( *impl ); // takes ownership
+ return custom;
+ }
+ DerivedCustomActor()
+ { }
+ ~DerivedCustomActor()
+ { }
+ DerivedCustomActor( Internal::CustomActor* impl )
+ : UnregisteredCustomActor( impl )
+ { }
+ DerivedCustomActor( Impl::UnregisteredCustomActor& impl )
+ : UnregisteredCustomActor( impl )
+ { }
+};
+
+// register custom
+DALI_TYPE_REGISTRATION_BEGIN( DerivedCustomActor, UnregisteredCustomActor, nullptr );
+DALI_TYPE_REGISTRATION_END()
+
+int UtcDaliCustomActorPropertyRegistrationDefaultValue(void)
+{
+ TestApplication application; // Need the type registry
+
+ // register our base and add a property with default value for it
+ Dali::TypeRegistration typeRegistration( typeid( UnregisteredCustomActor ), typeid( Dali::CustomActor ), nullptr );
+
+ auto derived = DerivedCustomActor::New();
+ Stage::GetCurrent().Add( derived );
+
+ // should have all actor properties
+ DALI_TEST_EQUALS( derived.GetPropertyType( Actor::Property::WORLD_MATRIX ), Property::MATRIX, TEST_LOCATION );
+ auto actorHandle = Actor::New();
+ DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount(), TEST_LOCATION );
+
+ // add a property in base class
+ AnimatablePropertyRegistration( typeRegistration, "Foobar", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, 10.f );
+
+ // should be one more property now
+ DALI_TEST_EQUALS( derived.GetPropertyCount(), actorHandle.GetPropertyCount() + 1, TEST_LOCATION );
+ // check that the default value is set for base class
+ DALI_TEST_EQUALS( UnregisteredCustomActor::New().GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
+ // check that the default value is set for the derived instance as well
+ DALI_TEST_EQUALS( derived.GetProperty(ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX).Get<float>(), 10.f, TEST_LOCATION );
+
+ END_TEST;
+}
+