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-fold-effect-impl.h"
29 const float CubeTransitionFoldEffect::mDisplacementRatio = 1.4142f; //sqrt(2)
31 CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize )
32 : CubeTransitionEffect( numRows, numColumns, viewAreaSize)
36 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
38 // Create the implementation
39 CubeTransitionFoldEffect* internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns, viewAreaSize );
41 // Pass ownership to CustomActor handle
42 Toolkit::CubeTransitionFoldEffect cubeTransEffect( internalCubeTransEffect );
45 internalCubeTransEffect->Initialize();
47 return cubeTransEffect;
50 void CubeTransitionFoldEffect::OnInitialize()
52 float offset = mTileSize.width*0.5f;
54 for( unsigned int y = 0; y < mNumRows; y++ )
57 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
59 mTiles[0][idx+x].SetZ( offset );
60 mTiles[1][idx+x].SetX( offset );
62 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
64 mTiles[0][idx+x].SetZ( offset );
65 mTiles[1][idx+x].SetX( -offset );
70 void CubeTransitionFoldEffect::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);
78 for( unsigned int y = 0; y < mNumRows; y++ )
80 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
82 idx = y*mNumColumns + x;
83 SetupAnimation( idx, -angle, translation0 );
85 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
87 idx = y*mNumColumns + x;
88 SetupAnimation( idx, angle, translation1 );
96 void CubeTransitionFoldEffect::OnStopTransition()
98 float angle = mRotateIndex * Math::PI_2 ;
100 for( unsigned int y = 0; y < mNumRows; y++ )
103 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
105 mBoxes[idx+x].SetOrientation( Radian(angle), Vector3::YAXIS );
107 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
109 mBoxes[idx+x].SetOrientation( Radian(-angle), Vector3::YAXIS );
114 void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, float angle, Vector3 resetTranslation)
116 Actor currentCube = mBoxes[actorIndex];
117 ImageActor sideTile = mTiles[mContainerIndex][actorIndex];
118 ImageActor frontTile = mTiles[mContainerIndex^1][actorIndex];
119 if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition, it is going to previous image
121 sideTile.SetOrientation( Radian( angle), Vector3::YAXIS );
123 else if( !mChangeTurningDirection ) // reset rotation, translation and color
125 sideTile.TranslateBy( resetTranslation );
126 sideTile.SetOrientation( Radian( angle), Vector3::YAXIS );
128 mAnimation.AnimateTo( Property( currentCube, Actor::Property::ORIENTATION ), Quaternion( Radian( -angle ), Vector3::YAXIS ), AlphaFunctions::Linear );
129 Vector3 position(currentCube.GetCurrentPosition());
130 mAnimation.AnimateTo( Property( currentCube, Actor::Property::POSITION ), Vector3( position.x*mDisplacementRatio, position.y, position.z ), AlphaFunctions::Bounce );
131 mAnimation.AnimateTo( Property( frontTile, Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunctions::EaseOut );
132 mAnimation.AnimateTo( Property( sideTile, Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunctions::EaseIn );
135 } // namespace Internal
137 } // namespace Toolkit