[Tizen] Implement partial update
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / transform-manager.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/update/manager/transform-manager.h>
20
21 //EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <cstring>
24 #include <type_traits>
25
26 //INTERNAL INCLUDES
27 #include <dali/public-api/common/constants.h>
28 #include <dali/internal/common/math.h>
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 namespace SceneGraph
37 {
38
39 namespace
40 {
41 //Default values for scale (1.0,1.0,1.0), orientation (Identity) and position (0.0,0.0,0.0)
42 static const float gDefaultTransformComponentAnimatableData[] = { 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f };
43
44 //Default values for anchor point (CENTER) and parent origin (TOP_LEFT)
45 static const float gDefaultTransformComponentStaticData[] = { 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, true };
46
47 static_assert( sizeof(gDefaultTransformComponentAnimatableData) == sizeof(TransformComponentAnimatable), "gDefaultTransformComponentAnimatableData should have the same number of floats as specified in TransformComponentAnimatable" );
48 static_assert( sizeof(gDefaultTransformComponentStaticData) == sizeof(TransformComponentStatic), "gDefaultTransformComponentStaticData should have the same number of floats as specified in TransformComponentStatic" );
49
50 /**
51  * @brief Calculates the center position for the transform component
52  * @param[out] centerPosition The calculated center-position of the transform component
53  * @param[in] transformComponentStatic A const reference to the static component transform struct
54  * @param[in] transformComponentAnimatable A const reference to the animatable component transform struct
55  * @param[in] size The size of the current transform component
56  * @param[in] half Halfway point of the transform
57  * @param[in] topLeft The top-left coords of the transform
58  */
59 inline void CalculateCenterPosition(
60   Vector3& centerPosition,
61   const TransformComponentStatic& transformComponentStatic,
62   const TransformComponentAnimatable& transformComponentAnimatable,
63   const Vector3& size,
64   const Vector3& half,
65   const Vector3& topLeft )
66 {
67   // Calculate the center-point by applying the scale and rotation on the anchor point.
68   centerPosition = ( half - transformComponentStatic.mAnchorPoint ) * size * transformComponentAnimatable.mScale;
69   centerPosition *= transformComponentAnimatable.mOrientation;
70
71   // If the position is ignoring the anchor-point, then remove the anchor-point shift from the position.
72   if( ! transformComponentStatic.mPositionUsesAnchorPoint )
73   {
74     centerPosition -= ( topLeft - transformComponentStatic.mAnchorPoint ) * size;
75   }
76 }
77
78 } // unnamed namespace
79
80 TransformManager::TransformManager()
81 :mComponentCount(0),
82  mReorder(false)
83 {}
84
85 TransformManager::~TransformManager()
86 {}
87
88 TransformId TransformManager::CreateTransform()
89 {
90   //Get id for the new component
91   TransformId id = mIds.Add(mComponentCount);
92
93   if( mTxComponentAnimatable.Size() <= mComponentCount )
94   {
95     //Make room for another component
96     mTxComponentAnimatable.PushBack(TransformComponentAnimatable());
97     mTxComponentStatic.PushBack(TransformComponentStatic());
98     mInheritanceMode.PushBack(INHERIT_ALL);
99     mComponentId.PushBack(id);
100     mSize.PushBack(Vector3(0.0f,0.0f,0.0f));
101     mParent.PushBack(INVALID_TRANSFORM_ID);
102     mWorld.PushBack(Matrix::IDENTITY);
103     mLocal.PushBack(Matrix::IDENTITY);
104     mBoundingSpheres.PushBack( Vector4(0.0f,0.0f,0.0f,0.0f) );
105     mTxComponentAnimatableBaseValue.PushBack(TransformComponentAnimatable());
106     mSizeBase.PushBack(Vector3(0.0f,0.0f,0.0f));
107     mComponentDirty.PushBack(false);
108     mLocalMatrixDirty.PushBack(false);
109     mComponentChanged.PushBack(false);
110     mPrevWorld.PushBack(Matrix::IDENTITY);
111     mUpdateSizeHint.PushBack(Vector3(0.0f,0.0f,0.0f));
112     mUpdateSizeHintBase.PushBack(Vector3(0.0f,0.0f,0.0f));
113   }
114   else
115   {
116     //Set default values
117     memcpy( &mTxComponentAnimatable[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
118     memcpy( &mTxComponentStatic[mComponentCount], &gDefaultTransformComponentStaticData, sizeof( TransformComponentStatic ) );
119     memcpy( &mTxComponentAnimatableBaseValue[mComponentCount], &gDefaultTransformComponentAnimatableData, sizeof( TransformComponentAnimatable ) );
120     mInheritanceMode[mComponentCount] = INHERIT_ALL;
121     mComponentId[mComponentCount] = id;
122     mSize[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
123     mParent[mComponentCount] = INVALID_TRANSFORM_ID;
124     mLocal[mComponentCount].SetIdentity();
125     mWorld[mComponentCount].SetIdentity();
126     mBoundingSpheres[mComponentCount] = Vector4(0.0f,0.0f,0.0f,0.0f);
127     mSizeBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
128     mComponentDirty[mComponentCount] = false;
129     mLocalMatrixDirty[mComponentCount] = false;
130     mComponentChanged[mComponentCount] = false;
131     mPrevWorld[mComponentCount].SetIdentity();
132     mUpdateSizeHint[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
133     mUpdateSizeHintBase[mComponentCount] = Vector3(0.0f,0.0f,0.0f);
134   }
135
136   mComponentCount++;
137   return id;
138 }
139
140 void TransformManager::RemoveTransform(TransformId id)
141 {
142   //Move the last element to the gap
143   mComponentCount--;
144   TransformId index = mIds[id];
145   mTxComponentAnimatable[index] = mTxComponentAnimatable[mComponentCount];
146   mTxComponentStatic[index] = mTxComponentStatic[mComponentCount];
147   mInheritanceMode[index] = mInheritanceMode[mComponentCount];
148   mSize[index] = mSize[mComponentCount];
149   mParent[index] = mParent[mComponentCount];
150   mWorld[index] = mWorld[mComponentCount];
151   mLocal[index] = mLocal[mComponentCount];
152   mTxComponentAnimatableBaseValue[index] = mTxComponentAnimatableBaseValue[mComponentCount];
153   mSizeBase[index] = mSizeBase[mComponentCount];
154   mComponentDirty[index] = mComponentDirty[mComponentCount];
155   mLocalMatrixDirty[index] = mLocalMatrixDirty[mComponentCount];
156   mBoundingSpheres[index] = mBoundingSpheres[mComponentCount];
157   mComponentChanged[index] = mComponentChanged[mComponentCount];
158   mPrevWorld[index] = mPrevWorld[mComponentCount];
159   mUpdateSizeHint[index] = mUpdateSizeHint[mComponentCount];
160   mUpdateSizeHintBase[index] = mUpdateSizeHintBase[mComponentCount];
161
162   TransformId lastItemId = mComponentId[mComponentCount];
163   mIds[ lastItemId ] = index;
164   mComponentId[index] = lastItemId;
165   mIds.Remove( id );
166
167   mReorder = true;
168 }
169
170 void TransformManager::SetParent( TransformId id, TransformId parentId )
171 {
172   DALI_ASSERT_ALWAYS( id != parentId );
173   TransformId index = mIds[id];
174   mParent[ index ] = parentId;
175   mComponentDirty[ index ] = true;
176   mReorder = true;
177 }
178
179 const Matrix& TransformManager::GetWorldMatrix( TransformId id ) const
180 {
181   return mWorld[ mIds[id] ];
182 }
183
184 Matrix& TransformManager::GetWorldMatrix( TransformId id )
185 {
186   return mWorld[ mIds[id] ];
187 }
188
189 void TransformManager::SetInheritPosition( TransformId id, bool inherit )
190 {
191   TransformId index = mIds[id];
192   if( inherit )
193   {
194     mInheritanceMode[ index ] |= INHERIT_POSITION;
195   }
196   else
197   {
198     mInheritanceMode[ index ] &= ~INHERIT_POSITION;
199   }
200
201   mComponentDirty[index] = true;
202 }
203
204 void TransformManager::SetInheritScale( TransformId id, bool inherit )
205 {
206   TransformId index = mIds[id];
207   if( inherit )
208   {
209     mInheritanceMode[ index ] |= INHERIT_SCALE;
210   }
211   else
212   {
213     mInheritanceMode[ index ] &= ~INHERIT_SCALE;
214   }
215
216   mComponentDirty[index] = true;
217 }
218
219 void TransformManager::SetInheritOrientation( TransformId id, bool inherit )
220 {
221   TransformId index = mIds[id];
222   if( inherit )
223   {
224     mInheritanceMode[ index ] |= INHERIT_ORIENTATION;
225   }
226   else
227   {
228     mInheritanceMode[ index ] &= ~INHERIT_ORIENTATION;
229   }
230   mComponentDirty[index] = true;
231 }
232
233 void TransformManager::ResetToBaseValue()
234 {
235   if( mComponentCount )
236   {
237     memcpy( &mTxComponentAnimatable[0], &mTxComponentAnimatableBaseValue[0], sizeof(TransformComponentAnimatable)*mComponentCount );
238     memcpy( &mSize[0], &mSizeBase[0], sizeof(Vector3)*mComponentCount );
239     memset( &mLocalMatrixDirty[0], false, sizeof(bool)*mComponentCount );
240     memcpy( &mUpdateSizeHint[0], &mUpdateSizeHintBase[0], sizeof(Vector3)*mComponentCount );
241   }
242 }
243
244 void TransformManager::Update()
245 {
246   if( mReorder )
247   {
248     //If some transform component has change its parent or has been removed since last update
249     //we need to reorder the vectors
250     ReorderComponents();
251     mReorder = false;
252   }
253
254   //Iterate through all components to compute its world matrix
255   Vector3 centerPosition;
256   Vector3 localPosition;
257   const Vector3 half( 0.5f,0.5f,0.5f );
258   const Vector3 topLeft( 0.0f, 0.0f, 0.5f );
259   for( unsigned int i(0); i<mComponentCount; ++i )
260   {
261     mPrevWorld[i] = mWorld[i];
262
263     if( DALI_LIKELY( mInheritanceMode[i] != DONT_INHERIT_TRANSFORM && mParent[i] != INVALID_TRANSFORM_ID ) )
264     {
265       const TransformId& parentIndex = mIds[mParent[i] ];
266       if( DALI_LIKELY( mInheritanceMode[i] == INHERIT_ALL ) )
267       {
268         if( mComponentDirty[i] || mLocalMatrixDirty[parentIndex])
269         {
270           //Full transform inherited
271           mLocalMatrixDirty[i] = true;
272           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
273           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
274           mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
275         }
276
277         //Update the world matrix
278         Matrix::Multiply( mWorld[i], mLocal[i], mWorld[parentIndex]);
279       }
280       else
281       {
282         //Some components are not inherited
283         Vector3 parentPosition, parentScale;
284         Quaternion parentOrientation;
285         const Matrix& parentMatrix = mWorld[parentIndex];
286         parentMatrix.GetTransformComponents( parentPosition, parentOrientation, parentScale );
287
288         Vector3 localScale = mTxComponentAnimatable[i].mScale;
289         if( (mInheritanceMode[i] & INHERIT_SCALE) == 0 )
290         {
291           //Don't inherit scale
292           localScale /= parentScale;
293         }
294
295         Quaternion localOrientation( mTxComponentAnimatable[i].mOrientation );
296         if( (mInheritanceMode[i] & INHERIT_ORIENTATION) == 0 )
297         {
298           //Don't inherit orientation
299           parentOrientation.Invert();
300           localOrientation = parentOrientation * mTxComponentAnimatable[i].mOrientation;
301         }
302
303         if( (mInheritanceMode[i] & INHERIT_POSITION) == 0 )
304         {
305           //Don't inherit position
306           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
307           mLocal[i].SetTransformComponents( localScale, localOrientation, Vector3::ZERO );
308           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
309           mWorld[i].SetTranslation( mTxComponentAnimatable[i].mPosition + centerPosition );
310         }
311         else
312         {
313           CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
314           localPosition = mTxComponentAnimatable[i].mPosition + centerPosition + ( mTxComponentStatic[i].mParentOrigin - half ) *  mSize[parentIndex];
315           mLocal[i].SetTransformComponents( localScale, localOrientation, localPosition );
316           Matrix::Multiply( mWorld[i], mLocal[i], parentMatrix );
317         }
318
319         mLocalMatrixDirty[i] = true;
320       }
321     }
322     else  //Component has no parent or doesn't inherit transform
323     {
324       CalculateCenterPosition( centerPosition, mTxComponentStatic[ i ], mTxComponentAnimatable[ i ], mSize[ i ], half, topLeft );
325       localPosition = mTxComponentAnimatable[i].mPosition + centerPosition;
326       mLocal[i].SetTransformComponents( mTxComponentAnimatable[i].mScale, mTxComponentAnimatable[i].mOrientation, localPosition );
327       mWorld[i] = mLocal[i];
328       mLocalMatrixDirty[i] = true;
329     }
330
331     //Update the bounding sphere
332     Vec3 centerToEdge = { mSize[i].Length() * 0.5f, 0.0f, 0.0f };
333     Vec3 centerToEdgeWorldSpace;
334     TransformVector3( centerToEdgeWorldSpace, mWorld[i].AsFloat(), centerToEdge );
335
336     mBoundingSpheres[i] = mWorld[i].GetTranslation();
337     mBoundingSpheres[i].w = Length( centerToEdgeWorldSpace );
338
339     mComponentChanged[i] = false;
340
341     // Due to parent transformation child transformation could be changed
342     if( mComponentDirty[i] ||
343         mPrevWorld[i] != mWorld[i] )
344     {
345       mComponentChanged[i] = true;
346     }
347
348     mComponentDirty[i] = false;
349
350   }
351 }
352
353 void TransformManager::SwapComponents( unsigned int i, unsigned int j )
354 {
355   std::swap( mTxComponentAnimatable[i], mTxComponentAnimatable[j] );
356   std::swap( mTxComponentStatic[i], mTxComponentStatic[j] );
357   std::swap( mInheritanceMode[i], mInheritanceMode[j] );
358   std::swap( mSize[i], mSize[j] );
359   std::swap( mParent[i], mParent[j] );
360   std::swap( mComponentId[i], mComponentId[j] );
361   std::swap( mTxComponentAnimatableBaseValue[i], mTxComponentAnimatableBaseValue[j] );
362   std::swap( mSizeBase[i], mSizeBase[j] );
363   std::swap( mLocal[i], mLocal[j] );
364   std::swap( mComponentDirty[i], mComponentDirty[j] );
365   std::swap( mBoundingSpheres[i], mBoundingSpheres[j] );
366   std::swap( mWorld[i], mWorld[j] );
367   std::swap( mComponentChanged[i], mComponentChanged[j] );
368   std::swap( mPrevWorld[i], mPrevWorld[j] );
369   std::swap( mUpdateSizeHint[i], mUpdateSizeHint[j] );
370   std::swap( mUpdateSizeHintBase[i], mUpdateSizeHintBase[j] );
371
372   mIds[ mComponentId[i] ] = i;
373   mIds[ mComponentId[j] ] = j;
374 }
375
376 void TransformManager::ReorderComponents()
377 {
378   mOrderedComponents.Resize(mComponentCount);
379
380   TransformId parentId;
381   for( TransformId i = 0; i<mComponentCount; ++i )
382   {
383     mOrderedComponents[i].id = mComponentId[i];
384     mOrderedComponents[i].level = 0u;
385
386     parentId = mParent[i];
387     while( parentId != INVALID_TRANSFORM_ID )
388     {
389       mOrderedComponents[i].level++;
390       parentId = mParent[ mIds[parentId] ];
391     }
392   }
393
394   std::stable_sort( mOrderedComponents.Begin(), mOrderedComponents.End());
395   TransformId previousIndex = 0;
396   for( TransformId newIndex = 0; newIndex < mComponentCount-1; ++newIndex )
397   {
398     previousIndex = mIds[mOrderedComponents[newIndex].id];
399     if( previousIndex != newIndex )
400     {
401       SwapComponents( previousIndex, newIndex);
402     }
403   }
404 }
405
406 Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property )
407 {
408   switch( property )
409   {
410     case TRANSFORM_PROPERTY_POSITION:
411     {
412       TransformId index( mIds[id] );
413       mComponentDirty[ index ] = true;
414       return mTxComponentAnimatable[ index ].mPosition;
415     }
416     case TRANSFORM_PROPERTY_SCALE:
417     {
418       TransformId index( mIds[id] );
419       mComponentDirty[ index ] = true;
420       return mTxComponentAnimatable[ index ].mScale;
421     }
422     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
423     {
424       TransformId index( mIds[id] );
425       mComponentDirty[ index ] = true;
426       return mTxComponentStatic[ index ].mParentOrigin;
427     }
428     case TRANSFORM_PROPERTY_ANCHOR_POINT:
429     {
430       TransformId index( mIds[id] );
431       mComponentDirty[ index ] = true;
432       return mTxComponentStatic[ index ].mAnchorPoint;
433     }
434     case TRANSFORM_PROPERTY_SIZE:
435     {
436       TransformId index( mIds[id] );
437       mComponentDirty[ index ] = true;
438       return mSize[ index ];
439     }
440     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
441     {
442       TransformId index( mIds[id] );
443       mComponentDirty[ index ] = true;
444       return mUpdateSizeHint[ index ];
445     }
446     default:
447     {
448       DALI_ASSERT_ALWAYS(false);
449       return mTxComponentAnimatable[ mIds[id] ].mPosition;
450     }
451   }
452 }
453
454 const Vector3& TransformManager::GetVector3PropertyValue( TransformId id, TransformManagerProperty property ) const
455 {
456   switch( property )
457   {
458     case TRANSFORM_PROPERTY_POSITION:
459     {
460       return mTxComponentAnimatable[ mIds[id] ].mPosition;
461     }
462     case TRANSFORM_PROPERTY_SCALE:
463     {
464       return mTxComponentAnimatable[ mIds[id] ].mScale;
465     }
466     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
467     {
468       return mTxComponentStatic[ mIds[id] ].mParentOrigin;
469     }
470     case TRANSFORM_PROPERTY_ANCHOR_POINT:
471     {
472       return mTxComponentStatic[ mIds[id] ].mAnchorPoint;
473     }
474     case TRANSFORM_PROPERTY_SIZE:
475     {
476       return mSize[ mIds[id] ];
477     }
478     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
479     {
480       return mUpdateSizeHint[ mIds[id] ];
481     }
482     default:
483     {
484       DALI_ASSERT_ALWAYS(false);
485       return mTxComponentAnimatable[ mIds[id] ].mPosition;
486     }
487   }
488 }
489
490 const float& TransformManager::GetVector3PropertyComponentValue(TransformId id, TransformManagerProperty property, unsigned int component ) const
491 {
492   switch( property )
493   {
494     case TRANSFORM_PROPERTY_POSITION:
495     {
496       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
497     }
498     case TRANSFORM_PROPERTY_SCALE:
499     {
500       return mTxComponentAnimatable[ mIds[id] ].mScale[component];
501     }
502     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
503     {
504       return mTxComponentStatic[ mIds[id] ].mParentOrigin[component];
505     }
506     case TRANSFORM_PROPERTY_ANCHOR_POINT:
507     {
508       return mTxComponentStatic[ mIds[id] ].mAnchorPoint[component];
509     }
510     case TRANSFORM_PROPERTY_SIZE:
511     {
512       return mSize[ mIds[id] ][component];
513     }
514     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
515     {
516       return mUpdateSizeHint[ mIds[id] ][component];
517     }
518     default:
519     {
520       DALI_ASSERT_ALWAYS(false);
521       return mTxComponentAnimatable[ mIds[id] ].mPosition[component];
522     }
523   }
524 }
525
526 void TransformManager::SetVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
527 {
528   TransformId index( mIds[id] );
529   mComponentDirty[ index ] = true;
530
531   switch( property )
532   {
533     case TRANSFORM_PROPERTY_POSITION:
534     {
535       mTxComponentAnimatable[ index ].mPosition = value;
536       break;
537     }
538     case TRANSFORM_PROPERTY_SCALE:
539     {
540       mTxComponentAnimatable[ index ].mScale = value;
541       break;
542     }
543     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
544     {
545       mTxComponentStatic[ index ].mParentOrigin = value;
546       break;
547     }
548     case TRANSFORM_PROPERTY_ANCHOR_POINT:
549     {
550       mTxComponentStatic[ index ].mAnchorPoint = value;
551       break;
552     }
553     case TRANSFORM_PROPERTY_SIZE:
554     {
555       mSize[ index ] = value;
556       break;
557     }
558     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
559     {
560       mUpdateSizeHint[ index ] = value;
561       break;
562     }
563     default:
564     {
565       DALI_ASSERT_ALWAYS(false);
566     }
567   }
568 }
569
570 void TransformManager::SetVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
571 {
572   TransformId index( mIds[id] );
573   mComponentDirty[ index ] = true;
574
575   switch( property )
576   {
577     case TRANSFORM_PROPERTY_POSITION:
578     {
579       mTxComponentAnimatable[ index ].mPosition[component] = value;
580       break;
581     }
582     case TRANSFORM_PROPERTY_SCALE:
583     {
584       mTxComponentAnimatable[ index ].mScale[component] = value;
585       break;
586     }
587     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
588     {
589       mTxComponentStatic[ index ].mParentOrigin[component] = value;
590       break;
591     }
592     case TRANSFORM_PROPERTY_ANCHOR_POINT:
593     {
594       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
595       break;
596     }
597     case TRANSFORM_PROPERTY_SIZE:
598     {
599       mSize[ index ][component] = value;
600       break;
601     }
602     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
603     {
604       mUpdateSizeHint[ index ][component] = value;
605       break;
606     }
607     default:
608     {
609       DALI_ASSERT_ALWAYS(false);
610     }
611   }
612 }
613
614 void TransformManager::BakeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
615 {
616   TransformId index( mIds[id] );
617   mComponentDirty[ index ] = true;
618
619   switch( property )
620   {
621     case TRANSFORM_PROPERTY_POSITION:
622     {
623       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = value;
624       break;
625     }
626     case TRANSFORM_PROPERTY_SCALE:
627     {
628       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = value;
629       break;
630     }
631     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
632     {
633       mTxComponentStatic[ index ].mParentOrigin = value;
634       break;
635     }
636     case TRANSFORM_PROPERTY_ANCHOR_POINT:
637     {
638       mTxComponentStatic[ index ].mAnchorPoint = value;
639       break;
640     }
641     case TRANSFORM_PROPERTY_SIZE:
642     {
643       mSize[ index ] = mSizeBase[index] = value;
644       break;
645     }
646     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
647     {
648       mUpdateSizeHint[ index ] = mUpdateSizeHintBase[index] = value;
649       break;
650     }
651     default:
652     {
653       DALI_ASSERT_ALWAYS(false);
654     }
655   }
656 }
657
658 void TransformManager::BakeRelativeVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
659 {
660   TransformId index( mIds[id] );
661   mComponentDirty[ index ] = true;
662
663   switch( property )
664   {
665     case TRANSFORM_PROPERTY_POSITION:
666     {
667       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = mTxComponentAnimatable[ index ].mPosition + value;
668       break;
669     }
670     case TRANSFORM_PROPERTY_SCALE:
671     {
672       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = mTxComponentAnimatable[ index ].mScale + value;
673       break;
674     }
675     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
676     {
677       mTxComponentStatic[ index ].mParentOrigin = mTxComponentStatic[ index ].mParentOrigin + value;
678       break;
679     }
680     case TRANSFORM_PROPERTY_ANCHOR_POINT:
681     {
682       mTxComponentStatic[ index ].mAnchorPoint = mTxComponentStatic[ index ].mAnchorPoint + value;
683       break;
684     }
685     case TRANSFORM_PROPERTY_SIZE:
686     {
687       mSize[ index ] = mSizeBase[index] = mSize[ index ] + value;
688       break;
689     }
690     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
691     {
692       mUpdateSizeHint[ index ] = mUpdateSizeHintBase[index] = mUpdateSizeHint[ index ] + value;
693       break;
694     }
695     default:
696     {
697       DALI_ASSERT_ALWAYS(false);
698     }
699   }
700 }
701
702 void TransformManager::BakeMultiplyVector3PropertyValue( TransformId id, TransformManagerProperty property, const Vector3& value )
703 {
704   TransformId index( mIds[id] );
705   mComponentDirty[ index ] = true;
706
707   switch( property )
708   {
709     case TRANSFORM_PROPERTY_POSITION:
710     {
711       mTxComponentAnimatable[ index ].mPosition = mTxComponentAnimatableBaseValue[index].mPosition = mTxComponentAnimatable[ index ].mPosition * value;
712       break;
713     }
714     case TRANSFORM_PROPERTY_SCALE:
715     {
716       mTxComponentAnimatable[ index ].mScale = mTxComponentAnimatableBaseValue[index].mScale = mTxComponentAnimatable[ index ].mScale * value;
717       break;
718     }
719     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
720     {
721       mTxComponentStatic[ index ].mParentOrigin = mTxComponentStatic[ index ].mParentOrigin * value;
722       break;
723     }
724     case TRANSFORM_PROPERTY_ANCHOR_POINT:
725     {
726       mTxComponentStatic[ index ].mAnchorPoint = mTxComponentStatic[ index ].mAnchorPoint * value;
727       break;
728     }
729     case TRANSFORM_PROPERTY_SIZE:
730     {
731       mSize[ index ] = mSizeBase[index] = mSize[ index ] * value;
732       break;
733     }
734     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
735     {
736       mUpdateSizeHint[ index ] = mUpdateSizeHintBase[index] = mUpdateSizeHint[ index ] * value;
737       break;
738     }
739     default:
740     {
741       DALI_ASSERT_ALWAYS(false);
742     }
743   }
744 }
745
746 void TransformManager::BakeVector3PropertyComponentValue( TransformId id, TransformManagerProperty property, float value, unsigned int component )
747 {
748   TransformId index( mIds[id] );
749   mComponentDirty[ index ] = true;
750
751   switch( property )
752   {
753     case TRANSFORM_PROPERTY_POSITION:
754     {
755       mTxComponentAnimatable[ index ].mPosition[component] = mTxComponentAnimatableBaseValue[index].mPosition[component] = value;
756       break;
757     }
758     case TRANSFORM_PROPERTY_SCALE:
759     {
760       mTxComponentAnimatable[ index ].mScale[component] = mTxComponentAnimatableBaseValue[index].mScale[component] = value;
761       break;
762     }
763     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
764     {
765       mTxComponentStatic[ index ].mParentOrigin[component] = value;
766       break;
767     }
768     case TRANSFORM_PROPERTY_ANCHOR_POINT:
769     {
770       mTxComponentStatic[ index ].mAnchorPoint[component] = value;
771       break;
772     }
773     case TRANSFORM_PROPERTY_SIZE:
774     {
775       mSize[ index ][component] = mSizeBase[index][component] = value;
776       break;
777     }
778     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
779     {
780       mUpdateSizeHint[ index ][component] = mUpdateSizeHintBase[index][component] = value;
781       break;
782     }
783     default:
784     {
785       DALI_ASSERT_ALWAYS(false);
786     }
787   }
788 }
789
790 void TransformManager::BakeXVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
791 {
792   TransformId index( mIds[id] );
793   mComponentDirty[ index ] = true;
794
795   switch( property )
796   {
797     case TRANSFORM_PROPERTY_POSITION:
798     {
799       mTxComponentAnimatable[ index ].mPosition.x = mTxComponentAnimatableBaseValue[index].mPosition.x = value;
800       break;
801     }
802     case TRANSFORM_PROPERTY_SCALE:
803     {
804       mTxComponentAnimatable[ index ].mScale.x = mTxComponentAnimatableBaseValue[index].mScale.x = value;
805       break;
806     }
807     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
808     {
809       mTxComponentStatic[ index ].mParentOrigin.x = value;
810       break;
811     }
812     case TRANSFORM_PROPERTY_ANCHOR_POINT:
813     {
814       mTxComponentStatic[ index ].mAnchorPoint.x = value;
815       break;
816     }
817     case TRANSFORM_PROPERTY_SIZE:
818     {
819       mSize[ index ].x = mSizeBase[index].x = value;
820       break;
821     }
822     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
823     {
824       mUpdateSizeHint[ index ].x = mUpdateSizeHintBase[index].x = value;
825       break;
826     }
827     default:
828     {
829       DALI_ASSERT_ALWAYS(false);
830     }
831   }
832 }
833
834 void TransformManager::BakeYVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
835 {
836   TransformId index( mIds[id] );
837   mComponentDirty[ index ] = true;
838
839   switch( property )
840   {
841     case TRANSFORM_PROPERTY_POSITION:
842     {
843       mTxComponentAnimatable[ index ].mPosition.y = mTxComponentAnimatableBaseValue[index].mPosition.y = value;
844       break;
845     }
846     case TRANSFORM_PROPERTY_SCALE:
847     {
848       mTxComponentAnimatable[ index ].mScale.y = mTxComponentAnimatableBaseValue[index].mScale.y = value;
849       break;
850     }
851     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
852     {
853       mTxComponentStatic[ index ].mParentOrigin.y = value;
854       break;
855     }
856     case TRANSFORM_PROPERTY_ANCHOR_POINT:
857     {
858       mTxComponentStatic[ index ].mAnchorPoint.y = value;
859       break;
860     }
861     case TRANSFORM_PROPERTY_SIZE:
862     {
863       mSize[ index ].y = mSizeBase[index].y = value;
864       break;
865     }
866     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
867     {
868       mUpdateSizeHint[ index ].y = mUpdateSizeHintBase[index].y = value;
869       break;
870     }
871     default:
872     {
873       DALI_ASSERT_ALWAYS(false);
874     }
875   }
876 }
877
878 void TransformManager::BakeZVector3PropertyValue( TransformId id, TransformManagerProperty property, float value )
879 {
880   TransformId index( mIds[id] );
881   mComponentDirty[ index ] = true;
882
883   switch( property )
884   {
885     case TRANSFORM_PROPERTY_POSITION:
886     {
887       mTxComponentAnimatable[ index ].mPosition.z = mTxComponentAnimatableBaseValue[index].mPosition.z = value;
888       break;
889     }
890     case TRANSFORM_PROPERTY_SCALE:
891     {
892       mTxComponentAnimatable[ index ].mScale.z = mTxComponentAnimatableBaseValue[index].mScale.z = value;
893       break;
894     }
895     case TRANSFORM_PROPERTY_PARENT_ORIGIN:
896     {
897       mTxComponentStatic[ index ].mParentOrigin.z = value;
898       break;
899     }
900     case TRANSFORM_PROPERTY_ANCHOR_POINT:
901     {
902       mTxComponentStatic[ index ].mAnchorPoint.z = value;
903       break;
904     }
905     case TRANSFORM_PROPERTY_SIZE:
906     {
907       mSize[ index ].z = mSizeBase[index].z = value;
908       break;
909     }
910     case TRANSFORM_PROPERTY_UPDATE_SIZE_HINT:
911     {
912       mUpdateSizeHint[ index ].z = mUpdateSizeHintBase[index].z = value;
913       break;
914     }
915     default:
916     {
917       DALI_ASSERT_ALWAYS(false);
918     }
919   }
920 }
921
922 Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id )
923 {
924   TransformId index( mIds[id] );
925   mComponentDirty[ index ] = true;
926   return mTxComponentAnimatable[ index ].mOrientation;
927 }
928
929 const Quaternion& TransformManager::GetQuaternionPropertyValue( TransformId id ) const
930 {
931   return mTxComponentAnimatable[ mIds[id] ].mOrientation;
932 }
933
934 void TransformManager::SetQuaternionPropertyValue( TransformId id, const Quaternion& q )
935 {
936   TransformId index( mIds[id] );
937   mTxComponentAnimatable[ index ].mOrientation = q;
938   mComponentDirty[ index ] = true;
939 }
940
941 void TransformManager::BakeQuaternionPropertyValue( TransformId id, const Quaternion& q )
942 {
943   TransformId index( mIds[id] );
944   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = q;
945   mComponentDirty[ index ] = true;
946 }
947
948 void TransformManager::BakeRelativeQuaternionPropertyValue( TransformId id, const Quaternion& q )
949 {
950   TransformId index( mIds[id] );
951   mTxComponentAnimatable[ index ].mOrientation = mTxComponentAnimatableBaseValue[index].mOrientation = mTxComponentAnimatable[ index ].mOrientation * q;
952   mComponentDirty[ index ] = true;
953 }
954
955 const Vector4& TransformManager::GetBoundingSphere( TransformId id ) const
956 {
957   return mBoundingSpheres[ mIds[id] ];
958 }
959
960 bool TransformManager::IsComponentChanged( TransformId id )
961 {
962   return mComponentChanged[ mIds[id]];
963 }
964
965 void TransformManager::GetWorldMatrixAndSize( TransformId id, Matrix& worldMatrix, Vector3& size ) const
966 {
967   TransformId index = mIds[id];
968   worldMatrix = mWorld[index];
969   size = mSize[index];
970 }
971
972 const Vector3& TransformManager::GetUpdateSizeHint( TransformId id ) const
973 {
974   return mUpdateSizeHint[ mIds[id] ];
975 }
976
977 void TransformManager::SetPositionUsesAnchorPoint( TransformId id, bool value )
978 {
979   TransformId index( mIds[ id ] );
980   mComponentDirty[ index ] = true;
981   mTxComponentStatic[ index ].mPositionUsesAnchorPoint = value;
982 }
983
984 } //namespace SceneGraph
985 } //namespace Internal
986 } //namespace Dali