Merge branch 'devel/master (1.1.1)' into tizen
[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/devel-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/event/common/event-thread-services.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
50 namespace SceneGraph
51 {
52
53 class DiscardQueue;
54 class Layer;
55 class NodeAttachment;
56 class RenderTask;
57 class UpdateManager;
58
59 /**
60  * Flag whether property has changed, during the Update phase.
61  */
62 enum NodePropertyFlags
63 {
64   NothingFlag          = 0x000,
65   TransformFlag        = 0x001,
66   VisibleFlag          = 0x002,
67   ColorFlag            = 0x004,
68   SizeFlag             = 0x008,
69   OverlayFlag          = 0x010,
70   SortModifierFlag     = 0x020,
71   ChildDeletedFlag     = 0x040
72 };
73
74 static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
75
76 /**
77  * Size is not inherited.
78  * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
79  */
80 static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
81
82 // Flags which require the scene renderable lists to be updated
83 static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag;
84
85 /**
86  * Node is the base class for all nodes in the Scene Graph.
87  *
88  * Each node provides a transformation which applies to the node and
89  * its children.  Node data is double-buffered. This allows an update
90  * thread to modify node data, without interferring with another
91  * thread reading the values from the previous update traversal.
92  */
93 class Node : public PropertyOwner, public NodeDataProvider
94 {
95 public:
96
97   // Defaults
98   static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE;
99   static const ColorMode DEFAULT_COLOR_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    */
230   void ConnectChild( Node* childNode );
231
232   /**
233    * Disconnect a child (& its children) from the scene-graph.
234    * @pre childNode is a child of this Node.
235    * @param[in] updateBufferIndex The current update buffer index.
236    * @param[in] childNode The node to disconnect.
237    * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
238    * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
239    */
240   void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set<Node*>& connectedNodes,  std::set<Node*>& disconnectedNodes );
241
242   /**
243    * Retrieve the children a Node.
244    * @return The container of children.
245    */
246   const NodeContainer& GetChildren() const
247   {
248     return mChildren;
249   }
250
251   /**
252    * Retrieve the children a Node.
253    * @return The container of children.
254    */
255   NodeContainer& GetChildren()
256   {
257     return mChildren;
258   }
259
260   // Update methods
261
262   /**
263    * Flag that one of the node values has changed in the current frame.
264    * @param[in] flag The flag to set.
265    */
266   void SetDirtyFlag(NodePropertyFlags flag)
267   {
268     mDirtyFlags |= flag;
269   }
270
271   /**
272    * Flag that all of the node values are dirty.
273    */
274   void SetAllDirtyFlags()
275   {
276     mDirtyFlags = AllFlags;
277   }
278
279   /**
280    * Query whether a node is dirty.
281    * @return The dirty flags
282    */
283   int GetDirtyFlags() const;
284
285   /**
286    * Query whether a node is clean.
287    * @return True if the node is clean.
288    */
289   bool IsClean() const
290   {
291     return ( NothingFlag == GetDirtyFlags() );
292   }
293
294   /**
295    * Retrieve the parent-origin of the node.
296    * @return The parent-origin.
297    */
298   const Vector3& GetParentOrigin() const
299   {
300     return mParentOrigin.mValue;
301   }
302
303   /**
304    * Sets both the local & base parent-origins of the node.
305    * @param[in] origin The new local & base parent-origins.
306    */
307   void SetParentOrigin(const Vector3& origin)
308   {
309     mParentOrigin.mValue = origin;
310     mParentOrigin.OnSet();
311   }
312
313   /**
314    * Retrieve the anchor-point of the node.
315    * @return The anchor-point.
316    */
317   const Vector3& GetAnchorPoint() const
318   {
319     return mAnchorPoint.mValue;
320   }
321
322   /**
323    * Sets both the local & base anchor-points of the node.
324    * @param[in] anchor The new local & base anchor-points.
325    */
326   void SetAnchorPoint(const Vector3& anchor)
327   {
328     mAnchorPoint.mValue = anchor;
329     mAnchorPoint.OnSet();
330   }
331
332   /**
333    * Retrieve the local position of the node, relative to its parent.
334    * @param[in] bufferIndex The buffer to read from.
335    * @return The local position.
336    */
337   const Vector3& GetPosition(BufferIndex bufferIndex) const
338   {
339     return mPosition[bufferIndex];
340   }
341
342   /**
343    * Sets both the local & base positions of the node.
344    * @param[in] updateBufferIndex The current update buffer index.
345    * @param[in] position The new local & base position.
346    */
347   void BakePosition(BufferIndex updateBufferIndex, const Vector3& position)
348   {
349     mPosition.Bake( updateBufferIndex, position );
350   }
351
352   /**
353    * Sets the world of the node derived from the position of all its parents.
354    * @param[in] updateBufferIndex The current update buffer index.
355    * @param[in] position The world position.
356    */
357   void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position )
358   {
359     mWorldPosition.Set( updateBufferIndex, position );
360   }
361
362   /**
363    * Sets the position of the node derived from the position of all its parents.
364    * This method should only be called when the parent's world position is up-to-date.
365    * With a non-central anchor-point, the local orientation and scale affects the world position.
366    * Therefore the world orientation & scale must be updated before the world position.
367    * @pre The node has a parent.
368    * @param[in] updateBufferIndex The current update buffer index.
369    */
370   void InheritWorldPosition(BufferIndex updateBufferIndex)
371   {
372     DALI_ASSERT_DEBUG(mParent != NULL);
373
374     switch( mPositionInheritanceMode )
375     {
376       case INHERIT_PARENT_POSITION  : ///@see Dali::PositionInheritanceMode for how these modes are expected to work
377       {
378         Vector3 finalPosition(-0.5f, -0.5f, -0.5f);
379
380         finalPosition += mParentOrigin.mValue;
381         finalPosition *= mParent->GetSize(updateBufferIndex);
382         finalPosition += mPosition[updateBufferIndex];
383         finalPosition *= mParent->GetWorldScale(updateBufferIndex);
384         const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex);
385         if(!parentWorldOrientation.IsIdentity())
386         {
387           finalPosition *= parentWorldOrientation;
388         }
389
390         // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central)
391         // dont use operator== as that does a slower comparison (and involves function calls)
392         Vector3 localOffset(0.5f, 0.5f, 0.5f);    // AnchorPoint::CENTER
393         localOffset -= mAnchorPoint.mValue;
394
395         if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) ||
396             ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) ||
397             ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) )
398         {
399           localOffset *= mSize[updateBufferIndex];
400
401           Vector3 scale = mWorldScale[updateBufferIndex];
402
403           // Pick up sign of local scale
404           if (mScale[updateBufferIndex].x < 0.0f)
405           {
406             scale.x = -scale.x;
407           }
408           if (mScale[updateBufferIndex].y < 0.0f)
409           {
410             scale.y = -scale.y;
411           }
412           if (mScale[updateBufferIndex].z < 0.0f)
413           {
414             scale.z = -scale.z;
415           }
416
417           // If the anchor-point is not central, then position is affected by the local orientation & scale
418           localOffset *= scale;
419           const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex];
420           if(!localWorldOrientation.IsIdentity())
421           {
422             localOffset *= localWorldOrientation;
423           }
424           finalPosition += localOffset;
425         }
426
427         finalPosition += mParent->GetWorldPosition(updateBufferIndex);
428         mWorldPosition.Set( updateBufferIndex, finalPosition );
429         break;
430       }
431       case USE_PARENT_POSITION_PLUS_LOCAL_POSITION :
432       {
433         // copy parents position plus local transform
434         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] );
435         break;
436       }
437       case USE_PARENT_POSITION :
438       {
439         // copy parents position
440         mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) );
441         break;
442       }
443       case DONT_INHERIT_POSITION :
444       {
445         // use local position as world position
446         mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] );
447         break;
448       }
449     }
450   }
451
452   /**
453    * Copies the previous inherited position, if this changed in the previous frame.
454    * This method should be called instead of InheritWorldPosition i.e. if the inherited position
455    * does not need to be recalculated in the current frame.
456    * @param[in] updateBufferIndex The current update buffer index.
457    */
458   void CopyPreviousWorldPosition( BufferIndex updateBufferIndex )
459   {
460     mWorldPosition.CopyPrevious( updateBufferIndex );
461   }
462
463   /**
464    * Retrieve the position of the node derived from the position of all its parents.
465    * @return The world position.
466    */
467   const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const
468   {
469     return mWorldPosition[bufferIndex];
470   }
471
472   /**
473    * Set the position inheritance mode.
474    * @see Dali::Actor::PositionInheritanceMode
475    * @param[in] mode The new position inheritance mode.
476    */
477   void SetPositionInheritanceMode( PositionInheritanceMode mode )
478   {
479     mPositionInheritanceMode = mode;
480
481     SetDirtyFlag(TransformFlag);
482   }
483
484   /**
485    * @return The position inheritance mode.
486    */
487   PositionInheritanceMode GetPositionInheritanceMode() const
488   {
489     return mPositionInheritanceMode;
490   }
491
492   /**
493    * Retrieve the local orientation of the node, relative to its parent.
494    * @param[in] bufferIndex The buffer to read from.
495    * @return The local orientation.
496    */
497   const Quaternion& GetOrientation(BufferIndex bufferIndex) const
498   {
499     return mOrientation[bufferIndex];
500   }
501
502   /**
503    * Sets both the local & base orientations of the node.
504    * @param[in] updateBufferIndex The current update buffer index.
505    * @param[in] orientation The new local & base orientation.
506    */
507   void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation)
508   {
509     mOrientation.Bake( updateBufferIndex, orientation );
510   }
511
512   /**
513    * Sets the orientation of the node derived from the rotation of all its parents.
514    * @param[in] updateBufferIndex The current update buffer index.
515    * @param[in] orientation The world orientation.
516    */
517   void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation )
518   {
519     mWorldOrientation.Set( updateBufferIndex, orientation );
520   }
521
522   /**
523    * Sets the orientation of the node derived from the rotation of all its parents.
524    * This method should only be called when the parents world orientation is up-to-date.
525    * @pre The node has a parent.
526    * @param[in] updateBufferIndex The current update buffer index.
527    */
528   void InheritWorldOrientation( BufferIndex updateBufferIndex )
529   {
530     DALI_ASSERT_DEBUG(mParent != NULL);
531
532     const Quaternion& localOrientation = mOrientation[updateBufferIndex];
533
534     if(localOrientation.IsIdentity())
535     {
536       mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) );
537     }
538     else
539     {
540       Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) );
541       finalOrientation *= localOrientation;
542       mWorldOrientation.Set( updateBufferIndex, finalOrientation );
543     }
544   }
545
546   /**
547    * Copies the previous inherited orientation, if this changed in the previous frame.
548    * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation
549    * does not need to be recalculated in the current frame.
550    * @param[in] updateBufferIndex The current update buffer index.
551    */
552   void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex )
553   {
554     mWorldOrientation.CopyPrevious( updateBufferIndex );
555   }
556
557   /**
558    * Retrieve the orientation of the node derived from the rotation of all its parents.
559    * @param[in] bufferIndex The buffer to read from.
560    * @return The world rotation.
561    */
562   const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const
563   {
564     return mWorldOrientation[bufferIndex];
565   }
566
567   /**
568    * Set whether the Node inherits orientation.
569    * @param[in] inherit True if the parent orientation is inherited.
570    */
571   void SetInheritOrientation(bool inherit)
572   {
573     if (inherit != mInheritOrientation)
574     {
575       mInheritOrientation = inherit;
576
577       SetDirtyFlag(TransformFlag);
578     }
579   }
580
581   /**
582    * Query whether the node inherits orientation from its parent.
583    * @return True if the parent orientation is inherited.
584    */
585   bool IsOrientationInherited() const
586   {
587     return mInheritOrientation;
588   }
589
590   /**
591    * Retrieve the local scale of the node, relative to its parent.
592    * @param[in] bufferIndex The buffer to read from.
593    * @return The local scale.
594    */
595   const Vector3& GetScale(BufferIndex bufferIndex) const
596   {
597     return mScale[bufferIndex];
598   }
599
600   /**
601    * Sets the scale of the node derived from the scale of all its parents and a pre-scale
602    * @param[in] updateBufferIndex The current update buffer index.
603    * @param[in] scale The world scale.
604    */
605   void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale)
606   {
607     mWorldScale.Set( updateBufferIndex, scale );
608   }
609
610   /**
611    * Sets the scale of the node derived from the scale of all its parents and a pre-scale.
612    * This method should only be called when the parents world scale is up-to-date.
613    * @pre The node has a parent.
614    * @param[in] updateBufferIndex The current update buffer index.
615    */
616   void InheritWorldScale(BufferIndex updateBufferIndex)
617   {
618     DALI_ASSERT_DEBUG(mParent != NULL);
619
620     mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] );
621   }
622
623   /**
624    * Copies the previous inherited scale, if this changed in the previous frame.
625    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
626    * does not need to be recalculated in the current frame.
627    * @param[in] updateBufferIndex The current update buffer index.
628    */
629   void CopyPreviousWorldScale( BufferIndex updateBufferIndex )
630   {
631     mWorldScale.CopyPrevious( updateBufferIndex );
632   }
633
634   /**
635    * Retrieve the scale of the node derived from the scale of all its parents.
636    * @param[in] bufferIndex The buffer to read from.
637    * @return The world scale.
638    */
639   const Vector3& GetWorldScale( BufferIndex bufferIndex ) const
640   {
641     return mWorldScale[bufferIndex];
642   }
643
644   /**
645    * Set whether the Node inherits scale.
646    * @param inherit True if the Node inherits scale.
647    */
648   void SetInheritScale( bool inherit )
649   {
650     if( inherit != mInheritScale )
651     {
652       mInheritScale = inherit;
653
654       SetDirtyFlag( TransformFlag );
655     }
656   }
657
658   /**
659    * Query whether the Node inherits scale.
660    * @return if scale is inherited
661    */
662   bool IsScaleInherited() const
663   {
664     return mInheritScale;
665   }
666
667   /**
668    * Copies the previously used size, if this changed in the previous frame.
669    * @param[in] updateBufferIndex The current update buffer index.
670    */
671   void CopyPreviousSize( BufferIndex updateBufferIndex )
672   {
673     SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) );
674   }
675
676   /**
677    * Retrieve the visibility of the node.
678    * @param[in] bufferIndex The buffer to read from.
679    * @return True if the node is visible.
680    */
681   bool IsVisible(BufferIndex bufferIndex) const
682   {
683     return mVisible[bufferIndex];
684   }
685
686   /**
687    * Retrieves whether a node is fully visible.
688    * A node is fully visible if is visible and all its ancestors are visible.
689    * @param[in] updateBufferIndex The current update buffer index.
690    * @return True if the node is fully visible.
691    */
692   bool IsFullyVisible( BufferIndex updateBufferIndex ) const;
693
694   /**
695    * Retrieve the opacity of the node.
696    * @param[in] bufferIndex The buffer to read from.
697    * @return The opacity.
698    */
699   float GetOpacity(BufferIndex bufferIndex) const
700   {
701     return mColor[bufferIndex].a;
702   }
703
704   /**
705    * Retrieve the color of the node.
706    * @param[in] bufferIndex The buffer to read from.
707    * @return The color.
708    */
709   const Vector4& GetColor(BufferIndex bufferIndex) const
710   {
711     return mColor[bufferIndex];
712   }
713
714   /**
715    * Sets the color of the node derived from the color of all its parents.
716    * @param[in] color The world color.
717    * @param[in] updateBufferIndex The current update buffer index.
718    */
719   void SetWorldColor(const Vector4& color, BufferIndex updateBufferIndex)
720   {
721     mWorldColor.Set( updateBufferIndex, color );
722   }
723
724   /**
725    * Sets the color of the node derived from the color of all its parents.
726    * This method should only be called when the parents world color is up-to-date.
727    * @pre The node has a parent.
728    * @param[in] updateBufferIndex The current update buffer index.
729    */
730   void InheritWorldColor( BufferIndex updateBufferIndex )
731   {
732     DALI_ASSERT_DEBUG(mParent != NULL);
733
734     // default first
735     if( mColorMode == USE_OWN_MULTIPLY_PARENT_ALPHA )
736     {
737       const Vector4& ownColor = mColor[updateBufferIndex];
738       mWorldColor.Set( updateBufferIndex, ownColor.r, ownColor.g, ownColor.b, ownColor.a * mParent->GetWorldColor(updateBufferIndex).a );
739     }
740     else if( mColorMode == USE_OWN_MULTIPLY_PARENT_COLOR )
741     {
742       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) * mColor[updateBufferIndex] );
743     }
744     else if( mColorMode == USE_PARENT_COLOR )
745     {
746       mWorldColor.Set( updateBufferIndex, mParent->GetWorldColor(updateBufferIndex) );
747     }
748     else // USE_OWN_COLOR
749     {
750       mWorldColor.Set( updateBufferIndex, mColor[updateBufferIndex] );
751     }
752   }
753
754   /**
755    * Copies the previous inherited scale, if this changed in the previous frame.
756    * This method should be called instead of InheritWorldScale i.e. if the inherited scale
757    * does not need to be recalculated in the current frame.
758    * @param[in] updateBufferIndex The current update buffer index.
759    */
760   void CopyPreviousWorldColor( BufferIndex updateBufferIndex )
761   {
762     mWorldColor.CopyPrevious( updateBufferIndex );
763   }
764
765   /**
766    * Retrieve the color of the node, possibly derived from the color
767    * of all its parents, depending on the value of mColorMode.
768    * @param[in] bufferIndex The buffer to read from.
769    * @return The world color.
770    */
771   const Vector4& GetWorldColor(BufferIndex bufferIndex) const
772   {
773     return mWorldColor[bufferIndex];
774   }
775
776   /**
777    * Set the color mode. This specifies whether the Node uses its own color,
778    * or inherits its parent color.
779    * @param[in] colorMode The new color mode.
780    */
781   void SetColorMode(ColorMode colorMode)
782   {
783     mColorMode = colorMode;
784
785     SetDirtyFlag(ColorFlag);
786   }
787
788   /**
789    * Retrieve the color mode.
790    * @return The color mode.
791    */
792   ColorMode GetColorMode() const
793   {
794     return mColorMode;
795   }
796
797   /**
798    * Sets the size of the node.
799    * @param[in] bufferIndex The buffer to write to.
800    * @param[in] size The size to write.
801    */
802   void SetSize( BufferIndex bufferIndex, const Vector3& size )
803   {
804     mSize[bufferIndex] = size;
805   }
806
807   /**
808    * Retrieve the size of the node.
809    * @param[in] bufferIndex The buffer to read from.
810    * @return The size.
811    */
812   const Vector3& GetSize(BufferIndex bufferIndex) const
813   {
814     return mSize[bufferIndex];
815   }
816
817   /**
818    * Set the world-matrix of a node, with scale + rotation + translation.
819    * Scale and rotation are centered at the origin.
820    * Translation is applied independently of the scale or rotatation axis.
821    * @param[in] updateBufferIndex The current update buffer index.
822    * @param[in] scale The scale.
823    * @param[in] rotation The rotation.
824    * @param[in] translation The translation.
825    */
826   void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation )
827   {
828     mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation );
829     mWorldMatrix.SetDirty( updateBufferIndex );
830   }
831
832   /**
833    * Retrieve the cached world-matrix of a node.
834    * @param[in] bufferIndex The buffer to read from.
835    * @return The world-matrix.
836    */
837   const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const
838   {
839     return mWorldMatrix[ bufferIndex ];
840   }
841
842   /**
843    * Copy previous frames world matrix
844    * @param[in] updateBufferIndex The current update buffer index.
845    */
846   void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex )
847   {
848     mWorldMatrix.CopyPrevious( updateBufferIndex );
849   }
850
851   /**
852    * Mark the node as exclusive to a single RenderTask.
853    * @param[in] renderTask The render-task, or NULL if the Node is not exclusive to a single RenderTask.
854    */
855   void SetExclusiveRenderTask( RenderTask* renderTask )
856   {
857     mExclusiveRenderTask = renderTask;
858   }
859
860   /**
861    * Query whether the node is exclusive to a single RenderTask.
862    * @return The render-task, or NULL if the Node is not exclusive to a single RenderTask.
863    */
864   RenderTask* GetExclusiveRenderTask() const
865   {
866     return mExclusiveRenderTask;
867   }
868
869   /**
870    * Set how the Node and its children should be drawn; see Dali::Actor::SetDrawMode() for more details.
871    * @param[in] drawMode The new draw-mode to use.
872    */
873   void SetDrawMode( const DrawMode::Type& drawMode )
874   {
875     mDrawMode = drawMode;
876   }
877
878   /**
879    * Returns whether node is an overlay or not.
880    * @return True if node is an overlay, false otherwise.
881    */
882   DrawMode::Type GetDrawMode() const
883   {
884     return mDrawMode;
885   }
886
887   /**
888    * Equality operator, checks for identity, not values.
889    *
890    */
891   bool operator==( const Node* rhs ) const
892   {
893     if ( this == rhs )
894     {
895       return true;
896     }
897     return false;
898   }
899
900   /**
901    * Set the inhibit local transform flag.@n
902    * Setting this flag will stop the node's local transform (position, scale and orientation)
903    * being applied on top of its parents transformation.
904    * @param[in] flag When true, local transformation is inhibited when calculating the world matrix.
905    */
906   void SetInhibitLocalTransform( bool flag )
907   {
908     SetDirtyFlag( TransformFlag );
909     mInhibitLocalTransform = flag;
910   }
911
912   /**
913    * Get the inhibit local transform flag.@n
914    * See @ref SetInhibitLocalTransform
915    * @result A flag, when true, local transformation is inhibited when calculating the world matrix.
916    */
917   bool GetInhibitLocalTransform() const
918   {
919     return mInhibitLocalTransform;
920   }
921
922   unsigned short GetDepth() const
923   {
924     return mDepth;
925   }
926
927 protected:
928
929   /**
930    * Set the parent of a Node.
931    * @param[in] parentNode the new parent.
932    */
933   void SetParent(Node& parentNode);
934
935   /**
936    * Protected constructor; See also Node::New()
937    */
938   Node();
939
940 private: // from NodeDataProvider
941
942   /**
943    * @copydoc NodeDataProvider::GetModelMatrix
944    */
945   virtual const Matrix& GetModelMatrix( unsigned int bufferId )
946   {
947     return GetWorldMatrix( bufferId );
948   }
949
950   /**
951    * @copydoc NodeDataProvider::GetRenderColor
952    */
953   virtual const Vector4& GetRenderColor( unsigned int bufferId )
954   {
955     return GetWorldColor( bufferId );
956   }
957
958   virtual const Vector3& GetRenderSize( unsigned int bufferId )
959   {
960     return GetSize( bufferId );
961   }
962
963
964 private:
965
966   // Undefined
967   Node(const Node&);
968
969   // Undefined
970   Node& operator=(const Node& rhs);
971
972   /**
973    * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
974    */
975   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex );
976
977   /**
978    * Recursive helper to disconnect a Node and its children.
979    * Disconnected Nodes have no parent or children.
980    * @param[in] updateBufferIndex The current update buffer index.
981    * @param[in] connectedNodes Disconnected Node attachments should be removed from here.
982    * @param[in] disconnectedNodes Disconnected Node attachments should be added here.
983    */
984   void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set<Node*>& connectedNodes, std::set<Node*>& disconnectedNodes );
985
986 public: // Default properties
987
988   PropertyVector3                mParentOrigin;  ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed
989   PropertyVector3                mAnchorPoint;   ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed
990
991   AnimatableProperty<Vector3>    mSize;          ///< Size is provided for layouting
992   AnimatableProperty<Vector3>    mPosition;      ///< Local transform; distance between parent-origin & anchor-point
993   AnimatableProperty<Quaternion> mOrientation;   ///< Local transform; rotation relative to parent node
994   AnimatableProperty<Vector3>    mScale;         ///< Local transform; scale relative to parent node
995   AnimatableProperty<bool>       mVisible;       ///< Visibility can be inherited from the Node hierachy
996   AnimatableProperty<Vector4>    mColor;         ///< Color can be inherited from the Node hierarchy
997
998   // Inherited properties; read-only from public API
999
1000   InheritedVector3    mWorldPosition;     ///< Full inherited position
1001   InheritedQuaternion mWorldOrientation;  ///< Full inherited orientation
1002   InheritedVector3    mWorldScale;        ///< Full inherited scale
1003   InheritedMatrix     mWorldMatrix;       ///< Full inherited world matrix
1004   InheritedColor      mWorldColor;        ///< Full inherited color
1005
1006 protected:
1007
1008   Node*               mParent;                       ///< Pointer to parent node (a child is owned by its parent)
1009   RenderTask*         mExclusiveRenderTask;          ///< Nodes can be marked as exclusive to a single RenderTask
1010
1011   NodeAttachmentOwner mAttachment;                   ///< Optional owned attachment
1012   NodeContainer       mChildren;                     ///< Container of children; not owned
1013
1014
1015   // flags, compressed to bitfield
1016   unsigned short mDepth: 12;                        ///< Depth in the hierarchy
1017   int  mDirtyFlags:8;                               ///< A composite set of flags for each of the Node properties
1018
1019   bool mIsRoot:1;                                    ///< True if the node cannot have a parent
1020   bool mInheritOrientation:1;                        ///< Whether the parent's orientation should be inherited.
1021   bool mInheritScale:1;                              ///< Whether the parent's scale should be inherited.
1022   bool mInhibitLocalTransform:1;                     ///< whether local transform should be applied.
1023   bool mIsActive:1;                                  ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified
1024
1025   DrawMode::Type          mDrawMode:2;               ///< How the Node and its children should be drawn
1026   PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough
1027   ColorMode               mColorMode:2;              ///< Determines whether mWorldColor is inherited, 2 bits is enough
1028
1029   // Changes scope, should be at end of class
1030   DALI_LOG_OBJECT_STRING_DECLARATION;
1031 };
1032
1033 // Messages for Node
1034
1035 inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1036 {
1037   typedef MessageValue1< Node, bool > LocalType;
1038
1039   // Reserve some memory inside the message queue
1040   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1041
1042   // Construct message in the message queue memory; note that delete should not be called on the return value
1043   new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
1044 }
1045
1046
1047
1048 inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
1049 {
1050   typedef MessageValue1< Node, Vector3 > LocalType;
1051
1052   // Reserve some memory inside the message queue
1053   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1054
1055   // Construct message in the message queue memory; note that delete should not be called on the return value
1056   new (slot) LocalType( &node, &Node::SetParentOrigin, origin );
1057 }
1058
1059 inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& anchor )
1060 {
1061   typedef MessageValue1< Node, Vector3 > LocalType;
1062
1063   // Reserve some memory inside the message queue
1064   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1065
1066   // Construct message in the message queue memory; note that delete should not be called on the return value
1067   new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor );
1068 }
1069
1070 inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode )
1071 {
1072   typedef MessageValue1< Node, PositionInheritanceMode > LocalType;
1073
1074   // Reserve some memory inside the message queue
1075   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1076
1077   // Construct message in the message queue memory; note that delete should not be called on the return value
1078   new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode );
1079 }
1080
1081 inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit )
1082 {
1083   typedef MessageValue1< Node, bool > LocalType;
1084
1085   // Reserve some memory inside the message queue
1086   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1087
1088   // Construct message in the message queue memory; note that delete should not be called on the return value
1089   new (slot) LocalType( &node, &Node::SetInheritScale, inherit );
1090 }
1091
1092 inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const Node& node, ColorMode colorMode )
1093 {
1094   typedef MessageValue1< Node, ColorMode > LocalType;
1095
1096   // Reserve some memory inside the message queue
1097   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1098
1099   // Construct message in the message queue memory; note that delete should not be called on the return value
1100   new (slot) LocalType( &node, &Node::SetColorMode, colorMode );
1101 }
1102
1103 inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const Node& node, DrawMode::Type drawMode )
1104 {
1105   typedef MessageValue1< Node, DrawMode::Type > LocalType;
1106
1107   // Reserve some memory inside the message queue
1108   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
1109
1110   // Construct message in the message queue memory; note that delete should not be called on the return value
1111   new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
1112 }
1113
1114 } // namespace SceneGraph
1115
1116 } // namespace Internal
1117
1118 } // namespace Dali
1119
1120 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_