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/dali.h>
20 #include <dali-toolkit/internal/controls/cluster/cluster-style-impl.h>
21 #include <dali-toolkit/public-api/controls/cluster/cluster.h>
26 namespace // unnamed namespace
30 const unsigned int STYLE_1_CHILDREN_NUMBER = 8;
32 const float STYLE_1_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
66 const Vector3 STYLE_1_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
70 const unsigned int STYLE_2_CHILDREN_NUMBER = 6;
72 const float STYLE_2_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
100 const Vector3 STYLE_2_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
102 // Cluster style three
104 const unsigned int STYLE_3_CHILDREN_NUMBER = 6;
106 const Vector3 STYLE_3_TITLE_SIZE_FACTOR = Vector3(0.4f, 0.15f, 1.0f);
108 const float STYLE_3_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
136 const Vector3 STYLE_3_TITLE_POSITION_OFFSET = Vector3(0.0f, 0.0f, 8.0f);
138 // Cluster style four
140 const unsigned int STYLE_4_CHILDREN_NUMBER = 6;
142 const float STYLE_4_BACKGROUND_IMAGE_OFFSET_Z = 1.0f;
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) };
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,
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.
173 const int STYLE_RANDOM_CHILDREN_NUMBER = 16;
178 * First order equation of the form y = Mx + C
179 * current' = current * relative + offset
181 struct FirstOrderEquationConstraint
184 * @param relative The relative multiplier of the source property
185 * @param offset The offset to add onto the result.
187 FirstOrderEquationConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
188 : mRelative(relative),
193 Vector3 operator()(const Vector3& current,
194 const PropertyInput& sourceProperty)
196 const Vector3 source = sourceProperty.GetVector3();
198 return source * mRelative + mOffset;
209 * current' = current.xy | + Vector3::ONE.z
211 struct DepthConstraint
220 Vector3 operator()(const Vector3& current,
221 const PropertyInput& depthProperty)
223 Vector3 position(current);
224 position.z = depthProperty.GetFloat();
231 * Position Constraint.
232 * current' = current * relative + offset
234 struct PositionConstraint
237 * @param relative The relative multiplier of the source property
238 * @param offset The offset to add onto the result.
240 PositionConstraint(Vector3 relative, Vector3 offset = Vector3::ZERO)
241 : mRelative(relative),
246 Vector3 operator()(const Vector3& current,
247 const PropertyInput& sourceProperty,
248 const PropertyInput& depthProperty)
250 const Vector3 source = sourceProperty.GetVector3();
252 Vector3 position(source * mRelative + mOffset);
253 position.z += depthProperty.GetFloat();
266 SetConstraint(T value)
272 T operator()(const T& current)
280 // random data generator //////////////////////////////////////////////////////
282 const unsigned int GEN_RAND_CONST = 0x15d9a373;
284 unsigned int genRandom(unsigned int& seed, unsigned int offset)
286 unsigned int shft = offset&31;
290 seed^= (seed << (shft) | seed >> (32 - shft)) * (offset * GEN_RAND_CONST);
295 float genRandomFloat(unsigned int& seed, unsigned int offset, float min, float max)
297 const float f = static_cast<float>(genRandom(seed, offset)) / 0xffffffff;
298 return f * (max - min) + min;
301 } // unnamed namespace
309 // ClusterStyle ///////////////////////////////////////////////////////////////
311 ClusterStyle::ClusterStyle()
313 mTitlePositionRelative(Vector3::ONE),
314 mTitlePositionOffset(Vector3::ZERO),
315 mTitleSize(Vector3::ONE),
316 mBackgroundPositionRelative(Vector3::ONE),
317 mBackgroundPositionOffset(Vector3::ZERO),
318 mBackgroundSize(Vector3::ONE)
322 ClusterStyle::~ClusterStyle()
327 void ClusterStyle::SetMaximumNumberOfChildren(unsigned int maxChildren)
329 mMaxChildren = maxChildren;
332 unsigned int ClusterStyle::GetMaximumNumberOfChildren() const
337 void ClusterStyle::SetTitleProperties(const Vector3& relativePosition,
338 const Vector3& offsetPosition,
341 mTitlePositionRelative = relativePosition;
342 mTitlePositionOffset = offsetPosition;
346 void ClusterStyle::SetBackgroundProperties(const Vector3& relativePosition,
347 const Vector3& offsetPosition,
350 mBackgroundPositionRelative = relativePosition;
351 mBackgroundPositionOffset = offsetPosition;
352 mBackgroundSize = size;
355 // ClusterStyleStandard ///////////////////////////////////////////////////////
357 ClusterStylePtr ClusterStyleStandard::New(StyleType style)
359 ClusterStylePtr impl( new ClusterStyleStandard(style) );
364 ClusterStyleStandard::ClusterStyleStandard(StyleType style)
371 case Toolkit::ClusterStyleStandard::ClusterStyle1:
373 SetMaximumNumberOfChildren(STYLE_1_CHILDREN_NUMBER);
374 SetSizes(STYLE_1_CHILD_SIZE_FACTOR);
375 SetPositions(STYLE_1_CHILD_POSITION_FACTOR);
376 SetTitleProperties(STYLE_1_TITLE_POSITION_FACTOR,
377 STYLE_1_TITLE_POSITION_OFFSET,
378 STYLE_1_TITLE_SIZE_FACTOR);
379 SetBackgroundProperties(Vector3::ZERO,
380 Vector3(0.0f, 0.0f, STYLE_1_BACKGROUND_IMAGE_OFFSET_Z),
384 case Toolkit::ClusterStyleStandard::ClusterStyle2:
386 SetMaximumNumberOfChildren(STYLE_2_CHILDREN_NUMBER);
387 SetSizes(STYLE_2_CHILD_SIZE_FACTOR);
388 SetPositions(STYLE_2_CHILD_POSITION_FACTOR);
389 SetTitleProperties(STYLE_2_TITLE_POSITION_FACTOR,
390 STYLE_2_TITLE_POSITION_OFFSET,
391 STYLE_2_TITLE_SIZE_FACTOR);
392 SetBackgroundProperties(Vector3::ZERO,
393 Vector3(0.0f, 0.0f, STYLE_2_BACKGROUND_IMAGE_OFFSET_Z),
397 case Toolkit::ClusterStyleStandard::ClusterStyle3:
399 SetMaximumNumberOfChildren(STYLE_3_CHILDREN_NUMBER);
400 SetSizes(STYLE_3_CHILD_SIZE_FACTOR);
401 SetPositions(STYLE_3_CHILD_POSITION_FACTOR);
402 SetTitleProperties(STYLE_3_TITLE_POSITION_FACTOR,
403 STYLE_3_TITLE_POSITION_OFFSET,
404 STYLE_3_TITLE_SIZE_FACTOR);
405 SetBackgroundProperties(Vector3::ZERO,
406 Vector3(0.0f, 0.0f, STYLE_3_BACKGROUND_IMAGE_OFFSET_Z),
410 case Toolkit::ClusterStyleStandard::ClusterStyle4:
412 SetMaximumNumberOfChildren(STYLE_4_CHILDREN_NUMBER);
413 SetSizes(STYLE_4_CHILD_SIZE_FACTOR);
414 SetPositions(STYLE_4_CHILD_POSITION_FACTOR);
415 SetTitleProperties(STYLE_4_TITLE_POSITION_FACTOR,
416 STYLE_4_TITLE_POSITION_OFFSET,
417 STYLE_4_TITLE_SIZE_FACTOR);
418 SetBackgroundProperties(Vector3::ZERO,
419 Vector3(0.0f, 0.0f, STYLE_4_BACKGROUND_IMAGE_OFFSET_Z),
425 DALI_ASSERT_ALWAYS(false && "Invalid Style");
431 void ClusterStyleStandard::SetSizes(const float *sizes)
436 void ClusterStyleStandard::SetPositions(const Vector3 *positions)
438 mPositions = positions;
441 void ClusterStyleStandard::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
445 const float& size = mSizes[index];
446 // counter top-left parent origin and top-left anchor point.
447 const Vector3 position = mPositions[index] - Vector3(0.5f, 0.5f, 0.0f) + Vector3(size, size, 0.0f) * 0.5f;
449 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
450 ParentSource( Actor::SIZE ),
451 FirstOrderEquationConstraint(Vector3(position.x, position.y, 0.0f),
452 Vector3(0.0f, 0.0f, position.z)) );
454 constraint.SetApplyTime(durationSeconds);
455 constraint.SetAlphaFunction(alpha);
456 constraint.SetRemoveAction(Constraint::Bake);
457 child.ApplyConstraint(constraint);
459 constraint = Constraint::New<Vector3>( Actor::SIZE,
460 ParentSource( Actor::SIZE ),
461 FirstOrderEquationConstraint(Vector3::ONE * size) );
462 constraint.SetApplyTime(durationSeconds);
463 constraint.SetAlphaFunction(alpha);
464 constraint.SetRemoveAction(Constraint::Bake);
465 child.ApplyConstraint(constraint);
467 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
468 SetConstraint<Quaternion>(Quaternion()) );
469 constraint.SetApplyTime(durationSeconds);
470 constraint.SetAlphaFunction(alpha);
471 constraint.SetRemoveAction(Constraint::Bake);
472 child.ApplyConstraint(constraint);
474 constraint = Constraint::New<Vector3>( Actor::SCALE,
475 SetConstraint<Vector3>(Vector3::ONE) );
476 constraint.SetApplyTime(durationSeconds);
477 constraint.SetAlphaFunction(alpha);
478 constraint.SetRemoveAction(Constraint::Bake);
479 child.ApplyConstraint(constraint);
483 void ClusterStyleStandard::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
485 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
486 ParentSource( Actor::SIZE ),
487 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
488 constraint.SetApplyTime(durationSeconds);
489 constraint.SetAlphaFunction(alpha);
490 constraint.SetRemoveAction(Constraint::Bake);
491 background.ApplyConstraint(constraint);
493 constraint = Constraint::New<Vector3>( Actor::SIZE,
494 ParentSource( Actor::SIZE ),
495 FirstOrderEquationConstraint(mBackgroundSize) );
496 constraint.SetApplyTime(durationSeconds);
497 constraint.SetAlphaFunction(alpha);
498 constraint.SetRemoveAction(Constraint::Bake);
499 background.ApplyConstraint(constraint);
502 void ClusterStyleStandard::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
504 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
505 ParentSource( Actor::SIZE ),
506 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
507 constraint.SetApplyTime(durationSeconds);
508 constraint.SetAlphaFunction(alpha);
509 constraint.SetRemoveAction(Constraint::Bake);
510 title.ApplyConstraint(constraint);
512 constraint = Constraint::New<Vector3>( Actor::SIZE,
513 ParentSource( Actor::SIZE ),
514 FirstOrderEquationConstraint(mTitleSize) );
515 constraint.SetApplyTime(durationSeconds);
516 constraint.SetAlphaFunction(alpha);
517 constraint.SetRemoveAction(Constraint::Bake);
518 title.ApplyConstraint(constraint);
521 // ClusterStyleRandom /////////////////////////////////////////////////////////
523 ClusterStylePtr ClusterStyleRandom::New()
525 ClusterStylePtr impl( new ClusterStyleRandom() );
530 ClusterStyleRandom::ClusterStyleRandom()
533 SetMaximumNumberOfChildren(STYLE_RANDOM_CHILDREN_NUMBER);
534 SetTitleProperties(Vector3::ZERO,
537 SetBackgroundProperties(Vector3::ZERO,
538 Vector3(0.0f, 0.0f, 0.0f),
542 void ClusterStyleRandom::ApplyStyle(Actor child, unsigned int index, AlphaFunction alpha, const TimePeriod& durationSeconds)
544 unsigned int seed = CLUSTER_RANDOM_SEED;
545 const float size = 0.5f;
546 const float rotation = genRandomFloat(seed, index, -1.0f, 1.0f) * Math::PI * 0.1; // +/- 18 degrees
547 const Vector3 position(genRandomFloat(seed, index, -0.1f, 0.1f),
548 genRandomFloat(seed, index, -0.1f, 0.1f),
551 Property::Index depthProperty = child.GetPropertyIndex(Toolkit::Cluster::CLUSTER_ACTOR_DEPTH);
553 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
554 ParentSource( Actor::SIZE ),
555 FirstOrderEquationConstraint( Vector3(position.x, position.y, 0.0f),
556 Vector3(0.0f, 0.0f, position.z) ) );
558 constraint.SetApplyTime(durationSeconds);
559 constraint.SetAlphaFunction(alpha);
560 constraint.SetRemoveAction(Constraint::Bake);
561 child.ApplyConstraint(constraint);
563 // this constraint overrides the Z position. setting it to cluster-actor-depth
564 constraint = Constraint::New<Vector3>( Actor::POSITION,
565 LocalSource( depthProperty ),
568 constraint.SetAlphaFunction(alpha);
569 constraint.SetRemoveAction(Constraint::Bake);
570 child.ApplyConstraint(constraint);
572 constraint = Constraint::New<Vector3>( Actor::SIZE,
573 ParentSource( Actor::SIZE ),
574 FirstOrderEquationConstraint(Vector3::ONE * size) );
575 constraint.SetApplyTime(durationSeconds);
576 constraint.SetAlphaFunction(alpha);
577 constraint.SetRemoveAction(Constraint::Bake);
578 child.ApplyConstraint(constraint);
580 constraint = Constraint::New<Quaternion>( Actor::ROTATION,
581 SetConstraint<Quaternion>(Quaternion(rotation, Vector3::ZAXIS)) );
582 constraint.SetApplyTime(durationSeconds);
583 constraint.SetAlphaFunction(alpha);
584 constraint.SetRemoveAction(Constraint::Bake);
585 child.ApplyConstraint(constraint);
587 constraint = Constraint::New<Vector3>( Actor::SCALE,
588 SetConstraint<Vector3>(Vector3::ONE) );
589 constraint.SetApplyTime(durationSeconds);
590 constraint.SetAlphaFunction(alpha);
591 constraint.SetRemoveAction(Constraint::Bake);
592 child.ApplyConstraint(constraint);
595 void ClusterStyleRandom::ApplyStyleToBackground(Actor background, AlphaFunction alpha, const TimePeriod& durationSeconds)
597 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
598 ParentSource( Actor::SIZE ),
599 FirstOrderEquationConstraint(mBackgroundPositionRelative, mBackgroundPositionOffset) );
600 constraint.SetApplyTime(durationSeconds);
601 constraint.SetAlphaFunction(alpha);
602 constraint.SetRemoveAction(Constraint::Bake);
603 background.ApplyConstraint(constraint);
605 constraint = Constraint::New<Vector3>( Actor::SIZE,
606 ParentSource( Actor::SIZE ),
607 FirstOrderEquationConstraint(mBackgroundSize) );
608 constraint.SetApplyTime(durationSeconds);
609 constraint.SetAlphaFunction(alpha);
610 constraint.SetRemoveAction(Constraint::Bake);
611 background.ApplyConstraint(constraint);
614 void ClusterStyleRandom::ApplyStyleToTitle(Actor title, AlphaFunction alpha, const TimePeriod& durationSeconds)
616 Constraint constraint = Constraint::New<Vector3>( Actor::POSITION,
617 ParentSource( Actor::SIZE ),
618 FirstOrderEquationConstraint(mTitlePositionRelative, mTitlePositionOffset) );
619 constraint.SetApplyTime(durationSeconds);
620 constraint.SetAlphaFunction(alpha);
621 constraint.SetRemoveAction(Constraint::Bake);
622 title.ApplyConstraint(constraint);
624 constraint = Constraint::New<Vector3>( Actor::SIZE,
625 ParentSource( Actor::SIZE ),
626 FirstOrderEquationConstraint(mTitleSize) );
627 constraint.SetApplyTime(durationSeconds);
628 constraint.SetAlphaFunction(alpha);
629 constraint.SetRemoveAction(Constraint::Bake);
630 title.ApplyConstraint(constraint);
633 } // namespace Internal
635 } // namespace Toolkit