Update keyboard focus direction enum for Control
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bubble-effect / bubble-emitter-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__
3
4 /*
5  * Copyright (c) 2014 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/actors/camera-actor.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/devel-api/actors/mesh-actor.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/frame-buffer-image.h>
27 #include <dali/devel-api/geometry/mesh.h>
28 #include <dali/public-api/render-tasks/render-task.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
33 #include <dali-toolkit/devel-api/shader-effects/bubble-effect/bubble-effect.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 /**
45  * BubbleEmitter implementation class.
46  */
47 class BubbleEmitter : public Control
48 {
49 public:
50
51   /**
52    * Destructor
53    */
54   ~BubbleEmitter();
55
56   /**
57    * @copydoc Toolkit::BubbleEmitter::New
58    */
59   static Toolkit::BubbleEmitter New( const Vector2& winSize,
60                                      Image shapeImage,
61                                      unsigned int maximumNumberOfBubble,
62                                      const Vector2& bubbleSizeRange );
63
64   /**
65    * @copydoc Toolkit::BubbleEmitter::GetRootActor
66    */
67   Actor GetRootActor();
68
69   /**
70    * @copydoc Toolkit::BubbleEmitter::SetBackground
71    */
72   void SetBackground( Image bgImage, const Vector3& hsvDelta );
73
74   /**
75    * @copydoc Toolkit::BubbleEmitter::SetShapeImage
76    */
77   void SetShapeImage( Image shapeImage );
78
79   /**
80    * @copydoc Toolkit::BubbleEmiter::SetBubbleScale
81    */
82   void SetBubbleScale( float scale );
83
84   /**
85    * @copydoc Toolkit::BubbleEmitter::SetBubbleDensity
86    */
87   void SetBubbleDensity( unsigned int density );
88
89   /**
90    * @copydoc Toolkit::BubbleEmitter::SetBlendMode
91    */
92   void SetBlendMode( bool enable );
93
94   /**
95    * @copydoc Toolkit::BubbleEmitter::EmitBubble
96    */
97   void EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement );
98
99   /**
100    * @copydoc Toolkit::BubbleEmitter::StartExplosion
101    */
102   void StartExplosion( float duration, float multiple );
103
104   /**
105    * @copydoc Toolkit::BubbleEmitter::Restore
106    */
107   void Restore();
108
109 private:
110
111   /**
112    * Construct a new BubbleEmitter object.
113    * @param[in] movementArea The size of the bubble moving area
114    * @param[in] shapeImage The alpha channnel of this texture defines the bubble shape.
115    * @param[in] maximumNumberOfBubble The maximum number of bubble needed.
116    * @param[in] bubbleSizeRange The size range of the bubbles; x component is the minimal size, and y component is the maximum size.
117    */
118   BubbleEmitter( const Vector2& movementArea,
119                  Image shapeImage,
120                  unsigned int maximumNumberOfBubble,
121                  const Vector2& bubbleSizeRange );
122
123   /**
124    * This method is called after the CubeTransitionEffect has been initialized.
125    * The meshActors and BubbleEffects are created here.
126    */
127   void OnInitialize();
128
129   /**
130    * Callback function of the finished signal of off-screen render task.
131    * @param[in] source The render task used to create the color adjusted background image.
132    */
133   void OnRenderFinished(RenderTask& source);
134
135   /**
136    * Callback function from Stage to tell us if the context has been regained.
137    */
138   void OnContextRegained();
139
140   /**
141    * Generate the material object which is attached to the meshActor to describe its color, texture, texture mapping mode etc.
142    */
143   void GenMaterial();
144
145   /**
146    * Add a vertex to the mesh data.
147    * @param[in] vertices The collection of vertices.
148    * @param[in] XYZ The vertex position coordinates.
149    * @param[in] UV The vertex texture coordinate.
150    */
151   void AddVertex(MeshData::VertexContainer& vertices, Vector3 XYZ, Vector2 UV);
152
153   /**
154    * Add a triangle to the mesh data.
155    * @param[in] faces The collection od FaceIndex items.
156    * @param[in] v0 The index of the first point of the triangle.
157    * @param[in] v1 The index of the second point of the triangle.
158    * @param[in] v3 The index of the first point of the triangle.
159    */
160   void AddTriangle(MeshData::FaceIndices& faces,size_t v0, size_t v1, size_t v2);
161
162   /**
163    * Create a new mesh.
164    * @param[in] meshData The MeshData object which encompasses all the data required to describe and render the 3D mesh.
165    * @param[in] numberOfBubble The triangle number in the meshData is 2*numOfBubble; two triangles for each bubble
166    */
167   void ConstructBubbleMesh( MeshData& meshData, unsigned int numOfBubble);
168
169   /**
170    * Set the uniform values to the shader effect to emit a bubble
171    * @param[in] effect The BubbleEffect to render the current bubble
172    * @param[in] curUniform The index of the uniform array in the shader
173    * @param[in] emitPosition The start position of the bubble movement.
174    * @param[in] displacement The displacement used to bound the moving distance of the bubble.
175    */
176   void SetBubbleParameter( BubbleEffect& effect, unsigned int curUniform,
177                            const Vector2& emitPosition, const Vector2& displacement );
178
179   /**
180    * Set the uniform values to the shader effect to emit a bubble
181    * @param[in] effect The BubbleEffect to render the current bubble
182    * @param[in] curUniform The index of the uniform array in the shader
183    * @param[in] emitPosition The start position of the bubble movement.
184    * @param[in] direction The direction used to constrain the bubble to move in an adjacent direction around it.
185    * @param[in] displacement The displacement used to bound the moving distance of the bubble.
186    */
187   void SetBubbleParameter( BubbleEffect& effect, unsigned int curUniform,
188                            const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement );
189
190   /**
191    * Callback function of the explosion animation finished signal to reset the shader parameters
192    * @param[in] source The explosion animation.
193    */
194   void OnExplosionFinished( Animation& source );
195
196   /**
197    * Return a random value between the given interval.
198    * @param[in] f0 The low bound
199    * @param[in] f1 The up bound
200    * @return A random value between the given interval
201    */
202   float RandomRange(float f0, float f1);
203
204 private:
205
206   Vector2                     mMovementArea;        ///< The size of the bubble moving area, usually the same size as the background image actor.
207   Image                       mShapeImage;          ///< The alpha channnel of this texture defines the bubble shape.
208   Actor                       mBubbleRoot;          ///<The bubble root actor. Need to add it to stage to get the bubbles rendered.
209
210   unsigned int                mNumBubblePerShader;  ///< How many bubbles for each BubbleEffect shader.
211   unsigned int                mNumShader;           ///< How many BubbleEffect shaders are used.
212   unsigned int                mTotalNumOfBubble;    ///< mNumBubblePerShader*mNumShader.
213   bool                        mRenderTaskRunning;   ///< If the background render task is currently running
214
215   Vector2                     mBubbleSizeRange;     ///< The bubble size range.
216
217   std::vector<Mesh>           mMesh;                ///< The mesh vector, each mesh is used to create a meshActor which applies a BubbleEffect.
218   std::vector<MeshActor>      mMeshActor;           ///< The meshActor vector, its size is mNumShader.
219   MeshActor                   mMeshActorForNoise;   ///< An Extra mesh data to emit bubbles which emit bubble in totally random angle.
220   Material                    mCustomMaterial;      ///< The material object which is attached to the meshActor to describe its color, texture, texture mapping mode etc.
221
222   std::vector<BubbleEffect>   mEffect;              ///< The bubbleEffect vector, corresponding to the mMeshActoe vector.
223   BubbleEffect                mEffectForNoise;      ///< The extra bubbleEffect, corresponding to the mMeshActorForNoise.
224
225   unsigned int                mCurrentUniform;      ///< Keep track of the uniform index for the newly emitted bubble
226
227   Vector3                     mHSVDelta;            ///< The HSV difference used to adjust the background image color.
228   Image                       mBackgroundImage;     ///< The original background image
229   FrameBufferImage            mEffectImage;         ///< The image stores the adjusted color of the background image.The bubbles pick color from this image.
230   CameraActor                 mCameraActor;         ///< The render task views the scene from the perspective of this actor.
231
232   unsigned int                mDensity;             ///< How many bubbles will emit at each time, they are controlled by same uniforms in the shader.
233
234 };
235
236 } // namespace Internal
237
238 // Helpers for public-api forwarding methods
239 inline Internal::BubbleEmitter& GetImpl(Dali::Toolkit::BubbleEmitter& obj)
240 {
241   DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
242   Dali::RefObject& handle = obj.GetImplementation();
243   return static_cast<Toolkit::Internal::BubbleEmitter&>(handle);
244 }
245
246 inline const Internal::BubbleEmitter& GetImpl(const Dali::Toolkit::BubbleEmitter& obj)
247 {
248   DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
249   const Dali::RefObject& handle = obj.GetImplementation();
250   return static_cast<const Toolkit::Internal::BubbleEmitter&>(handle);
251 }
252
253 } // namespace Toolkit
254
255 } // namespace Dali
256
257 #endif /* __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__ */