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