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