Fix builder animation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition-effects / cube-transition-fold-effect-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 // CLASS HEADER
18 #include "cube-transition-fold-effect-impl.h"
19
20 namespace Dali
21 {
22
23 namespace Toolkit
24 {
25
26 namespace Internal
27 {
28 const float CubeTransitionFoldEffect::mDisplacementRatio = 1.4142f; //sqrt(2)
29
30 CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize )
31 : CubeTransitionEffect( numRows, numColumns, viewAreaSize)
32 {
33 }
34
35 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
36 {
37   // Create the implementation
38   CubeTransitionFoldEffect* internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns, viewAreaSize );
39
40   // Pass ownership to CustomActor handle
41   Toolkit::CubeTransitionFoldEffect cubeTransEffect( internalCubeTransEffect );
42
43   //Initialization
44   internalCubeTransEffect->Initialize();
45
46   return cubeTransEffect;
47 }
48
49 void CubeTransitionFoldEffect::OnInitialize()
50 {
51   float offset = mTileSize.width*0.5f;
52   unsigned int idx;
53   for( unsigned int y = 0; y < mNumRows; y++ )
54   {
55     idx = y*mNumColumns;
56     for( unsigned int x = y%2; x < mNumColumns; x=x+2)
57     {
58       mTiles[0][idx+x].SetZ( offset );
59       mTiles[1][idx+x].SetX( offset );
60     }
61     for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
62     {
63       mTiles[0][idx+x].SetZ( offset );
64       mTiles[1][idx+x].SetX( -offset );
65     }
66   }
67 }
68
69 void CubeTransitionFoldEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
70 {
71   float angle = mRotateIndex * Math::PI_2 ;
72   Vector3 translation0 = mTiles[mContainerIndex][ 0 ].GetCurrentPosition()*(-2.f);
73   Vector3 translation1 = mTiles[mContainerIndex][ mNumColumns ].GetCurrentPosition()*(-2.f);
74
75   unsigned int idx;
76
77   for( unsigned int y = 0; y < mNumRows; y++ )
78   {
79     for( unsigned int x = y%2; x < mNumColumns; x=x+2)
80     {
81       idx = y*mNumColumns + x;
82       SetupAnimation( idx, -angle, translation0 );
83     }
84     for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
85     {
86       idx = y*mNumColumns + x;
87       SetupAnimation( idx, angle, translation1 );
88     }
89   }
90
91   mAnimation.Play();
92   mIsAnimating = true;
93 }
94
95 void CubeTransitionFoldEffect::OnStopTransition()
96 {
97   float angle = mRotateIndex * Math::PI_2 ;
98   unsigned int idx;
99   for( unsigned int y = 0; y < mNumRows; y++ )
100   {
101     idx = y*mNumColumns;
102     for( unsigned int x = y%2; x < mNumColumns; x=x+2)
103     {
104       mBoxes[idx+x].SetRotation( Radian(angle), Vector3::YAXIS );
105     }
106     for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
107     {
108       mBoxes[idx+x].SetRotation( Radian(-angle), Vector3::YAXIS );
109     }
110   }
111 }
112
113 void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, float angle, Vector3 resetTranslation)
114 {
115   Actor currentCube = mBoxes[actorIndex];
116   ImageActor sideTile = mTiles[mContainerIndex][actorIndex];
117   ImageActor frontTile = mTiles[mContainerIndex^1][actorIndex];
118   if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition, it is going to previous image
119   {
120     sideTile.SetRotation( Radian( angle),   Vector3::YAXIS );
121   }
122   else if( !mChangeTurningDirection )   // reset rotation, translation and color
123   {
124     sideTile.MoveBy( resetTranslation );
125     sideTile.SetRotation( Radian( angle),   Vector3::YAXIS );
126   }
127   mAnimation.RotateTo( currentCube, Radian( -angle ), Vector3::YAXIS, AlphaFunctions::Linear );
128   Vector3 position(currentCube.GetCurrentPosition());
129   mAnimation.MoveTo(currentCube, Vector3( position.x*mDisplacementRatio, position.y, position.z ), AlphaFunctions::Bounce);
130   mAnimation.ColorTo( frontTile, HALF_BRIGHTNESS, AlphaFunctions::EaseOut );
131   mAnimation.ColorTo( sideTile, FULL_BRIGHTNESS, AlphaFunctions::EaseIn );
132 }
133
134 } // namespace Internal
135
136 } // namespace Toolkit
137
138 } // namespace Dali