Merge "Fix the texture bleeding with wrapping in atlas" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / transition-effects / cube-transition-effect-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H
2 #define DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/rendering/renderer.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/devel-api/transition-effects/cube-transition-effect.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class CubeTransitionEffect;
36
37 namespace Internal
38 {
39
40 /**
41  * CubeTransitionEffect implementation class
42  */
43 class CubeTransitionEffect : public Control
44 {
45
46 public:
47
48   /**
49    * Destructor
50    */
51   ~CubeTransitionEffect();
52
53   /**
54    * @copydoc Toolkit::CubeTransitionEffect::SetTransitionDuration
55    */
56   void SetTransitionDuration( float duration );
57
58   /**
59    * @copydoc Toolkit::CubeTransitionEffect::GetTransitionDuration
60    */
61   float GetTransitionDuration() const;
62
63   /**
64    * @copydoc Toolkit::CubeTransitionEffect::SetCubeDisplacement
65    */
66   void SetCubeDisplacement( float displacement );
67
68   /**
69    * @copydoc Toolkit::CubeTransitionEffect::GetCubeDisplacement
70    */
71   float GetCubeDisplacement() const;
72
73   /**
74    * @copydoc Toolkit::CubeTransitionEffect::IsTransitioning
75    */
76   bool IsTransitioning();
77
78   /**
79    * @copydoc Toolkit::CubeTransitionEffect::SetCurrentTexture
80    */
81   void SetCurrentTexture( Texture texture );
82
83   /**
84    * @copydoc Toolkit::CubeTransitionEffect::SetTargetTexture
85    */
86   void SetTargetTexture( Texture texture );
87
88   /**
89    * @copydoc Toolkit::CubeTransitionEffect::StartTransition(bool)
90    */
91   void StartTransition( bool toNextImage = true );
92
93   /**
94    * @copydoc Toolkit::CubeTransitionEffect::StartTransition(Vector2, Vector2)
95    */
96   void StartTransition( Vector2 panPosition, Vector2 panDisplacement );
97
98   /**
99    * @copydoc Toolkit::CubeTransitionEffect::PauseTransition()
100    */
101   void PauseTransition();
102
103   /**
104    * @copydoc Toolkit::CubeTransitionEffect::ResumeTransition()
105    */
106   void ResumeTransition();
107
108   /**
109    * @copydoc Toolkit::CubeTransitionEffect::StopTransition()
110    */
111   void StopTransition();
112
113 public: //Signal
114
115   /**
116    * @copydoc Toolkit::CubeTransitionEffect::TransitionCompletedSignal()
117    */
118   Toolkit::CubeTransitionEffect::TransitionCompletedSignalType& TransitionCompletedSignal();
119
120   /**
121    * Connects a callback function with the object's signals.
122    * @param[in] object The object providing the signal.
123    * @param[in] tracker Used to disconnect the signal.
124    * @param[in] signalName The signal to connect to.
125    * @param[in] functor A newly allocated FunctorDelegate.
126    * @return True if the signal was connected.
127    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
128    */
129   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
130
131 protected:
132   /**
133    * @copydoc CustomActorImpl::OnStageConnection()
134    */
135   virtual void OnStageConnection( int depth );
136
137   /**
138    * @copydoc CustomActorImpl::OnStageDisconnection()
139    */
140   virtual void OnStageDisconnection();
141
142 protected:
143
144   /**
145    * Construct a new CubeTransitionEffect object
146    * Called in the constructor of subclasses
147    * @param[in] numRows How many rows of cubes
148    * @param[in] numColumns How many columns of cubes
149    */
150   CubeTransitionEffect( unsigned int numRows, unsigned int numColumns );
151
152   /**
153    * Initialization steps: creating a layer, two groups of tiles,
154    * and one group of actors (cubes) serving as parents of every two tiles (one from each image).
155    */
156   void Initialize();
157
158
159 protected:
160   void SetTargetLeft( unsigned int idx );
161   void SetTargetRight( unsigned int idx );
162   void SetTargetTop( unsigned int idx );
163   void SetTargetBottom( unsigned int idx );
164
165 private:
166
167   /**
168    * Callback function of transition animation finished
169    * Hide transition layer, show current image, and set isAnimating flag to false
170    * @param[in] source The cube transition animation
171    */
172   void OnTransitionFinished(Animation& source);
173
174   /**
175    * This method is called after the CubeTransitionEffect has been initialized.  Derived classes should do
176    * any second phase initialization by overriding this method.
177    */
178   virtual void OnInitialize() { }
179
180   /**
181    * This method is called after the a new transition is activated.
182    * Derived classes should do any specialized transition process by overriding this method.
183    * @param[in] panPosition The press down position of panGesture
184    * @param[in] panDisplacement The displacement vector of panGesture
185    */
186   virtual void OnStartTransition( Vector2 panPosition, Vector2 panDisplacement ) {}
187
188   /**
189    * This method is called when the transition is forced stop in the middle of animation.
190    * Derived classed should set the rotation status of the cubes to the same as the final state when the animation is finished completely.
191    * So that the next transition would be started correctly.
192    */
193   virtual void OnStopTransition() {}
194
195   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
196
197   void ResetToInitialState();
198
199
200 protected:
201   typedef std::vector< Actor > ActorArray;
202   enum FACE { TOP, BOTTOM, LEFT, RIGHT };
203
204   ActorArray                 mBoxes;
205   Vector< FACE >             mBoxType;
206   ActorArray                 mCurrentTiles;
207   ActorArray                 mTargetTiles;
208
209   Actor                      mBoxRoot;
210
211   unsigned int               mRows;
212   unsigned int               mColumns;
213
214   Renderer                   mCurrentRenderer;
215   Renderer                   mTargetRenderer;
216
217   Texture                    mCurrentTexture;
218   Texture                    mTargetTexture;
219
220   Animation                  mAnimation;
221
222   Vector2                    mTileSize;
223
224   bool                       mIsAnimating;
225   bool                       mIsPaused;
226
227   float                      mAnimationDuration;
228   float                      mCubeDisplacement;
229
230   static const Vector4       FULL_BRIGHTNESS;
231   static const Vector4       HALF_BRIGHTNESS;
232
233 private:
234
235   Toolkit::CubeTransitionEffect::TransitionCompletedSignalType mTransitionCompletedSignal;
236
237 };
238
239 } // namespace Internal
240
241 // Helpers for public-api forwarding methods
242
243 inline Internal::CubeTransitionEffect& GetImpl(Dali::Toolkit::CubeTransitionEffect& obj)
244 {
245   DALI_ASSERT_ALWAYS(obj);
246
247   Dali::RefObject& handle = obj.GetImplementation();
248
249   return static_cast<Internal::CubeTransitionEffect&>(handle);
250 }
251
252 inline const Internal::CubeTransitionEffect& GetImpl(const Dali::Toolkit::CubeTransitionEffect& obj)
253 {
254   DALI_ASSERT_ALWAYS(obj);
255
256   const Dali::RefObject& handle = obj.GetImplementation();
257
258   return static_cast<const Internal::CubeTransitionEffect&>(handle);
259 }
260
261 } // namespace Toolkit
262
263 } // namespace Dali
264
265 #endif // DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H