2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
24 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
29 namespace // unnamed namespace
33 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
35 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
69 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
73 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
75 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
103 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
105 // Cluster style three
107 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
109 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
111 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
139 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
141 // Cluster style four
143 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
145 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
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.
176 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
181 * First order equation of the form y = Mx + C
182 * current' = current * relative + offset
184 struct FirstOrderEquationConstraint
187 * @param relative The relative multiplier of the source property
188 * @param offset The offset to add onto the result.
190 FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
191 : mRelative(relative),
196 Vector3 operator()(const Vector3& current,
197 const PropertyInput& sourceProperty)
199 const Vector3 source = sourceProperty.GetVector3();
201 return source * mRelative + mOffset;
212 * current' = current.xy | + Vector3::ONE.z
214 struct DepthConstraint
223 Vector3 operator()(const Vector3& current,
224 const PropertyInput& depthProperty)
226 Vector3 position(current);
227 position.z = depthProperty.GetFloat();
234 * Position Constraint.
235 * current' = current * relative + offset
237 struct PositionConstraint
240 * @param relative The relative multiplier of the source property
241 * @param offset The offset to add onto the result.
243 PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
244 : mRelative(relative),
249 Vector3 operator()(const Vector3& current,
250 const PropertyInput& sourceProperty,
251 const PropertyInput& depthProperty)
253 const Vector3 source = sourceProperty.GetVector3();
255 Vector3 position(source * mRelative + mOffset);
256 position.z += depthProperty.GetFloat();
269 SetConstraint(T value)
275 T operator()(const T& current)
283 // random data generator //////////////////////////////////////////////////////
285 const unsigned int GEN_RAND_CONST = 0x15d9a373;
287 unsigned int genRandom(unsigned int& seed, unsigned int offset)
289 unsigned int shft = offset&31;
293 seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
298 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
300 const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
301 return f * (max - min) + min;
304 } // unnamed namespace
312 // ClusterStyle ///////////////////////////////////////////////////////////////
314 ClusterStyle::ClusterStyle()
316 mTitlePositionRelative(Vector3::ONE),
317 mTitlePositionOffset(Vector3::ZERO),
318 mTitleSize(Vector3::ONE),
319 mBackgroundPositionRelative(Vector3::ONE),
320 mBackgroundPositionOffset(Vector3::ZERO),
321 mBackgroundSize(Vector3::ONE)
325 ClusterStyle::~ClusterStyle()
330 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
332 mMaxChildren = maxChildren;
335 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
340 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
341 const Vector3& offsetPosition,
344 mTitlePositionRelative = relativePosition;
345 mTitlePositionOffset = offsetPosition;
349 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
350 const Vector3& offsetPosition,
353 mBackgroundPositionRelative = relativePosition;
354 mBackgroundPositionOffset = offsetPosition;
355 mBackgroundSize = size;
358 // ClusterStyleStandard ///////////////////////////////////////////////////////
360 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
362 ClusterStylePtr impl( new ClusterStyleStandard(style) );
367 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
374 case Toolkit::ClusterStyleStandard::ClusterStyle1:
376 SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
377 SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
378 SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
379 SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
380 STYLE_1_TITLE_POSITION_OFFSET,
381 STYLE_1_TITLE_SIZE_FACTOR);
382 SetBackgroundProperties(Vector3::ZERO,
383 Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
387 case Toolkit::ClusterStyleStandard::ClusterStyle2:
389 SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
390 SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
391 SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
392 SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
393 STYLE_2_TITLE_POSITION_OFFSET,
394 STYLE_2_TITLE_SIZE_FACTOR);
395 SetBackgroundProperties(Vector3::ZERO,
396 Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
400 case Toolkit::ClusterStyleStandard::ClusterStyle3:
402 SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
403 SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
404 SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
405 SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
406 STYLE_3_TITLE_POSITION_OFFSET,
407 STYLE_3_TITLE_SIZE_FACTOR);
408 SetBackgroundProperties(Vector3::ZERO,
409 Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
413 case Toolkit::ClusterStyleStandard::ClusterStyle4:
415 SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
416 SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
417 SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
418 SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
419 STYLE_4_TITLE_POSITION_OFFSET,
420 STYLE_4_TITLE_SIZE_FACTOR);
421 SetBackgroundProperties(Vector3::ZERO,
422 Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
428 DALI_ASSERT_ALWAYS(false && "Invalid Style");
434 void ClusterStyleStandard::SetSizes(const float *sizes)
439 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
441 mPositions = positions;
444 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
448 const float& size = mSizes[index];
449 // counter top-left parent origin and top-left anchor point.
450 const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
452 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
453 ParentSource( Actor::SIZE ),
454 FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
455 Vector3(0.0f, 0.0f, position.z)) );
457 constraint.SetApplyTime(durationSeconds);
458 constraint.SetAlphaFunction(alpha);
459 constraint.SetRemoveAction(Constraint::Bake);
460 child.ApplyConstraint(constraint);
462 constraint = Constraint::New<Vector3>( Actor::SIZE,
463 ParentSource( Actor::SIZE ),
464 FirstOrderEquationConstraint(Vector3::ONE * size) );
465 constraint.SetApplyTime(durationSeconds);
466 constraint.SetAlphaFunction(alpha);
467 constraint.SetRemoveAction(Constraint::Bake);
468 child.ApplyConstraint(constraint);
470 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
471 SetConstraint<Quaternion>(Quaternion()) );
472 constraint.SetApplyTime(durationSeconds);
473 constraint.SetAlphaFunction(alpha);
474 constraint.SetRemoveAction(Constraint::Bake);
475 child.ApplyConstraint(constraint);
477 constraint = Constraint::New<Vector3>( Actor::SCALE,
478 SetConstraint<Vector3>(Vector3::ONE) );
479 constraint.SetApplyTime(durationSeconds);
480 constraint.SetAlphaFunction(alpha);
481 constraint.SetRemoveAction(Constraint::Bake);
482 child.ApplyConstraint(constraint);
486 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
488 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
489 ParentSource( Actor::SIZE ),
490 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
491 constraint.SetApplyTime(durationSeconds);
492 constraint.SetAlphaFunction(alpha);
493 constraint.SetRemoveAction(Constraint::Bake);
494 background.ApplyConstraint(constraint);
496 constraint = Constraint::New<Vector3>( Actor::SIZE,
497 ParentSource( Actor::SIZE ),
498 FirstOrderEquationConstraint(mBackgroundSize) );
499 constraint.SetApplyTime(durationSeconds);
500 constraint.SetAlphaFunction(alpha);
501 constraint.SetRemoveAction(Constraint::Bake);
502 background.ApplyConstraint(constraint);
505 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
507 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
508 ParentSource( Actor::SIZE ),
509 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
510 constraint.SetApplyTime(durationSeconds);
511 constraint.SetAlphaFunction(alpha);
512 constraint.SetRemoveAction(Constraint::Bake);
513 title.ApplyConstraint(constraint);
515 constraint = Constraint::New<Vector3>( Actor::SIZE,
516 ParentSource( Actor::SIZE ),
517 FirstOrderEquationConstraint(mTitleSize) );
518 constraint.SetApplyTime(durationSeconds);
519 constraint.SetAlphaFunction(alpha);
520 constraint.SetRemoveAction(Constraint::Bake);
521 title.ApplyConstraint(constraint);
524 // ClusterStyleRandom /////////////////////////////////////////////////////////
526 ClusterStylePtr ClusterStyleRandom::New()
528 ClusterStylePtr impl( new ClusterStyleRandom() );
533 ClusterStyleRandom::ClusterStyleRandom()
536 SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
537 SetTitleProperties(Vector3::ZERO,
540 SetBackgroundProperties(Vector3::ZERO,
541 Vector3(0.0f, 0.0f, 0.0f),
545 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
547 unsigned int seed = CLUSTER_RANDOM_SEED;
548 const float size = 0.5f;
549 const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
550 const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
551 genRandomFloat(seed, index, -0.1f, 0.1f),
554 Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
556 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
557 ParentSource( Actor::SIZE ),
558 FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
559 Vector3(0.0f, 0.0f, position.z) ) );
561 constraint.SetApplyTime(durationSeconds);
562 constraint.SetAlphaFunction(alpha);
563 constraint.SetRemoveAction(Constraint::Bake);
564 child.ApplyConstraint(constraint);
566 // this constraint overrides the Z position. setting it to cluster-actor-depth
567 constraint = Constraint::New<Vector3>( Actor::POSITION,
568 LocalSource( depthProperty ),
571 constraint.SetAlphaFunction(alpha);
572 constraint.SetRemoveAction(Constraint::Bake);
573 child.ApplyConstraint(constraint);
575 constraint = Constraint::New<Vector3>( Actor::SIZE,
576 ParentSource( Actor::SIZE ),
577 FirstOrderEquationConstraint(Vector3::ONE * size) );
578 constraint.SetApplyTime(durationSeconds);
579 constraint.SetAlphaFunction(alpha);
580 constraint.SetRemoveAction(Constraint::Bake);
581 child.ApplyConstraint(constraint);
583 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
584 SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
585 constraint.SetApplyTime(durationSeconds);
586 constraint.SetAlphaFunction(alpha);
587 constraint.SetRemoveAction(Constraint::Bake);
588 child.ApplyConstraint(constraint);
590 constraint = Constraint::New<Vector3>( Actor::SCALE,
591 SetConstraint<Vector3>(Vector3::ONE) );
592 constraint.SetApplyTime(durationSeconds);
593 constraint.SetAlphaFunction(alpha);
594 constraint.SetRemoveAction(Constraint::Bake);
595 child.ApplyConstraint(constraint);
598 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
600 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
601 ParentSource( Actor::SIZE ),
602 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
603 constraint.SetApplyTime(durationSeconds);
604 constraint.SetAlphaFunction(alpha);
605 constraint.SetRemoveAction(Constraint::Bake);
606 background.ApplyConstraint(constraint);
608 constraint = Constraint::New<Vector3>( Actor::SIZE,
609 ParentSource( Actor::SIZE ),
610 FirstOrderEquationConstraint(mBackgroundSize) );
611 constraint.SetApplyTime(durationSeconds);
612 constraint.SetAlphaFunction(alpha);
613 constraint.SetRemoveAction(Constraint::Bake);
614 background.ApplyConstraint(constraint);
617 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
619 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
620 ParentSource( Actor::SIZE ),
621 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
622 constraint.SetApplyTime(durationSeconds);
623 constraint.SetAlphaFunction(alpha);
624 constraint.SetRemoveAction(Constraint::Bake);
625 title.ApplyConstraint(constraint);
627 constraint = Constraint::New<Vector3>( Actor::SIZE,
628 ParentSource( Actor::SIZE ),
629 FirstOrderEquationConstraint(mTitleSize) );
630 constraint.SetApplyTime(durationSeconds);
631 constraint.SetAlphaFunction(alpha);
632 constraint.SetRemoveAction(Constraint::Bake);
633 title.ApplyConstraint(constraint);
636 } // namespace Internal
638 } // namespace Toolkit