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