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