Actor's Transformation API Cleanup
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_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 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/actors/draw-mode.h>
24 #include <dali/public-api/common/set-wrapper.h>
25 #include <dali/public-api/math/quaternion.h>
26 #include <dali/public-api/math/math-utils.h>
27 #include <dali/public-api/math/vector3.h>
28 #include <dali/internal/common/message.h>
29 #include <dali/internal/common/event-to-update.h>
30 #include <dali/internal/update/common/animatable-property.h>
31 #include <dali/internal/update/common/property-owner.h>
32 #include <dali/internal/update/common/property-vector3.h>
33 #include <dali/internal/update/common/scene-graph-buffers.h>
34 #include <dali/internal/update/common/inherited-property.h>
35 #include <dali/integration-api/debug.h>
36 #include <dali/internal/update/nodes/node-declarations.h>
37 #include <dali/internal/update/node-attachments/node-attachment-declarations.h>
38 #include <dali/internal/render/renderers/render-data-provider.h>
39
40 namespace Dali
41 {
42
43 namespace Internal
44 {
45
46 // value types used by messages
47 template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {};
48 template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {};
49 template <> struct ParameterType< SizeMode > : public BasicType< SizeMode > {};
50
51 namespace SceneGraph
52 {
53
54 class DiscardQueue;
55 class Layer;
56 class NodeAttachment;
57 class RenderTask;
58 class UpdateManager;
59
60 /**
61  * Flag whether property has changed, during the Update phase.
62  */
63 enum NodePropertyFlags
64 {
65   NothingFlag          = 0x000,
66   TransformFlag        = 0x001,
67   VisibleFlag          = 0x002,
68   ColorFlag            = 0x004,
69   SizeFlag             = 0x008,
70   OverlayFlag          = 0x010,
71   SortModifierFlag     = 0x020,
72   ChildDeletedFlag     = 0x040
73 };
74
75 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
76
77 /**
78  * Size is not inherited.
79  * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
80  */
81 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
82
83 // Flags which require the scene renderable lists to be updated
84 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
85
86 /**
87  * Node is the base class for all nodes in the Scene Graph.
88  * Each node provides a transformation which applies to the node and its children.
89  * Node data is double-buffered. This allows an update thread to modify node data, without interferring
90  * with another thread reading the values from the previous update traversal.
91  */
92 class Node : public PropertyOwner, public RenderDataProvider
93 {
94 public:
95
96   // Defaults
97   static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
98   static const ColorMode DEFAULT_COLOR_MODE;
99   static const SizeMode DEFAULT_SIZE_MODE;
100
101   // Creation methods
102
103   /**
104    * Construct a new Node.
105    */
106   static Node* New();
107
108   /**
109    * Virtual destructor
110    */
111   virtual ~Node();
112
113   /**
114    * When a Node is marked "active" it has been disconnected, but its properties have been modified.
115    * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage.
116    * @param[in] isActive True if the Node is active.
117    */
118   void SetActive( bool isActive )
119   {
120     mIsActive = isActive;
121   }
122
123   /**
124    * Query whether the Node is active.
125    * @return True if the Node is active.
126    */
127   bool IsActive() const
128   {
129     return mIsActive;
130   }
131
132   /**
133    * Called during UpdateManager::DestroyNode shortly before Node is destroyed.
134    */
135   void OnDestroy();
136
137   // Layer interface
138
139   /**
140    * Query whether the node is a layer.
141    * @return True if the node is a layer.
142    */
143   bool IsLayer()
144   {
145     return (GetLayer() != NULL);
146   }
147
148   /**
149    * Convert a node to a layer.
150    * @return A pointer to the layer, or NULL.
151    */
152   virtual Layer* GetLayer()
153   {
154     return NULL;
155   }
156
157   // Attachments
158
159   /**
160    * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
161    * @pre The Node does not already have an attachment.
162    * @param[in] attachment The object to attach.
163    */
164   void Attach( NodeAttachment& attachment );
165
166   /**
167    * Query the node if it has an attachment.
168    * @return True if it has an attachment.
169    */
170   bool HasAttachment() const
171   {
172     return mAttachment;
173   }
174
175   /**
176    * Retreive the object attached to this node.
177    * @return The attachment.
178    */
179   NodeAttachment& GetAttachment() const
180   {
181     return *mAttachment;
182   }
183
184   // Containment methods
185
186   /**
187    * Query whether a node is the root node. Root nodes cannot have a parent node.
188    * A node becomes a root node, when it is installed by UpdateManager.
189    * @return True if the node is a root node.
190    */
191   bool IsRoot() const
192   {
193     return mIsRoot;
194   }
195
196   /**
197    * Set whether a node is the root node. Root nodes cannot have a parent node.
198    * This method should only be called by UpdateManager.
199    * @pre When isRoot is true, the node must not have a parent.
200    * @param[in] isRoot Whether the node is now a root node.
201    */
202   void SetRoot(bool isRoot);
203
204   /**
205    * Retrieve the parent of a Node.
206    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
207    */
208   Node* GetParent()
209   {
210     return mParent;
211   }
212
213   /**
214    * Retrieve the parent of a Node.
215    * @return The parent node, or NULL if the Node has not been added to the scene-graph.
216    */
217   const Node* GetParent() const
218   {
219     return mParent;
220   }
221
222   /**
223    * Connect a node to the scene-graph.
224    * @pre A node cannot be added to itself.
225    * @pre The parent node is connected to the scene-graph.
226    * @pre The childNode does not already have a parent.
227    * @pre The childNode is not a root node.
228    * @param[in] childNode The child to add.
229    * @param[in] index to insert at, if not supplied or -1 it will be appended
230    *
231    */
232   void ConnectChild( Node* childNode, int index = -1);
233
234   /**
235    * Disconnect a child (& its children) from the scene-graph.
236    * @pre childNode is a child of this Node.
237    * @param[in] updateBufferIndex The current update buffer index.
238    * @param[in] childNode The node to disconnect.
239    * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
240    * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
241    */
242   void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes,  std::set<Node*>& disconnectedNodes );
243
244   /**
245    * Retrieve the children a Node.
246    * @return The container of children.
247    */
248   const NodeContainer& GetChildren() const
249   {
250     return mChildren;
251   }
252
253   /**
254    * Retrieve the children a Node.
255    * @return The container of children.
256    */
257   NodeContainer& GetChildren()
258   {
259     return mChildren;
260   }
261
262   // Update methods
263
264   /**
265    * Flag that one of the node values has changed in the current frame.
266    * @param[in] flag The flag to set.
267    */
268   void SetDirtyFlag(NodePropertyFlags flag)
269   {
270     mDirtyFlags |= flag;
271   }
272
273   /**
274    * Flag that all of the node values are dirty.
275    */
276   void SetAllDirtyFlags()
277   {
278     mDirtyFlags = AllFlags;
279   }
280
281   /**
282    * Query whether a node is dirty.
283    * @return The dirty flags
284    */
285   int GetDirtyFlags() const;
286
287   /**
288    * Query whether a node is clean.
289    * @return True if the node is clean.
290    */
291   bool IsClean() const
292   {
293     return ( NothingFlag == GetDirtyFlags() );
294   }
295
296   /**
297    * Retrieve the parent-origin of the node.
298    * @return The parent-origin.
299    */
300   const Vector3& GetParentOrigin() const
301   {
302     return mParentOrigin.mValue;
303   }
304
305   /**
306    * Sets both the local & base parent-origins of the node.
307    * @param[in] origin The new local & base parent-origins.
308    */
309   void SetParentOrigin(const Vector3& origin)
310   {
311     mParentOrigin.mValue = origin;
312     mParentOrigin.OnSet();
313   }
314
315   /**
316    * Retrieve the anchor-point of the node.
317    * @return The anchor-point.
318    */
319   const Vector3& GetAnchorPoint() const
320   {
321     return mAnchorPoint.mValue;
322   }
323
324   /**
325    * Sets both the local & base anchor-points of the node.
326    * @param[in] anchor The new local & base anchor-points.
327    */
328   void SetAnchorPoint(const Vector3& anchor)
329   {
330     mAnchorPoint.mValue = anchor;
331     mAnchorPoint.OnSet();
332   }
333
334   /**
335    * Retrieve the local position of the node, relative to its parent.
336    * @param[in] bufferIndex The buffer to read from.
337    * @return The local position.
338    */
339   const Vector3& GetPosition(BufferIndex bufferIndex) const
340   {
341     return mPosition[bufferIndex];
342   }
343
344   /**
345    * Sets both the local & base positions of the node.
346    * @param[in] updateBufferIndex The current update buffer index.
347    * @param[in] position The new local & base position.
348    */
349   void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
350   {
351     mPosition.Bake( updateBufferIndex, position );
352   }
353
354   /**
355    * Sets the world of the node derived from the position of all its parents.
356    * @param[in] updateBufferIndex The current update buffer index.
357    * @param[in] position The world position.
358    */
359   void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
360   {
361     mWorldPosition.Set( updateBufferIndex, position );
362   }
363
364   /**
365    * Sets the position of the node derived from the position of all its parents.
366    * This method should only be called when the parent's world position is up-to-date.
367    * With a non-central anchor-point, the local orientation and scale affects the world position.
368    * Therefore the world orientation & scale must be updated before the world position.
369    * @pre The node has a parent.
370    * @param[in] updateBufferIndex The current update buffer index.
371    */
372   void InheritWorldPosition(BufferIndex updateBufferIndex)
373   {
374     DALI_ASSERT_DEBUG(mParent != NULL);
375
376     switch( mPositionInheritanceMode )
377     {
378       case INHERIT_PARENT_POSITION  : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
379       {
380         Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
381
382         finalPosition += mParentOrigin.mValue;
383         finalPosition *= mParent->GetSize(updateBufferIndex);
384         finalPosition += mPosition[updateBufferIndex];
385         finalPosition *= mParent->GetWorldScale(updateBufferIndex);
386         const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
387         if(!parentWorldOrientation.IsIdentity())
388         {
389           finalPosition *= parentWorldOrientation;
390         }
391
392         // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
393         // dont use operator== as that does a slower comparison (and involves function calls)
394         Vector3 localOffset(0.5f, 0.5f, 0.5f);    // AnchorPoint::CENTER
395         localOffset -= mAnchorPoint.mValue;
396
397         if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
398             ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
399             ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
400         {
401           localOffset *= mSize[updateBufferIndex];
402
403           Vector3 scale = mWorldScale[updateBufferIndex];
404           if(GetTransmitGeometryScaling())
405           {
406             // Remove geometry scaling to get back to actor scale
407             scale /= mGeometryScale;
408           }
409           // Also pick up sign of local scale
410           if (mScale[updateBufferIndex].x < 0.0f)
411           {
412             scale.x = -scale.x;
413           }
414           if (mScale[updateBufferIndex].y < 0.0f)
415           {
416             scale.y = -scale.y;
417           }
418           if (mScale[updateBufferIndex].z < 0.0f)
419           {
420             scale.z = -scale.z;
421           }
422
423           // If the anchor-point is not central, then position is affected by the local orientation & scale
424           localOffset *= scale;
425           const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
426           if(!localWorldOrientation.IsIdentity())
427           {
428             localOffset *= localWorldOrientation;
429           }
430           finalPosition += localOffset;
431         }
432
433         finalPosition += mParent->GetWorldPosition(updateBufferIndex);
434         mWorldPosition.Set( updateBufferIndex, finalPosition );
435         break;
436       }
437       case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
438       {
439         // copy parents position plus local transform
440         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
441         break;
442       }
443       case USE_PARENT_POSITION :
444       {
445         // copy parents position
446         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
447         break;
448       }
449       case DONT_INHERIT_POSITION :
450       {
451         // use local position as world position
452         mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
453         break;
454       }
455     }
456   }
457
458   /**
459    * Copies the previous inherited position, if this changed in the previous frame.
460    * This method should be called instead of InheritWorldPosition i.e. if the inherited position
461    * does not need to be recalculated in the current frame.
462    * @param[in] updateBufferIndex The current update buffer index.
463    */
464   void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
465   {
466     mWorldPosition.CopyPrevious( updateBufferIndex );
467   }
468
469   /**
470    * Retrieve the position of the node derived from the position of all its parents.
471    * @return The world position.
472    */
473   const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
474   {
475     return mWorldPosition[bufferIndex];
476   }
477
478   /**
479    * Set the position inheritance mode.
480    * @see Dali::Actor::PositionInheritanceMode
481    * @param[in] mode The new position inheritance mode.
482    */
483   void SetPositionInheritanceMode( PositionInheritanceMode mode )
484   {
485     mPositionInheritanceMode = mode;
486
487     SetDirtyFlag(TransformFlag);
488   }
489
490   /**
491    * @return The position inheritance mode.
492    */
493   PositionInheritanceMode GetPositionInheritanceMode() const
494   {
495     return mPositionInheritanceMode;
496   }
497
498   /**
499    * Retrieve the local orientation of the node, relative to its parent.
500    * @param[in] bufferIndex The buffer to read from.
501    * @return The local orientation.
502    */
503   const Quaternion& GetOrientation(BufferIndex bufferIndex) const
504   {
505     return mOrientation[bufferIndex];
506   }
507
508   /**
509    * Sets both the local & base orientations of the node.
510    * @param[in] updateBufferIndex The current update buffer index.
511    * @param[in] orientation The new local & base orientation.
512    */
513   void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
514   {
515     mOrientation.Bake( updateBufferIndex, orientation );
516   }
517
518   /**
519    * Sets the orientation of the node derived from the rotation of all its parents.
520    * @param[in] updateBufferIndex The current update buffer index.
521    * @param[in] orientation The world orientation.
522    */
523   void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
524   {
525     mWorldOrientation.Set( updateBufferIndex, orientation );
526   }
527
528   /**
529    * Sets the orientation of the node derived from the rotation of all its parents.
530    * This method should only be called when the parents world orientation is up-to-date.
531    * @pre The node has a parent.
532    * @param[in] updateBufferIndex The current update buffer index.
533    */
534   void InheritWorldOrientation( BufferIndex updateBufferIndex )
535   {
536     DALI_ASSERT_DEBUG(mParent != NULL);
537
538     const Quaternion& localOrientation = mOrientation[updateBufferIndex];
539
540     if(localOrientation.IsIdentity())
541     {
542       mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
543     }
544     else
545     {
546       Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
547       finalOrientation *= localOrientation;
548       mWorldOrientation.Set( updateBufferIndex, finalOrientation );
549     }
550   }
551
552   /**
553    * Copies the previous inherited orientation, if this changed in the previous frame.
554    * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
555    * does not need to be recalculated in the current frame.
556    * @param[in] updateBufferIndex The current update buffer index.
557    */
558   void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
559   {
560     mWorldOrientation.CopyPrevious( updateBufferIndex );
561   }
562
563   /**
564    * Retrieve the orientation of the node derived from the rotation of all its parents.
565    * @param[in] bufferIndex The buffer to read from.
566    * @return The world rotation.
567    */
568   const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
569   {
570     return mWorldOrientation[bufferIndex];
571   }
572
573   /**
574    * Set whether the Node inherits orientation.
575    * @param[in] inherit True if the parent orientation is inherited.
576    */
577   void SetInheritOrientation(bool inherit)
578   {
579     if (inherit != mInheritOrientation)
580     {
581       mInheritOrientation = inherit;
582
583       SetDirtyFlag(TransformFlag);
584     }
585   }
586
587   /**
588    * Query whether the node inherits orientation from its parent.
589    * @return True if the parent orientation is inherited.
590    */
591   bool IsOrientationInherited() const
592   {
593     return mInheritOrientation;
594   }
595
596   /**
597    * @brief Defines how a child actor's size is affected by its parent's size.
598    * @param[in] mode The size relative to parent mode to use.
599    */
600   void SetSizeMode( SizeMode mode )
601   {
602     if ( mode != mSizeMode )
603     {
604       mSizeMode = mode;
605
606       SetDirtyFlag( TransformFlag );
607     }
608   }
609
610   /**
611    * Query how the child actor's size is affected by its parent's size.
612    * @return The size relative to parent mode in use.
613    */
614   SizeMode GetSizeMode() const
615   {
616     return mSizeMode;
617   }
618
619   /**
620    * Sets the factor of the parents size used for the child actor.
621    * Note: Only used for certain SizeModes.
622    * @param[in] factor The vector to multiply the parents size by to get the childs size.
623    */
624   void SetSizeModeFactor( const Vector3& factor )
625   {
626     mSizeModeFactor = factor;
627
628     SetDirtyFlag( TransformFlag );
629   }
630
631   /**
632    * Gets the factor of the parents size used for the child actor.
633    * Note: Only used for certain SizeModes.
634    * @return The vector being used to multiply the parents size by to get the childs size.
635    */
636   const Vector3& GetSizeModeFactor() const
637   {
638     return mSizeModeFactor;
639   }
640
641   /**
642    * Set the initial volume of the node. Used for calculating geometry scaling
643    * as the node size is changed  when transmitGeometryScaling is set to true.
644    *
645    * This property is not animatable.
646    *
647    * @param[in] volume The initial volume of this nodes meshes & children
648    */
649   void SetInitialVolume( const Vector3& volume )
650   {
651     mInitialVolume = volume;
652     SetDirtyFlag(SizeFlag);
653   }
654
655   /**
656    * Get the initial volume.  Used for calculating geometry scaling
657    * when TransmitGeometryScaling is true (i.e., the scaling is baked
658    * into the node tranform)
659    *
660    * @return The initial volume of this node and children.
661    */
662   Vector3 GetInitialVolume()
663   {
664     return mInitialVolume;
665   }
666
667   /**
668    * Sets whether the geometry scaling should be applied to the node
669    * (In which case, set the initial scale using SetInitialVolume()).
670    *
671    * If it is applied to the node, then the attachments are not scaled,
672    * as the scaling is then already baked into the node transform.
673    *
674    * @param[in] transmitGeometryScaling true if scaling is to be applied
675    * to the node.
676    */
677   void SetTransmitGeometryScaling(bool transmitGeometryScaling)
678   {
679     mTransmitGeometryScaling = transmitGeometryScaling;
680     SetDirtyFlag(SizeFlag);
681   }
682
683   /**
684    * Find out whether the node allows geometry scaling to be transmitted to its children.
685    * @return true if transmitted.
686    */
687   bool GetTransmitGeometryScaling() const
688   {
689     return mTransmitGeometryScaling;
690   }
691
692   /**
693    * Retrieve the local scale of the node, relative to its parent.
694    * @param[in] bufferIndex The buffer to read from.
695    * @return The local scale.
696    */
697   const Vector3& GetScale(BufferIndex bufferIndex) const
698   {
699     return mScale[bufferIndex];
700   }
701
702   /**
703    * Sets the scale of the node derived from the scale of all its parents and a pre-scale
704    * @param[in] updateBufferIndex The current update buffer index.
705    * @param[in] scale The world scale.
706    */
707   void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
708   {
709     mWorldScale.Set( updateBufferIndex, mGeometryScale * scale );
710   }
711
712   /**
713    * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
714    * This method should only be called when the parents world scale is up-to-date.
715    * @pre The node has a parent.
716    * @param[in] updateBufferIndex The current update buffer index.
717    */
718   void InheritWorldScale(BufferIndex updateBufferIndex)
719   {
720     DALI_ASSERT_DEBUG(mParent != NULL);
721
722     mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mGeometryScale * mScale[updateBufferIndex] );
723   }
724
725   /**
726    * Copies the previous inherited scale, if this changed in the previous frame.
727    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
728    * does not need to be recalculated in the current frame.
729    * @param[in] updateBufferIndex The current update buffer index.
730    */
731   void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
732   {
733     mWorldScale.CopyPrevious( updateBufferIndex );
734   }
735
736   /**
737    * Retrieve the scale of the node derived from the scale of all its parents.
738    * @param[in] bufferIndex The buffer to read from.
739    * @return The world scale.
740    */
741   const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
742   {
743     return mWorldScale[bufferIndex];
744   }
745
746   /**
747    * Set whether the Node inherits scale.
748    * @param inherit True if the Node inherits scale.
749    */
750   void SetInheritScale( bool inherit )
751   {
752     if( inherit != mInheritScale )
753     {
754       mInheritScale = inherit;
755
756       SetDirtyFlag( TransformFlag );
757     }
758   }
759
760   /**
761    * Query whether the Node inherits scale.
762    * @return if scale is inherited
763    */
764   bool IsScaleInherited() const
765   {
766     return mInheritScale;
767   }
768
769   /**
770    * Sets a geometry scale, calculated when TransmitGeometryScaling is true.
771    * Must only be used from render thread.
772    * @param[in] geometryScale The geometry scale value
773    */
774   void SetGeometryScale(Vector3 geometryScale)
775   {
776     mGeometryScale = geometryScale;
777
778     SetDirtyFlag( TransformFlag );
779   }
780
781   /**
782    * Retrieve the geometry scale, calculated when TransmitGeometryScaling is true.
783    * @return The geometry scale value.
784    */
785   const Vector3& GetGeometryScale() const
786   {
787     return mGeometryScale;
788   }
789
790   /**
791    * Copies the previously used size, if this changed in the previous frame.
792    * @param[in] updateBufferIndex The current update buffer index.
793    */
794   void CopyPreviousSize( BufferIndex updateBufferIndex )
795   {
796     SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) );
797   }
798
799   /**
800    * Retrieve the visibility of the node.
801    * @param[in] bufferIndex The buffer to read from.
802    * @return True if the node is visible.
803    */
804   bool IsVisible(BufferIndex bufferIndex) const
805   {
806     return mVisible[bufferIndex];
807   }
808
809   /**
810    * Retrieves whether a node is fully visible.
811    * A node is fully visible if is visible and all its ancestors are visible.
812    * @param[in] updateBufferIndex The current update buffer index.
813    * @return True if the node is fully visible.
814    */
815   bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
816
817   /**
818    * Retrieve the opacity of the node.
819    * @param[in] bufferIndex The buffer to read from.
820    * @return The opacity.
821    */
822   float GetOpacity(BufferIndex bufferIndex) const
823   {
824     return mColor[bufferIndex].a;
825   }
826
827   /**
828    * Retrieve the color of the node.
829    * @param[in] bufferIndex The buffer to read from.
830    * @return The color.
831    */
832   const Vector4& GetColor(BufferIndex bufferIndex) const
833   {
834     return mColor[bufferIndex];
835   }
836
837   /**
838    * Sets the color of the node derived from the color of all its parents.
839    * @param[in] color The world color.
840    * @param[in] updateBufferIndex The current update buffer index.
841    */
842   void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
843   {
844     mWorldColor.Set( updateBufferIndex, color );
845   }
846
847   /**
848    * Sets the color of the node derived from the color of all its parents.
849    * This method should only be called when the parents world color is up-to-date.
850    * @pre The node has a parent.
851    * @param[in] updateBufferIndex The current update buffer index.
852    */
853   void InheritWorldColor( BufferIndex updateBufferIndex )
854   {
855     DALI_ASSERT_DEBUG(mParent != NULL);
856
857     // default first
858     if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
859     {
860       const Vector4& ownColor = mColor[updateBufferIndex];
861       mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
862     }
863     else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
864     {
865       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
866     }
867     else if( mColorMode == USE_PARENT_COLOR )
868     {
869       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
870     }
871     else // USE_OWN_COLOR
872     {
873       mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
874     }
875   }
876
877   /**
878    * Copies the previous inherited scale, if this changed in the previous frame.
879    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
880    * does not need to be recalculated in the current frame.
881    * @param[in] updateBufferIndex The current update buffer index.
882    */
883   void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
884   {
885     mWorldColor.CopyPrevious( updateBufferIndex );
886   }
887
888   /**
889    * Retrieve the color of the node, possibly derived from the color
890    * of all its parents, depending on the value of mColorMode.
891    * @param[in] bufferIndex The buffer to read from.
892    * @return The world color.
893    */
894   const Vector4& GetWorldColor(BufferIndex bufferIndex) const
895   {
896     return mWorldColor[bufferIndex];
897   }
898
899   /**
900    * Set the color mode. This specifies whether the Node uses its own color,
901    * or inherits its parent color.
902    * @param[in] colorMode The new color mode.
903    */
904   void SetColorMode(ColorMode colorMode)
905   {
906     mColorMode = colorMode;
907
908     SetDirtyFlag(ColorFlag);
909   }
910
911   /**
912    * Retrieve the color mode.
913    * @return The color mode.
914    */
915   ColorMode GetColorMode() const
916   {
917     return mColorMode;
918   }
919
920   /**
921    * Sets the size of the node.
922    * @param[in] bufferIndex The buffer to write to.
923    * @param[in] size The size to write.
924    */
925   void SetSize( BufferIndex bufferIndex, const Vector3& size )
926   {
927     mSize[bufferIndex] = size;
928   }
929
930   /**
931    * Retrieve the size of the node.
932    * @param[in] bufferIndex The buffer to read from.
933    * @return The size.
934    */
935   const Vector3& GetSize(BufferIndex bufferIndex) const
936   {
937     return mSize[bufferIndex];
938   }
939
940   /**
941    * Set the world-matrix of a node, with scale + rotation + translation.
942    * Scale and rotation are centered at the origin.
943    * Translation is applied independently of the scale or rotatation axis.
944    * @param[in] updateBufferIndex The current update buffer index.
945    * @param[in] scale The scale.
946    * @param[in] rotation The rotation.
947    * @param[in] translation The translation.
948    */
949   void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
950   {
951     mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
952     mWorldMatrix.SetDirty( updateBufferIndex );
953   }
954
955   /**
956    * Retrieve the cached world-matrix of a node.
957    * @param[in] bufferIndex The buffer to read from.
958    * @return The world-matrix.
959    */
960   const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
961   {
962     return mWorldMatrix[ bufferIndex ];
963   }
964
965   /**
966    * Copy previous frames world matrix
967    * @param[in] updateBufferIndex The current update buffer index.
968    */
969   void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
970   {
971     mWorldMatrix.CopyPrevious( updateBufferIndex );
972   }
973
974   /**
975    * Mark the node as exclusive to a single RenderTask.
976    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
977    */
978   void SetExclusiveRenderTask( RenderTask* renderTask )
979   {
980     mExclusiveRenderTask = renderTask;
981   }
982
983   /**
984    * Query whether the node is exclusive to a single RenderTask.
985    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
986    */
987   RenderTask* GetExclusiveRenderTask() const
988   {
989     return mExclusiveRenderTask;
990   }
991
992   /**
993    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
994    * @param[in] drawMode The new draw-mode to use.
995    */
996   void SetDrawMode( const DrawMode::Type& drawMode )
997   {
998     mDrawMode = drawMode;
999   }
1000
1001   /**
1002    * Returns whether node is an overlay or not.
1003    * @return True if node is an overlay, false otherwise.
1004    */
1005   DrawMode::Type GetDrawMode() const
1006   {
1007     return mDrawMode;
1008   }
1009
1010   /**
1011    * Equality operator, checks for identity, not values.
1012    *
1013    */
1014   bool operator==( const Node* rhs ) const
1015   {
1016     if ( this == rhs )
1017     {
1018       return true;
1019     }
1020     return false;
1021   }
1022
1023   /**
1024    * Set the inhibit local transform flag.@n
1025    * Setting this flag will stop the node's local transform (position, scale and orientation)
1026    * being applied on top of its parents transformation.
1027    * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
1028    */
1029   void SetInhibitLocalTransform( bool flag )
1030   {
1031     SetDirtyFlag( TransformFlag );
1032     mInhibitLocalTransform = flag;
1033   }
1034
1035   /**
1036    * Get the inhibit local transform flag.@n
1037    * See @ref SetInhibitLocalTransform
1038    * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
1039    */
1040   bool GetInhibitLocalTransform() const
1041   {
1042     return mInhibitLocalTransform;
1043   }
1044
1045 protected:
1046
1047   /**
1048    * Set the parent of a Node.
1049    * @param[in] parentNode the new parent.
1050    */
1051   void SetParent(Node& parentNode);
1052
1053   /**
1054    * Protected constructor; See also Node::New()
1055    */
1056   Node();
1057
1058 private: // from RenderDataProvider
1059
1060   /**
1061    * @copydoc RenderDataProvider::GetModelMatrix
1062    */
1063   virtual const Matrix& GetModelMatrix( unsigned int bufferId )
1064   {
1065     return GetWorldMatrix( bufferId );
1066   }
1067
1068   /**
1069    * @copydoc RenderDataProvider::GetRenderColor
1070    */
1071   virtual const Vector4& GetRenderColor( unsigned int bufferId )
1072   {
1073     return GetWorldColor( bufferId );
1074   }
1075
1076 private:
1077
1078   // Undefined
1079   Node(const Node&);
1080
1081   // Undefined
1082   Node& operator=(const Node& rhs);
1083
1084   /**
1085    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
1086    */
1087   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
1088
1089   /**
1090    * Recursive helper to disconnect a Node and its children.
1091    * Disconnected Nodes have no parent or children.
1092    * @param[in] updateBufferIndex The current update buffer index.
1093    * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
1094    * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
1095    */
1096   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
1097
1098 public: // Default properties
1099
1100   PropertyVector3                mParentOrigin;  ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
1101   PropertyVector3                mAnchorPoint;   ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
1102
1103   AnimatableProperty<Vector3>    mSize;          ///< Size is provided for layouting
1104   AnimatableProperty<Vector3>    mPosition;      ///< Local transform; distance between parent-origin & anchor-point
1105   AnimatableProperty<Quaternion> mOrientation;   ///< Local transform; rotation relative to parent node
1106   AnimatableProperty<Vector3>    mScale;         ///< Local transform; scale relative to parent node
1107   AnimatableProperty<bool>       mVisible;       ///< Visibility can be inherited from the Node hierachy
1108   AnimatableProperty<Vector4>    mColor;         ///< Color can be inherited from the Node hierarchy
1109
1110   // Inherited properties; read-only from public API
1111
1112   InheritedVector3    mWorldPosition;     ///< Full inherited position
1113   InheritedQuaternion mWorldOrientation;  ///< Full inherited orientation
1114   InheritedVector3    mWorldScale;        ///< Full inherited scale
1115   InheritedMatrix     mWorldMatrix;       ///< Full inherited world matrix
1116   InheritedColor      mWorldColor;        ///< Full inherited color
1117
1118 protected:
1119
1120   Node*               mParent;                       ///< Pointer to parent node (a child is owned by its parent)
1121   RenderTask*         mExclusiveRenderTask;          ///< Nodes can be marked as exclusive to a single RenderTask
1122
1123   NodeAttachmentOwner mAttachment;                   ///< Optional owned attachment
1124   NodeContainer       mChildren;                     ///< Container of children; not owned
1125
1126   Vector3             mGeometryScale;                ///< Applied before calculating world transform.
1127   Vector3             mInitialVolume;                ///< Initial volume... TODO - need a better name.
1128   Vector3             mSizeModeFactor;               ///< Factor of parent size. Used for certain SizeModes.
1129
1130   // flags, compressed to bitfield
1131   int  mDirtyFlags:10;                               ///< A composite set of flags for each of the Node properties
1132
1133   bool mIsRoot:1;                                    ///< True if the node cannot have a parent
1134   bool mInheritOrientation:1;                        ///< Whether the parent's orientation should be inherited.
1135   bool mInheritScale:1;                              ///< Whether the parent's scale should be inherited.
1136   bool mTransmitGeometryScaling:1;                   ///< Whether geometry scaling should be applied to world transform.
1137   bool mInhibitLocalTransform:1;                     ///< whether local transform should be applied.
1138   bool mIsActive:1;                                  ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1139
1140   DrawMode::Type          mDrawMode:2;               ///< How the Node and its children should be drawn
1141   PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1142   ColorMode               mColorMode:2;              ///< Determines whether mWorldColor is inherited, 2 bits is enough
1143   SizeMode                mSizeMode:2;               ///< Determines how the actors parent affects the actors size.
1144
1145   // Changes scope, should be at end of class
1146   DALI_LOG_OBJECT_STRING_DECLARATION;
1147 };
1148
1149 // Messages for Node
1150
1151 inline void SetInheritOrientationMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1152 {
1153   typedef MessageValue1< Node, bool > LocalType;
1154
1155   // Reserve some memory inside the message queue
1156   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1157
1158   // Construct message in the message queue memory; note that delete should not be called on the return value
1159   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1160 }
1161
1162 inline void SetSizeModeMessage( EventToUpdate& eventToUpdate, const Node& node, SizeMode mode )
1163 {
1164   typedef MessageValue1< Node, SizeMode > LocalType;
1165
1166   // Reserve some memory inside the message queue
1167   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1168
1169   // Construct message in the message queue memory; note that delete should not be called on the return value
1170   new (slot) LocalType( &node, &Node::SetSizeMode, mode );
1171 }
1172
1173 inline void SetSizeModeFactorMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& factor )
1174 {
1175   typedef MessageValue1< Node, Vector3 > LocalType;
1176
1177   // Reserve some memory inside the message queue
1178   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1179
1180   // Construct message in the message queue memory; note that delete should not be called on the return value
1181   new (slot) LocalType( &node, &Node::SetSizeModeFactor, factor );
1182 }
1183
1184 inline void SetInitialVolumeMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& initialVolume )
1185 {
1186   typedef MessageValue1< Node, Vector3 > LocalType;
1187
1188   // Reserve some memory inside the message queue
1189   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1190
1191   // Construct message in the message queue memory; note that delete should not be called on the return value
1192   new (slot) LocalType( &node, &Node::SetInitialVolume, initialVolume );
1193 }
1194
1195 inline void SetTransmitGeometryScalingMessage( EventToUpdate& eventToUpdate, const Node& node, bool transmitGeometryScaling )
1196 {
1197   typedef MessageValue1< Node, bool > LocalType;
1198
1199   // Reserve some memory inside the message queue
1200   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1201
1202   // Construct message in the message queue memory; note that delete should not be called on the return value
1203   new (slot) LocalType( &node, &Node::SetTransmitGeometryScaling, transmitGeometryScaling );
1204 }
1205
1206 inline void SetParentOriginMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& origin )
1207 {
1208   typedef MessageValue1< Node, Vector3 > LocalType;
1209
1210   // Reserve some memory inside the message queue
1211   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1212
1213   // Construct message in the message queue memory; note that delete should not be called on the return value
1214   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1215 }
1216
1217 inline void SetAnchorPointMessage( EventToUpdate& eventToUpdate, const Node& node, const Vector3& anchor )
1218 {
1219   typedef MessageValue1< Node, Vector3 > LocalType;
1220
1221   // Reserve some memory inside the message queue
1222   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1223
1224   // Construct message in the message queue memory; note that delete should not be called on the return value
1225   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1226 }
1227
1228 inline void SetPositionInheritanceModeMessage( EventToUpdate& eventToUpdate, const Node& node, PositionInheritanceMode mode )
1229 {
1230   typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1231
1232   // Reserve some memory inside the message queue
1233   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1234
1235   // Construct message in the message queue memory; note that delete should not be called on the return value
1236   new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1237 }
1238
1239 inline void SetInheritScaleMessage( EventToUpdate& eventToUpdate, const Node& node, bool inherit )
1240 {
1241   typedef MessageValue1< Node, bool > LocalType;
1242
1243   // Reserve some memory inside the message queue
1244   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1245
1246   // Construct message in the message queue memory; note that delete should not be called on the return value
1247   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1248 }
1249
1250 inline void SetColorModeMessage( EventToUpdate& eventToUpdate, const Node& node, ColorMode colorMode )
1251 {
1252   typedef MessageValue1< Node, ColorMode > LocalType;
1253
1254   // Reserve some memory inside the message queue
1255   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1256
1257   // Construct message in the message queue memory; note that delete should not be called on the return value
1258   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1259 }
1260
1261 inline void SetDrawModeMessage( EventToUpdate& eventToUpdate, const Node& node, DrawMode::Type drawMode )
1262 {
1263   typedef MessageValue1< Node, DrawMode::Type > LocalType;
1264
1265   // Reserve some memory inside the message queue
1266   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
1267
1268   // Construct message in the message queue memory; note that delete should not be called on the return value
1269   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1270 }
1271
1272 } // namespace SceneGraph
1273
1274 } // namespace Internal
1275
1276 } // namespace Dali
1277
1278 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_