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