Dali 3D User Interface Engine
object-impl-helper.h
Go to the documentation of this file.
1 #ifndef DALI_INTERNAL_OBJECT_IMPL_HELPER_H
2 #define DALI_INTERNAL_OBJECT_IMPL_HELPER_H
3 
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20 
21 // EXTERNAL INCLUDEs
22 #include <cstring>
23 
24 // INTERNAL INCLUDES
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
32 
33 namespace Dali
34 {
35 namespace Internal
36 {
37 class PropertyMetadata;
38 class AnimatablePropertyMetadata;
39 class CustomPropertyMetadata;
40 class PropertyInputImpl;
41 
42 namespace SceneGraph
43 {
44 
45 class PropertyBase;
46 class PropertyOwner;
47 
48 
49 } // namespace SceneGraph
50 
51 // Typedefs to allow object methods to be passed via parameter
54 
55 
66 template<int DEFAULT_PROPERTY_COUNT>
68 {
70 
71  unsigned int GetDefaultPropertyCount() const
72  {
73  return DEFAULT_PROPERTY_COUNT;
74  }
75 
77  {
78  indices.Reserve( DEFAULT_PROPERTY_COUNT );
79 
80  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
81  {
83  }
84  }
85 
86  const char* GetDefaultPropertyName( Property::Index index ) const
87  {
88  const char* name = NULL;
89 
90  if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
91  {
92  name = DEFAULT_PROPERTY_DETAILS[index].name;
93  }
94 
95  return name;
96  }
97 
98  Property::Index GetDefaultPropertyIndex( const std::string& name ) const
99  {
101 
102  // Look for name in default properties
103  for( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
104  {
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
107  {
108  index = i;
109  break;
110  }
111  }
112 
113  return index;
114  }
115 
117  {
118  bool isWritable = false;
119 
120  if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
121  {
122  isWritable = DEFAULT_PROPERTY_DETAILS[index].writable;
123  }
124 
125  return isWritable;
126  }
127 
129  {
130  bool isAnimatable = false;
131 
132  if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
133  {
134  isAnimatable = DEFAULT_PROPERTY_DETAILS[index].animatable;
135  }
136 
137  return isAnimatable;
138  }
139 
141  {
142  bool isConstraintInput = false;
143 
144  if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
145  {
146  isConstraintInput = DEFAULT_PROPERTY_DETAILS[index].constraintInput;
147  }
148 
149  return isConstraintInput;
150  }
151 
153  {
155 
156  if( index >= DEFAULT_OBJECT_PROPERTY_START_INDEX && index < DEFAULT_PROPERTY_COUNT )
157  {
158  type = DEFAULT_PROPERTY_DETAILS[index].type;
159  }
160 
161  return type;
162  }
163 
164  // Get the (animatable) scene graph property. (All registered scene graph properties are animatable)
166  const Object* object,
167  FindAnimatablePropertyMethod findAnimatablePropertyMethod,
168  FindCustomPropertyMethod findCustomPropertyMethod,
169  Property::Index index ) const
170  {
171  const SceneGraph::PropertyBase* property = NULL;
173  {
174  AnimatablePropertyMetadata* animatable = (object->*findAnimatablePropertyMethod)( index );
175  DALI_ASSERT_ALWAYS( animatable && "Property index is invalid" );
176  property = animatable->GetSceneGraphProperty();
177  }
178  else if ( index >= DEFAULT_PROPERTY_MAX_COUNT )
179  {
180  CustomPropertyMetadata* custom = (object->*findCustomPropertyMethod)( index );
181  DALI_ASSERT_ALWAYS( custom && "Property index is invalid" );
182  property = custom->GetSceneGraphProperty();
183  }
184  return property;
185  }
186 
187  void SetSceneGraphProperty( EventThreadServices& eventThreadServices,
188  const Object* object,
189  Property::Index index,
190  const PropertyMetadata& entry,
191  const Property::Value& value ) const
192  {
193  const SceneGraph::PropertyOwner* sceneObject = object->GetSceneObject();
194 
195  switch ( entry.GetType() )
196  {
197  case Property::BOOLEAN:
198  {
199  const SceneGraph::AnimatableProperty<bool>* property = dynamic_cast< const SceneGraph::AnimatableProperty<bool>* >( entry.GetSceneGraphProperty() );
200  DALI_ASSERT_DEBUG( NULL != property );
201 
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>() );
204 
205  break;
206  }
207 
208  case Property::FLOAT:
209  {
211  DALI_ASSERT_DEBUG( NULL != property );
212 
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>() );
215 
216  break;
217  }
218 
219  case Property::INTEGER:
220  {
221  const SceneGraph::AnimatableProperty<int>* property = dynamic_cast< const SceneGraph::AnimatableProperty<int>* >( entry.GetSceneGraphProperty() );
222  DALI_ASSERT_DEBUG( NULL != property );
223 
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>() );
226 
227  break;
228  }
229 
230  case Property::VECTOR2:
231  {
233  DALI_ASSERT_DEBUG( NULL != property );
234 
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>() );
237 
238  break;
239  }
240 
241  case Property::VECTOR3:
242  {
244  DALI_ASSERT_DEBUG( NULL != property );
245 
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>() );
248 
249  break;
250  }
251 
252  case Property::VECTOR4:
253  {
255  DALI_ASSERT_DEBUG( NULL != property );
256 
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>() );
259 
260  break;
261  }
262 
263  case Property::ROTATION:
264  {
266  DALI_ASSERT_DEBUG( NULL != property );
267 
268  // property is being used in a separate thread; queue a message to set the property
270 
271  break;
272  }
273 
274  case Property::MATRIX:
275  {
277  DALI_ASSERT_DEBUG( NULL != property );
278 
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>() );
281 
282  break;
283  }
284 
285  case Property::MATRIX3:
286  {
288  DALI_ASSERT_DEBUG( NULL != property );
289 
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>() );
292 
293  break;
294  }
295 
296  default:
297  {
298  DALI_ASSERT_ALWAYS( false && "Property type enumeration out of bounds" ); // should not come here
299  break;
300  }
301  }
302  }
303 
305  {
306  // TODO: MESH_REWORK
307  DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
308  return 0;
309  }
310 };
311 
312 
313 
314 } // namespace Internal
315 
316 } // namespace Dali
317 
318 #endif // DALI_INTERNAL_OBJECT_IMPL_HELPER_H
Dali Docs Home
Read more about Dali