tet_infoline("Positive Test Dali::Handle::RegisterProperty()");
TestApplication application;
+ Stage stage = Stage::GetCurrent();
+
Actor actor = Actor::New();
- DALI_TEST_CHECK( ParentOrigin::TOP_LEFT == actor.GetProperty( Actor::Property::PARENT_ORIGIN ).Get<Vector3>() );
+ stage.Add( actor );
+
+ const unsigned int defaultPropertyCount = actor.GetPropertyCount();
+
+ application.SendNotification();
+ application.Render();
+
+ Property::Index index1 = actor.RegisterProperty( "MyProperty", Vector3::ONE );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index1 ), Vector3::ONE, TEST_LOCATION );
+
+ // No new property should be registered when we call the below function
+ Property::Index index2 = actor.RegisterProperty( "MyProperty", Vector3::ZAXIS );
+
+ application.SendNotification();
+ application.Render();
+
+
+ DALI_TEST_EQUALS( index1, index2, TEST_LOCATION ); // We should have the same index as per the first registration
+ DALI_TEST_EQUALS( actor.GetPropertyCount(), defaultPropertyCount + 1, TEST_LOCATION ); // Property count should be the same
+ DALI_TEST_EQUALS( actor.GetProperty< Vector3 >( index2 ), Vector3::ZAXIS, TEST_LOCATION ); // Value should be what we sent on second RegisterProperty call
END_TEST;
}
DALI_TEST_CHECK( handle.GetProperty<float>(index) == 5.0f );
END_TEST;
}
+
int UtcDaliHandleWeightNew(void)
{
TestApplication application;
END_TEST;
}
+
}
}
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
+Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue )
{
- Property::Index index = RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
-
- /// @todo: don't keep a table of mappings per handle.
- AddUniformMapping(index, name);
-
- return index;
+ return RegisterProperty( name, propertyValue, Property::ANIMATABLE );
}
-Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
+Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
{
- Property::Index index; // No need to initialise as it's overridden anyway
-
- if(Property::ANIMATABLE == accessMode)
+ // If property with the required name already exists, then just set it.
+ Property::Index index = GetPropertyIndex( name );
+ if( index != Property::INVALID_INDEX )
{
- index = RegisterProperty(name, propertyValue);
+ SetProperty( index, propertyValue );
}
else
{
- // Add entry to the property lookup
- index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
- mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
+ // Otherwise register the property
+
+ if(Property::ANIMATABLE == accessMode)
+ {
+ index = RegisterSceneGraphProperty( name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue );
+ AddUniformMapping( index, name );
+ }
+ else
+ {
+ // Add entry to the property lookup
+ index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
+ mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
+ }
}
return index;
void ShaderEffect::SetUniform( const std::string& name, Property::Value value, UniformCoordinateType uniformCoordinateType )
{
- // Register the property if it does not exist
- Property::Index index = GetPropertyIndex( name );
- if ( Property::INVALID_INDEX == index )
- {
- index = RegisterProperty( name, value );
- }
-
- SetProperty( index, value );
+ // Register/Set the property
+ Property::Index index = RegisterProperty( name, value );
// RegisterProperty guarantees a positive value as index
DALI_ASSERT_DEBUG( static_cast<unsigned int>(index) >= CustomPropertyStartIndex() );
* @param [in] name The name of the property.
* @param [in] propertyValue The new value of the property.
* @return The index of the property or Property::INVALID_INDEX if registration failed
+ * @note If a property with the desired name already exists, then the value given is just set.
*/
Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue );
* @param [in] propertyValue The new value of the property.
* @param [in] accessMode The property access mode (writable, animatable etc).
* @return The index of the property
+ * @note If a property with the desired name already exists, then the value given is just set.
*/
Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );