Follow the include-order coding conventions
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / cluster / cluster-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CLUSTER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CLUSTER_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 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/ref-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
26 #include <dali-toolkit/public-api/controls/cluster/cluster-style.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class Cluster;
39
40 typedef IntrusivePtr<Cluster> ClusterPtr;
41
42 class ChildInfo
43 {
44
45 public:
46
47   ChildInfo()
48   : mExpanded(false)
49   {
50   }
51
52   ChildInfo(Actor actor, unsigned int positionIndex)
53   : mActor(actor),
54     mExpanded(false),
55     mPositionIndex(positionIndex)
56   {
57   }
58
59   Actor mActor;
60   bool mExpanded;
61   unsigned int mPositionIndex;
62 };
63
64 typedef std::vector<ChildInfo> ChildInfoContainer;
65 typedef ChildInfoContainer::iterator ChildInfoIter;
66 typedef ChildInfoContainer::const_iterator ChildInfoConstIter;
67
68 /**
69  * Cluster is a container of grouped actors positioned in different cluster styles.
70  * Multiple cluster styles may be provided, to determine the position, size, rotation, scale, color and visibility
71  * of the child actors in the cluster.
72  */
73 class Cluster : public Control
74 {
75 public:
76
77   /**
78    * Create a new Cluster.
79    * @param[in] style of the cluster
80    * @return A public handle to the newly allocated Cluster.
81    */
82   static Dali::Toolkit::Cluster New(Toolkit::ClusterStyle& style);
83
84   /**
85    * @copydoc Toolkit::Cluster::AddChild( Actor child )
86    */
87   void AddChild( Actor child );
88
89   /**
90    * @copydoc Toolkit::Cluster::AddChild( Actor child, unsigned int positionIndex )
91    */
92   void AddChild( Actor child, unsigned int positionIndex );
93
94   /**
95    * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int index );
96    */
97   void AddChildAt( Actor child, unsigned int index );
98
99   /**
100    * @copydoc Toolkit::Cluster::AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
101    */
102   void AddChildAt( Actor child, unsigned int positionIndex, unsigned int index );
103
104   /**
105    * Adds a ChildInfo struct to the end of the children list.
106    * @param[in] childInfo the child info to that to children list.
107    */
108   void AddChildInfo( ChildInfo childInfo );
109
110   /**
111    * Adds a ChildInfo struct before the specified index.
112    * @param[in] childInfo the child info to that to children list.
113    * @param[in] index the index within the children list to insert
114    * ChildInfo
115    */
116   void AddChildInfoAt( ChildInfo childInfo, unsigned int index );
117
118   /**
119    * @copydoc Toolkit::Cluster::GetChildAt
120    */
121   Actor GetChildAt( unsigned int index );
122
123   /**
124    * @copydoc Toolkit::Cluster::RemoveChildAt
125    */
126   Actor RemoveChildAt( unsigned int index );
127
128   /**
129    * @copydoc Toolkit::Cluster::ExpandChild
130    */
131   void ExpandChild( unsigned int index );
132
133   /**
134    * @copydoc Toolkit::Cluster::ExpandAllChildren
135    */
136   void ExpandAllChildren();
137
138   /**
139    * @copydoc Toolkit::Cluster::CollapseChild
140    */
141   void CollapseChild( unsigned int index, bool front );
142
143   /**
144    * @copydoc Toolkit::Cluster::CollapseAllChildren
145    */
146   void CollapseAllChildren( bool front );
147
148   /**
149    * @copydoc Toolkit::Cluster::TransformChild
150    */
151   void TransformChild( unsigned int index, const Vector3& position, const Vector3& scale, const Quaternion& rotation, AlphaFunction alpha, const TimePeriod& period );
152
153   /**
154    * @copydoc Toolkit::Cluster::RestoreChild
155    */
156   void RestoreChild( unsigned int index, AlphaFunction alpha, const TimePeriod& period, bool front );
157
158   /**
159    * @copydoc Toolkit::Cluster::SetBackgroundImage
160    */
161   void SetBackgroundImage( Actor image );
162
163   /**
164    * @copydoc Toolkit::Cluster::SetTitle
165    */
166   void SetTitle( Actor text );
167
168   /**
169    * @copydoc Toolkit::Cluster::SetStyle
170    */
171   void SetStyle(Toolkit::ClusterStyle style);
172
173   /**
174    * @copydoc Toolkit::Cluster::GetStyle
175    */
176   Toolkit::ClusterStyle GetStyle() const;
177
178   /**
179    * @copydoc Toolkit::Cluster::GetExpandedCount
180    */
181   unsigned int GetExpandedCount() const;
182
183   /**
184    * @copydoc Toolkit::Cluster::GetTotalCount
185    */
186   unsigned int GetTotalCount() const;
187
188 private:
189
190   ChildInfo GetChildInfoAt( unsigned int index );
191
192   void SetDepth( ChildInfo& childInfo, float depth );
193
194   /**
195    * Updates the style of the Background
196    * (occurs when either background changes or style changes)
197    * @param[in] duration apply duration for style
198    */
199   void UpdateBackground(float duration);
200
201   /**
202    * Updates the style of the Title
203    * (occurs when either background changes or style changes)
204    * @param[in] duration apply duration for style
205    */
206   void UpdateTitle(float duration);
207
208   /**
209    * Action: Expand
210    * Expands one or more actors.
211    *
212    * @param[in] attributes list of indices of actors to expand.
213    * (if no attributes specifies, then all actors expand)
214    */
215   void DoExpandAction(const PropertyValueContainer& attributes);
216
217   /**
218    * Action: Collapse
219    * Collapses one or more actors.
220    *
221    * @param[in] attributes list of indices of actors to collapse.
222    * (if no attributes specifies, then all actors collapse)
223    */
224   void DoCollapseAction(const PropertyValueContainer& attributes);
225
226   /**
227    * Action: Transform
228    * Transforms one actor (index) to a specified position (Vector3),
229    * scale (Vector3), and rotation (Quaternion).
230    *
231    * @param[in] attributes index and transform values.
232    */
233   void DoTransformAction(const PropertyValueContainer& attributes);
234
235 private: // From Control
236   /**
237    * From Control; called shortly before a child is removed from the owning actor.
238    * @param[in] child The child being removed.Ptr
239    */
240   virtual void OnControlChildRemove(Actor& child);
241
242 public:
243
244   /**
245    * Performs actions as requested using the action name.
246    * @param[in] object The object on which to perform the action.
247    * @param[in] actionName The action to perform.
248    * @param[in] attributes The attributes with which to perfrom this action.
249    * @return true if action has been accepted by this control
250    */
251   static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
252
253 private: // From Control
254
255   /**
256    * @copydoc Toolkit::Control::OnInitialize()
257    */
258   virtual void OnInitialize();
259
260   /**
261    *
262    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
263    */
264   virtual void OnControlSizeSet( const Vector3& targetSize );
265
266 protected:
267
268   /**
269    * Construct a new Cluster.
270    * @param[in] style of the cluster
271    */
272   Cluster(Toolkit::ClusterStyle& style);
273
274   /**
275    * A reference counted object may only be deleted by calling Unreference()
276    */
277   virtual ~Cluster();
278
279 private:
280
281   // Undefined
282   Cluster(const Cluster&);
283
284   // Undefined
285   Cluster& operator=(const Cluster& rhs);
286
287 private:
288
289   Toolkit::ClusterStyle mClusterStyle;
290   ChildInfoContainer mChildren;
291   Vector3 mClusterSize;
292
293   Actor mBackgroundImage;           ///< Stores the background image.
294   Actor mTitle;                     ///< Stores the text title.
295   unsigned int mExpandedCount;      ///< A count of how many children have been expanded.
296
297 };
298
299 } // namespace Internal
300
301 // Helpers for public-api forwarding methods
302
303 inline Toolkit::Internal::Cluster& GetImpl(Toolkit::Cluster& cluster)
304 {
305   DALI_ASSERT_ALWAYS(cluster);
306
307   Dali::RefObject& handle = cluster.GetImplementation();
308
309   return static_cast<Toolkit::Internal::Cluster&>(handle);
310 }
311
312 inline const Toolkit::Internal::Cluster& GetImpl(const Toolkit::Cluster& cluster)
313 {
314   DALI_ASSERT_ALWAYS(cluster);
315
316   const Dali::RefObject& handle = cluster.GetImplementation();
317
318   return static_cast<const Toolkit::Internal::Cluster&>(handle);
319 }
320
321 } // namespace Toolkit
322
323 } // namespace Dali
324
325 #endif // __DALI_TOOLKIT_INTERNAL_CLUSTER_H__