2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "cube-transition-cross-effect-impl.h"
30 CubeTransitionCrossEffect::CubeTransitionCrossEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize )
31 : CubeTransitionEffect( numRows, numColumns, viewAreaSize)
35 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
37 // Create the implementation
38 CubeTransitionCrossEffect* internalCubeTransEffect = new CubeTransitionCrossEffect( numRows, numColumns, viewAreaSize );
40 // Pass ownership to CustomActor handle
41 Toolkit::CubeTransitionCrossEffect cubeTransEffect( internalCubeTransEffect );
44 internalCubeTransEffect->Initialize();
46 return cubeTransEffect;
49 void CubeTransitionCrossEffect::OnInitialize()
51 float offsetX = -mTileSize.width*0.5f;
52 float offsetY = -mTileSize.height*0.5f;
54 for( unsigned int y = 0; y < mNumRows; y++ )
57 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
59 mBoxes[idx+x].SetZ( offsetY );
60 mTiles[0][idx+x].SetZ( -offsetY );
61 mTiles[1][idx+x].SetY( offsetY );
63 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
65 mTiles[0][idx+x].SetZ( -offsetX );
66 mTiles[1][idx+x].SetX( offsetX );
71 void CubeTransitionCrossEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
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);
78 mDisplacementRatio = 1.f + mCubeDisplacement / (mTileSize.width + mTileSize.height);
80 for( unsigned int y = 0; y < mNumRows; y++ )
82 for( unsigned int x = y%2; x < mNumColumns; x=x+2) // rotate vertically
84 idx = y*mNumColumns + x;
85 SetupAnimation( idx, -angle, Vector3::XAXIS, translation0 );
87 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) // rotate horizontally
89 idx = y*mNumColumns + x;
90 SetupAnimation( idx, angle, Vector3::YAXIS, translation1 );
98 void CubeTransitionCrossEffect::OnStopTransition()
100 float angle = mRotateIndex * Math::PI_2 ;
102 for( unsigned int y = 0; y < mNumRows; y++ )
104 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
106 idx = y*mNumColumns + x;
107 mBoxes[idx].SetRotation( Radian(angle), Vector3::XAXIS );
109 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
111 idx = y*mNumColumns + x;
112 mBoxes[idx].SetRotation( Radian(-angle), Vector3::YAXIS );
117 void CubeTransitionCrossEffect::SetupAnimation(unsigned int actorIndex, float angle,
118 const Vector3 axis, Vector3 resetTranslation)
120 if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition and it is going to previous image
122 mTiles[mContainerIndex][actorIndex].SetRotation( Radian( angle), axis );
124 else if( !mChangeTurningDirection ) // reset rotation, translation and color
126 mTiles[mContainerIndex][actorIndex].MoveBy( resetTranslation );
127 mTiles[mContainerIndex][actorIndex].SetRotation( Radian( angle), axis );
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 );
136 } // namespace Internal
138 } // namespace Toolkit