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 "cube-transition-fold-effect-impl.h"
28 const float CubeTransitionFoldEffect::mDisplacementRatio = 1.4142f; //sqrt(2)
30 CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize )
31 : CubeTransitionEffect( numRows, numColumns, viewAreaSize)
35 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
37 // Create the implementation
38 CubeTransitionFoldEffect* internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns, viewAreaSize );
40 // Pass ownership to CustomActor handle
41 Toolkit::CubeTransitionFoldEffect cubeTransEffect( internalCubeTransEffect );
44 internalCubeTransEffect->Initialize();
46 return cubeTransEffect;
49 void CubeTransitionFoldEffect::OnInitialize()
51 float offset = mTileSize.width*0.5f;
53 for( unsigned int y = 0; y < mNumRows; y++ )
56 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
58 mTiles[0][idx+x].SetZ( offset );
59 mTiles[1][idx+x].SetX( offset );
61 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
63 mTiles[0][idx+x].SetZ( offset );
64 mTiles[1][idx+x].SetX( -offset );
69 void CubeTransitionFoldEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
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);
77 for( unsigned int y = 0; y < mNumRows; y++ )
79 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
81 idx = y*mNumColumns + x;
82 SetupAnimation( idx, -angle, translation0 );
84 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
86 idx = y*mNumColumns + x;
87 SetupAnimation( idx, angle, translation1 );
95 void CubeTransitionFoldEffect::OnStopTransition()
97 float angle = mRotateIndex * Math::PI_2 ;
99 for( unsigned int y = 0; y < mNumRows; y++ )
102 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
104 mBoxes[idx+x].SetRotation( Radian(angle), Vector3::YAXIS );
106 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
108 mBoxes[idx+x].SetRotation( Radian(-angle), Vector3::YAXIS );
113 void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, float angle, Vector3 resetTranslation)
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
120 sideTile.SetRotation( Radian( angle), Vector3::YAXIS );
122 else if( !mChangeTurningDirection ) // reset rotation, translation and color
124 sideTile.MoveBy( resetTranslation );
125 sideTile.SetRotation( Radian( angle), Vector3::YAXIS );
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 );
134 } // namespace Internal
136 } // namespace Toolkit