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::INTEGER:
532 newProperty = new AnimatableProperty<int>( propertyValue.Get<int>() );
536 case Property::UNSIGNED_INTEGER:
538 newProperty = new AnimatableProperty<unsigned int>( propertyValue.Get<unsigned int>() );
542 case Property::FLOAT:
544 newProperty = new AnimatableProperty<float>( propertyValue.Get<float>() );
548 case Property::VECTOR2:
550 newProperty = new AnimatableProperty<Vector2>( propertyValue.Get<Vector2>() );
554 case Property::VECTOR3:
556 newProperty = new AnimatableProperty<Vector3>( propertyValue.Get<Vector3>() );
560 case Property::VECTOR4:
562 newProperty = new AnimatableProperty<Vector4>( propertyValue.Get<Vector4>() );
566 case Property::MATRIX:
568 newProperty = new AnimatableProperty<Matrix>( propertyValue.Get<Matrix>() );
572 case Property::MATRIX3:
574 newProperty = new AnimatableProperty<Matrix3>( propertyValue.Get<Matrix3>() );
578 case Property::ROTATION:
580 newProperty = new AnimatableProperty<Quaternion>( propertyValue.Get<Quaternion>() );
584 case Property::RECTANGLE:
585 case Property::STRING:
586 case Property::ARRAY:
589 DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() );
590 DALI_ASSERT_ALWAYS( !"PropertyType is not animatable" );
596 DALI_LOG_WARNING( "Property Type %d\n", propertyValue.GetType() );
597 DALI_ASSERT_ALWAYS( !"PropertyType enumeration is out of bounds" );
602 // get the scene property owner from derived class
603 const SceneGraph::PropertyOwner* scenePropertyOwner = GetPropertyOwner();
604 // we can only pass properties to scene graph side if there is a scene object
605 if( scenePropertyOwner )
607 // keep a local pointer to the property as the OwnerPointer will pass its copy to the message
608 const PropertyBase* property = newProperty.Get();
609 if(index >= PROPERTY_CUSTOM_START_INDEX)
611 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue.GetType(), property ) );
615 mAnimatableProperties.PushBack( new AnimatablePropertyMetadata( index, propertyValue.GetType(), property ) );
618 // queue a message to add the property
619 InstallCustomPropertyMessage( const_cast<EventThreadServices&>(GetEventThreadServices()), *scenePropertyOwner, newProperty.Release() ); // Message takes ownership
621 // notify the derived class (optional) method in case it needs to do some more work on the new property
622 // note! have to use the local pointer as OwnerPointer now points to NULL as it handed over its ownership
623 NotifyScenePropertyInstalled( *property, name, index );
629 // property was orphaned and killed so return invalid index
630 return Property::INVALID_INDEX;
634 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue)
636 return RegisterSceneGraphProperty(name, PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count(), propertyValue);
639 Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode)
641 Property::Index index = Property::INVALID_INDEX;
643 if(Property::ANIMATABLE == accessMode)
645 index = RegisterProperty(name, propertyValue);
649 // Add entry to the property lookup
650 index = PROPERTY_CUSTOM_START_INDEX + mCustomProperties.Count();
651 mCustomProperties.PushBack( new CustomPropertyMetadata( name, propertyValue, accessMode ) );
657 Dali::PropertyNotification Object::AddPropertyNotification(Property::Index index,
659 const Dali::PropertyCondition& condition)
661 if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
663 if ( index <= PROPERTY_REGISTRATION_MAX_INDEX )
665 DALI_ASSERT_ALWAYS( false && "Property notification added to event side only property." );
667 else if ( ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX ) && ( index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX ) )
669 // check whether the animatable property is registered already, if not then register one.
670 AnimatablePropertyMetadata* animatable = FindAnimatableProperty( index );
673 const TypeInfo* typeInfo( GetTypeInfo() );
676 if( Property::INVALID_INDEX != RegisterSceneGraphProperty( typeInfo->GetPropertyName( index ), index, Property::Value( typeInfo->GetPropertyType( index ) ) ) )
678 animatable = FindAnimatableProperty( index );
682 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
684 else if ( mCustomProperties.Count() > 0 )
686 CustomPropertyMetadata* custom = FindCustomProperty( index );
687 DALI_ASSERT_ALWAYS( custom && "Invalid property index" );
688 DALI_ASSERT_ALWAYS( custom->IsAnimatable() && "Property notification added to event side only property." );
692 Dali::Handle self(this);
693 Property target( self, index );
695 PropertyNotificationPtr internal = PropertyNotification::New( target, componentIndex, condition );
696 Dali::PropertyNotification propertyNotification(internal.Get());
698 if( !mPropertyNotifications )
700 mPropertyNotifications = new PropertyNotificationContainer;
702 mPropertyNotifications->push_back(propertyNotification);
704 return propertyNotification;
707 void Object::RemovePropertyNotification(Dali::PropertyNotification propertyNotification)
709 if( mPropertyNotifications )
711 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
712 while(iter != mPropertyNotifications->end() )
714 if(*iter == propertyNotification)
716 mPropertyNotifications->erase(iter);
717 // As we can't ensure all references are removed, we can just disable
719 GetImplementation(propertyNotification).Disable();
727 void Object::RemovePropertyNotifications()
729 if( mPropertyNotifications )
731 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
732 while(iter != mPropertyNotifications->end() )
734 // As we can't ensure all references are removed, we can just disable
736 GetImplementation(*iter).Disable();
740 mPropertyNotifications->clear();
744 void Object::EnablePropertyNotifications()
746 if( mPropertyNotifications )
748 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
749 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
751 for( ; iter != endIter; ++iter )
753 GetImplementation(*iter).Enable();
758 void Object::DisablePropertyNotifications()
760 if( mPropertyNotifications )
762 PropertyNotificationContainerIter iter = mPropertyNotifications->begin();
763 PropertyNotificationContainerIter endIter = mPropertyNotifications->end();
765 for( ; iter != endIter; ++iter )
767 GetImplementation(*iter).Disable();
772 Property::Value Object::GetPropertyValue( const PropertyMetadata* entry ) const
774 Property::Value value;
776 DALI_ASSERT_ALWAYS( entry && "Invalid property metadata" );
778 if( !entry->IsAnimatable() )
780 value = entry->value;
784 BufferIndex bufferIndex( GetEventThreadServices().GetEventBufferIndex() );
786 switch ( entry->type )
788 case Property::BOOLEAN:
790 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry->GetSceneGraphProperty() );
791 DALI_ASSERT_DEBUG( NULL != property );
793 value = (*property)[ bufferIndex ];
797 case Property::INTEGER:
799 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry->GetSceneGraphProperty() );
800 DALI_ASSERT_DEBUG( NULL != property );
802 value = (*property)[ bufferIndex ];
806 case Property::UNSIGNED_INTEGER:
808 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry->GetSceneGraphProperty() );
809 DALI_ASSERT_DEBUG( NULL != property );
811 value = (*property)[ bufferIndex ];
815 case Property::FLOAT:
817 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry->GetSceneGraphProperty() );
818 DALI_ASSERT_DEBUG( NULL != property );
820 value = (*property)[ bufferIndex ];
824 case Property::VECTOR2:
826 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry->GetSceneGraphProperty() );
827 DALI_ASSERT_DEBUG( NULL != property );
829 value = (*property)[ bufferIndex ];
833 case Property::VECTOR3:
835 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry->GetSceneGraphProperty() );
836 DALI_ASSERT_DEBUG( NULL != property );
838 value = (*property)[ bufferIndex ];
842 case Property::VECTOR4:
844 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry->GetSceneGraphProperty() );
845 DALI_ASSERT_DEBUG( NULL != property );
847 value = (*property)[ bufferIndex ];
851 case Property::MATRIX:
853 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry->GetSceneGraphProperty() );
854 DALI_ASSERT_DEBUG( NULL != property );
856 value = (*property)[ bufferIndex ];
860 case Property::MATRIX3:
862 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry->GetSceneGraphProperty() );
863 DALI_ASSERT_DEBUG( NULL != property );
865 value = (*property)[ bufferIndex ];
869 case Property::ROTATION:
871 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry->GetSceneGraphProperty() );
872 DALI_ASSERT_DEBUG( NULL != property );
874 value = (*property)[ bufferIndex ];
880 DALI_ASSERT_ALWAYS( false && "PropertyType enumeration is out of bounds" );
889 void Object::SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value )
891 switch ( entry.type )
893 case Property::BOOLEAN:
895 const AnimatableProperty<bool>* property = dynamic_cast< const AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
896 DALI_ASSERT_DEBUG( NULL != property );
898 // property is being used in a separate thread; queue a message to set the property
899 BakeMessage<bool>( GetEventThreadServices(), *property, value.Get<bool>() );
903 case Property::INTEGER:
905 const AnimatableProperty<int>* property = dynamic_cast< const AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
906 DALI_ASSERT_DEBUG( NULL != property );
908 // property is being used in a separate thread; queue a message to set the property
909 BakeMessage<int>( GetEventThreadServices(), *property, value.Get<int>() );
913 case Property::UNSIGNED_INTEGER:
915 const AnimatableProperty<unsigned int>* property = dynamic_cast< const AnimatableProperty<unsigned int>* >( entry.GetSceneGraphProperty() );
916 DALI_ASSERT_DEBUG( NULL != property );
918 // property is being used in a separate thread; queue a message to set the property
919 BakeMessage<unsigned int>( GetEventThreadServices(), *property, value.Get<unsigned int>() );
923 case Property::FLOAT:
925 const AnimatableProperty<float>* property = dynamic_cast< const AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
926 DALI_ASSERT_DEBUG( NULL != property );
928 // property is being used in a separate thread; queue a message to set the property
929 BakeMessage<float>( GetEventThreadServices(), *property, value.Get<float>() );
933 case Property::VECTOR2:
935 const AnimatableProperty<Vector2>* property = dynamic_cast< const AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
936 DALI_ASSERT_DEBUG( NULL != property );
938 // property is being used in a separate thread; queue a message to set the property
939 BakeMessage<Vector2>( GetEventThreadServices(), *property, value.Get<Vector2>() );
943 case Property::VECTOR3:
945 const AnimatableProperty<Vector3>* property = dynamic_cast< const AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
946 DALI_ASSERT_DEBUG( NULL != property );
948 // property is being used in a separate thread; queue a message to set the property
949 BakeMessage<Vector3>( GetEventThreadServices(), *property, value.Get<Vector3>() );
953 case Property::VECTOR4:
955 const AnimatableProperty<Vector4>* property = dynamic_cast< const AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
956 DALI_ASSERT_DEBUG( NULL != property );
958 // property is being used in a separate thread; queue a message to set the property
959 BakeMessage<Vector4>( GetEventThreadServices(), *property, value.Get<Vector4>() );
963 case Property::ROTATION:
965 const AnimatableProperty<Quaternion>* property = dynamic_cast< const AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
966 DALI_ASSERT_DEBUG( NULL != property );
968 // property is being used in a separate thread; queue a message to set the property
969 BakeMessage<Quaternion>( GetEventThreadServices(), *property, value.Get<Quaternion>() );
973 case Property::MATRIX:
975 const AnimatableProperty<Matrix>* property = dynamic_cast< const AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
976 DALI_ASSERT_DEBUG( NULL != property );
978 // property is being used in a separate thread; queue a message to set the property
979 BakeMessage<Matrix>( GetEventThreadServices(), *property, value.Get<Matrix>() );
983 case Property::MATRIX3:
985 const AnimatableProperty<Matrix3>* property = dynamic_cast< const AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
986 DALI_ASSERT_DEBUG( NULL != property );
988 // property is being used in a separate thread; queue a message to set the property
989 BakeMessage<Matrix3>( GetEventThreadServices(), *property, value.Get<Matrix3>() );
995 // non-animatable scene graph property, do nothing
1000 const TypeInfo* Object::GetTypeInfo() const
1004 // This uses a dynamic_cast so can be quite expensive so we only really want to do it once
1005 // especially as the type-info does not change during the life-time of an application
1007 Dali::TypeInfo typeInfoHandle = TypeRegistry::Get()->GetTypeInfo( this );
1008 if ( typeInfoHandle )
1010 mTypeInfo = &GetImplementation( typeInfoHandle );
1017 void Object::ApplyConstraint( ConstraintBase& constraint )
1021 mConstraints = new ConstraintContainer;
1023 mConstraints->push_back( Dali::Constraint( &constraint ) );
1026 void Object::RemoveConstraint( ConstraintBase& constraint )
1028 // NULL if the Constraint sources are destroyed before Constraint::Apply()
1031 ConstraintIter it( std::find( mConstraints->begin(), mConstraints->end(), Dali::Constraint( &constraint ) ) );
1032 if( it != mConstraints->end() )
1034 mConstraints->erase( it );
1039 void Object::RemoveConstraints()
1041 // guard against constraint sending messages during core destruction
1042 if( mConstraints && Stage::IsInstalled() )
1044 // If we have nothing in the scene-graph, just clear constraint containers
1045 const SceneGraph::PropertyOwner* propertyOwner = GetSceneObject();
1046 if ( NULL != propertyOwner )
1048 const ConstraintConstIter endIter = mConstraints->end();
1049 for ( ConstraintIter iter = mConstraints->begin(); endIter != iter; ++iter )
1051 GetImplementation( *iter ).RemoveInternal();
1055 delete mConstraints;
1056 mConstraints = NULL;
1060 void Object::RemoveConstraints( unsigned int tag )
1062 // guard against constraint sending messages during core destruction
1063 if( mConstraints && Stage::IsInstalled() )
1065 ConstraintIter iter( mConstraints->begin() );
1066 while(iter != mConstraints->end() )
1068 ConstraintBase& constraint = GetImplementation( *iter );
1069 if( constraint.GetTag() == tag )
1071 GetImplementation( *iter ).RemoveInternal();
1072 iter = mConstraints->erase( iter );
1080 if ( mConstraints->empty() )
1082 delete mConstraints;
1083 mConstraints = NULL;
1088 void Object::SetTypeInfo( const TypeInfo* typeInfo )
1090 mTypeInfo = typeInfo;
1095 // Notification for observers
1096 for( ConstObserverIter iter = mObservers.Begin(), endIter = mObservers.End(); iter != endIter; ++iter)
1098 (*iter)->ObjectDestroyed(*this);
1101 delete mConstraints;
1102 delete mPropertyNotifications;
1105 CustomPropertyMetadata* Object::FindCustomProperty( Property::Index index ) const
1107 CustomPropertyMetadata* property( NULL );
1108 int arrayIndex = index - PROPERTY_CUSTOM_START_INDEX;
1109 if( arrayIndex >= 0 )
1111 if( arrayIndex < (int)mCustomProperties.Count() ) // we can only access the first 2 billion custom properties
1113 property = static_cast<CustomPropertyMetadata*>(mCustomProperties[ arrayIndex ]);
1119 AnimatablePropertyMetadata* Object::FindAnimatableProperty( Property::Index index ) const
1121 for ( int arrayIndex = 0; arrayIndex < (int)mAnimatableProperties.Count(); arrayIndex++ )
1123 AnimatablePropertyMetadata* property = static_cast<AnimatablePropertyMetadata*>( mAnimatableProperties[ arrayIndex ] );
1124 if( property->index == index )
1132 } // namespace Internal