X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fevent%2Fcommon%2Fobject-impl.cpp;h=501775d1244c880701266c9b60694c9d85ff4a37;hb=fa2ac55c940f922fe37a53b3544fd27d4f60b5c5;hp=e5568c181b73f1d0d7989033beab095bdde04647;hpb=f139c6fbfc335c384bfd7ac744830c7c2f992fb5;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/event/common/object-impl.cpp b/dali/internal/event/common/object-impl.cpp index e5568c1..501775d 100644 --- a/dali/internal/event/common/object-impl.cpp +++ b/dali/internal/event/common/object-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,6 +50,8 @@ typedef Dali::Vector::ConstIterator ConstObserverIter; #if defined(DEBUG_ENABLED) Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" ); #endif + + } // unnamed namespace Object::Object() @@ -86,17 +88,6 @@ void Object::RemoveObserver(Observer& observer) void Object::OnSceneObjectAdd() { - // Notification for this object's constraints - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentSceneObjectAdded(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter) { @@ -109,17 +100,6 @@ void Object::OnSceneObjectAdd() void Object::OnSceneObjectRemove() { - // Notification for this object's constraints - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentSceneObjectRemoved(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter ) { @@ -132,7 +112,21 @@ void Object::OnSceneObjectRemove() int Object::GetPropertyComponentIndex( Property::Index index ) const { - return Property::INVALID_COMPONENT_INDEX; + int componentIndex = Property::INVALID_COMPONENT_INDEX; + + const TypeInfo* typeInfo( GetTypeInfo() ); + if ( typeInfo ) + { + componentIndex = typeInfo->GetComponentIndex(index); + } + + // For animatable property, check whether it is registered already and register it if not yet. + if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) && ( NULL == RegisterAnimatableProperty(index) ) ) + { + componentIndex = Property::INVALID_COMPONENT_INDEX; + } + + return componentIndex; } bool Object::Supports( Capability capability ) const @@ -208,14 +202,9 @@ Property::Index Object::GetPropertyIndex(const std::string& name) const if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index ); - if(!animatableProperty) + if ( NULL == RegisterAnimatableProperty(index) ) { - const TypeInfo* typeInfo( GetTypeInfo() ); - if (typeInfo) - { - index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index))); - } + index = Property::INVALID_INDEX; } } } @@ -369,7 +358,7 @@ Property::Type Object::GetPropertyType( Property::Index index ) const CustomPropertyMetadata* custom = FindCustomProperty( index ); if( custom ) { - return custom->type; + return custom->GetType(); } return Property::NONE; } @@ -378,6 +367,8 @@ void Object::SetProperty( Property::Index index, const Property::Value& property { DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" ); + bool propertySet( true ); + if ( index < DEFAULT_PROPERTY_MAX_COUNT ) { SetDefaultProperty( index, propertyValue ); @@ -392,23 +383,17 @@ void Object::SetProperty( Property::Index index, const Property::Value& property else { DALI_LOG_ERROR("Cannot find property index\n"); + propertySet = false; } } else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index ); + AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index ); if(!animatableProperty) { - const TypeInfo* typeInfo( GetTypeInfo() ); - if (!typeInfo) - { - DALI_LOG_ERROR("Cannot find property index\n"); - } - else if ( Property::INVALID_INDEX == RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, propertyValue ) ) - { - DALI_LOG_ERROR("Cannot register property\n"); - } + DALI_LOG_ERROR("Cannot find property index\n"); + propertySet = false; } else { @@ -429,15 +414,26 @@ void Object::SetProperty( Property::Index index, const Property::Value& property else if( custom->IsWritable() ) { custom->value = propertyValue; - OnPropertySet(index, propertyValue); } - // trying to set value on read only property is no-op + else + { + // trying to set value on read only property is no-op + propertySet = false; + } } else { DALI_LOG_ERROR("Invalid property index\n"); + propertySet = false; } } + + // Let derived classes know that a property has been set + // TODO: We should not call this for read-only properties, SetDefaultProperty() && TypeInfo::SetProperty() should return a bool, which would be true if the property is set + if ( propertySet ) + { + OnPropertySet(index, propertyValue); + } } Property::Value Object::GetProperty(Property::Index index) const @@ -465,25 +461,10 @@ Property::Value Object::GetProperty(Property::Index index) const else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index ); + AnimatablePropertyMetadata* animatableProperty = RegisterAnimatableProperty( index ); if(!animatableProperty) { - const TypeInfo* typeInfo( GetTypeInfo() ); - if (typeInfo) - { - if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)))) - { - value = Property::Value(typeInfo->GetPropertyType(index)); // Return an initialized property value according to the type - } - else - { - DALI_LOG_ERROR("Cannot register property\n"); - } - } - else - { - DALI_LOG_ERROR("Cannot find property index\n"); - } + DALI_LOG_ERROR("Cannot find property index\n"); } else { @@ -510,7 +491,7 @@ Property::Value Object::GetProperty(Property::Index index) const void Object::GetPropertyIndices( Property::IndexContainer& indices ) const { - indices.clear(); + indices.Clear(); // Default Properties GetDefaultPropertyIndices( indices ); @@ -525,14 +506,14 @@ void Object::GetPropertyIndices( Property::IndexContainer& indices ) const // Custom Properties if ( mCustomProperties.Count() > 0 ) { - indices.reserve( indices.size() + mCustomProperties.Count() ); + indices.Reserve( indices.Size() + mCustomProperties.Count() ); PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End(); int i=0; for ( ; iter != endIter; ++iter, ++i ) { - indices.push_back( PROPERTY_CUSTOM_START_INDEX + i ); + indices.PushBack( PROPERTY_CUSTOM_START_INDEX + i ); } } } @@ -550,15 +531,15 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop break; } - case Property::FLOAT: + case Property::INTEGER: { - newProperty = new AnimatableProperty( propertyValue.Get() ); + newProperty = new AnimatableProperty( propertyValue.Get() ); break; } - case Property::INTEGER: + case Property::FLOAT: { - newProperty = new AnimatableProperty( propertyValue.Get() ); + newProperty = new AnimatableProperty( propertyValue.Get() ); break; } @@ -598,23 +579,15 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop break; } - case Property::UNSIGNED_INTEGER: case Property::RECTANGLE: case Property::STRING: case Property::ARRAY: case Property::MAP: + case Property::NONE: { - DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() ); DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" ); break; } - - default: - { - DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() ); - DALI_ASSERT_ALWAYS( !"PropertyType enumeration is out of bounds" ); - break; - } } // get the scene property owner from derived class @@ -630,7 +603,7 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop } else { - mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue.GetType(), property ) ); + mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, Property::INVALID_COMPONENT_INDEX, propertyValue.GetType(), property ) ); // base property } // queue a message to add the property @@ -651,7 +624,12 @@ Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Prop Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue) { - return RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), 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; } Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode) @@ -685,18 +663,7 @@ Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) { // check whether the animatable property is registered already, if not then register one. - AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index ); - if( !animatable ) - { - const TypeInfo* typeInfo( GetTypeInfo() ); - if ( typeInfo ) - { - if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) ) - { - animatable = FindAnimatableProperty( index ); - } - } - } + AnimatablePropertyMetadata* animatable = RegisterAnimatableProperty( index ); DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" ); } else if ( mCustomProperties.Count() > 0 ) @@ -787,43 +754,55 @@ void Object::DisablePropertyNotifications() } } -Dali::ActiveConstraint Object::ApplyConstraint( Constraint& constraint ) -{ - return Dali::ActiveConstraint( DoApplyConstraint( constraint, Dali::Handle() ) ); -} - -Dali::ActiveConstraint Object::ApplyConstraint( Constraint& constraint, Dali::Handle weightObject ) -{ - return Dali::ActiveConstraint( DoApplyConstraint( constraint, weightObject ) ); -} - -ActiveConstraintBase* Object::DoApplyConstraint( Constraint& constraint, Dali::Handle weightObject ) +void Object::AddUniformMapping( Property::Index propertyIndex, const std::string& uniformName ) { - ActiveConstraintBase* activeConstraintImpl = constraint.CreateActiveConstraint(); - DALI_ASSERT_DEBUG( NULL != activeConstraintImpl ); + // Get the address of the property if it's a scene property + const PropertyInputImpl* propertyPtr = GetSceneObjectInputProperty( propertyIndex ); - Dali::ActiveConstraint activeConstraint( activeConstraintImpl ); - - if( weightObject ) + // Check instead for newly registered properties + if( propertyPtr == NULL ) { - Object& weightObjectImpl = GetImplementation( weightObject ); - Property::Index weightIndex = weightObjectImpl.GetPropertyIndex( "weight" ); - - if( Property::INVALID_INDEX != weightIndex ) + PropertyMetadata* animatable = FindAnimatableProperty( propertyIndex ); + if( animatable != NULL ) { - activeConstraintImpl->SetCustomWeightObject( weightObjectImpl, weightIndex ); + propertyPtr = animatable->GetSceneGraphProperty(); } } - if( !mConstraints ) + if( propertyPtr == NULL ) { - mConstraints = new ActiveConstraintContainer; + PropertyMetadata* custom = FindCustomProperty( propertyIndex ); + if( custom != NULL ) + { + propertyPtr = custom->GetSceneGraphProperty(); + } } - mConstraints->push_back( activeConstraint ); - activeConstraintImpl->FirstApply( *this, constraint.GetApplyTime() ); + // @todo MESH_REWORK Store mappings for unstaged objects? - return activeConstraintImpl; + if( propertyPtr != NULL ) + { + const SceneGraph::PropertyOwner* sceneObject = GetPropertyOwner(); + + if( sceneObject != NULL ) + { + SceneGraph::UniformPropertyMapping* map = new SceneGraph::UniformPropertyMapping( uniformName, propertyPtr ); + // Message takes ownership of Uniform map (and will delete it after copy) + AddUniformMapMessage( GetEventThreadServices(), *sceneObject, map); + } + else + { + // @todo MESH_REWORK FIXME Need to store something that can be sent to the scene + // object when staged. + DALI_ASSERT_ALWAYS(0 && "MESH_REWORK - Need to store property whilst off-stage" ); + } + } +} + +void Object::RemoveUniformMapping( const std::string& uniformName ) +{ + const SceneGraph::PropertyOwner* sceneObject = GetSceneObject(); + RemoveUniformMapMessage( GetEventThreadServices(), *sceneObject, uniformName); } Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const @@ -840,7 +819,7 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const { BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() ); - switch ( entry->type ) + switch ( entry->GetType() ) { case Property::BOOLEAN: { @@ -851,18 +830,18 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const break; } - case Property::FLOAT: + case Property::INTEGER: { - const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); value = (*property)[ bufferIndex ]; break; } - case Property::INTEGER: + case Property::FLOAT: { - const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); value = (*property)[ bufferIndex ]; @@ -874,7 +853,18 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); - value = (*property)[ bufferIndex ]; + if(entry->componentIndex == 0) + { + value = (*property)[ bufferIndex ].x; + } + else if(entry->componentIndex == 1) + { + value = (*property)[ bufferIndex ].y; + } + else + { + value = (*property)[ bufferIndex ]; + } break; } @@ -883,7 +873,22 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); - value = (*property)[ bufferIndex ]; + if(entry->componentIndex == 0) + { + value = (*property)[ bufferIndex ].x; + } + else if(entry->componentIndex == 1) + { + value = (*property)[ bufferIndex ].y; + } + else if(entry->componentIndex == 2) + { + value = (*property)[ bufferIndex ].z; + } + else + { + value = (*property)[ bufferIndex ]; + } break; } @@ -892,7 +897,26 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry->GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); - value = (*property)[ bufferIndex ]; + if(entry->componentIndex == 0) + { + value = (*property)[ bufferIndex ].x; + } + else if(entry->componentIndex == 1) + { + value = (*property)[ bufferIndex ].y; + } + else if(entry->componentIndex == 2) + { + value = (*property)[ bufferIndex ].z; + } + else if(entry->componentIndex == 3) + { + value = (*property)[ bufferIndex ].w; + } + else + { + value = (*property)[ bufferIndex ]; + } break; } @@ -936,7 +960,7 @@ Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value ) { - switch ( entry.type ) + switch ( entry.GetType() ) { case Property::BOOLEAN: { @@ -948,23 +972,23 @@ void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadat break; } - case Property::FLOAT: + case Property::INTEGER: { - const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry.GetSceneGraphProperty() ); + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry.GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); // property is being used in a separate thread; queue a message to set the property - BakeMessage( GetEventThreadServices(), *property, value.Get() ); + BakeMessage( GetEventThreadServices(), *property, value.Get() ); break; } - case Property::INTEGER: + case Property::FLOAT: { - const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry.GetSceneGraphProperty() ); + const AnimatableProperty* property = dynamic_cast< const AnimatableProperty* >( entry.GetSceneGraphProperty() ); DALI_ASSERT_DEBUG( NULL != property ); // property is being used in a separate thread; queue a message to set the property - BakeMessage( GetEventThreadServices(), *property, value.Get() ); + BakeMessage( GetEventThreadServices(), *property, value.Get() ); break; } @@ -974,7 +998,18 @@ void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadat DALI_ASSERT_DEBUG( NULL != property ); // property is being used in a separate thread; queue a message to set the property - BakeMessage( GetEventThreadServices(), *property, value.Get() ); + if(entry.componentIndex == 0) + { + SetXComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 1) + { + SetYComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else + { + BakeMessage( GetEventThreadServices(), *property, value.Get() ); + } break; } @@ -984,7 +1019,23 @@ void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadat DALI_ASSERT_DEBUG( NULL != property ); // property is being used in a separate thread; queue a message to set the property - BakeMessage( GetEventThreadServices(), *property, value.Get() ); + if(entry.componentIndex == 0) + { + SetXComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 1) + { + SetYComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 2) + { + SetZComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else + { + BakeMessage( GetEventThreadServices(), *property, value.Get() ); + } + break; } @@ -994,7 +1045,26 @@ void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadat DALI_ASSERT_DEBUG( NULL != property ); // property is being used in a separate thread; queue a message to set the property - BakeMessage( GetEventThreadServices(), *property, value.Get() ); + if(entry.componentIndex == 0) + { + SetXComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 1) + { + SetYComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 2) + { + SetZComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else if(entry.componentIndex == 3) + { + SetWComponentMessage( GetEventThreadServices(), *property, value.Get() ); + } + else + { + BakeMessage( GetEventThreadServices(), *property, value.Get() ); + } break; } @@ -1052,32 +1122,46 @@ const TypeInfo* Object::GetTypeInfo() const return mTypeInfo; } -void Object::RemoveConstraint( ActiveConstraint& constraint, bool isInScenegraph ) +void Object::ApplyConstraint( ConstraintBase& constraint ) { - // guard against constraint sending messages during core destruction - if ( Stage::IsInstalled() ) + if( !mConstraints ) + { + mConstraints = new ConstraintContainer; + } + mConstraints->push_back( Dali::Constraint( &constraint ) ); +} + +void Object::RemoveConstraint( ConstraintBase& constraint ) +{ + // NULL if the Constraint sources are destroyed before Constraint::Apply() + if( mConstraints ) { - if( isInScenegraph ) + ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) ); + if( it != mConstraints->end() ) { - ActiveConstraintBase& baseConstraint = GetImplementation( constraint ); - baseConstraint.BeginRemove(); + mConstraints->erase( it ); } } } -void Object::RemoveConstraint( Dali::ActiveConstraint activeConstraint ) +void Object::RemoveConstraints() { // guard against constraint sending messages during core destruction if( mConstraints && Stage::IsInstalled() ) { - bool isInSceneGraph( NULL != GetSceneObject() ); - - ActiveConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), activeConstraint ) ); - if( it != mConstraints->end() ) + // If we have nothing in the scene-graph, just clear constraint containers + const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); + if ( NULL != propertyOwner ) { - RemoveConstraint( *it, isInSceneGraph ); - mConstraints->erase( it ); + const ConstraintConstIter endIter = mConstraints->end(); + for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) + { + GetImplementation( *iter ).RemoveInternal(); + } } + + delete mConstraints; + mConstraints = NULL; } } @@ -1086,15 +1170,13 @@ void Object::RemoveConstraints( unsigned int tag ) // guard against constraint sending messages during core destruction if( mConstraints && Stage::IsInstalled() ) { - bool isInSceneGraph( NULL != GetSceneObject() ); - - ActiveConstraintIter iter( mConstraints->begin() ); + ConstraintIter iter( mConstraints->begin() ); while(iter != mConstraints->end() ) { - ActiveConstraintBase& constraint = GetImplementation( *iter ); + ConstraintBase& constraint = GetImplementation( *iter ); if( constraint.GetTag() == tag ) { - RemoveConstraint( *iter, isInSceneGraph ); + GetImplementation( *iter ).RemoveInternal(); iter = mConstraints->erase( iter ); } else @@ -1102,27 +1184,12 @@ void Object::RemoveConstraints( unsigned int tag ) ++iter; } } - } -} -void Object::RemoveConstraints() -{ - // guard against constraint sending messages during core destruction - if( mConstraints && Stage::IsInstalled() ) - { - // If we have nothing in the scene-graph, just clear constraint containers - const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject(); - if ( NULL != propertyOwner ) + if ( mConstraints->empty() ) { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - RemoveConstraint( *iter, true ); - } + delete mConstraints; + mConstraints = NULL; } - - delete mConstraints; - mConstraints = NULL; } } @@ -1133,18 +1200,6 @@ void Object::SetTypeInfo( const TypeInfo* typeInfo ) Object::~Object() { - // Notification for this object's constraints - // (note that the ActiveConstraint handles may outlive the Object) - if( mConstraints ) - { - const ActiveConstraintConstIter endIter = mConstraints->end(); - for ( ActiveConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter ) - { - ActiveConstraintBase& baseConstraint = GetImplementation( *iter ); - baseConstraint.OnParentDestroyed(); - } - } - // Notification for observers for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter) { @@ -1182,6 +1237,52 @@ AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index inde return NULL; } +AnimatablePropertyMetadata* Object::RegisterAnimatableProperty(Property::Index index) const +{ + DALI_ASSERT_ALWAYS( (( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )) + && "Property index is out of bounds" ); + + // check whether the animatable property is registered already, if not then register one. + AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index ); + if(!animatableProperty) + { + const TypeInfo* typeInfo( GetTypeInfo() ); + if (typeInfo) + { + Property::Index basePropertyIndex = typeInfo->GetBasePropertyIndex(index); + if(basePropertyIndex == Property::INVALID_INDEX) + { + // If the property is not a component of a base property, register the whole property itself. + index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index))); + } + else + { + // Since the property is a component of a base property, check whether the base property is regsitered. + animatableProperty = FindAnimatableProperty( basePropertyIndex ); + 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)))) + { + animatableProperty = static_cast(mAnimatableProperties[mAnimatableProperties.Size()-1]); + } + } + + if(animatableProperty) + { + // Create the metadata for the property component. + mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, typeInfo->GetComponentIndex(index), animatableProperty->GetType(), animatableProperty->GetSceneGraphProperty() ) ); + } + } + + // The metadata has just been added and therefore should be in the end of the vector. + animatableProperty = static_cast(mAnimatableProperties[mAnimatableProperties.Size()-1]); + } + } + + return animatableProperty; +} + } // namespace Internal } // namespace Dali