[dali_1.0.9] Merge branch 'tizen'
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / node-attachment.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_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/internal/common/message.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace SceneGraph
31 {
32
33 class Node;
34 class RenderableAttachment;
35 class SceneController;
36
37 /**
38  * NodeAttachment is a base class for objects attached to Nodes in the scene graph.
39  * The position of the object is provided by its parent node.
40  * NodeAttachment data is double-buffered. This allows an update thread to modify node data, without interferring
41  * with another thread reading the values from the previous update traversal.
42  */
43 class NodeAttachment
44 {
45 public:
46
47   /**
48    * Virtual destructor
49    */
50   virtual ~NodeAttachment();
51
52   /**
53    * Second-phase construction.
54    * This is called by the UpdateManager, when the attachment is attached to the scene-graph.
55    * @param[in] sceneController Allows attachments to get light/camera controllers.
56    * @param[in] updateBufferIndex The current update buffer index.
57    */
58   virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex ) = 0;
59
60   /**
61    * Called shortly before destruction.
62    * After this method has been called, the SceneController cannot be safely accessed.
63    */
64   virtual void OnDestroy() = 0;
65
66   /**
67    * Set the parent of a NodeAttachment.
68    * @param[in] parent the new parent.
69    */
70   void SetParent( Node& parent );
71
72   /**
73    * Retrieve the parent node of a NodeAttachment.
74    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
75    */
76   Node& GetParent()
77   {
78     DALI_ASSERT_DEBUG( mParent != NULL );
79     return *mParent;
80   }
81
82   /**
83    * Retrieve the parent node of a NodeAttachment.
84    * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
85    */
86   Node& GetParent() const
87   {
88     DALI_ASSERT_DEBUG( mParent != NULL );
89     return *mParent;
90   }
91
92   // RenderableAttachment interface
93
94   /**
95    * Query whether the attachment is renderable i.e. implements the SceneGraph::RenderableAttachment interface.
96    * @return True if the attachment is renderable.
97    */
98   bool IsRenderable()
99   {
100     return (GetRenderable() != NULL);
101   }
102
103   /**
104    * Convert an attachment to a renderable attachment.
105    * @return A pointer to the renderable attachment, or NULL.
106    */
107   virtual RenderableAttachment* GetRenderable() = 0;
108
109   // Update methods
110
111   /**
112    * Called when the attachment or it's owning node is flagged as dirty during scene graph updates.
113    * Allows derived classes to perform extra processing
114    * @param[in] updateBufferIndex The current update buffer index.
115    * @param[in] owningNode The attachment's owning node
116    * @param[in] nodeDirtyFlags of the owning node
117    */
118   virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags ) {}
119
120 protected:
121
122   /**
123    * Derived versions of NodeAttachment should be constructed.
124    */
125   NodeAttachment();
126
127 private:
128
129   // Undefined
130   NodeAttachment( const NodeAttachment& );
131
132   // Undefined
133   NodeAttachment& operator=( const NodeAttachment& rhs );
134
135 protected:
136
137   Node* mParent; ///< Pointer to parent node which owns the attachment.
138 };
139
140 } // namespace SceneGraph
141
142 } // namespace Internal
143
144 } // namespace Dali
145
146 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__