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),
32 mDisplacementRatio( 1.f )
36 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize)
38 // Create the implementation
39 CubeTransitionCrossEffect* internalCubeTransEffect = new CubeTransitionCrossEffect( numRows, numColumns, viewAreaSize );
41 // Pass ownership to CustomActor handle
42 Toolkit::CubeTransitionCrossEffect cubeTransEffect( internalCubeTransEffect );
45 internalCubeTransEffect->Initialize();
47 return cubeTransEffect;
50 void CubeTransitionCrossEffect::OnInitialize()
52 float offsetX = -mTileSize.width*0.5f;
53 float offsetY = -mTileSize.height*0.5f;
55 for( unsigned int y = 0; y < mNumRows; y++ )
58 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
60 mBoxes[idx+x].SetZ( offsetY );
61 mTiles[0][idx+x].SetZ( -offsetY );
62 mTiles[1][idx+x].SetY( offsetY );
64 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
66 mTiles[0][idx+x].SetZ( -offsetX );
67 mTiles[1][idx+x].SetX( offsetX );
72 void CubeTransitionCrossEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
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);
79 mDisplacementRatio = 1.f + mCubeDisplacement / (mTileSize.width + mTileSize.height);
81 for( unsigned int y = 0; y < mNumRows; y++ )
83 for( unsigned int x = y%2; x < mNumColumns; x=x+2) // rotate vertically
85 idx = y*mNumColumns + x;
86 SetupAnimation( idx, -angle, Vector3::XAXIS, translation0 );
88 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) // rotate horizontally
90 idx = y*mNumColumns + x;
91 SetupAnimation( idx, angle, Vector3::YAXIS, translation1 );
99 void CubeTransitionCrossEffect::OnStopTransition()
101 float angle = mRotateIndex * Math::PI_2 ;
103 for( unsigned int y = 0; y < mNumRows; y++ )
105 for( unsigned int x = y%2; x < mNumColumns; x=x+2)
107 idx = y*mNumColumns + x;
108 mBoxes[idx].SetOrientation( Radian(angle), Vector3::XAXIS );
110 for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2)
112 idx = y*mNumColumns + x;
113 mBoxes[idx].SetOrientation( Radian(-angle), Vector3::YAXIS );
118 void CubeTransitionCrossEffect::SetupAnimation(unsigned int actorIndex, float angle,
119 const Vector3 axis, Vector3 resetTranslation)
121 if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition and it is going to previous image
123 mTiles[mContainerIndex][actorIndex].SetOrientation( Radian( angle), axis );
125 else if( !mChangeTurningDirection ) // reset rotation, translation and color
127 mTiles[mContainerIndex][actorIndex].TranslateBy( resetTranslation );
128 mTiles[mContainerIndex][actorIndex].SetOrientation( Radian( angle), axis );
130 mAnimation.AnimateTo( Property( mBoxes[actorIndex], Actor::Property::ORIENTATION ), Quaternion( Radian( -angle ), axis ), AlphaFunction::EASE_IN_OUT_SINE );
131 Vector3 position(mBoxes[actorIndex].GetCurrentPosition());
132 mAnimation.AnimateTo( Property( mBoxes[actorIndex], Actor::Property::POSITION ), position * mDisplacementRatio + Vector3( 0.f, 0.f, mCubeDisplacement ), AlphaFunction::BOUNCE );
133 mAnimation.AnimateTo( Property( mTiles[mContainerIndex^1][actorIndex], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
134 mAnimation.AnimateTo( Property( mTiles[mContainerIndex][actorIndex], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
137 } // namespace Internal
139 } // namespace Toolkit