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