DALI_TEST_CHECK( handle );
Actor customActor = Actor::DownCast( handle );
DALI_TEST_CHECK( customActor );
+ Stage::GetCurrent().Add(customActor);
unsigned int customPropertyCount( customActor.GetPropertyCount() );
std::string animatablePropertyName( "animatableProp1" );
int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
Property::Type animatablePropertyType( Property::FLOAT );
- AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
+ AnimatablePropertyRegistration animatableProperty( customType1, animatablePropertyName, animatablePropertyIndex, animatablePropertyType );
// Check property count after registration
DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
application.Render();
// Check the animatable property value
- DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.0f, TEST_LOCATION );
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 25.f, TEST_LOCATION );
// Check the animatable property name
DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
unsigned int customActorIndices = indices.Size();
DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
+ // check that the property is animatable
+ Animation animation = Animation::New(0.2f);
+ animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 15.f, AlphaFunction::LINEAR );
+ animation.Play();
+ // Render and notify, animation play for 0.05 seconds
+ application.SendNotification();
+ application.Render(50);
+ DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 22.5f, TEST_LOCATION );
+ // Render and notify, animation play for another 0.1 seconds
+ application.SendNotification();
+ application.Render(100);
+ DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
+
END_TEST;
}
END_TEST;
}
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultP(void)
+{
+ TestApplication application;
+ TypeRegistry typeRegistry = TypeRegistry::Get();
+
+ // Check property count before property registration
+ TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
+ DALI_TEST_CHECK( typeInfo );
+ BaseHandle handle = typeInfo.CreateInstance();
+ DALI_TEST_CHECK( handle );
+ Actor customActor = Actor::DownCast( handle );
+ DALI_TEST_CHECK( customActor );
+ Stage::GetCurrent().Add(customActor);
+
+ unsigned int customPropertyCount( customActor.GetPropertyCount() );
+
+ // Register animatable property
+ std::string animatablePropertyName( "animatableProp1" );
+ int animatablePropertyIndex( ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX );
+ AnimatablePropertyRegistration animatableProperty1( customType1, animatablePropertyName, animatablePropertyIndex, 10.f );
+
+ // Check property count after registration
+ DALI_TEST_EQUALS( customPropertyCount + 1u, customActor.GetPropertyCount(), TEST_LOCATION );
+
+ // Render and notify
+ application.SendNotification();
+ application.Render();
+
+ // Check the animatable property value
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 10.f, TEST_LOCATION );
+
+ // Check the animatable property name
+ DALI_TEST_EQUALS( customActor.GetPropertyName( animatablePropertyIndex ), animatablePropertyName, TEST_LOCATION );
+
+ // Check the animatable property index
+ DALI_TEST_EQUALS( customActor.GetPropertyIndex( animatablePropertyName ), animatablePropertyIndex, TEST_LOCATION );
+
+ // Check the animatable property type
+ DALI_TEST_EQUALS( customActor.GetPropertyType( animatablePropertyIndex ), Property::FLOAT, TEST_LOCATION );
+
+ // Check property count of type-info is 1
+ Property::IndexContainer indices;
+ typeInfo.GetPropertyIndices( indices );
+ DALI_TEST_EQUALS( indices.Size(), 1u, TEST_LOCATION );
+
+ // Ensure indices returned from actor and customActor differ by one
+ Actor actor = Actor::New();
+ actor.GetPropertyIndices( indices );
+ unsigned int actorIndices = indices.Size();
+ customActor.GetPropertyIndices( indices );
+ unsigned int customActorIndices = indices.Size();
+ DALI_TEST_EQUALS( actorIndices + 1u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
+
+ // check that the property is animatable
+ Animation animation = Animation::New(0.2f);
+ animation.AnimateTo( Property( customActor, animatablePropertyIndex ), 20.f, AlphaFunction::LINEAR );
+ animation.Play();
+ // Render and notify, animation play for 0.05 seconds
+ application.SendNotification();
+ application.Render(50);
+ DALI_TEST_EQUALS( 0.25f, animation.GetCurrentProgress(), TEST_LOCATION );
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 12.5f, TEST_LOCATION );
+ // Render and notify, animation play for another 0.1 seconds
+ application.SendNotification();
+ application.Render(100);
+ DALI_TEST_EQUALS( 0.75f, animation.GetCurrentProgress(), TEST_LOCATION );
+ DALI_TEST_EQUALS( customActor.GetProperty< float >( animatablePropertyIndex ), 17.5f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliTypeRegistryAnimatablePropertyRegistrationWithDefaultN(void)
+{
+ TestApplication application;
+ TypeRegistry typeRegistry = TypeRegistry::Get();
+
+ // Attempt to register an animatable property type out-of-bounds index (less than)
+ try
+ {
+ AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX - 1, false );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
+ }
+
+ // Attempt to register an animatable property type out-of-bounds index (greater than)
+ try
+ {
+ AnimatablePropertyRegistration property1( customType1, "animPropName", ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX + 1, true );
+ tet_result( TET_FAIL );
+ }
+ catch ( DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
int UtcDaliTypeRegistryAnimatablePropertyComponentRegistrationP(void)
{
TestApplication application;
#define DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, valueType, enumIndex) \
AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, Property::valueType );
+#define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, value, enumIndex) \
+ AnimatablePropertyRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, value );
+
#define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( count, typeRegistrationObject, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex) \
AnimatablePropertyComponentRegistration DALI_TOKEN_PASTE( property, count ) ( typeRegistrationObject, text, objectNamespace::objectType::Property::enumIndex, objectNamespace::objectType::Property::baseEnumIndex, componentIndex );
#define DALI_ANIMATABLE_PROPERTY_REGISTRATION( objectNamespace, objectType, text, valueType, enumIndex ) \
DALI_ANIMATABLE_PROPERTY_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, valueType, enumIndex )
+#define DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( objectNamespace, objectType, text, value, enumIndex ) \
+ DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, value, enumIndex )
+
#define DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex ) \
DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION_INTERNAL( __COUNTER__, typeRegistration, objectNamespace, objectType, text, enumIndex, baseEnumIndex, componentIndex )
}
}
-void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName )
+void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const
{
// Get the address of the property if it's a scene property
const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex );
{
SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr );
// Message takes ownership of Uniform map (and will delete it after copy)
- AddUniformMapMessage( GetEventThreadServices(), *sceneObject, map);
+ AddUniformMapMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *sceneObject, map);
}
else
{
if(basePropertyIndex == Property::INVALID_INDEX)
{
// If the property is not a component of a base property, register the whole property itself.
- RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
+ const std::string& propertyName = typeInfo->GetPropertyName(index);
+ RegisterSceneGraphProperty(propertyName, index, typeInfo->GetPropertyDefaultValue(index));
+ AddUniformMapping( index, propertyName );
}
else
{
if(!animatableProperty)
{
// If the base property is not registered yet, register the base property first.
- if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(basePropertyIndex), basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
+ const std::string& basePropertyName = typeInfo->GetPropertyName(basePropertyIndex);
+ if(Property::INVALID_INDEX != RegisterSceneGraphProperty(basePropertyName, basePropertyIndex, Property::Value(typeInfo->GetPropertyType(basePropertyIndex))))
{
animatableProperty = static_cast<AnimatablePropertyMetadata*>(mAnimatableProperties[mAnimatableProperties.Size()-1]);
+ AddUniformMapping( basePropertyIndex, basePropertyName );
}
}
/**
* @copydoc Dali::Handle::AddUniformMapping()
*/
- void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName );
+ void AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) const;
/**
* @copydoc Dali::Handle::RemoveUniformMapping( )
}
}
+void TypeInfo::AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue )
+{
+ RegisteredPropertyContainer::iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
+ PairFinder< Property::Index, RegisteredPropertyPair>(index) );
+
+ if ( iter == mRegisteredProperties.end() )
+ {
+ mRegisteredProperties.push_back( RegisteredPropertyPair( index, RegisteredProperty( defaultValue.GetType(), NULL, NULL, name, Property::INVALID_INDEX, Property::INVALID_COMPONENT_INDEX ) ) );
+ mPropertyDefaultValues.push_back( PropertyDefaultValuePair( index, defaultValue ) );
+ }
+ else
+ {
+ DALI_ASSERT_ALWAYS( ! "Property index already added to Type" );
+ }
+}
+
void TypeInfo::AddAnimatablePropertyComponent( const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
{
Property::Type type = GetPropertyType( baseIndex );
return type;
}
+Property::Value TypeInfo::GetPropertyDefaultValue( Property::Index index ) const
+{
+ PropertyDefaultValueContainer::const_iterator iter = find_if( mPropertyDefaultValues.begin(), mPropertyDefaultValues.end(),
+ PairFinder< Property::Index, PropertyDefaultValuePair >( index ) );
+ if( iter != mPropertyDefaultValues.end() )
+ {
+ return iter->second;
+ }
+ else
+ {
+ return Property::Value( GetPropertyType( index ) );
+ }
+}
+
void TypeInfo::SetProperty( BaseObject *object, Property::Index index, const Property::Value& value ) const
{
RegisteredPropertyContainer::const_iterator iter = find_if( mRegisteredProperties.begin(), mRegisteredProperties.end(),
void AddAnimatableProperty( const std::string& name, Property::Index index, Property::Type type );
/**
+ * Adds an animatable property with the given default value.
+ * @param[in] name The name of the property.
+ * @param[in] index The index of the property
+ * @param[in] type The Property::Type.
+ */
+ void AddAnimatableProperty( const std::string& name, Property::Index index, const Property::Value& defaultValue );
+
+ /**
* Adds a component of an animatable property to the type.
* The animatable property must have been type-registered and must be a Vector2, Vector3 or Vector4 type.
* @param[in] name The name of the component.
Property::Type GetPropertyType( Property::Index index ) const;
/**
+ * Retrieve the default value of the property at the given index.
+ * @param[in] index The property index.
+ * @return The default property value at that index.
+ */
+ Property::Value GetPropertyDefaultValue( Property::Index index ) const;
+
+ /**
* Sets the value of a property at the index specified for the given object.
* @param[in] object The object whose property is to be set.
* @param[in] index The property index.
typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunction > ConnectionPair;
typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
+ typedef std::pair<Property::Index, Property::Value> PropertyDefaultValuePair;
typedef std::vector< ActionPair > ActionContainer;
typedef std::vector< ConnectionPair > ConnectorContainer;
typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
+ typedef std::vector< PropertyDefaultValuePair > PropertyDefaultValueContainer;
std::string mTypeName;
std::string mBaseTypeName;
ActionContainer mActions;
ConnectorContainer mSignalConnectors;
RegisteredPropertyContainer mRegisteredProperties;
+ PropertyDefaultValueContainer mPropertyDefaultValues;
};
} // namespace Internal
return false;
}
+bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
+{
+ RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
+
+ if( iter != mRegistryLut.end() )
+ {
+ DALI_ASSERT_DEBUG(iter->second);
+
+ GetImplementation(iter->second).AddAnimatableProperty( name, index, value );
+
+ return true;
+ }
+
+ return false;
+}
+
bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
{
RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
/**
+ * Register a scene graph only property with a default value
+ * @param [in] registered TypeRegistration object used to register the type
+ * @param [in] name Property name
+ * @param [in] index Property index
+ * @param [in] value Property default value
+ * @return true if registered
+ */
+ bool RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& defaultValue );
+
+ /**
* Register a component of a scene graph only property that supports components (i.e. Vector2, Vector3 and Vector4)
* @param [in] registered TypeRegistration object used to register the type
* @param [in] name Component name
Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, type );
}
+AnimatablePropertyRegistration::AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
+{
+ DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
+
+ Internal::TypeRegistry::Get()->RegisterAnimatableProperty( registered, name, index, value );
+}
+
AnimatablePropertyComponentRegistration::AnimatablePropertyComponentRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex)
{
DALI_ASSERT_ALWAYS( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) );
* @pre "registered" must be registered with the TypeRegistry.
*/
AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type );
+
+ /**
+ * @brief This constructor registers the animatable property with the registered default value.
+ *
+ * This constructor is for scene-graph only properties where the
+ * value of the property can be retrieved and set via specified
+ * functions.
+ *
+ * @param [in] registered The TypeRegistration object
+ * @param [in] name The name of the property
+ * @param [in] index The property index. Must be a value between ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX and ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX inclusive.
+ * @param [in] value The property default value.
+ *
+ * @pre "registered" must be registered with the TypeRegistry.
+ */
+ AnimatablePropertyRegistration( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value );
};
/**