2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/object-impl.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/internal/update/animation/scene-graph-constraint-base.h>
27 #include <dali/internal/update/common/animatable-property.h>
28 #include <dali/internal/update/common/property-owner-messages.h>
29 #include <dali/internal/event/animation/constraint-impl.h>
30 #include <dali/internal/event/common/stage-impl.h>
31 #include <dali/internal/event/common/property-notification-impl.h>
32 #include <dali/internal/event/common/type-registry-impl.h>
34 using Dali::Internal::SceneGraph::AnimatableProperty;
35 using Dali::Internal::SceneGraph::PropertyBase;
43 namespace // unnamed namespace
45 const int SUPPORTED_CAPABILITIES = Dali::Handle::DYNAMIC_PROPERTIES; // Object provides this capability
46 typedef Dali::Vector<Object::Observer*>::Iterator ObserverIter;
47 typedef Dali::Vector<Object::Observer*>::ConstIterator ConstObserverIter;
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_OBJECT" );
52 } // unnamed namespace
55 : mEventThreadServices( *Stage::GetCurrent() ),
58 mPropertyNotifications( NULL )
62 void Object::AddObserver(Observer& observer)
64 // make sure an observer doesn't observe the same object twice
65 // otherwise it will get multiple calls to OnSceneObjectAdd(), OnSceneObjectRemove() and ObjectDestroyed()
66 DALI_ASSERT_DEBUG( mObservers.End() == std::find( mObservers.Begin(), mObservers.End(), &observer));
68 mObservers.PushBack( &observer );
71 void Object::RemoveObserver(Observer& observer)
73 // Find the observer...
74 const ConstObserverIter endIter = mObservers.End();
75 for( ObserverIter iter = mObservers.Begin(); iter != endIter; ++iter)
77 if( (*iter) == &observer)
79 mObservers.Erase( iter );
83 DALI_ASSERT_DEBUG(endIter != mObservers.End());
86 void Object::OnSceneObjectAdd()
88 // Notification for observers
89 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
91 (*iter)->SceneObjectAdded(*this);
94 // enable property notifications in scene graph
95 EnablePropertyNotifications();
98 void Object::OnSceneObjectRemove()
100 // Notification for observers
101 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter )
103 (*iter)->SceneObjectRemoved(*this);
106 // disable property notifications in scene graph
107 DisablePropertyNotifications();
110 int Object::GetPropertyComponentIndex( Property::Index index ) const
112 return Property::INVALID_COMPONENT_INDEX;
115 bool Object::Supports( Capability capability ) const
117 return (capability & SUPPORTED_CAPABILITIES);
120 unsigned int Object::GetPropertyCount() const
122 unsigned int count = GetDefaultPropertyCount();
124 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Default Properties: %d\n", count );
126 const TypeInfo* typeInfo( GetTypeInfo() );
129 unsigned int manual( typeInfo->GetPropertyCount() );
132 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Manual Properties: %d\n", manual );
135 unsigned int custom( mCustomProperties.Count() );
137 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Custom Properties: %d\n", custom );
139 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Total Properties: %d\n", count );
144 std::string Object::GetPropertyName( Property::Index index ) const
146 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index out of bounds" );
148 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
150 return GetDefaultPropertyName( index );
153 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
154 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
156 const TypeInfo* typeInfo( GetTypeInfo() );
159 return typeInfo->GetPropertyName( index );
163 DALI_ASSERT_ALWAYS( ! "Property index is invalid" );
167 CustomPropertyMetadata* custom = FindCustomProperty( index );
175 Property::Index Object::GetPropertyIndex(const std::string& name) const
177 Property::Index index = GetDefaultPropertyIndex( name );
179 if(index == Property::INVALID_INDEX)
181 const TypeInfo* typeInfo( GetTypeInfo() );
184 index = typeInfo->GetPropertyIndex( name );
185 if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
187 // check whether the animatable property is registered already, if not then register one.
188 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
189 if(!animatableProperty)
191 const TypeInfo* typeInfo( GetTypeInfo() );
194 index = RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index)));
201 if( (index == Property::INVALID_INDEX)&&( mCustomProperties.Count() > 0 ) )
203 Property::Index count = PROPERTY_CUSTOM_START_INDEX;
204 const PropertyMetadataLookup::ConstIterator end = mCustomProperties.End();
205 for( PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin(); iter != end; ++iter, ++count )
207 CustomPropertyMetadata* custom = static_cast<CustomPropertyMetadata*>(*iter);
208 if ( custom->name == name )
219 bool Object::IsPropertyWritable( Property::Index index ) const
221 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
223 bool writable = false;
225 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
227 writable = IsDefaultPropertyWritable( index );
229 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
231 const TypeInfo* typeInfo( GetTypeInfo() );
234 writable = typeInfo->IsPropertyWritable( index );
238 DALI_ASSERT_ALWAYS( ! "Invalid property index" );
241 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
243 // Type Registry scene-graph properties are writable.
248 CustomPropertyMetadata* custom = FindCustomProperty( index );
251 writable = custom->IsWritable();
258 bool Object::IsPropertyAnimatable( Property::Index index ) const
260 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
262 bool animatable = false;
264 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
266 animatable = IsDefaultPropertyAnimatable( index );
268 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
270 // Type Registry event-thread only properties are not animatable.
273 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
275 // Type Registry scene-graph properties are animatable.
280 CustomPropertyMetadata* custom = FindCustomProperty( index );
283 animatable = custom->IsAnimatable();
290 bool Object::IsPropertyAConstraintInput( Property::Index index ) const
292 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds");
294 bool isConstraintInput = false;
296 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
298 isConstraintInput = IsDefaultPropertyAConstraintInput( index );
300 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
302 // Type Registry event-thread only properties cannot be used as an input to a constraint.
303 isConstraintInput = false;
305 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
307 // scene graph properties can be used as input to a constraint.
308 isConstraintInput = true;
312 CustomPropertyMetadata* custom = FindCustomProperty( index );
315 // ... custom properties can be used as input to a constraint.
316 isConstraintInput = true;
320 return isConstraintInput;
323 Property::Type Object::GetPropertyType( Property::Index index ) const
325 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
327 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
329 return GetDefaultPropertyType( index );
332 if ( ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
333 || ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) ) )
335 const TypeInfo* typeInfo( GetTypeInfo() );
338 return typeInfo->GetPropertyType( index );
342 DALI_ASSERT_ALWAYS( ! "Cannot find property index" );
346 CustomPropertyMetadata* custom = FindCustomProperty( index );
351 return Property::NONE;
354 void Object::SetProperty( Property::Index index, const Property::Value& propertyValue )
356 DALI_ASSERT_ALWAYS(index > Property::INVALID_INDEX && "Property index is out of bounds" );
358 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
360 SetDefaultProperty( index, propertyValue );
362 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
364 const TypeInfo* typeInfo( GetTypeInfo() );
367 typeInfo->SetProperty( this, index, propertyValue );
371 DALI_LOG_ERROR("Cannot find property index\n");
374 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
376 // check whether the animatable property is registered already, if not then register one.
377 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
378 if(!animatableProperty)
380 const TypeInfo* typeInfo( GetTypeInfo() );
383 DALI_LOG_ERROR("Cannot find property index\n");
385 else if ( Property::INVALID_INDEX == RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, propertyValue ) )
387 DALI_LOG_ERROR("Cannot register property\n");
392 // set the scene graph property value
393 SetSceneGraphProperty( index, *animatableProperty, propertyValue );
398 CustomPropertyMetadata* custom = FindCustomProperty( index );
401 if( custom->IsAnimatable() )
403 // set the scene graph property value
404 SetSceneGraphProperty( index, *custom, propertyValue );
406 else if( custom->IsWritable() )
408 custom->value = propertyValue;
409 OnPropertySet(index, propertyValue);
411 // trying to set value on read only property is no-op
415 DALI_LOG_ERROR("Invalid property index\n");
420 Property::Value Object::GetProperty(Property::Index index) const
422 DALI_ASSERT_ALWAYS( index > Property::INVALID_INDEX && "Property index is out of bounds" );
424 Property::Value value;
426 if ( index < DEFAULT_PROPERTY_MAX_COUNT )
428 value = GetDefaultProperty( index );
430 else if ( ( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX ) )
432 const TypeInfo* typeInfo( GetTypeInfo() );
435 value = typeInfo->GetProperty( this, index );
439 DALI_LOG_ERROR("Cannot find property index\n");
442 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
444 // check whether the animatable property is registered already, if not then register one.
445 AnimatablePropertyMetadata* animatableProperty = FindAnimatableProperty( index );
446 if(!animatableProperty)
448 const TypeInfo* typeInfo( GetTypeInfo() );
451 if(Property::INVALID_INDEX != RegisterSceneGraphProperty(typeInfo->GetPropertyName(index), index, Property::Value(typeInfo->GetPropertyType(index))))
453 value = Property::Value(typeInfo->GetPropertyType(index)); // Return an initialized property value according to the type
457 DALI_LOG_ERROR("Cannot register property\n");
462 DALI_LOG_ERROR("Cannot find property index\n");
467 // get the animatable property value
468 value = GetPropertyValue( animatableProperty );
471 else if(mCustomProperties.Count() > 0)
473 CustomPropertyMetadata* custom = FindCustomProperty( index );
476 // get the custom property value
477 value = GetPropertyValue( custom );
481 DALI_LOG_ERROR("Invalid property index\n");
488 void Object::GetPropertyIndices( Property::IndexContainer& indices ) const
492 // Default Properties
493 GetDefaultPropertyIndices( indices );
496 const TypeInfo* typeInfo( GetTypeInfo() );
499 typeInfo->GetPropertyIndices( indices );
503 if ( mCustomProperties.Count() > 0 )
505 indices.reserve( indices.size() + mCustomProperties.Count() );
507 PropertyMetadataLookup::ConstIterator iter = mCustomProperties.Begin();
508 const PropertyMetadataLookup::ConstIterator endIter = mCustomProperties.End();
510 for ( ; iter != endIter; ++iter, ++i )
512 indices.push_back( PROPERTY_CUSTOM_START_INDEX + i );
517 Property::Index Object::RegisterSceneGraphProperty(const std::string& name, Property::Index index, const Property::Value& propertyValue) const
519 // Create a new property
520 Dali::Internal::OwnerPointer<PropertyBase> newProperty;
522 switch ( propertyValue.GetType() )
524 case Property::BOOLEAN:
526 newProperty = new AnimatableProperty<bool>( propertyValue.Get<bool>() );
530 case Property::FLOAT:
532 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
536 case Property::INTEGER:
538 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
542 case Property::VECTOR2:
544 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
548 case Property::VECTOR3:
550 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
554 case Property::VECTOR4:
556 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
560 case Property::MATRIX:
562 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
566 case Property::MATRIX3:
568 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
572 case Property::ROTATION:
574 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
578 case Property::UNSIGNED_INTEGER:
579 case Property::RECTANGLE:
580 case Property::STRING:
581 case Property::ARRAY:
584 DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() );
585 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
591 DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() );
592 DALI_ASSERT_ALWAYS( !"PropertyType enumeration is out of bounds" );
597 // get the scene property owner from derived class
598 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
599 // we can only pass properties to scene graph side if there is a scene object
600 if( scenePropertyOwner )
602 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
603 const PropertyBase* property = newProperty.Get();
604 if(index >= PROPERTY_CUSTOM_START_INDEX)
606 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
610 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue.GetType(), property ) );
613 // queue a message to add the property
614 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
616 // notify the derived class (optional) method in case it needs to do some more work on the new property
617 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
618 NotifyScenePropertyInstalled( *property, name, index );
624 // property was orphaned and killed so return invalid index
625 return Property::INVALID_INDEX;
629 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
631 return RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
634 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
636 Property::Index index = Property::INVALID_INDEX;
638 if(Property::ANIMATABLE == accessMode)
640 index = RegisterProperty(name, propertyValue);
644 // Add entry to the property lookup
645 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
646 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
652 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
654 const Dali::PropertyCondition& condition)
656 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
658 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
660 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
662 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
664 // check whether the animatable property is registered already, if not then register one.
665 AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index );
668 const TypeInfo* typeInfo( GetTypeInfo() );
671 if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) )
673 animatable = FindAnimatableProperty( index );
677 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
679 else if ( mCustomProperties.Count() > 0 )
681 CustomPropertyMetadata* custom = FindCustomProperty( index );
682 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
683 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
687 Dali::Handle self(this);
688 Property target( self, index );
690 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
691 Dali::PropertyNotification propertyNotification(internal.Get());
693 if( !mPropertyNotifications )
695 mPropertyNotifications = new PropertyNotificationContainer;
697 mPropertyNotifications->push_back(propertyNotification);
699 return propertyNotification;
702 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
704 if( mPropertyNotifications )
706 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
707 while(iter != mPropertyNotifications->end() )
709 if(*iter == propertyNotification)
711 mPropertyNotifications->erase(iter);
712 // As we can't ensure all references are removed, we can just disable
714 GetImplementation(propertyNotification).Disable();
722 void Object::RemovePropertyNotifications()
724 if( mPropertyNotifications )
726 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
727 while(iter != mPropertyNotifications->end() )
729 // As we can't ensure all references are removed, we can just disable
731 GetImplementation(*iter).Disable();
735 mPropertyNotifications->clear();
739 void Object::EnablePropertyNotifications()
741 if( mPropertyNotifications )
743 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
744 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
746 for( ; iter != endIter; ++iter )
748 GetImplementation(*iter).Enable();
753 void Object::DisablePropertyNotifications()
755 if( mPropertyNotifications )
757 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
758 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
760 for( ; iter != endIter; ++iter )
762 GetImplementation(*iter).Disable();
767 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
769 Property::Value value;
771 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
773 if( !entry->IsAnimatable() )
775 value = entry->value;
779 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
781 switch ( entry->type )
783 case Property::BOOLEAN:
785 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
786 DALI_ASSERT_DEBUG( NULL != property );
788 value = (*property)[ bufferIndex ];
792 case Property::FLOAT:
794 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
795 DALI_ASSERT_DEBUG( NULL != property );
797 value = (*property)[ bufferIndex ];
801 case Property::INTEGER:
803 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
804 DALI_ASSERT_DEBUG( NULL != property );
806 value = (*property)[ bufferIndex ];
810 case Property::VECTOR2:
812 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
813 DALI_ASSERT_DEBUG( NULL != property );
815 value = (*property)[ bufferIndex ];
819 case Property::VECTOR3:
821 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
822 DALI_ASSERT_DEBUG( NULL != property );
824 value = (*property)[ bufferIndex ];
828 case Property::VECTOR4:
830 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
831 DALI_ASSERT_DEBUG( NULL != property );
833 value = (*property)[ bufferIndex ];
837 case Property::MATRIX:
839 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
840 DALI_ASSERT_DEBUG( NULL != property );
842 value = (*property)[ bufferIndex ];
846 case Property::MATRIX3:
848 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
849 DALI_ASSERT_DEBUG( NULL != property );
851 value = (*property)[ bufferIndex ];
855 case Property::ROTATION:
857 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
858 DALI_ASSERT_DEBUG( NULL != property );
860 value = (*property)[ bufferIndex ];
866 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
875 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
877 switch ( entry.type )
879 case Property::BOOLEAN:
881 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
882 DALI_ASSERT_DEBUG( NULL != property );
884 // property is being used in a separate thread; queue a message to set the property
885 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
889 case Property::FLOAT:
891 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
892 DALI_ASSERT_DEBUG( NULL != property );
894 // property is being used in a separate thread; queue a message to set the property
895 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
899 case Property::INTEGER:
901 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
902 DALI_ASSERT_DEBUG( NULL != property );
904 // property is being used in a separate thread; queue a message to set the property
905 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
909 case Property::VECTOR2:
911 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
912 DALI_ASSERT_DEBUG( NULL != property );
914 // property is being used in a separate thread; queue a message to set the property
915 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
919 case Property::VECTOR3:
921 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
922 DALI_ASSERT_DEBUG( NULL != property );
924 // property is being used in a separate thread; queue a message to set the property
925 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
929 case Property::VECTOR4:
931 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
932 DALI_ASSERT_DEBUG( NULL != property );
934 // property is being used in a separate thread; queue a message to set the property
935 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
939 case Property::ROTATION:
941 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
942 DALI_ASSERT_DEBUG( NULL != property );
944 // property is being used in a separate thread; queue a message to set the property
945 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
949 case Property::MATRIX:
951 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
952 DALI_ASSERT_DEBUG( NULL != property );
954 // property is being used in a separate thread; queue a message to set the property
955 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
959 case Property::MATRIX3:
961 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
962 DALI_ASSERT_DEBUG( NULL != property );
964 // property is being used in a separate thread; queue a message to set the property
965 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
971 // non-animatable scene graph property, do nothing
976 const TypeInfo* Object::GetTypeInfo() const
980 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
981 // especially as the type-info does not change during the life-time of an application
983 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
984 if ( typeInfoHandle )
986 mTypeInfo = &GetImplementation( typeInfoHandle );
993 void Object::ApplyConstraint( ConstraintBase& constraint )
997 mConstraints = new ConstraintContainer;
999 mConstraints->push_back( Dali::Constraint( &constraint ) );
1002 void Object::RemoveConstraint( ConstraintBase& constraint )
1004 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1007 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1008 if( it != mConstraints->end() )
1010 mConstraints->erase( it );
1015 void Object::RemoveConstraints()
1017 // guard against constraint sending messages during core destruction
1018 if( mConstraints && Stage::IsInstalled() )
1020 // If we have nothing in the scene-graph, just clear constraint containers
1021 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1022 if ( NULL != propertyOwner )
1024 const ConstraintConstIter endIter = mConstraints->end();
1025 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1027 GetImplementation( *iter ).RemoveInternal();
1031 delete mConstraints;
1032 mConstraints = NULL;
1036 void Object::RemoveConstraints( unsigned int tag )
1038 // guard against constraint sending messages during core destruction
1039 if( mConstraints && Stage::IsInstalled() )
1041 ConstraintIter iter( mConstraints->begin() );
1042 while(iter != mConstraints->end() )
1044 ConstraintBase& constraint = GetImplementation( *iter );
1045 if( constraint.GetTag() == tag )
1047 GetImplementation( *iter ).RemoveInternal();
1048 iter = mConstraints->erase( iter );
1056 if ( mConstraints->empty() )
1058 delete mConstraints;
1059 mConstraints = NULL;
1064 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1066 mTypeInfo = typeInfo;
1071 // Notification for observers
1072 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1074 (*iter)->ObjectDestroyed(*this);
1077 delete mConstraints;
1078 delete mPropertyNotifications;
1081 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1083 CustomPropertyMetadata* property( NULL );
1084 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1085 if( arrayIndex >= 0 )
1087 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1089 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1095 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1097 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1099 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1100 if( property->index == index )
1108 } // namespace Internal