Remove obsolete and non functional SizeChanged signal from actor
[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 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 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/animation/animation.h>
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
25
26 namespace Dali
27 {
28
29 namespace // unnamed namespace
30 {
31 // Cluster style one
32
33 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
34
35 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
36
37 const float STYLE_1_CHILD_OFFSET_Z = 2.0f;
38 const float STYLE_1_CHILD_GAP_FACTOR = 0.03f;
39 const float STYLE_1_CHILD_SIZE_FACTOR[] = { 0.4f, 0.15f, 0.25f, 0.15f, 0.4f, 0.15f, 0.25f, 0.15f };
40 const Vector3 STYLE_1_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
41                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
42                                                             STYLE_1_CHILD_OFFSET_Z),
43                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
44                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[1] - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
45                                                             STYLE_1_CHILD_OFFSET_Z + 0.5f),
46                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
47                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[2] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
48                                                             STYLE_1_CHILD_OFFSET_Z + 1.0f),
49                                                     Vector3(0.5f + STYLE_1_CHILD_SIZE_FACTOR[2] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
50                                                             0.5f - STYLE_1_CHILD_SIZE_FACTOR[3] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
51                                                             STYLE_1_CHILD_OFFSET_Z + 1.5f),
52                                                     Vector3(0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
53                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
54                                                             STYLE_1_CHILD_OFFSET_Z + 2.0f),
55                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[5] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
56                                                             0.5f + STYLE_1_CHILD_SIZE_FACTOR[6] + STYLE_1_CHILD_GAP_FACTOR * 1.5f,
57                                                             STYLE_1_CHILD_OFFSET_Z + 2.5f),
58                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
59                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
60                                                             STYLE_1_CHILD_OFFSET_Z + 3.0f),
61                                                     Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[6] - STYLE_1_CHILD_SIZE_FACTOR[7] - STYLE_1_CHILD_GAP_FACTOR * 1.5f,
62                                                             0.5f + STYLE_1_CHILD_GAP_FACTOR * 0.5f,
63                                                             STYLE_1_CHILD_OFFSET_Z + 3.5f) };
64
65 const Vector3 STYLE_1_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
66 const Vector3 STYLE_1_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f,
67                                                         0.5f - STYLE_1_CHILD_SIZE_FACTOR[0] - STYLE_1_CHILD_GAP_FACTOR * 0.5f - STYLE_1_TITLE_SIZE_FACTOR.height + 0.02f,
68                                                         0.0f);
69 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
70
71 // Cluster style two
72
73 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
74
75 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
76
77 const float STYLE_2_CHILD_OFFSET_Z = 2.0f;
78 const float STYLE_2_CHILD_GAP_FACTOR = 0.03f;
79 const float STYLE_2_CHILD_SIZE_FACTOR[] = { 0.4f, 0.25f, 0.15f, 0.4f, 0.25f, 0.15f };
80 const Vector3 STYLE_2_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
81                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f,
82                                                             STYLE_2_CHILD_OFFSET_Z),
83                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
84                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[1] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
85                                                             STYLE_2_CHILD_OFFSET_Z + 0.5f),
86                                                     Vector3(0.5f + STYLE_2_CHILD_SIZE_FACTOR[1] + STYLE_2_CHILD_GAP_FACTOR * 1.5f,
87                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[2] - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f - STYLE_2_CHILD_GAP_FACTOR,
88                                                             STYLE_2_CHILD_OFFSET_Z + 1.0f),
89                                                     Vector3(0.5f + STYLE_2_CHILD_GAP_FACTOR * 0.5f,
90                                                             0.5f - STYLE_2_CHILD_SIZE_FACTOR[3] * 0.25f,
91                                                             STYLE_2_CHILD_OFFSET_Z + 1.5f),
92                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
93                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
94                                                             STYLE_2_CHILD_OFFSET_Z + 2.0f),
95                                                     Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[4] - STYLE_2_CHILD_SIZE_FACTOR[5] - STYLE_2_CHILD_GAP_FACTOR * 1.5f,
96                                                             0.5f + STYLE_2_CHILD_SIZE_FACTOR[0] * 0.25f + STYLE_2_CHILD_GAP_FACTOR,
97                                                             STYLE_2_CHILD_OFFSET_Z + 2.5f) };
98
99 const Vector3 STYLE_2_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
100 const Vector3 STYLE_2_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] - STYLE_2_CHILD_GAP_FACTOR * 0.5f,
101                                                         0.5f - STYLE_2_CHILD_SIZE_FACTOR[0] * 0.75f - STYLE_2_TITLE_SIZE_FACTOR.height + 0.02f,
102                                                         0.0f);
103 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
104
105 // Cluster style three
106
107 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
108
109 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
110
111 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
112
113 const float STYLE_3_CHILD_OFFSET_Z = 2.0f;
114 const float STYLE_3_CHILD_GAP_FACTOR = 0.03f;
115 const float STYLE_3_CHILD_SIZE_FACTOR[] = { 0.4f, 0.4f, 0.15f, 0.25f, 0.25f, 0.15f };
116 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;
117 const Vector3 STYLE_3_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
118                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
119                                                               STYLE_3_CHILD_OFFSET_Z),
120                                                       Vector3(0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f,
121                                                               0.5f - STYLE_3_CHILD_SIZE_FACTOR[1] - STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
122                                                               STYLE_3_CHILD_OFFSET_Z + 0.5f),
123                                                       Vector3(0.5f + STYLE_3_CHILD_SIZE_FACTOR[3] + STYLE_3_CHILD_GAP_FACTOR * 1.5f,
124                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
125                                                               STYLE_3_CHILD_OFFSET_Z + 1.0f),
126                                                       Vector3(0.5f + 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 + 1.5f),
129                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
130                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
131                                                               STYLE_3_CHILD_OFFSET_Z + 2.0f),
132                                                       Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[4] - STYLE_3_CHILD_SIZE_FACTOR[5] - STYLE_3_CHILD_GAP_FACTOR * 1.5f,
133                                                               0.5f + STYLE_3_CHILD_GAP_FACTOR * 0.5f + STYLE_3_CHILD_POSITION_OFFSET_Y,
134                                                               STYLE_3_CHILD_OFFSET_Z + 2.5f) };
135
136 const Vector3 STYLE_3_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_3_CHILD_SIZE_FACTOR[0] - STYLE_3_CHILD_GAP_FACTOR * 0.5f,
137                                                           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,
138                                                           0.0f);
139 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
140
141 // Cluster style four
142
143 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
144
145 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
146
147 const float STYLE_4_CHILD_OFFSET_Z = 2.0f;
148 const float STYLE_4_CHILD_GAP_FACTOR = 0.03f;
149 const float STYLE_4_CHILD_SIZE_FACTOR[] = { 0.4f, 0.22f, 0.13f, 0.4f, 0.22f, 0.13f };
150 const Vector3 STYLE_4_CHILD_POSITION_FACTOR[] = { Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
151                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
152                                                              STYLE_4_CHILD_OFFSET_Z),
153                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_GAP_FACTOR,
154                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[1] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
155                                                              STYLE_4_CHILD_OFFSET_Z + 0.5f),
156                                                      Vector3(0.5f + STYLE_4_CHILD_SIZE_FACTOR[0] * 0.1f + STYLE_4_CHILD_SIZE_FACTOR[1] + STYLE_4_CHILD_GAP_FACTOR * 2.0f,
157                                                              0.5f - STYLE_4_CHILD_SIZE_FACTOR[2] - STYLE_4_CHILD_GAP_FACTOR * 0.5f,
158                                                              STYLE_4_CHILD_OFFSET_Z + 1.0f),
159                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f,
160                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
161                                                              STYLE_4_CHILD_OFFSET_Z + 1.5f),
162                                                      Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[3] * 0.1f - STYLE_4_CHILD_SIZE_FACTOR[4] - STYLE_4_CHILD_GAP_FACTOR,
163                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
164                                                              STYLE_4_CHILD_OFFSET_Z + 2.0f),
165                                                      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,
166                                                              0.5f + STYLE_4_CHILD_GAP_FACTOR * 0.5f,
167                                                              STYLE_4_CHILD_OFFSET_Z + 2.5f) };
168
169 const Vector3 STYLE_4_TITLE_SIZE_FACTOR = Vector3(0.3f, 0.11f, 1.0f);
170 const Vector3 STYLE_4_TITLE_POSITION_FACTOR = Vector3(0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] * 0.9f,
171                                                          0.5f - STYLE_4_CHILD_SIZE_FACTOR[0] - STYLE_4_CHILD_GAP_FACTOR * 0.5f - STYLE_4_TITLE_SIZE_FACTOR.height + 0.02f,
172                                                          0.0f);
173 const Vector3 STYLE_4_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
174 const unsigned int CLUSTER_RANDOM_SEED(0x17eac9f3);         ///< Random seed for cluster data.
175
176 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
177
178 Vector3 FirstOrderEquation( const Vector3& source, const Vector3& relative, const Vector3& offset = Vector3::ZERO  )
179 {
180   return source * relative + offset;
181 }
182
183 // random data generator //////////////////////////////////////////////////////
184
185 const unsigned int GEN_RAND_CONST = 0x15d9a373;
186
187 unsigned int genRandom(unsigned int& seed, unsigned int offset)
188 {
189   unsigned int shft = offset&31;
190
191   offset++;
192
193   seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
194
195   return seed;
196 }
197
198 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
199 {
200   const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
201   return f * (max - min) + min;
202 }
203
204 } // unnamed namespace
205
206 namespace Toolkit
207 {
208
209 namespace Internal
210 {
211
212 // ClusterStyle ///////////////////////////////////////////////////////////////
213
214 ClusterStyle::ClusterStyle()
215 : mMaxChildren(0),
216   mTitlePositionRelative(Vector3::ONE),
217   mTitlePositionOffset(Vector3::ZERO),
218   mTitleSize(Vector3::ONE),
219   mBackgroundPositionRelative(Vector3::ONE),
220   mBackgroundPositionOffset(Vector3::ZERO),
221   mBackgroundSize(Vector3::ONE),
222   mClusterSize( Vector3::ZERO )
223 {
224 }
225
226 ClusterStyle::~ClusterStyle()
227 {
228
229 }
230
231 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
232 {
233   mMaxChildren = maxChildren;
234 }
235
236 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
237 {
238   return mMaxChildren;
239 }
240
241 void ClusterStyle::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
242 {
243   Apply( background,
244          FirstOrderEquation( GetClusterSize(), mBackgroundPositionRelative, mBackgroundPositionOffset ),
245          FirstOrderEquation( GetClusterSize(), mBackgroundSize ),
246          alpha,
247          durationSeconds);
248 }
249
250 void ClusterStyle::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
251 {
252   Apply( title,
253          FirstOrderEquation( GetClusterSize(), mTitlePositionRelative, mTitlePositionOffset ),
254          FirstOrderEquation( GetClusterSize(), mTitleSize ),
255          alpha,
256          durationSeconds);
257 }
258
259 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
260                                       const Vector3& offsetPosition,
261                                       const Vector3& size)
262 {
263   mTitlePositionRelative = relativePosition;
264   mTitlePositionOffset = offsetPosition;
265   mTitleSize = size;
266 }
267
268 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
269                                            const Vector3& offsetPosition,
270                                            const Vector3& size)
271 {
272   mBackgroundPositionRelative = relativePosition;
273   mBackgroundPositionOffset = offsetPosition;
274   mBackgroundSize = size;
275 }
276
277 void ClusterStyle::SetClusterSize( const Vector3& clusterSize )
278 {
279   mClusterSize = clusterSize;
280 }
281
282 Vector3 ClusterStyle::GetClusterSize() const
283 {
284   return mClusterSize;
285 }
286
287 void ClusterStyle::Apply( Actor actor,
288                           const Vector3& position,
289                           const Vector3& size,
290                           AlphaFunction alpha,
291                           const TimePeriod& durationSeconds)
292 {
293   float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds;
294   if( animationDuration > 0.f )
295   {
296     Animation animation = Animation::New(animationDuration);
297     animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
298     animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
299     animation.Play();
300   }
301   else
302   {
303     actor.SetPosition( position );
304     actor.SetSize( size );
305   }
306 }
307
308 void ClusterStyle::Apply( Actor actor,
309                           const Vector3& position,
310                           const Vector3& size,
311                           const Quaternion& rotation,
312                           const Vector3& scale,
313                           AlphaFunction alpha,
314                           const TimePeriod& durationSeconds)
315 {
316   float animationDuration = durationSeconds.delaySeconds + durationSeconds.durationSeconds;
317   if( animationDuration > 0.f )
318   {
319     Animation animation = Animation::New(animationDuration);
320     animation.MoveTo( actor, position, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
321     animation.Resize( actor, size, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
322     animation.RotateTo( actor, rotation, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
323     animation.ScaleTo( actor, scale, alpha, durationSeconds.delaySeconds, durationSeconds.durationSeconds );
324     animation.Play();
325   }
326   else
327   {
328     actor.SetPosition( position );
329     actor.SetSize( size );
330     actor.SetRotation( rotation );
331     actor.SetScale( scale );
332   }
333 }
334
335 // ClusterStyleStandard ///////////////////////////////////////////////////////
336
337 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
338 {
339   ClusterStylePtr impl( new ClusterStyleStandard(style) );
340
341   return impl;
342 }
343
344 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
345 : ClusterStyle(),
346   mSizes(NULL),
347   mPositions(NULL)
348 {
349   switch(style)
350   {
351     case Toolkit::ClusterStyleStandard::ClusterStyle1:
352     {
353       SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
354       SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
355       SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
356       SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
357                          STYLE_1_TITLE_POSITION_OFFSET,
358                          STYLE_1_TITLE_SIZE_FACTOR);
359       SetBackgroundProperties(Vector3::ZERO,
360                               Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
361                               Vector3::ONE);
362       break;
363     }
364     case Toolkit::ClusterStyleStandard::ClusterStyle2:
365     {
366       SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
367       SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
368       SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
369       SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
370                          STYLE_2_TITLE_POSITION_OFFSET,
371                          STYLE_2_TITLE_SIZE_FACTOR);
372       SetBackgroundProperties(Vector3::ZERO,
373                               Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
374                               Vector3::ONE);
375       break;
376     }
377     case Toolkit::ClusterStyleStandard::ClusterStyle3:
378     {
379       SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
380       SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
381       SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
382       SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
383                          STYLE_3_TITLE_POSITION_OFFSET,
384                          STYLE_3_TITLE_SIZE_FACTOR);
385       SetBackgroundProperties(Vector3::ZERO,
386                               Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
387                               Vector3::ONE);
388       break;
389     }
390     case Toolkit::ClusterStyleStandard::ClusterStyle4:
391     {
392       SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
393       SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
394       SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
395       SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
396                          STYLE_4_TITLE_POSITION_OFFSET,
397                          STYLE_4_TITLE_SIZE_FACTOR);
398       SetBackgroundProperties(Vector3::ZERO,
399                               Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
400                               Vector3::ONE);
401       break;
402     }
403     default:
404     {
405       DALI_ASSERT_ALWAYS(false && "Invalid Style");
406       break;
407     }
408   } // end switch
409 }
410
411 void ClusterStyleStandard::SetSizes(const float *sizes)
412 {
413   mSizes = sizes;
414 }
415
416 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
417 {
418   mPositions = positions;
419 }
420
421 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
422 {
423   if(mPositions)
424   {
425     const float& size = mSizes[index];
426     // counter top-left parent origin and top-left anchor point.
427     const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
428
429     Apply( child,
430            FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, position.z) ),
431            FirstOrderEquation( GetClusterSize(), Vector3::ONE * size ),
432            Quaternion(),
433            Vector3::ONE,
434            alpha,
435            durationSeconds);
436   }
437 }
438
439 // ClusterStyleRandom /////////////////////////////////////////////////////////
440
441 ClusterStylePtr ClusterStyleRandom::New()
442 {
443   ClusterStylePtr impl( new ClusterStyleRandom() );
444
445   return impl;
446 }
447
448 ClusterStyleRandom::ClusterStyleRandom()
449 : ClusterStyle()
450 {
451   SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
452   SetTitleProperties(Vector3::ZERO,
453                      Vector3::ZERO,
454                      Vector3::ONE);
455   SetBackgroundProperties(Vector3::ZERO,
456                           Vector3(0.0f, 0.0f, 0.0f),
457                           Vector3::ONE);
458 }
459
460 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
461 {
462   unsigned int seed = CLUSTER_RANDOM_SEED;
463   const float size = 0.5f;
464   const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
465   const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
466                          genRandomFloat(seed, index, -0.1f, 0.1f),
467                          0.0f);
468
469   Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
470   float depthPropertyValue = child.GetProperty<float>( depthProperty );
471
472
473   Apply( child,
474          FirstOrderEquation( GetClusterSize(), Vector3(position.x, position.y, 0.0f), Vector3(0.0f, 0.0f, depthPropertyValue) ),
475          FirstOrderEquation( GetClusterSize(), Vector3::ONE * size),
476          Quaternion(rotation, Vector3::ZAXIS),
477          Vector3::ONE,
478          alpha,
479          durationSeconds);
480 }
481
482 } // namespace Internal
483
484 } // namespace Toolkit
485
486 } // namespace Dali