[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / cluster / cluster-style-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // INTERNAL INCLUDES
18 #include <dali/dali.h>
19 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
20 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
21
22 namespace Dali
23 {
24
25 namespace // unnamed namespace
26 {
27 // Cluster style one
28
29 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
30
31 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
32
33 const float STYLE_1_CHILD_OFFSET_Z = 2.0f;
34 const float STYLE_1_CHILD_GAP_FACTOR = 0.03f;
35 const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f };
36 const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
37                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
38                                                             STYLE_1_CHILD_OFFSET_Z),
39                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
40                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
41                                                             STYLE_1_CHILD_OFFSET_Z + 0.5f),
42                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
43                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
44                                                             STYLE_1_CHILD_OFFSET_Z + 1.0f),
45                                                     Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
46                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
47                                                             STYLE_1_CHILD_OFFSET_Z + 1.5f),
48                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
49                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
50                                                             STYLE_1_CHILD_OFFSET_Z + 2.0f),
51                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
52                                                             0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
53                                                             STYLE_1_CHILD_OFFSET_Z + 2.5f),
54                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
55                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
56                                                             STYLE_1_CHILD_OFFSET_Z + 3.0f),
57                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
58                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
59                                                             STYLE_1_CHILD_OFFSET_Z + 3.5f) };
60
61 const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
62 const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
63                                                         0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f,
64                                                         0.0f);
65 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
66
67 // Cluster style two
68
69 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
70
71 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
72
73 const float STYLE_2_CHILD_OFFSET_Z = 2.0f;
74 const float STYLE_2_CHILD_GAP_FACTOR = 0.03f;
75 const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f };
76 const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
77                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f,
78                                                             STYLE_2_CHILD_OFFSET_Z),
79                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
80                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
81                                                             STYLE_2_CHILD_OFFSET_Z + 0.5f),
82                                                     Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f,
83                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
84                                                             STYLE_2_CHILD_OFFSET_Z + 1.0f),
85                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
86                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f,
87                                                             STYLE_2_CHILD_OFFSET_Z + 1.5f),
88                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
89                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
90                                                             STYLE_2_CHILD_OFFSET_Z + 2.0f),
91                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f,
92                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
93                                                             STYLE_2_CHILD_OFFSET_Z + 2.5f) };
94
95 const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
96 const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
97                                                         0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f,
98                                                         0.0f);
99 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
100
101 // Cluster style three
102
103 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
104
105 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
106
107 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
108
109 const float STYLE_3_CHILD_OFFSET_Z = 2.0f;
110 const float STYLE_3_CHILD_GAP_FACTOR = 0.03f;
111 const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f };
112 const float STYLE_3_CHILD_POSITION_OFFSET_Y = (1.0f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_SIZE_FACTOR[3] - STYLE_3_CHILD_GAP_FACTOR - STYLE_3_TITLE_SIZE_FACTOR.height) * 0.5f;
113 const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
114                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
115                                                               STYLE_3_CHILD_OFFSET_Z),
116                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
117                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
118                                                               STYLE_3_CHILD_OFFSET_Z + 0.5f),
119                                                       Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f,
120                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
121                                                               STYLE_3_CHILD_OFFSET_Z + 1.0f),
122                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
123                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
124                                                               STYLE_3_CHILD_OFFSET_Z + 1.5f),
125                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
126                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
127                                                               STYLE_3_CHILD_OFFSET_Z + 2.0f),
128                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f,
129                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
130                                                               STYLE_3_CHILD_OFFSET_Z + 2.5f) };
131
132 const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
133                                                           0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y - STYLE_3_TITLE_SIZE_FACTOR.height + 0.02f,
134                                                           0.0f);
135 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
136
137 // Cluster style four
138
139 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
140
141 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
142
143 const float STYLE_4_CHILD_OFFSET_Z = 2.0f;
144 const float STYLE_4_CHILD_GAP_FACTOR = 0.03f;
145 const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f };
146 const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
147                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
148                                                              STYLE_4_CHILD_OFFSET_Z),
149                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR,
150                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
151                                                              STYLE_4_CHILD_OFFSET_Z + 0.5f),
152                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f,
153                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
154                                                              STYLE_4_CHILD_OFFSET_Z + 1.0f),
155                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f,
156                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
157                                                              STYLE_4_CHILD_OFFSET_Z + 1.5f),
158                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR,
159                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
160                                                              STYLE_4_CHILD_OFFSET_Z + 2.0f),
161                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_SIZE_FACTOR[5] - STYLE_4_CHILD_GAP_FACTOR * 2.0f,
162                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
163                                                              STYLE_4_CHILD_OFFSET_Z + 2.5f) };
164
165 const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
166 const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
167                                                          0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f,
168                                                          0.0f);
169 const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
170 const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3);         ///< Random seed for cluster data.
171
172 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
173
174 // Constraints
175
176 /**
177  * First order equation of the form y = Mx + C
178  * current' = current * relative + offset
179  */
180 struct FirstOrderEquationConstraint
181 {
182   /**
183    * @param relative The relative multiplier of the source property
184    * @param offset The offset to add onto the result.
185    */
186   FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
187   : mRelative(relative),
188     mOffset(offset)
189   {
190   }
191
192   Vector3 operator()(const Vector3&    current,
193                      const PropertyInput& sourceProperty)
194   {
195     const Vector3 source = sourceProperty.GetVector3();
196
197     return source * mRelative + mOffset;
198   }
199
200 public:
201
202   Vector3 mRelative;
203   Vector3 mOffset;
204 };
205
206 /**
207  * Depth Constraint.
208  * current' = current.xy | + Vector3::ONE.z
209  */
210 struct DepthConstraint
211 {
212   /**
213    * constructor
214    */
215   DepthConstraint()
216   {
217   }
218
219   Vector3 operator()(const Vector3&    current,
220                      const PropertyInput& depthProperty)
221   {
222     Vector3 position(current);
223     position.z = depthProperty.GetFloat();
224     return position;
225   }
226 };
227
228
229 /**
230  * Position Constraint.
231  * current' = current * relative + offset
232  */
233 struct PositionConstraint
234 {
235   /**
236    * @param relative The relative multiplier of the source property
237    * @param offset The offset to add onto the result.
238    */
239   PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
240   : mRelative(relative),
241     mOffset(offset)
242   {
243   }
244
245   Vector3 operator()(const Vector3&    current,
246                      const PropertyInput& sourceProperty,
247                      const PropertyInput& depthProperty)
248   {
249     const Vector3 source = sourceProperty.GetVector3();
250
251     Vector3 position(source * mRelative + mOffset);
252     position.z += depthProperty.GetFloat();
253     return position;
254   }
255
256 public:
257
258   Vector3 mRelative;
259   Vector3 mOffset;
260 };
261
262 template <class T>
263 struct SetConstraint
264 {
265   SetConstraint(T value)
266   : mValue(value)
267   {
268
269   }
270
271   T operator()(const T&    current)
272   {
273     return mValue;
274   }
275
276   T mValue;
277 };
278
279 // random data generator //////////////////////////////////////////////////////
280
281 const unsigned int GEN_RAND_CONST = 0x15d9a373;
282
283 unsigned int genRandom(unsigned int& seed, unsigned int offset)
284 {
285   unsigned int shft = offset&31;
286
287   offset++;
288
289   seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
290
291   return seed;
292 }
293
294 float genRandomFloat(unsigned int& seed, unsigned int offset)
295 {
296   return static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
297 }
298
299 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
300 {
301   const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
302   return f * (max - min) + min;
303 }
304
305 } // unnamed namespace
306
307 namespace Toolkit
308 {
309
310 namespace Internal
311 {
312
313 // ClusterStyle ///////////////////////////////////////////////////////////////
314
315 ClusterStyle::ClusterStyle()
316 : mMaxChildren(0),
317   mTitlePositionRelative(Vector3::ONE),
318   mTitlePositionOffset(Vector3::ZERO),
319   mTitleSize(Vector3::ONE),
320   mBackgroundPositionRelative(Vector3::ONE),
321   mBackgroundPositionOffset(Vector3::ZERO),
322   mBackgroundSize(Vector3::ONE)
323 {
324 }
325
326 ClusterStyle::~ClusterStyle()
327 {
328
329 }
330
331 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
332 {
333   mMaxChildren = maxChildren;
334 }
335
336 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
337 {
338   return mMaxChildren;
339 }
340
341 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
342                                       const Vector3& offsetPosition,
343                                       const Vector3& size)
344 {
345   mTitlePositionRelative = relativePosition;
346   mTitlePositionOffset = offsetPosition;
347   mTitleSize = size;
348 }
349
350 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
351                                            const Vector3& offsetPosition,
352                                            const Vector3& size)
353 {
354   mBackgroundPositionRelative = relativePosition;
355   mBackgroundPositionOffset = offsetPosition;
356   mBackgroundSize = size;
357 }
358
359 // ClusterStyleStandard ///////////////////////////////////////////////////////
360
361 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
362 {
363   ClusterStylePtr impl( new ClusterStyleStandard(style) );
364
365   return impl;
366 }
367
368 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
369 : ClusterStyle(),
370   mSizes(NULL),
371   mPositions(NULL)
372 {
373   switch(style)
374   {
375     case Toolkit::ClusterStyleStandard::ClusterStyle1:
376     {
377       SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
378       SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
379       SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
380       SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
381                          STYLE_1_TITLE_POSITION_OFFSET,
382                          STYLE_1_TITLE_SIZE_FACTOR);
383       SetBackgroundProperties(Vector3::ZERO,
384                               Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
385                               Vector3::ONE);
386       break;
387     }
388     case Toolkit::ClusterStyleStandard::ClusterStyle2:
389     {
390       SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
391       SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
392       SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
393       SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
394                          STYLE_2_TITLE_POSITION_OFFSET,
395                          STYLE_2_TITLE_SIZE_FACTOR);
396       SetBackgroundProperties(Vector3::ZERO,
397                               Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
398                               Vector3::ONE);
399       break;
400     }
401     case Toolkit::ClusterStyleStandard::ClusterStyle3:
402     {
403       SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
404       SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
405       SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
406       SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
407                          STYLE_3_TITLE_POSITION_OFFSET,
408                          STYLE_3_TITLE_SIZE_FACTOR);
409       SetBackgroundProperties(Vector3::ZERO,
410                               Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
411                               Vector3::ONE);
412       break;
413     }
414     case Toolkit::ClusterStyleStandard::ClusterStyle4:
415     {
416       SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
417       SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
418       SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
419       SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
420                          STYLE_4_TITLE_POSITION_OFFSET,
421                          STYLE_4_TITLE_SIZE_FACTOR);
422       SetBackgroundProperties(Vector3::ZERO,
423                               Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
424                               Vector3::ONE);
425       break;
426     }
427     default:
428     {
429       DALI_ASSERT_ALWAYS(false && "Invalid Style");
430       break;
431     }
432   } // end switch
433 }
434
435 void ClusterStyleStandard::SetSizes(const float *sizes)
436 {
437   mSizes = sizes;
438 }
439
440 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
441 {
442   mPositions = positions;
443 }
444
445 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
446 {
447   if(mPositions)
448   {
449     const float& size = mSizes[index];
450     // counter top-left parent origin and top-left anchor point.
451     const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
452
453     Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
454                                                       ParentSource( Actor::SIZE ),
455                                                       FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
456                                                                                    Vector3(0.0f, 0.0f, position.z)) );
457
458     constraint.SetApplyTime(durationSeconds);
459     constraint.SetAlphaFunction(alpha);
460     constraint.SetRemoveAction(Constraint::Bake);
461     child.ApplyConstraint(constraint);
462
463     constraint = Constraint::New<Vector3>( Actor::SIZE,
464                                            ParentSource( Actor::SIZE ),
465                                            FirstOrderEquationConstraint(Vector3::ONE * size) );
466     constraint.SetApplyTime(durationSeconds);
467     constraint.SetAlphaFunction(alpha);
468     constraint.SetRemoveAction(Constraint::Bake);
469     child.ApplyConstraint(constraint);
470
471     constraint = Constraint::New<Quaternion>( Actor::ROTATION,
472                                               SetConstraint<Quaternion>(Quaternion()) );
473     constraint.SetApplyTime(durationSeconds);
474     constraint.SetAlphaFunction(alpha);
475     constraint.SetRemoveAction(Constraint::Bake);
476     child.ApplyConstraint(constraint);
477
478     constraint = Constraint::New<Vector3>( Actor::SCALE,
479                                            SetConstraint<Vector3>(Vector3::ONE) );
480     constraint.SetApplyTime(durationSeconds);
481     constraint.SetAlphaFunction(alpha);
482     constraint.SetRemoveAction(Constraint::Bake);
483     child.ApplyConstraint(constraint);
484   }
485 }
486
487 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
488 {
489   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
490                                          ParentSource( Actor::SIZE ),
491                                          FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
492   constraint.SetApplyTime(durationSeconds);
493   constraint.SetAlphaFunction(alpha);
494   constraint.SetRemoveAction(Constraint::Bake);
495   background.ApplyConstraint(constraint);
496
497   constraint = Constraint::New<Vector3>( Actor::SIZE,
498                                          ParentSource( Actor::SIZE ),
499                                          FirstOrderEquationConstraint(mBackgroundSize) );
500   constraint.SetApplyTime(durationSeconds);
501   constraint.SetAlphaFunction(alpha);
502   constraint.SetRemoveAction(Constraint::Bake);
503   background.ApplyConstraint(constraint);
504 }
505
506 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
507 {
508   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
509                                          ParentSource( Actor::SIZE ),
510                                          FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
511   constraint.SetApplyTime(durationSeconds);
512   constraint.SetAlphaFunction(alpha);
513   constraint.SetRemoveAction(Constraint::Bake);
514   title.ApplyConstraint(constraint);
515
516   constraint = Constraint::New<Vector3>( Actor::SIZE,
517                                          ParentSource( Actor::SIZE ),
518                                          FirstOrderEquationConstraint(mTitleSize) );
519   constraint.SetApplyTime(durationSeconds);
520   constraint.SetAlphaFunction(alpha);
521   constraint.SetRemoveAction(Constraint::Bake);
522   title.ApplyConstraint(constraint);
523 }
524
525 // ClusterStyleRandom /////////////////////////////////////////////////////////
526
527 ClusterStylePtr ClusterStyleRandom::New()
528 {
529   ClusterStylePtr impl( new ClusterStyleRandom() );
530
531   return impl;
532 }
533
534 ClusterStyleRandom::ClusterStyleRandom()
535 : ClusterStyle()
536 {
537   SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
538   SetTitleProperties(Vector3::ZERO,
539                      Vector3::ZERO,
540                      Vector3::ONE);
541   SetBackgroundProperties(Vector3::ZERO,
542                           Vector3(0.0f, 0.0f, 0.0f),
543                           Vector3::ONE);
544 }
545
546 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
547 {
548   unsigned int seed = CLUSTER_RANDOM_SEED;
549   const float size = 0.5f;
550   const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
551   const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
552                          genRandomFloat(seed, index, -0.1f, 0.1f),
553                          0.0f);
554
555   Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
556
557   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
558                                                     ParentSource( Actor::SIZE ),
559                                                     FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
560                                                                                   Vector3(0.0f, 0.0f, position.z) ) );
561
562   constraint.SetApplyTime(durationSeconds);
563   constraint.SetAlphaFunction(alpha);
564   constraint.SetRemoveAction(Constraint::Bake);
565   child.ApplyConstraint(constraint);
566
567   // this constraint overrides the Z position. setting it to cluster-actor-depth
568   constraint = Constraint::New<Vector3>( Actor::POSITION,
569                                          LocalSource( depthProperty ),
570                                          DepthConstraint() );
571
572   constraint.SetAlphaFunction(alpha);
573   constraint.SetRemoveAction(Constraint::Bake);
574   child.ApplyConstraint(constraint);
575
576   constraint = Constraint::New<Vector3>( Actor::SIZE,
577                                          ParentSource( Actor::SIZE ),
578                                          FirstOrderEquationConstraint(Vector3::ONE * size) );
579   constraint.SetApplyTime(durationSeconds);
580   constraint.SetAlphaFunction(alpha);
581   constraint.SetRemoveAction(Constraint::Bake);
582   child.ApplyConstraint(constraint);
583
584   constraint = Constraint::New<Quaternion>( Actor::ROTATION,
585                                             SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
586   constraint.SetApplyTime(durationSeconds);
587   constraint.SetAlphaFunction(alpha);
588   constraint.SetRemoveAction(Constraint::Bake);
589   child.ApplyConstraint(constraint);
590
591   constraint = Constraint::New<Vector3>( Actor::SCALE,
592                                          SetConstraint<Vector3>(Vector3::ONE) );
593   constraint.SetApplyTime(durationSeconds);
594   constraint.SetAlphaFunction(alpha);
595   constraint.SetRemoveAction(Constraint::Bake);
596   child.ApplyConstraint(constraint);
597 }
598
599 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
600 {
601   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
602                                          ParentSource( Actor::SIZE ),
603                                          FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
604   constraint.SetApplyTime(durationSeconds);
605   constraint.SetAlphaFunction(alpha);
606   constraint.SetRemoveAction(Constraint::Bake);
607   background.ApplyConstraint(constraint);
608
609   constraint = Constraint::New<Vector3>( Actor::SIZE,
610                                          ParentSource( Actor::SIZE ),
611                                          FirstOrderEquationConstraint(mBackgroundSize) );
612   constraint.SetApplyTime(durationSeconds);
613   constraint.SetAlphaFunction(alpha);
614   constraint.SetRemoveAction(Constraint::Bake);
615   background.ApplyConstraint(constraint);
616 }
617
618 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
619 {
620   Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
621                                          ParentSource( Actor::SIZE ),
622                                          FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
623   constraint.SetApplyTime(durationSeconds);
624   constraint.SetAlphaFunction(alpha);
625   constraint.SetRemoveAction(Constraint::Bake);
626   title.ApplyConstraint(constraint);
627
628   constraint = Constraint::New<Vector3>( Actor::SIZE,
629                                          ParentSource( Actor::SIZE ),
630                                          FirstOrderEquationConstraint(mTitleSize) );
631   constraint.SetApplyTime(durationSeconds);
632   constraint.SetAlphaFunction(alpha);
633   constraint.SetRemoveAction(Constraint::Bake);
634   title.ApplyConstraint(constraint);
635 }
636
637 } // namespace Internal
638
639 } // namespace Toolkit
640
641 } // namespace Dali