Fix issues with text scrolling & transition effects using GetVectorXY() incorrectly
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition-effects / cube-transition-cross-effect-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include "cube-transition-cross-effect-impl.h"
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Internal
28 {
29
30 CubeTransitionCrossEffect::CubeTransitionCrossEffect( unsigned int numRows, unsigned int numColumns )
31 : CubeTransitionEffect( numRows, numColumns ),
32   mDisplacementSpreadFactor( 0.008f )
33 {
34 }
35
36 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns )
37 {
38   // Create the implementation
39   IntrusivePtr< CubeTransitionCrossEffect > internalCubeTransEffect = new CubeTransitionCrossEffect( numRows, numColumns );
40
41   // Pass ownership to CustomActor handle
42   Toolkit::CubeTransitionCrossEffect cubeTransEffect( *internalCubeTransEffect );
43
44   //Initialization
45   internalCubeTransEffect->Initialize();
46
47   return cubeTransEffect;
48 }
49
50 void CubeTransitionCrossEffect::OnInitialize()
51 {
52   unsigned int idx;
53   for( unsigned int y = 0; y < mRows; y++ )
54   {
55     for( unsigned int x = y % 2; x < mColumns; x += 2 )
56     {
57       idx = y * mColumns + x;
58       SetTargetTop( idx );
59     }
60     for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
61     {
62       idx = y * mColumns + x;
63       SetTargetRight( idx );
64     }
65   }
66 }
67
68 void CubeTransitionCrossEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
69 {
70   float angle = Math::PI_2;
71   unsigned int idx;
72
73   if( panDisplacement.x < 0 )
74   {
75     for( unsigned int y = 0; y < mRows; y++ )
76     {
77       for( unsigned int x = y % 2; x < mColumns; x += 2 )
78       {
79         idx = y * mColumns + x;
80         SetTargetTop( idx );
81       }
82       for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
83       {
84         idx = y * mColumns + x;
85         SetTargetRight( idx );
86       }
87     }
88   }
89   else
90   {
91     angle = -angle;
92
93     for( unsigned int y = 0; y < mRows; y++ )
94     {
95       for( unsigned int x = y % 2; x < mColumns; x += 2 )
96       {
97         idx = y * mColumns + x;
98         SetTargetBottom( idx );
99       }
100       for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
101       {
102         idx = y * mColumns + x;
103         SetTargetLeft( idx );
104       }
105     }
106   }
107
108   const Vector2 halfSize = Self().GetCurrentSize().GetVectorXY() * 0.5f;
109   //the centre to "explode" the tiles outwards from
110   Vector3 centre( halfSize.x, halfSize.y, -1.0f / mDisplacementSpreadFactor );
111
112   for( unsigned int y = 0; y < mRows; y++ )
113   {
114     for( unsigned int x = y%2; x < mColumns; x=x+2) // rotate vertically
115     {
116       idx = y*mColumns + x;
117       SetupAnimation( idx, x, y, -angle, Vector3::XAXIS, centre );
118     }
119     for( unsigned int x = (y+1)%2; x < mColumns; x=x+2) // rotate horizontally
120     {
121       idx = y*mColumns + x;
122       SetupAnimation( idx, x, y, angle, Vector3::YAXIS, centre );
123     }
124   }
125
126   mAnimation.Play();
127   mIsAnimating = true;
128 }
129
130 void CubeTransitionCrossEffect::SetupAnimation( unsigned int actorIndex, unsigned int x, unsigned int y, float angle, const Vector3 axis, const Vector3& displacementCentre )
131 {
132   const Vector2 size = Self().GetCurrentSize().GetVectorXY();
133   Vector2 halfSize = size * 0.5f;
134
135   //the position of the centre of the front face tile
136   Vector3 position( halfSize.x * (2.0f * x + 1.0f) / mColumns, halfSize.y * (2.0f * y + 1.0f ) / mRows, 0.0f );
137
138   Vector3 direction = position - displacementCentre;
139   float length = direction.Length();
140   direction.Normalize();
141
142   float deltaLength = mCubeDisplacement / direction.z; //the length along the direction vector such that the projected direction onto the z axis is equal to mCubeDisplacement
143
144   Vector3 newPosition = ( direction * (length + deltaLength ) ) + displacementCentre;
145   Vector3 newLocalPosition = newPosition - position;
146
147   mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::ORIENTATION ), Quaternion( Radian( -angle ), axis ), AlphaFunction::EASE_IN_OUT_SINE );
148   mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::POSITION ), newLocalPosition, AlphaFunction::BOUNCE );
149
150   mAnimation.AnimateTo( Property( mCurrentTiles[ actorIndex ], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
151   mAnimation.AnimateTo( Property( mTargetTiles[ actorIndex ], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
152 }
153
154 } // namespace Internal
155
156 } // namespace Toolkit
157
158 } // namespace Dali