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-cross-effect-impl.h"
29 CubeTransitionCrossEffect::CubeTransitionCrossEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize )
30 : CubeTransitionEffect( numRows, numColumns, viewAreaSize)
34 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
36 // Create the implementation
37 CubeTransitionCrossEffect* internalCubeTransEffect = new CubeTransitionCrossEffect( numRows, numColumns, viewAreaSize );
39 // Pass ownership to CustomActor handle
40 Toolkit::CubeTransitionCrossEffect cubeTransEffect( internalCubeTransEffect );
43 internalCubeTransEffect->Initialize();
45 return cubeTransEffect;
48 void CubeTransitionCrossEffect::OnInitialize()
50 float offsetX = -mTileSize.width*0.5f;
51 float offsetY = -mTileSize.height*0.5f;
53 for( unsigned int y = 0; y < mNumRows; y++ )
56 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
58 mBoxes[idx+x].SetZ( offsetY );
59 mTiles[0][idx+x].SetZ( -offsetY );
60 mTiles[1][idx+x].SetY( offsetY );
62 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
64 mTiles[0][idx+x].SetZ( -offsetX );
65 mTiles[1][idx+x].SetX( offsetX );
70 void CubeTransitionCrossEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
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);
77 mDisplacementRatio = 1.f + mCubeDisplacement / (mTileSize.width + mTileSize.height);
79 for( unsigned int y = 0; y < mNumRows; y++ )
81 for( unsigned int x = y%2; x < mNumColumns; x=x+2) // rotate vertically
83 idx = y*mNumColumns + x;
84 SetupAnimation( idx, -angle, Vector3::XAXIS, translation0 );
86 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) // rotate horizontally
88 idx = y*mNumColumns + x;
89 SetupAnimation( idx, angle, Vector3::YAXIS, translation1 );
97 void CubeTransitionCrossEffect::OnStopTransition()
99 float angle = mRotateIndex * Math::PI_2 ;
101 for( unsigned int y = 0; y < mNumRows; y++ )
103 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
105 idx = y*mNumColumns + x;
106 mBoxes[idx].SetRotation( Radian(angle), Vector3::XAXIS );
108 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
110 idx = y*mNumColumns + x;
111 mBoxes[idx].SetRotation( Radian(-angle), Vector3::YAXIS );
116 void CubeTransitionCrossEffect::SetupAnimation(unsigned int actorIndex, float angle,
117 const Vector3 axis, Vector3 resetTranslation)
119 if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition and it is going to previous image
121 mTiles[mContainerIndex][actorIndex].SetRotation( Radian( angle), axis );
123 else if( !mChangeTurningDirection ) // reset rotation, translation and color
125 mTiles[mContainerIndex][actorIndex].MoveBy( resetTranslation );
126 mTiles[mContainerIndex][actorIndex].SetRotation( Radian( angle), axis );
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 );
135 } // namespace Internal
137 } // namespace Toolkit