X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftransition-effects%2Fcube-transition-fold-effect-impl.cpp;h=5866bbc4e010e54219d3c02c064eee5126371bda;hp=803ed2a0161b6b36323ea6e4b8cbac43337409dc;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=2ddfbb9e23a7c3fc30e604236c41e0ef6d2ed6a2 diff --git a/dali-toolkit/internal/transition-effects/cube-transition-fold-effect-impl.cpp b/dali-toolkit/internal/transition-effects/cube-transition-fold-effect-impl.cpp index 803ed2a..5866bbc 100644 --- a/dali-toolkit/internal/transition-effects/cube-transition-fold-effect-impl.cpp +++ b/dali-toolkit/internal/transition-effects/cube-transition-fold-effect-impl.cpp @@ -20,26 +20,22 @@ namespace Dali { - namespace Toolkit { - namespace Internal { -const float CubeTransitionFoldEffect::mDisplacementRatio = 1.4142f; //sqrt(2) - -CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize ) -: CubeTransitionEffect( numRows, numColumns, viewAreaSize) +CubeTransitionFoldEffect::CubeTransitionFoldEffect(unsigned int numRows, unsigned int numColumns) +: CubeTransitionEffect(numRows, numColumns) { } -Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns, Size viewAreaSize) +Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns) { // Create the implementation - CubeTransitionFoldEffect* internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns, viewAreaSize ); + IntrusivePtr internalCubeTransEffect = new CubeTransitionFoldEffect(numRows, numColumns); // Pass ownership to CustomActor handle - Toolkit::CubeTransitionFoldEffect cubeTransEffect( internalCubeTransEffect ); + Toolkit::CubeTransitionFoldEffect cubeTransEffect(*internalCubeTransEffect); //Initialization internalCubeTransEffect->Initialize(); @@ -49,87 +45,97 @@ Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int num void CubeTransitionFoldEffect::OnInitialize() { - float offset = mTileSize.width*0.5f; unsigned int idx; - for( unsigned int y = 0; y < mNumRows; y++ ) + for(unsigned int y = 0; y < mRows; y++) { - idx = y*mNumColumns; - for( unsigned int x = y%2; x < mNumColumns; x=x+2) + idx = y * mColumns; + for(unsigned int x = y % 2; x < mColumns; x = x + 2) { - mTiles[0][idx+x].SetZ( offset ); - mTiles[1][idx+x].SetX( offset ); + SetTargetLeft(idx + x); } - for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) + for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2) { - mTiles[0][idx+x].SetZ( offset ); - mTiles[1][idx+x].SetX( -offset ); + SetTargetRight(idx + x); } } } -void CubeTransitionFoldEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement ) +void CubeTransitionFoldEffect::OnStartTransition(Vector2 panPosition, Vector2 panDisplacement) { - float angle = mRotateIndex * Math::PI_2 ; - Vector3 translation0 = mTiles[mContainerIndex][ 0 ].GetCurrentPosition()*(-2.f); - Vector3 translation1 = mTiles[mContainerIndex][ mNumColumns ].GetCurrentPosition()*(-2.f); + float angle = Math::PI_2; unsigned int idx; - - for( unsigned int y = 0; y < mNumRows; y++ ) + if(panDisplacement.x < 0) { - for( unsigned int x = y%2; x < mNumColumns; x=x+2) + for(unsigned int y = 0; y < mRows; y++) { - idx = y*mNumColumns + x; - SetupAnimation( idx, -angle, translation0 ); + idx = y * mColumns; + for(unsigned int x = y % 2; x < mColumns; x = x + 2) + { + SetTargetLeft(idx + x); + } + for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2) + { + SetTargetRight(idx + x); + } } - for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) + } + else + { + angle = -angle; + + for(unsigned int y = 0; y < mRows; y++) { - idx = y*mNumColumns + x; - SetupAnimation( idx, angle, translation1 ); + idx = y * mColumns; + for(unsigned int x = y % 2; x < mColumns; x = x + 2) + { + SetTargetRight(idx + x); + } + for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2) + { + SetTargetLeft(idx + x); + } } } - mAnimation.Play(); - mIsAnimating = true; -} - -void CubeTransitionFoldEffect::OnStopTransition() -{ - float angle = mRotateIndex * Math::PI_2 ; - unsigned int idx; - for( unsigned int y = 0; y < mNumRows; y++ ) + for(unsigned int y = 0; y < mRows; y++) { - idx = y*mNumColumns; - for( unsigned int x = y%2; x < mNumColumns; x=x+2) + idx = y * mColumns; + for(unsigned int x = y % 2; x < mColumns; x = x + 2) { - mBoxes[idx+x].SetRotation( Radian(angle), Vector3::YAXIS ); + SetupAnimation(idx + x, x, angle); } - for( unsigned int x = (y+1)%2; x < mNumColumns; x=x+2) + for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2) { - mBoxes[idx+x].SetRotation( Radian(-angle), Vector3::YAXIS ); + SetupAnimation(idx + x, x, -angle); } } + + mAnimation.Play(); + mIsAnimating = true; } -void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, float angle, Vector3 resetTranslation) +void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, unsigned int x, float angle) { - Actor currentCube = mBoxes[actorIndex]; - ImageActor sideTile = mTiles[mContainerIndex][actorIndex]; - ImageActor frontTile = mTiles[mContainerIndex^1][actorIndex]; - if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition, it is going to previous image - { - sideTile.SetRotation( Radian( angle), Vector3::YAXIS ); - } - else if( !mChangeTurningDirection ) // reset rotation, translation and color - { - sideTile.MoveBy( resetTranslation ); - sideTile.SetRotation( Radian( angle), Vector3::YAXIS ); - } - mAnimation.RotateTo( currentCube, Radian( -angle ), Vector3::YAXIS, AlphaFunctions::Linear ); - Vector3 position(currentCube.GetCurrentPosition()); - mAnimation.MoveTo(currentCube, Vector3( position.x*mDisplacementRatio, position.y, position.z ), AlphaFunctions::Bounce); - mAnimation.ColorTo( frontTile, HALF_BRIGHTNESS, AlphaFunctions::EaseOut ); - mAnimation.ColorTo( sideTile, FULL_BRIGHTNESS, AlphaFunctions::EaseIn ); + //rotate and translate the cube such that the edges remain in constant contact + //calculate the maximum distance the cube has to move when it the box has rotated 45 degrees + //ie distance from of centre of square to a vertex is given by: + // distance = width / sqrt(2) + //therefore the delta distance the cube should move is given by: + // delta_distance = ( width / 2 ) - distance + //re-arranging we get: + // delta_distance = ( width / 2 ) * ( sqrt(2) - 1 ) + //accumulating over the length of the row we get: + // delta_distance_at_x = x * delta_distance; + + float delta = (float)x * mTileSize.x * (1.4142f - 1.0f); + + Vector3 position(mBoxes[actorIndex].GetCurrentProperty(Actor::Property::POSITION)); + mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::ORIENTATION), Quaternion(Radian(angle), Vector3::YAXIS), AlphaFunction::LINEAR); + mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::POSITION_X), position.x + delta, AlphaFunction::BOUNCE); + + mAnimation.AnimateTo(Property(mCurrentTiles[actorIndex], Actor::Property::COLOR), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT); + mAnimation.AnimateTo(Property(mTargetTiles[actorIndex], Actor::Property::COLOR), FULL_BRIGHTNESS, AlphaFunction::EASE_IN); } } // namespace Internal