1 #ifndef DALI_INTERNAL_OBJECT_IMPL_HELPER_H
2 #define DALI_INTERNAL_OBJECT_IMPL_HELPER_H
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
25 #include <dali/public-api/object/property.h> // Dali::Property
26 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
27 #include <dali/internal/event/common/property-helper.h> // Dali::Internal::PropertyDetails
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/update/common/animatable-property.h>
30 #include <dali/internal/update/common/property-owner-messages.h>
31 #include <dali/internal/update/manager/update-manager.h>
37 class PropertyMetadata;
38 class AnimatablePropertyMetadata;
39 class CustomPropertyMetadata;
40 class PropertyInputImpl;
49 } // namespace SceneGraph
51 // Typedefs to allow object methods to be passed via parameter
52 typedef AnimatablePropertyMetadata* (Object::*FindAnimatablePropertyMethod)( Property::Index index ) const;
53 typedef CustomPropertyMetadata* (Object::*FindCustomPropertyMethod)( Property::Index index ) const;
57 * Helper template class to be used by class that implement Object
61 * typename ObjectImplHelper<DEFAULT_PROPERTY_COUNT, DEFAULT_PROPERTY_DETAILS> MyObjectImpl;
63 * MyObjectImpl::GetDefaultPropertyCount();
66 template<int DEFAULT_PROPERTY_COUNT>
67 struct ObjectImplHelper
69 const PropertyDetails* DEFAULT_PROPERTY_DETAILS;
71 unsigned int GetDefaultPropertyCount() const
73 return DEFAULT_PROPERTY_COUNT;
76 void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
78 indices.Reserve( DEFAULT_PROPERTY_COUNT );
80 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
82 indices.PushBack( DEFAULT_OBJECT_PROPERTY_START_INDEX + i );
86 const char* GetDefaultPropertyName( Property::Index index ) const
88 const char* name = NULL;
90 if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
92 name = DEFAULT_PROPERTY_DETAILS[index].name;
98 Property::Index GetDefaultPropertyIndex( const std::string& name ) const
100 Property::Index index = Property::INVALID_INDEX;
102 // Look for name in default properties
103 for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
105 const Internal::PropertyDetails* property = &DEFAULT_PROPERTY_DETAILS[ i ];
106 if( 0 == strcmp( name.c_str(), property->name ) ) // dont want to convert rhs to string
116 bool IsDefaultPropertyWritable( Property::Index index ) const
118 bool isWritable = false;
120 if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
122 isWritable = DEFAULT_PROPERTY_DETAILS[index].writable;
128 bool IsDefaultPropertyAnimatable( Property::Index index ) const
130 bool isAnimatable = false;
132 if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
134 isAnimatable = DEFAULT_PROPERTY_DETAILS[index].animatable;
140 bool IsDefaultPropertyAConstraintInput( Property::Index index ) const
142 bool isConstraintInput = false;
144 if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
146 isConstraintInput = DEFAULT_PROPERTY_DETAILS[index].constraintInput;
149 return isConstraintInput;
152 Property::Type GetDefaultPropertyType( Property::Index index ) const
154 Property::Type type = Property::NONE;
156 if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
158 type = DEFAULT_PROPERTY_DETAILS[index].type;
164 // Get the (animatable) scene graph property. (All registered scene graph properties are animatable)
165 const SceneGraph::PropertyBase* GetRegisteredSceneGraphProperty(
166 const Object* object,
167 FindAnimatablePropertyMethod findAnimatablePropertyMethod,
168 FindCustomPropertyMethod findCustomPropertyMethod,
169 Property::Index index ) const
171 const SceneGraph::PropertyBase* property = NULL;
172 if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
174 AnimatablePropertyMetadata* animatable = (object->*findAnimatablePropertyMethod)( index );
175 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
176 property = animatable->GetSceneGraphProperty();
178 else if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
180 CustomPropertyMetadata* custom = (object->*findCustomPropertyMethod)( index );
181 DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
182 property = custom->GetSceneGraphProperty();
187 void SetSceneGraphProperty( EventThreadServices& eventThreadServices,
188 const Object* object,
189 Property::Index index,
190 const PropertyMetadata& entry,
191 const Property::Value& value ) const
193 const SceneGraph::PropertyOwner* sceneObject = object->GetSceneObject();
195 switch ( entry.GetType() )
197 case Property::BOOLEAN:
199 const SceneGraph::AnimatableProperty<bool>* property = dynamic_cast< const SceneGraph::AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
200 DALI_ASSERT_DEBUG( NULL != property );
202 // property is being used in a separate thread; queue a message to set the property
203 SceneGraph::AnimatablePropertyMessage<bool>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<bool>::Bake, value.Get<bool>() );
208 case Property::FLOAT:
210 const SceneGraph::AnimatableProperty<float>* property = dynamic_cast< const SceneGraph::AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
211 DALI_ASSERT_DEBUG( NULL != property );
213 // property is being used in a separate thread; queue a message to set the property
214 SceneGraph::AnimatablePropertyMessage<float>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<float>::Bake, value.Get<float>() );
219 case Property::INTEGER:
221 const SceneGraph::AnimatableProperty<int>* property = dynamic_cast< const SceneGraph::AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
222 DALI_ASSERT_DEBUG( NULL != property );
224 // property is being used in a separate thread; queue a message to set the property
225 SceneGraph::AnimatablePropertyMessage<int>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<int>::Bake, value.Get<int>() );
230 case Property::VECTOR2:
232 const SceneGraph::AnimatableProperty<Vector2>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
233 DALI_ASSERT_DEBUG( NULL != property );
235 // property is being used in a separate thread; queue a message to set the property
236 SceneGraph::AnimatablePropertyMessage<Vector2>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector2>::Bake, value.Get<Vector2>() );
241 case Property::VECTOR3:
243 const SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
244 DALI_ASSERT_DEBUG( NULL != property );
246 // property is being used in a separate thread; queue a message to set the property
247 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector3>::Bake, value.Get<Vector3>() );
252 case Property::VECTOR4:
254 const SceneGraph::AnimatableProperty<Vector4>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
255 DALI_ASSERT_DEBUG( NULL != property );
257 // property is being used in a separate thread; queue a message to set the property
258 SceneGraph::AnimatablePropertyMessage<Vector4>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector4>::Bake, value.Get<Vector4>() );
263 case Property::ROTATION:
265 const SceneGraph::AnimatableProperty<Quaternion>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
266 DALI_ASSERT_DEBUG( NULL != property );
268 // property is being used in a separate thread; queue a message to set the property
269 SceneGraph::AnimatablePropertyMessage<Quaternion>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Quaternion>::Bake, value.Get<Quaternion>() );
274 case Property::MATRIX:
276 const SceneGraph::AnimatableProperty<Matrix>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
277 DALI_ASSERT_DEBUG( NULL != property );
279 // property is being used in a separate thread; queue a message to set the property
280 SceneGraph::AnimatablePropertyMessage<Matrix>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Matrix>::Bake, value.Get<Matrix>() );
285 case Property::MATRIX3:
287 const SceneGraph::AnimatableProperty<Matrix3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
288 DALI_ASSERT_DEBUG( NULL != property );
290 // property is being used in a separate thread; queue a message to set the property
291 SceneGraph::AnimatablePropertyMessage<Matrix3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Matrix3>::Bake, value.Get<Matrix3>() );
298 DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here
304 int GetPropertyComponentIndex( Property::Index index ) const
307 DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
314 } // namespace Internal
318 #endif // DALI_INTERNAL_OBJECT_IMPL_HELPER_H