2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
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.
18 #include <dali-toolkit/public-api/controls/scrollable/item-view/album-layout.h>
21 using namespace Dali::Toolkit;
24 namespace // unnamed namespace
26 const float DEFAULT_SCROLL_SPEED_FACTOR = 0.005f;
27 const float DEFAULT_MAXIMUM_SWIPE_SPEED = 3.0f;
28 const float DEFAULT_ITEM_FLICK_ANIMATION_DURATION = 0.25f;
30 const float SELECTED_RIGHT = 2.5f;
31 const float SELECTED_LEFT = 3.5f;
32 const float SELECTED_CENTER = 3.0f;
34 const float LAYOUT_POSITION_NAGATIVE_1 = -1.0f;
35 const float LAYOUT_POSITION_0 = 0.0f;
36 const float LAYOUT_POSITION_2 = 2.0f;
37 const float LAYOUT_POSITION_3 = 3.0f;
38 const float LAYOUT_POSITION_4 = 4.0f;
39 const float LAYOUT_POSITION_6 = 6.0f;
40 const float LAYOUT_POSITION_7 = 7.0f;
42 const Vector3 POSITION_0 = Vector3(850.0f,-250.0f,0.0f);
43 const Vector3 POSITION_1 = Vector3(700.0f,50.0f,0.0f);
44 const Vector3 POSITION_2 = Vector3(440.0f,227.0f,0.0f);
45 const Vector3 POSITION_4 = Vector3(-440.0f,227.0f,0.0f);
46 const Vector3 POSITION_5 = Vector3(-700.0f,50.0f,0.0f);
47 const Vector3 POSITION_6 = Vector3(-850.0f,-250.0f,0.0f);
49 const float ROTATION_0 = Math::PI/6.0f;
50 const float ROTATION_1 = 0.0f;
51 const float ROTATION_2 = Math::PI/6.0f;
52 const float ROTATION_4 = -Math::PI/6.0f;
53 const float ROTATION_5 = 0.0f;
54 const float ROTATION_6 = -Math::PI/6.0f;
56 const float SCALE = 1.0f;
58 const Vector2 COLOR = Vector2(1.0f,1.0f);
60 const Vector3 SELECTED_ITEM_POSITION = Vector3( 0.0f,-80.0f,140.0f);
61 const float SELECETED_ITEM_SCALE = 1.72f;
62 const Vector2 SELECTED_ITEM_COLOR = Vector2(1.0f,1.0f);
63 const Vector3 VIRTUAL_ITEM_POSITION_RIGHT = Vector3( 280.0f,130.0f,130.0f);
64 const Vector3 VIRTUAL_ITEM_POSITION_LEFT = Vector3( -280.0f,130.0f,130.0f);
65 const float ROTATION_X = Math::PI/4.0f;
66 const float SCALE_RIGHT = 1.0f;
67 const float SCALE_LEFT = 1.0f;
68 const Vector2 COLOR_RIGHT = Vector2(1.0f,1.0f);
69 const Vector2 COLOR_LEFT = Vector2(1.0f,1.0f);
70 const Vector3 POSITION_RIGHT = Vector3(710.0f,-450.0f,0.0f);
71 const Vector3 POSITION_LEFT = Vector3(-710.0f,-450.0f,0.0f);
72 const float ROTATION_RIGHT = -Math::PI / 6.0f;
73 const float ROTATION_LEFT = Math::PI / 6.0f;
75 const float ALBUM_HIGHT = 7.0f;
76 const float ALPHA = 1.1f;
77 const float ALPHA_OF_SIZE = 0.35f;
78 const float LINE_OF_BOTTOM = 360.0f;
80 const float CHANCE_OF_RANDOM_ROTATION_OF_STACK = 0.5f;
81 const float RANGE_OF_RANDOM_ROTATION_OF_STACK = 0.5f;
83 const float THRESHHOLD_OF_MOVING = 0.02f;
84 const int NUM_OF_FRAME_FILTERED = 5;
86 const unsigned int SPREAD_ITEM_NUM = 6;
95 struct DefaultItemSizeFunction
97 Vector3 operator()(const Vector3& layoutSize)
99 float width = layoutSize.height * ALPHA_OF_SIZE;
100 return Vector3(width, width, width);
104 struct AlbumScaleConstraint
106 AlbumScaleConstraint(const float scaleRight, const float scaleLeft, const float selectedItemScale, vector<float> scaleSpread)
108 mScaleRight = scaleRight;
109 mScaleLeft = scaleLeft;
110 mSelectedItemScale = selectedItemScale;
112 if(scaleSpread.size() == SPREAD_ITEM_NUM)
114 mScaleVecSpread = scaleSpread;
118 Vector3 operator()(const Vector3& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)
122 float beginScale = 0.0f;
123 float endScale = 0.0f;
125 float pos = layoutPosition + SELECTED_CENTER;
127 if(pos <= LAYOUT_POSITION_NAGATIVE_1)/*items of right stack*/
131 else if(pos > LAYOUT_POSITION_NAGATIVE_1 && pos < LAYOUT_POSITION_0)/*items between -1.0f and 0.0f*/
133 beginScale = mScaleVecSpread.at(0);
134 endScale = mScaleRight;
136 scale = (endScale - beginScale) * fabs(pos) + beginScale;
138 else if(pos >= LAYOUT_POSITION_0 && pos < SELECTED_RIGHT)/*items between 0.0f and center*/
145 beginScale = mScaleVecSpread.at(begin);
146 endScale = mScaleVecSpread.at(end);
148 scale = (endScale - beginScale) * fabs(pos - int(pos)) + beginScale;
152 scale = mScaleVecSpread.at(int(pos));
155 else if(pos >= SELECTED_RIGHT && pos <= SELECTED_LEFT)/*items of center*/
157 scale = mSelectedItemScale;
159 else if(pos > SELECTED_LEFT && pos <= LAYOUT_POSITION_6)/*items between center and 6.0f*/
166 beginScale = mScaleVecSpread.at(begin);
167 endScale = mScaleVecSpread.at(end);
169 scale = (endScale - beginScale) * fabs(pos - int(pos)) + beginScale;
173 scale = mScaleVecSpread.at(int(pos)-1);
176 else if(pos > LAYOUT_POSITION_6 && pos < LAYOUT_POSITION_7)/*items between 6.0f and 7.0f*/
178 beginScale = mScaleVecSpread.at(5);
179 endScale = mScaleLeft;
181 scale = (endScale - beginScale) * fabs(pos - int(pos)) + beginScale;
183 else if(pos >= LAYOUT_POSITION_7)/*items of left stack*/
192 return Vector3(scale,scale,1.0f);
197 float mSelectedItemScale;
198 vector<float> mScaleVecSpread;
201 Vector3 CalculatePosition(Vector3 pos, float rotateX)
203 pos.z = pos.z - fabs(pos.y - LINE_OF_BOTTOM) * sinf(rotateX) / cosf(rotateX);
207 Vector3 CalculateStackPosition(Vector3 pos, float rotateX, int num, bool left)
209 pos.z = pos.z - fabs(pos.y - LINE_OF_BOTTOM) * sinf(rotateX) / cosf(rotateX);
213 pos.x = pos.x + num * ALPHA;
217 pos.x = pos.x - num * ALPHA;
220 pos.y -= num * ALBUM_HIGHT * sinf(rotateX);
221 pos.z += num * ALBUM_HIGHT * cosf(rotateX);
226 Vector3 GetPosition(float layoutPos, Vector3 posRight, Vector3 posLeft, Vector3 posSelectedItem, vector<Vector3> posVecSpread, float rotateX)
233 Vector3 beginPos = Vector3::ZERO;
234 Vector3 endPos = Vector3::ZERO;
236 Vector3 pos = Vector3::ZERO;
238 if(layoutPos <= LAYOUT_POSITION_NAGATIVE_1)/*items of right stack*/
240 if(int(layoutPos) > layoutPos)
242 begin = int(layoutPos);
243 end = int(layoutPos)-1;
245 beginPos = CalculateStackPosition(posRight, rotateX, int(LAYOUT_POSITION_NAGATIVE_1) - int(layoutPos),false);
247 endPos = CalculateStackPosition(posRight, rotateX, - int(layoutPos),false);
249 alpha = fabs(layoutPos - int(layoutPos));
251 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
252 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
253 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
259 return CalculateStackPosition(posRight,rotateX,int(LAYOUT_POSITION_NAGATIVE_1) - int(layoutPos),false);
262 else if(layoutPos < LAYOUT_POSITION_0 && layoutPos > LAYOUT_POSITION_NAGATIVE_1)/*items between -1.0f and 0.0f*/
264 beginPos = CalculatePosition(posVecSpread.at(int(LAYOUT_POSITION_0)),rotateX);
265 endPos = CalculateStackPosition(posRight, rotateX, int(layoutPos),false);
269 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
270 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
271 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
275 else if(layoutPos >= LAYOUT_POSITION_0 && layoutPos <= LAYOUT_POSITION_2)/*items between 0.0f and 2.0f*/
277 if(int(layoutPos) < layoutPos)
279 begin = int(layoutPos);
280 end = int(layoutPos) + 1;
282 beginPos = posVecSpread.at(begin);
283 endPos = posVecSpread.at(end);
285 alpha = fabs(layoutPos - int(layoutPos));
287 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
288 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
289 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
293 pos = posVecSpread.at(int(layoutPos));
296 else if(layoutPos >LAYOUT_POSITION_2 && layoutPos<SELECTED_RIGHT)/*items between 2.0f and center*/
298 beginPos = posVecSpread.at(int(LAYOUT_POSITION_2));
299 endPos = VIRTUAL_ITEM_POSITION_RIGHT;
301 alpha = (layoutPos - LAYOUT_POSITION_2) / (SELECTED_RIGHT - LAYOUT_POSITION_2);
303 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
304 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
305 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
307 else if(layoutPos > SELECTED_LEFT && layoutPos < LAYOUT_POSITION_4)/*items between center and 4.0f*/
309 beginPos = posVecSpread.at(int(LAYOUT_POSITION_3));
310 endPos = VIRTUAL_ITEM_POSITION_LEFT;
312 alpha = (LAYOUT_POSITION_4 - layoutPos) / (LAYOUT_POSITION_4 - SELECTED_LEFT);
314 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
315 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
316 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
318 else if(layoutPos >= LAYOUT_POSITION_4 && layoutPos <= LAYOUT_POSITION_6)/*items between 4.0f and 6.0f*/
320 if(int(layoutPos) < layoutPos)
322 begin = int(layoutPos);
323 end = int(layoutPos) + 1;
325 beginPos = posVecSpread.at(begin - 1);
326 endPos = posVecSpread.at(end - 1);
328 alpha = fabs(layoutPos - int(layoutPos));
330 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
331 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
332 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
336 pos = posVecSpread.at(int(layoutPos) -1);
339 else if(layoutPos > LAYOUT_POSITION_6 && layoutPos < LAYOUT_POSITION_7)/*items between 6.0f and 7.0f*/
341 beginPos = CalculatePosition(posVecSpread.at(int(LAYOUT_POSITION_6) - 1),rotateX);
342 endPos = CalculateStackPosition(posLeft, rotateX, int(layoutPos) + 1 - int(LAYOUT_POSITION_7),true);
344 alpha = fabs(layoutPos - int(layoutPos));
346 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
347 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
348 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
352 else if(layoutPos >= LAYOUT_POSITION_7)/*items of left stack*/
354 if(int(layoutPos) < layoutPos)
356 begin = int(layoutPos);
357 end = int(layoutPos) + 1;
359 beginPos = CalculateStackPosition(posLeft, rotateX, int(layoutPos) - int(LAYOUT_POSITION_7),true);
361 endPos = CalculateStackPosition(posLeft, rotateX, int(layoutPos) + 1 - int(LAYOUT_POSITION_7),true);
363 alpha = fabs(layoutPos - int(layoutPos));
365 pos.x = (endPos.x - beginPos.x) * alpha + beginPos.x;
366 pos.y = (endPos.y - beginPos.y) * alpha + beginPos.y;
367 pos.z = (endPos.z - beginPos.z) * alpha + beginPos.z;
373 return CalculateStackPosition(posLeft, rotateX, int(layoutPos) - int(LAYOUT_POSITION_7),true);
377 return CalculatePosition(pos,rotateX);
380 struct AlbumPositionConstraint
382 AlbumPositionConstraint(const Vector3 posRight, const Vector3 posLeft, const Vector3 posSelectedItem, const vector<Vector3> posVecSpread, float rotateX)
384 mPositionRight = posRight;
385 mPositionLeft = posLeft;
386 mSelectedItemPosition = posSelectedItem;
387 mRotationX = rotateX;
389 if(posVecSpread.size() == SPREAD_ITEM_NUM)
391 mPositionVecSpread = posVecSpread;
395 Vector3 operator()(const Vector3& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)
397 float pos = layoutPosition + SELECTED_CENTER;
399 /*handle if the item is selected item(in the center)*/
400 if(pos >= SELECTED_RIGHT && pos <= SELECTED_LEFT)
402 return SELECTED_ITEM_POSITION;
405 /*get the spread items position*/
406 return GetPosition(pos,mPositionRight,mPositionLeft,mSelectedItemPosition,mPositionVecSpread,mRotationX);
409 Vector3 mPositionRight;
410 Vector3 mPositionLeft;
411 Vector3 mSelectedItemPosition;
412 vector<Vector3> mPositionVecSpread;
416 Quaternion GetRotation(float layoutPos, vector<float> rotateVecStack, vector<float> rotateVecSpread, float rotateX)
423 float beginRotation = 0.0f;
424 float endRotation = 0.0f;
426 float rotation = 0.0f;
427 if(layoutPos <= LAYOUT_POSITION_NAGATIVE_1)/*items of right stack*/
429 if(int(layoutPos) > layoutPos)
431 begin = int(layoutPos) + 1;
432 end = int(layoutPos);
437 beginRotation = rotateVecStack.at(begin);
438 endRotation = rotateVecStack.at(end);
440 alpha = fabs(layoutPos - int(layoutPos));
442 rotation = (endRotation - beginRotation) * alpha + beginRotation;
446 rotation = rotateVecStack.at(-int(layoutPos)-1);
449 else if(layoutPos > LAYOUT_POSITION_NAGATIVE_1 && layoutPos < LAYOUT_POSITION_0)/*items between -1.0f and 0.0f*/
454 beginRotation = rotateVecSpread.at(begin);
455 endRotation = rotateVecStack.at(end);
457 alpha = fabs(layoutPos);
459 rotation = (endRotation - beginRotation) * alpha + beginRotation;
461 else if(layoutPos >= LAYOUT_POSITION_0 && layoutPos < LAYOUT_POSITION_3)
463 if(int(layoutPos) < layoutPos)
465 begin = int(layoutPos);
466 end = int(layoutPos) + 1;
468 beginRotation = rotateVecSpread.at(begin);
469 endRotation = rotateVecSpread.at(end);
471 alpha = fabs(layoutPos - int(layoutPos));
473 rotation = (endRotation - beginRotation) * alpha + beginRotation;
477 rotation = rotateVecSpread.at(int(layoutPos));
480 else if(layoutPos > LAYOUT_POSITION_3 && layoutPos <= LAYOUT_POSITION_6)
482 if(int(layoutPos) < layoutPos)
484 begin = int(layoutPos) - 1;
485 end = int(layoutPos);
487 beginRotation = rotateVecSpread.at(begin);
488 endRotation = rotateVecSpread.at(end);
490 alpha = fabs(layoutPos - int(layoutPos));
492 rotation = (endRotation - beginRotation) * alpha + beginRotation;
496 rotation = rotateVecSpread.at(int(layoutPos)-1);
499 else if(layoutPos > LAYOUT_POSITION_6 && layoutPos < LAYOUT_POSITION_7)
504 beginRotation = rotateVecSpread.at(begin);
505 endRotation = rotateVecStack.at(end);
507 alpha = fabs(layoutPos - int(LAYOUT_POSITION_6));
509 rotation = (endRotation - beginRotation) * alpha + beginRotation;
511 else if(layoutPos >= LAYOUT_POSITION_7)
513 if(int(layoutPos) < layoutPos)
515 begin = int(layoutPos) - int(LAYOUT_POSITION_7);
516 end = int(layoutPos) - int(LAYOUT_POSITION_7) + 1;
518 beginRotation = rotateVecStack.at(begin);
519 endRotation = rotateVecStack.at(end);
521 alpha = fabs(layoutPos - int(layoutPos));
523 rotation = (endRotation - beginRotation) * alpha + beginRotation;
527 rotation = rotateVecStack.at(int(layoutPos)-int(LAYOUT_POSITION_7));
531 return Quaternion(rotateX, Vector3::XAXIS) * Quaternion(rotation, Vector3::ZAXIS);
534 struct AlbumRotationConstraint
536 AlbumRotationConstraint(const vector<float> rotatVecSpread, const vector<float> rotatVecStack, const float rotateX, int num)
538 mRotationX = rotateX;
543 mLastPosition = 0.0f;
546 if(rotatVecSpread.size() == SPREAD_ITEM_NUM)
548 mRotationVecSpread = rotatVecSpread;
551 mRotationVecStack = rotatVecStack;
554 Quaternion operator()(const Quaternion& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)
556 float pos = layoutPosition + SELECTED_CENTER;
558 if(mIndex == mNumOfItems)
565 if(mLastIndex != mIndex)
569 if(mLeft == SCROLL_RIGHT)
571 if(pos > mLastPosition + THRESHHOLD_OF_MOVING)
576 else if(pos < mLastPosition)
579 mLeft = SCROLL_RIGHT;
584 if(mTimes > NUM_OF_FRAME_FILTERED)
591 else if(mLeft == SCROLL_LEFT)
593 if(pos > mLastPosition)
598 else if(pos < mLastPosition - THRESHHOLD_OF_MOVING)
601 mLeft = SCROLL_RIGHT;
606 if(mTimes > NUM_OF_FRAME_FILTERED)
615 if(pos < mLastPosition)
617 mLeft = SCROLL_RIGHT;
619 else if(pos > mLastPosition)
631 /*rotation for the selected item(center)*/
632 if(pos >= SELECTED_RIGHT && pos < SELECTED_LEFT)
634 if(mLeft == SCROLL_LEFT)
636 return Quaternion(-fabs(SELECTED_CENTER - pos), Vector3::YAXIS);
638 else if(mLeft == SCROLL_RIGHT)
640 return Quaternion(fabs(pos - SELECTED_CENTER), Vector3::YAXIS);
644 return Quaternion(0.0f, Vector3::YAXIS);
649 /*rotation for the spread item*/
650 return GetRotation(pos,mRotationVecStack,mRotationVecSpread,mRotationX);
653 vector<float> mRotationVecSpread;
654 vector<float> mRotationVecStack;
656 Actor mScrollDirectionActor;
661 ScrollDirection mLeft;
665 struct AlbumColorConstraint
667 AlbumColorConstraint(const Vector2 colorRight, const Vector2 colorLeft, const Vector2 colorSelectedItem, const vector<Vector2> spreadVecColor, const int stackNum)
669 mColorRight = colorRight;
670 mColorLeft = colorLeft;
671 mSelectedItemColor = colorSelectedItem;
672 mStackNum = stackNum;
674 if(spreadVecColor.size() == SPREAD_ITEM_NUM)
676 mColorVecSpread = spreadVecColor;
680 Vector4 operator()(const Vector4& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)
683 Vector4 color = current;
684 float pos = layoutPosition + SELECTED_CENTER;
685 Vector2 temp = Vector2(0.0f,0.0f);
690 Vector2 beginColor = Vector2(0.0f,0.0f);
691 Vector2 endColor = Vector2(0.0f,0.0f);
693 if(pos <= -mStackNum-1)
698 else if(pos > -mStackNum-1 && pos < -mStackNum)
700 beginColor = mColorRight;
701 endColor = Vector2(0.0f,0.0f);
703 color.w = (endColor.x - beginColor.x) * fabs(pos - int(pos)) + beginColor.x;
704 black = (endColor.y - beginColor.y) * fabs(pos - int(pos)) + beginColor.y;
706 else if(pos <= LAYOUT_POSITION_NAGATIVE_1 && pos >= -mStackNum)
708 color.w = mColorRight.x;
709 black = mColorRight.y;
711 else if(pos > LAYOUT_POSITION_NAGATIVE_1 && pos < LAYOUT_POSITION_0)
713 beginColor = mColorVecSpread.at(int(LAYOUT_POSITION_0));
714 endColor = mColorRight;
716 color.w = (endColor.x - beginColor.x) * fabs(pos) + beginColor.x;
717 black = (endColor.y - beginColor.y) * fabs(pos) + beginColor.y;
719 else if(pos >= LAYOUT_POSITION_0 && pos <= LAYOUT_POSITION_2)
726 beginColor = mColorVecSpread.at(begin);
727 endColor = mColorVecSpread.at(end);
729 temp = (endColor - beginColor) * fabs(pos - int(pos)) + beginColor;
736 beginColor = mColorVecSpread.at(int(pos));
738 color.w = beginColor.x;
739 black = beginColor.y;
742 else if(pos > LAYOUT_POSITION_2 && pos < SELECTED_RIGHT)/*items between 2.0f and center*/
744 beginColor = mColorVecSpread.at(int(LAYOUT_POSITION_2));
745 endColor = Vector2(0.0f,0.0f);
747 temp = (endColor - beginColor) * (pos - LAYOUT_POSITION_2)/(SELECTED_RIGHT - LAYOUT_POSITION_2) + beginColor;
752 else if(pos >= SELECTED_RIGHT && pos <= SELECTED_LEFT)/*items of center*/
754 color.w = mSelectedItemColor.x;
755 black = mSelectedItemColor.y;
757 else if(pos > SELECTED_LEFT && pos < LAYOUT_POSITION_4)/*items between center and 4.0f*/
759 beginColor = Vector2(0.0f,0.0f);
760 endColor = mColorVecSpread.at(int(LAYOUT_POSITION_3));
762 temp = (endColor - beginColor) * (pos - SELECTED_LEFT)/(LAYOUT_POSITION_4 - SELECTED_LEFT) + beginColor;
767 else if(pos >= LAYOUT_POSITION_4 && pos <= LAYOUT_POSITION_6)/*items between 4.0f and 6.0f*/
771 begin = int(pos) - 1;
774 beginColor = mColorVecSpread.at(begin);
775 endColor = mColorVecSpread.at(end);
777 temp = (endColor - beginColor) * fabs(pos - int(pos)) + beginColor;
784 beginColor = mColorVecSpread.at(int(pos) - 1);
786 color.w = beginColor.x;
787 black = beginColor.y;
790 else if(pos > LAYOUT_POSITION_6 && pos < LAYOUT_POSITION_7)/*items between 6.0f and 7.0f*/
792 beginColor = mColorVecSpread.at(int(LAYOUT_POSITION_6) - 1);
793 endColor = mColorLeft;
795 color.w = (endColor.x - beginColor.x) * fabs(pos - int(pos)) + beginColor.x;
796 black = (endColor.y - beginColor.y) * fabs(pos - int(pos)) + beginColor.y;
798 else if(pos >= LAYOUT_POSITION_7 && pos <= mStackNum + int(LAYOUT_POSITION_7))/*items of left stack*/
800 color.w = mColorLeft.x;
801 black = mColorLeft.y;
803 else if(pos > mStackNum + int(LAYOUT_POSITION_7) && pos < mStackNum + int(LAYOUT_POSITION_7) + 1)
805 beginColor = mColorLeft;
806 endColor = Vector2(0.0f,0.0f);
808 color.w = (endColor.x - beginColor.x) * fabs(pos - int(pos)) + beginColor.x;
809 black = (endColor.y - beginColor.y) * fabs(pos - int(pos)) + beginColor.y;
811 else if(pos >= mStackNum + int(LAYOUT_POSITION_7) +1)
817 color.r = color.r * black;
818 color.g = color.g * black;
819 color.b = color.b * black;
827 Vector2 mSelectedItemColor;
828 vector<Vector2> mColorVecSpread;
831 struct AlbumVisibilityConstraintPortrait
833 AlbumVisibilityConstraintPortrait()
837 bool operator()(const bool& current, const float& layoutPosition, const float& scrollSpeed, const Vector3& layoutSize)
843 } // unnamed namespace
851 struct AlbumLayout::Impl
854 : mItemSizeFunction(DefaultItemSizeFunction()),
855 mScrollSpeedFactor(DEFAULT_SCROLL_SPEED_FACTOR),
856 mMaximumSwipeSpeed(DEFAULT_MAXIMUM_SWIPE_SPEED),
857 mItemFlickAnimationDuration(DEFAULT_ITEM_FLICK_ANIMATION_DURATION),
860 /*Initialize the variables*/
861 mSelectedItemScale = SELECETED_ITEM_SCALE;
862 mRotationX = ROTATION_X;
863 mScaleRight = SCALE_RIGHT;
864 mScaleLeft = SCALE_LEFT;
865 mRotationRight = ROTATION_RIGHT;
866 mRotationLeft = ROTATION_LEFT;
867 mSelectedItemColor = SELECTED_ITEM_COLOR;
868 mSelectedItemPosition = SELECTED_ITEM_POSITION;
869 mColorRight = COLOR_RIGHT;
870 mColorLeft = COLOR_LEFT;
871 mPositionRight = POSITION_RIGHT;
872 mPositionLeft = POSITION_LEFT;
875 /*Initialize the position of spread items*/
876 mPositionVecSpread.push_back(POSITION_0);
877 mPositionVecSpread.push_back(POSITION_1);
878 mPositionVecSpread.push_back(POSITION_2);
879 mPositionVecSpread.push_back(POSITION_4);
880 mPositionVecSpread.push_back(POSITION_5);
881 mPositionVecSpread.push_back(POSITION_6);
883 /*Initialize the rotation of spread items*/
884 mRotationVecSpread.push_back(ROTATION_0);
885 mRotationVecSpread.push_back(ROTATION_1);
886 mRotationVecSpread.push_back(ROTATION_2);
887 mRotationVecSpread.push_back(ROTATION_4);
888 mRotationVecSpread.push_back(ROTATION_5);
889 mRotationVecSpread.push_back(ROTATION_6);
891 /*Initialize the scale of spread items*/
892 for(unsigned int i=0; i<SPREAD_ITEM_NUM; i++)
894 mScaleVecSpread.push_back(SCALE);
897 /*Initialize the color of spread items*/
898 for(unsigned int i=0; i<SPREAD_ITEM_NUM; i++)
900 mColorVecSpread.push_back(COLOR);
904 void SetPosition(vector<Vector3> positionList)
906 if(positionList.size() == SPREAD_ITEM_NUM)
908 mPositionVecSpread = positionList;
912 vector<Vector3> GetPosition() const
914 return mPositionVecSpread;
917 void SetColor(vector<Vector2> colorList)
919 if(colorList.size() == SPREAD_ITEM_NUM)
921 mColorVecSpread = colorList;
925 vector<Vector2> GetColor() const
927 return mColorVecSpread;
930 void SetScale(vector<float> scaleList)
932 if(scaleList.size() == SPREAD_ITEM_NUM)
934 mScaleVecSpread = scaleList;
938 vector<float> GetScale() const
940 return mScaleVecSpread;
943 void SetRotationX(float rotat_x)
945 mRotationX = rotat_x;
948 float GetRotationX() const
953 void SetRotationZ(vector<float> rotationList)
955 if(rotationList.size() == SPREAD_ITEM_NUM)
957 mRotationVecSpread = rotationList;
961 vector<float> GetRotationZ() const
963 return mRotationVecSpread;
966 void SetCenterPosition(Vector3 pos)
968 mSelectedItemPosition = pos;
971 Vector3 GetCenterPosition() const
973 return mSelectedItemPosition;
976 void SetCenterScale(float scale)
978 mSelectedItemScale = scale;
981 float GetCenterScale() const
983 return mSelectedItemScale;
986 void SetCenterColor(Vector2 color)
988 mSelectedItemColor = color;
991 Vector2 GetCenterColor() const
993 return mSelectedItemColor;
996 void SetStackPosition(Vector3 rightPos, Vector3 leftPos)
998 mPositionRight = rightPos;
999 mPositionLeft = leftPos;
1002 Vector3 GetRightStackPosition() const
1004 return mPositionRight;
1007 Vector3 GetLeftStackPosition() const
1009 return mPositionLeft;
1012 void SetStackScale(float rightScale, float leftScale)
1014 mScaleRight = rightScale;
1015 mScaleLeft = leftScale;
1018 float GetRightStackScale() const
1023 float GetLeftStackScale() const
1028 void SetStackColor(Vector2 rightColor, Vector2 leftColor)
1030 mColorRight = rightColor;
1031 mColorLeft = leftColor;
1034 Vector2 GetRightStackColor() const
1039 Vector2 GetLeftStackColor() const
1044 void SetNumOfItems(int num)
1048 /*Initialize the rotation of stack items*/
1049 for(int i=0; i<mNumOfItems; i++)
1051 if(Random::Chance(CHANCE_OF_RANDOM_ROTATION_OF_STACK))
1053 mRotationVecStack.push_back(Random::Range(-RANGE_OF_RANDOM_ROTATION_OF_STACK,RANGE_OF_RANDOM_ROTATION_OF_STACK));
1057 mRotationVecStack.push_back(0.0f);
1062 int GetNumOfItems() const
1067 void SetStackNum(int num)
1072 int GetStackNum() const
1077 ItemSizeFunction mItemSizeFunction;
1079 float mScrollSpeedFactor;
1080 float mMaximumSwipeSpeed;
1081 float mItemFlickAnimationDuration;
1083 Vector3 mSelectedItemPosition;/*position of selected item*/
1084 float mSelectedItemScale;/*scale of selected item*/
1085 Vector2 mSelectedItemColor;/*color of selected item*/
1087 float mRotationX;/*rotation around X*/
1089 vector<Vector3> mPositionVecSpread;/*positions of the spread items*/
1090 vector<float> mRotationVecSpread;/*rotations of the spread items*/
1091 vector<float> mScaleVecSpread;/*scales of the spread items*/
1092 vector<Vector2> mColorVecSpread;/*colors of the spread items*/
1094 vector<float> mRotationVecStack;/*rotations of the stack items*/
1096 float mRotationRight;/*rotation of right album stack*/
1097 float mRotationLeft;/*rotation of left album stack*/
1099 float mScaleRight;/*scale of right album stack*/
1100 float mScaleLeft;/*scale of left album stack*/
1102 Vector2 mColorRight;/*color of right album stack*/
1103 Vector2 mColorLeft;/*color of left album stack*/
1105 Vector3 mPositionRight;/*position of right album stack*/
1106 Vector3 mPositionLeft;/*position of left album stack*/
1108 int mNumOfItems;/*num of items*/
1109 int mStackNum;/*num of items of stack*/
1112 AlbumLayoutPtr AlbumLayout::New()
1114 return AlbumLayoutPtr(new AlbumLayout());
1117 AlbumLayout::~AlbumLayout()
1122 void AlbumLayout::SetItemSizeFunction(ItemSizeFunction function)
1124 mImpl->mItemSizeFunction = function;
1127 AlbumLayout::ItemSizeFunction AlbumLayout::GetItemSizeFunction() const
1129 return mImpl->mItemSizeFunction;
1132 void AlbumLayout::SetScrollSpeedFactor(float scrollSpeed)
1134 mImpl->mScrollSpeedFactor = scrollSpeed;
1137 void AlbumLayout::SetMaximumSwipeSpeed(float speed)
1139 mImpl->mMaximumSwipeSpeed = speed;
1142 void AlbumLayout::SetItemFlickAnimationDuration(float durationSeconds)
1144 mImpl->mItemFlickAnimationDuration = durationSeconds;
1147 float AlbumLayout::GetScrollSpeedFactor() const
1149 return mImpl->mScrollSpeedFactor;
1152 float AlbumLayout::GetMaximumSwipeSpeed() const
1154 return mImpl->mMaximumSwipeSpeed;
1157 float AlbumLayout::GetItemFlickAnimationDuration() const
1159 return mImpl->mItemFlickAnimationDuration;
1162 float AlbumLayout::GetMinimumLayoutPosition(unsigned int numberOfItems, Vector3 layoutSize) const
1164 return - static_cast<float>(numberOfItems) + 1;
1167 float AlbumLayout::GetClosestAnchorPosition(float layoutPosition) const
1169 return round(layoutPosition);
1172 float AlbumLayout::GetItemScrollToPosition(unsigned int itemId) const
1174 return -(static_cast<float>(itemId));
1177 ItemRange AlbumLayout::GetItemsWithinArea(float firstItemPosition, Vector3 layoutSize) const
1179 return ItemRange(0, mImpl->mNumOfItems);
1182 unsigned int AlbumLayout::GetReserveItemCount(Vector3 layoutSize) const
1187 bool AlbumLayout::GetItemSize(unsigned int itemId, Vector3 layoutSize, Vector3& itemSize) const
1189 itemSize = mImpl->mItemSizeFunction(layoutSize);
1193 void AlbumLayout::GetResizeAnimation(Animation& animation, Actor actor, Vector3 size, float durationSeconds) const
1197 animation.Resize(actor, size);
1201 bool AlbumLayout::GetPositionConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const
1203 constraint = AlbumPositionConstraint(mImpl->mPositionRight,mImpl->mPositionLeft,mImpl->mSelectedItemPosition,mImpl->mPositionVecSpread,mImpl->mRotationX);
1207 bool AlbumLayout::GetRotationConstraint(unsigned int itemId, ItemLayout::QuaternionFunction& constraint) const
1209 constraint = AlbumRotationConstraint(mImpl->mRotationVecSpread,mImpl->mRotationVecStack,mImpl->mRotationX,mImpl->mNumOfItems);
1213 bool AlbumLayout::GetScaleConstraint(unsigned int itemId, ItemLayout::Vector3Function& constraint) const
1215 constraint = AlbumScaleConstraint(mImpl->mScaleRight,mImpl->mScaleLeft,mImpl->mSelectedItemScale,mImpl->mScaleVecSpread);
1219 bool AlbumLayout::GetColorConstraint(unsigned int itemId, ItemLayout::Vector4Function& constraint) const
1221 constraint = AlbumColorConstraint(mImpl->mColorRight,mImpl->mColorLeft,mImpl->mSelectedItemColor,mImpl->mColorVecSpread,mImpl->mStackNum);
1225 bool AlbumLayout::GetVisibilityConstraint(unsigned int itemId, ItemLayout::BoolFunction& constraint) const
1227 constraint = AlbumVisibilityConstraintPortrait();
1231 Degree AlbumLayout::GetScrollDirection() const
1233 Degree scrollDirection(0);
1235 scrollDirection = -90.0f;
1237 return scrollDirection;
1240 void AlbumLayout::SetNumOfItems(int num)
1242 mImpl->SetNumOfItems(num);
1245 int AlbumLayout::GetNumOfItems() const
1247 return mImpl->GetNumOfItems();
1250 void AlbumLayout::SetStackNum(int num)
1252 mImpl->SetStackNum(num);
1255 int AlbumLayout::GetStackNum() const
1257 return mImpl->GetStackNum();
1260 void AlbumLayout::SetPosition(vector<Vector3> positionList)
1262 mImpl->SetPosition(positionList);
1265 vector<Vector3> AlbumLayout::GetPosition() const
1267 return mImpl->GetPosition();
1270 void AlbumLayout::SetScale(vector<float> scaleList)
1272 mImpl->SetScale(scaleList);
1275 vector<float> AlbumLayout::GetScale() const
1277 return mImpl->GetScale();
1280 void AlbumLayout::SetColor(vector<Vector2> colorList)
1282 mImpl->SetColor(colorList);
1285 vector<Vector2> AlbumLayout::GetColor() const
1287 return mImpl->GetColor();
1290 void AlbumLayout::SetRotationX(float rotation)
1292 mImpl->SetRotationX(rotation);
1295 float AlbumLayout::GetRotationX() const
1297 return mImpl->GetRotationX();
1300 void AlbumLayout::SetRotationZ(vector<float> rotationList)
1302 mImpl->SetRotationZ(rotationList);
1305 vector<float> AlbumLayout::GetRotationZ() const
1307 return mImpl->GetRotationZ();
1310 void AlbumLayout::SetCenterPosition(Vector3 pos)
1312 mImpl->SetCenterPosition(pos);
1315 Vector3 AlbumLayout::GetCenterPosition() const
1317 return mImpl->GetCenterPosition();
1320 void AlbumLayout::SetCenterScale(float scale)
1322 mImpl->SetCenterScale(scale);
1325 float AlbumLayout::GetCenterScale() const
1327 return mImpl->GetCenterScale();
1330 void AlbumLayout::SetCenterColor(Vector2 color)
1332 mImpl->SetCenterColor(color);
1335 Vector2 AlbumLayout::GetCenterColor() const
1337 return mImpl->GetCenterColor();
1340 void AlbumLayout::SetStackPosition(Vector3 rightPos, Vector3 leftPos)
1342 mImpl->SetStackPosition(rightPos, leftPos);
1345 Vector3 AlbumLayout::GetRightStackPosition() const
1347 return mImpl->GetRightStackPosition();
1350 Vector3 AlbumLayout::GetLeftStackPosition() const
1352 return mImpl->GetLeftStackPosition();
1355 void AlbumLayout::SetStackScale(float rightScale, float leftScale)
1357 mImpl->SetStackScale(rightScale,leftScale);
1360 float AlbumLayout::GetRightStackScale() const
1362 return mImpl->GetRightStackScale();
1365 float AlbumLayout::GetLeftStackScale() const
1367 return mImpl->GetLeftStackScale();
1370 void AlbumLayout::SetStackColor(Vector2 rightColor, Vector2 leftColor)
1372 mImpl->SetStackColor(rightColor, leftColor);
1375 Vector2 AlbumLayout::GetRightStackColor() const
1377 return mImpl->GetRightStackColor();
1380 Vector2 AlbumLayout::GetLeftStackColor() const
1382 return mImpl->GetLeftStackColor();
1385 AlbumLayout::AlbumLayout()
1391 } // namespace Toolkit