1 #ifndef DALI_INTERNAL_OBJECT_IMPL_HELPER_H
2 #define DALI_INTERNAL_OBJECT_IMPL_HELPER_H
5 * Copyright (c) 2018 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/internal/event/common/event-thread-services.h>
27 #include <dali/internal/update/common/animatable-property.h>
28 #include <dali/internal/update/common/property-owner-messages.h>
29 #include <dali/internal/update/manager/update-manager.h>
35 class PropertyMetadata;
36 class AnimatablePropertyMetadata;
37 class CustomPropertyMetadata;
38 class PropertyInputImpl;
46 } // namespace SceneGraph
48 // methods needed as parameters
49 using FindAnimatablePropertyMethod = AnimatablePropertyMetadata* (Object::*)(Property::Index index) const;
50 using FindCustomPropertyMethod = CustomPropertyMetadata* (Object::*)(Property::Index index) const;
53 * Helper utilities to be used by class that implement Object
55 namespace ObjectImplHelper
57 // Get the (animatable) scene graph property. (All registered scene graph properties are animatable)
58 inline const SceneGraph::PropertyBase* GetRegisteredSceneGraphProperty( const Object* object,
59 FindAnimatablePropertyMethod findAnimatablePropertyMethod,
60 FindCustomPropertyMethod findCustomPropertyMethod,
61 Property::Index index )
63 const SceneGraph::PropertyBase* property = NULL;
64 if ( index >= ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX && index <= ANIMATABLE_PROPERTY_REGISTRATION_MAX_INDEX )
66 AnimatablePropertyMetadata* animatable = (object->*findAnimatablePropertyMethod)( index );
67 DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
68 property = animatable->GetSceneGraphProperty();
70 else if ( ( index > CHILD_PROPERTY_REGISTRATION_START_INDEX ) && // Child properties are also stored as custom properties
71 ( index <= PROPERTY_CUSTOM_MAX_INDEX ) )
73 CustomPropertyMetadata* custom = (object->*findCustomPropertyMethod)( index );
74 DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
75 property = custom->GetSceneGraphProperty();
80 inline void SetSceneGraphProperty( EventThreadServices& eventThreadServices,
82 Property::Index index,
83 const PropertyMetadata& entry,
84 const Property::Value& value )
86 const SceneGraph::PropertyOwner* sceneObject = object->GetSceneObject();
88 switch ( entry.GetType() )
90 case Property::BOOLEAN:
92 const SceneGraph::AnimatableProperty<bool>* property = dynamic_cast< const SceneGraph::AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
93 DALI_ASSERT_DEBUG( NULL != property );
95 // property is being used in a separate thread; queue a message to set the property
96 SceneGraph::AnimatablePropertyMessage<bool>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<bool>::Bake, value.Get<bool>() );
101 case Property::FLOAT:
103 const SceneGraph::AnimatableProperty<float>* property = dynamic_cast< const SceneGraph::AnimatableProperty<float>* >( entry.GetSceneGraphProperty() );
104 DALI_ASSERT_DEBUG( NULL != property );
106 // property is being used in a separate thread; queue a message to set the property
107 SceneGraph::AnimatablePropertyMessage<float>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<float>::Bake, value.Get<float>() );
112 case Property::INTEGER:
114 const SceneGraph::AnimatableProperty<int>* property = dynamic_cast< const SceneGraph::AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
115 DALI_ASSERT_DEBUG( NULL != property );
117 // property is being used in a separate thread; queue a message to set the property
118 SceneGraph::AnimatablePropertyMessage<int>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<int>::Bake, value.Get<int>() );
123 case Property::VECTOR2:
125 const SceneGraph::AnimatableProperty<Vector2>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector2>* >( entry.GetSceneGraphProperty() );
126 DALI_ASSERT_DEBUG( NULL != property );
128 // property is being used in a separate thread; queue a message to set the property
129 SceneGraph::AnimatablePropertyMessage<Vector2>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector2>::Bake, value.Get<Vector2>() );
134 case Property::VECTOR3:
136 const SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector3>* >( entry.GetSceneGraphProperty() );
137 DALI_ASSERT_DEBUG( NULL != property );
139 // property is being used in a separate thread; queue a message to set the property
140 SceneGraph::AnimatablePropertyMessage<Vector3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector3>::Bake, value.Get<Vector3>() );
145 case Property::VECTOR4:
147 const SceneGraph::AnimatableProperty<Vector4>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Vector4>* >( entry.GetSceneGraphProperty() );
148 DALI_ASSERT_DEBUG( NULL != property );
150 // property is being used in a separate thread; queue a message to set the property
151 SceneGraph::AnimatablePropertyMessage<Vector4>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Vector4>::Bake, value.Get<Vector4>() );
156 case Property::ROTATION:
158 const SceneGraph::AnimatableProperty<Quaternion>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Quaternion>* >( entry.GetSceneGraphProperty() );
159 DALI_ASSERT_DEBUG( NULL != property );
161 // property is being used in a separate thread; queue a message to set the property
162 SceneGraph::AnimatablePropertyMessage<Quaternion>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Quaternion>::Bake, value.Get<Quaternion>() );
167 case Property::MATRIX:
169 const SceneGraph::AnimatableProperty<Matrix>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix>* >( entry.GetSceneGraphProperty() );
170 DALI_ASSERT_DEBUG( NULL != property );
172 // property is being used in a separate thread; queue a message to set the property
173 SceneGraph::AnimatablePropertyMessage<Matrix>::Send( eventThreadServices, sceneObject, property,&SceneGraph::AnimatableProperty<Matrix>::Bake, value.Get<Matrix>() );
178 case Property::MATRIX3:
180 const SceneGraph::AnimatableProperty<Matrix3>* property = dynamic_cast< const SceneGraph::AnimatableProperty<Matrix3>* >( entry.GetSceneGraphProperty() );
181 DALI_ASSERT_DEBUG( NULL != property );
183 // property is being used in a separate thread; queue a message to set the property
184 SceneGraph::AnimatablePropertyMessage<Matrix3>::Send( eventThreadServices, sceneObject, property, &SceneGraph::AnimatableProperty<Matrix3>::Bake, value.Get<Matrix3>() );
191 // ignore non-scene-graph types
199 } // namespace Internal
203 #endif // DALI_INTERNAL_OBJECT_IMPL_HELPER_H