DALi Version 1.1.30
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / bubble-effect / bubble-actor.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_BUBBLE_ACTOR_H_
2 #define __DALI_TOOLKIT_INTERNAL_BUBBLE_ACTOR_H_
3
4 /*
5  * Copyright (c) 2015 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 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/object/property-map.h>
23 #include <dali/devel-api/rendering/renderer.h>
24
25 namespace Dali
26 {
27
28 namespace Toolkit
29 {
30
31 namespace Internal
32 {
33
34 /**
35  * BubbleActor is a group of bubbles.Each bubble can be moved separately.
36  * Its custom shader achieves similar effect of particle system by applying on a specially created mesh
37  * Each bubble is rendered on a patch with two triangles; and each mesh can contain multiple such patches, thus a group.
38  */
39 class BubbleActor : public RefObject
40 {
41 public:
42
43   /**
44    * Constructor
45    * @param[in] numberOfBubble How many groups of uniforms are used to control the bubble movement.
46    * Note: Limited by the maximum available uniforms, this parameter cannot be bigger than 100.
47    * Ideally use one group of uniform to control one bubble.
48    * If the num of patches in the MeshActor is more than groups of uniforms,
49    * the uniform values will be shared by multiple bubbles. Allow up to 9 times.
50    * @param[in] movementArea The size of the bubble moving area, usually the same size as the background image actor.
51    * @return A newly allocated object.
52    */
53   BubbleActor( unsigned int numberOfBubble,
54                const Vector2& movementArea);
55
56   /**
57    * @brief Destructor
58    */
59   ~BubbleActor(){}
60
61   /**
62    * Prepare for the rendering: create and add renderer, and register properties
63    * @param[in] geometry The geometry to be used by the renderer
64    * @param[in] material The material to be used by the renderer
65    */
66   void MakeRenderable( Geometry geometry, Material material  );
67
68   /**
69    * Return the mesh actor which is used to display the bubbles
70    */
71   Actor GetMeshActor();
72
73   /**
74    * Sets the geometry to be used by the renderer
75    * @param[in] geometry The geometry to be used by the renderer
76    */
77   void SetGeometry( Geometry geometry );
78
79   /**
80    * Set the bubble movement area for the BubbleEffect
81    * @param[in] movementArea The size of bubble movement area; by default, it is the stage size
82    */
83   void SetMovementArea( const Vector2& movementArea );
84
85   /**
86    * Set the start and end positions of the index-th bubble's movement.
87    * @param[in] index Indicate which bubble these properties are applied on.
88    * @param[in] startAndEndPosition The start and the end position of movement.
89    */
90   void SetStartAndEndPosition( unsigned int index, const Vector4& startAndEndPosition );
91
92   /**
93    * Set the movement completed percentage of the index-th bubble.
94    * The bubble will appear at start position when percentage equals to zero,
95    * and disappear near end position (affected by gravity) when percentage equals to one.
96    * This percentage property is used to animate the bubble movement.
97    * @param[in] index Indicate which bubble this property is applied on.
98    * @param[in] percentage Set the percentage property value ( between zero and one ).
99    */
100   void SetPercentage( unsigned int index, float percentage );
101
102   /**
103    * Set the gravity applied to the y direction, which makes the bubbles no longer moving on a straight line.
104    * @param[in] gravity The gravity on the y direction.
105    */
106   void SetGravity( float gravity );
107
108   /**
109    * Set the scale factor applied to the bubbles
110    * @param[in] scale The scale factor applied on all bubbles.
111    */
112   void SetDynamicScale( float scale );
113
114   /**
115    * Get the idx-th percentage property.
116    * @param[in] idx The percentage property index.
117    * @return the idx-th percentage property.
118    */
119   Property GetPercentageProperty( unsigned int idx );
120
121   /**
122    * Reset the uniform values to default.
123    */
124   void ResetProperties();
125
126 private:
127
128   Actor        mActor;
129   Renderer     mRenderer;
130
131   Vector2      mMovementArea;      ///< The size of the bubble moving area, usually the same size as the background image actor.
132
133   //properties mapped as uniforms
134   std::vector<Property::Index> mIndicesOffset;             ///< Indices of the properties mapping to uniform array 'uOffset'
135   std::vector<Property::Index> mIndiceStartEndPos;         ///< Indices of the properties mapping to uniform array 'uStartAndEndPos'
136   std::vector<Property::Index> mIndicesPercentage;         ///< Indices of the properties mapping to uniform array 'uPercentage'
137   Property::Index              mIndexGravity;              ///< Index of the property mapping to uniform 'uGravity'
138   Property::Index              mIndexDynamicScale;         ///< Index of the property mapping to uniform 'uDynamicScale'
139   Property::Index              mIndexInvertedMovementArea; ///< Index of the property mapping to uniform 'uInvertedMovementArea'
140
141   unsigned int mNumBubble;  ///< How many groups of uniforms are used to control the bubble movement.
142   unsigned int mRandomSeed; ///< Seed to generate random number.
143 };
144
145 } // namespace Internal
146
147 } // namespace Toolkit
148
149 } // namespace Dali
150
151 #endif /* __DALI_TOOLKIT_INTERNAL_BUBBLE_ACTOR_H_ */