[dali_2.3.20] Merge branch '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) 2021 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 namespace Toolkit
32 {
33 class CubeTransitionEffect;
34
35 namespace Internal
36 {
37 /**
38  * CubeTransitionEffect implementation class
39  */
40 class CubeTransitionEffect : public Control
41 {
42 public:
43   /**
44    * Destructor
45    */
46   ~CubeTransitionEffect();
47
48   /**
49    * @copydoc Toolkit::CubeTransitionEffect::SetTransitionDuration
50    */
51   void SetTransitionDuration(float duration);
52
53   /**
54    * @copydoc Toolkit::CubeTransitionEffect::GetTransitionDuration
55    */
56   float GetTransitionDuration() const;
57
58   /**
59    * @copydoc Toolkit::CubeTransitionEffect::SetCubeDisplacement
60    */
61   void SetCubeDisplacement(float displacement);
62
63   /**
64    * @copydoc Toolkit::CubeTransitionEffect::GetCubeDisplacement
65    */
66   float GetCubeDisplacement() const;
67
68   /**
69    * @copydoc Toolkit::CubeTransitionEffect::IsTransitioning
70    */
71   bool IsTransitioning();
72
73   /**
74    * @copydoc Toolkit::CubeTransitionEffect::SetCurrentTexture
75    */
76   void SetCurrentTexture(Texture texture);
77
78   /**
79    * @copydoc Toolkit::CubeTransitionEffect::SetTargetTexture
80    */
81   void SetTargetTexture(Texture texture);
82
83   /**
84    * @copydoc Toolkit::CubeTransitionEffect::StartTransition(bool)
85    */
86   void StartTransition(bool toNextImage = true);
87
88   /**
89    * @copydoc Toolkit::CubeTransitionEffect::StartTransition(Vector2, Vector2)
90    */
91   void StartTransition(Vector2 panPosition, Vector2 panDisplacement);
92
93   /**
94    * @copydoc Toolkit::CubeTransitionEffect::PauseTransition()
95    */
96   void PauseTransition();
97
98   /**
99    * @copydoc Toolkit::CubeTransitionEffect::ResumeTransition()
100    */
101   void ResumeTransition();
102
103   /**
104    * @copydoc Toolkit::CubeTransitionEffect::StopTransition()
105    */
106   void StopTransition();
107
108 public: //Signal
109   /**
110    * @copydoc Toolkit::CubeTransitionEffect::TransitionCompletedSignal()
111    */
112   Toolkit::CubeTransitionEffect::TransitionCompletedSignalType& TransitionCompletedSignal();
113
114   /**
115    * Connects a callback function with the object's signals.
116    * @param[in] object The object providing the signal.
117    * @param[in] tracker Used to disconnect the signal.
118    * @param[in] signalName The signal to connect to.
119    * @param[in] functor A newly allocated FunctorDelegate.
120    * @return True if the signal was connected.
121    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
122    */
123   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
124
125 protected:
126   /**
127    * @copydoc CustomActorImpl::OnSceneConnection()
128    */
129   void OnSceneConnection(int depth) override;
130
131   /**
132    * @copydoc CustomActorImpl::OnSceneDisconnection()
133    */
134   void OnSceneDisconnection() override;
135
136 protected:
137   /**
138    * Construct a new CubeTransitionEffect object
139    * Called in the constructor of subclasses
140    * @param[in] numRows How many rows of cubes
141    * @param[in] numColumns How many columns of cubes
142    */
143   CubeTransitionEffect(unsigned int numRows, unsigned int numColumns);
144
145   /**
146    * Initialization steps: creating a layer, two groups of tiles,
147    * and one group of actors (cubes) serving as parents of every two tiles (one from each image).
148    */
149   void Initialize();
150
151 protected:
152   void SetTargetLeft(unsigned int idx);
153   void SetTargetRight(unsigned int idx);
154   void SetTargetTop(unsigned int idx);
155   void SetTargetBottom(unsigned int idx);
156
157 private:
158   /**
159    * Callback function of transition animation finished
160    * Hide transition layer, show current image, and set isAnimating flag to false
161    * @param[in] source The cube transition animation
162    */
163   void OnTransitionFinished(Animation& source);
164
165   /**
166    * This method is called after the CubeTransitionEffect has been initialized.  Derived classes should do
167    * any second phase initialization by overriding this method.
168    */
169   virtual void OnInitialize()
170   {
171   }
172
173   /**
174    * This method is called after the a new transition is activated.
175    * Derived classes should do any specialized transition process by overriding this method.
176    * @param[in] panPosition The press down position of panGesture
177    * @param[in] panDisplacement The displacement vector of panGesture
178    */
179   virtual void OnStartTransition(Vector2 panPosition, Vector2 panDisplacement)
180   {
181   }
182
183   /**
184    * This method is called when the transition is forced stop in the middle of animation.
185    * Derived classed should set the rotation status of the cubes to the same as the final state when the animation is finished completely.
186    * So that the next transition would be started correctly.
187    */
188   virtual void OnStopTransition()
189   {
190   }
191
192   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
193
194   void ResetToInitialState();
195
196 protected:
197   typedef std::vector<Actor> ActorArray;
198   enum FACE
199   {
200     TOP,
201     BOTTOM,
202     LEFT,
203     RIGHT
204   };
205
206   ActorArray   mBoxes;
207   Vector<FACE> mBoxType;
208   ActorArray   mCurrentTiles;
209   ActorArray   mTargetTiles;
210
211   Actor mBoxRoot;
212
213   unsigned int mRows;
214   unsigned int mColumns;
215
216   Renderer mCurrentRenderer;
217   Renderer mTargetRenderer;
218
219   Texture mCurrentTexture;
220   Texture mTargetTexture;
221
222   Animation mAnimation;
223
224   Vector2 mTileSize;
225
226   bool mIsAnimating;
227   bool mIsPaused;
228
229   float mAnimationDuration;
230   float mCubeDisplacement;
231
232   static const Vector4 FULL_BRIGHTNESS;
233   static const Vector4 HALF_BRIGHTNESS;
234
235 private:
236   Toolkit::CubeTransitionEffect::TransitionCompletedSignalType mTransitionCompletedSignal;
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