Change filter mode in TextLabel to improve quality while scaling
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition-effects / cube-transition-fold-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-fold-effect-impl.h"
20
21 namespace Dali
22 {
23
24 namespace Toolkit
25 {
26
27 namespace Internal
28 {
29 CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns )
30 : CubeTransitionEffect( numRows, numColumns )
31 {
32 }
33
34 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns )
35 {
36   // Create the implementation
37   IntrusivePtr< CubeTransitionFoldEffect > internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns );
38
39   // Pass ownership to CustomActor handle
40   Toolkit::CubeTransitionFoldEffect cubeTransEffect( *internalCubeTransEffect );
41
42   //Initialization
43   internalCubeTransEffect->Initialize();
44
45   return cubeTransEffect;
46 }
47
48 void CubeTransitionFoldEffect::OnInitialize()
49 {
50   unsigned int idx;
51   for( unsigned int y = 0; y < mRows; y++ )
52   {
53     idx = y*mColumns;
54     for( unsigned int x = y%2; x < mColumns; x=x+2)
55     {
56       SetTargetLeft( idx + x );
57     }
58     for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
59     {
60       SetTargetRight( idx + x );
61     }
62   }
63 }
64
65 void CubeTransitionFoldEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
66 {
67   float angle = Math::PI_2;
68
69   unsigned int idx;
70   if( panDisplacement.x < 0 )
71   {
72     for( unsigned int y = 0; y < mRows; y++ )
73     {
74       idx = y*mColumns;
75       for( unsigned int x = y%2; x < mColumns; x=x+2)
76       {
77         SetTargetLeft( idx + x );
78       }
79       for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
80       {
81         SetTargetRight( idx + x );
82       }
83     }
84   }
85   else
86   {
87     angle = -angle;
88
89     for( unsigned int y = 0; y < mRows; y++ )
90     {
91       idx = y*mColumns;
92       for( unsigned int x = y%2; x < mColumns; x=x+2)
93       {
94         SetTargetRight( idx + x );
95       }
96       for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
97       {
98         SetTargetLeft( idx + x );
99       }
100     }
101   }
102
103   for( unsigned int y = 0; y < mRows; y++ )
104   {
105     idx = y*mColumns;
106     for( unsigned int x = y%2; x < mColumns; x=x+2)
107     {
108       SetupAnimation( idx + x, x, angle );
109     }
110     for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
111     {
112       SetupAnimation( idx + x, x, -angle );
113     }
114   }
115
116   mAnimation.Play();
117   mIsAnimating = true;
118 }
119
120 void CubeTransitionFoldEffect::SetupAnimation( unsigned int actorIndex, unsigned int x, float angle )
121 {
122   //rotate and translate the cube such that the edges remain in constant contact
123   //calculate the maximum distance the cube has to move when it the box has rotated 45 degrees
124   //ie distance from of centre of square to a vertex is given by:
125   //  distance = width / sqrt(2)
126   //therefore the delta distance the cube should move is given by:
127   //  delta_distance = ( width / 2 ) - distance
128   //re-arranging we get:
129   //  delta_distance = ( width / 2 ) * ( sqrt(2) - 1 )
130   //accumulating over the length of the row we get:
131   //  delta_distance_at_x = x * delta_distance;
132
133   float delta = (float)x * mTileSize.x * ( 1.4142f - 1.0f );
134
135   Vector3 position( mBoxes[ actorIndex ].GetCurrentPosition() );
136   mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::ORIENTATION ), Quaternion( Radian( angle ), Vector3::YAXIS ), AlphaFunction::LINEAR );
137   mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::POSITION_X ), position.x + delta, AlphaFunction::BOUNCE );
138
139   mAnimation.AnimateTo( Property( mCurrentTiles[ actorIndex ], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
140   mAnimation.AnimateTo( Property( mTargetTiles[ actorIndex ], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
141 }
142
143 } // namespace Internal
144
145 } // namespace Toolkit
146
147 } // namespace Dali