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