1 #ifndef __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/common/stage.h>
24 #include <dali/public-api/images/frame-buffer-image.h>
25 #include <dali/public-api/render-tasks/render-task.h>
26 #include <dali/devel-api/object/property-buffer.h>
27 #include <dali/devel-api/rendering/geometry.h>
28 #include <dali/devel-api/rendering/renderer.h>
29 #include <dali/devel-api/rendering/sampler.h>
30 #include <dali/devel-api/rendering/shader.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
46 typedef IntrusivePtr<BubbleActor> BubbleActorPtr;
49 * BubbleEmitter implementation class.
51 class BubbleEmitter : public Control
61 * @copydoc Toolkit::BubbleEmitter::New
63 static Toolkit::BubbleEmitter New( const Vector2& winSize,
65 unsigned int maximumNumberOfBubble,
66 const Vector2& bubbleSizeRange );
69 * @copydoc Toolkit::BubbleEmitter::GetRootActor
74 * @copydoc Toolkit::BubbleEmitter::SetBackground
76 void SetBackground( Image bgImage, const Vector3& hsvDelta );
79 * @copydoc Toolkit::BubbleEmitter::SetShapeImage
81 void SetShapeImage( Image shapeImage );
84 * @copydoc Toolkit::BubbleEmiter::SetBubbleScale
86 void SetBubbleScale( float scale );
89 * @copydoc Toolkit::BubbleEmitter::SetBubbleDensity
91 void SetBubbleDensity( unsigned int density );
94 * @copydoc Toolkit::BubbleEmitter::EmitBubble
96 void EmitBubble( Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement );
99 * @copydoc Toolkit::BubbleEmitter::Restore
106 * Construct a new BubbleEmitter object.
107 * @param[in] movementArea The size of the bubble moving area
108 * @param[in] shapeImage The alpha channnel of this texture defines the bubble shape.
109 * @param[in] maximumNumberOfBubble The maximum number of bubble needed.
110 * @param[in] bubbleSizeRange The size range of the bubbles; x component is the minimal size, and y component is the maximum size.
112 BubbleEmitter( const Vector2& movementArea,
114 unsigned int maximumNumberOfBubble,
115 const Vector2& bubbleSizeRange );
118 * This method is called after the CubeTransitionEffect has been initialized.
119 * The meshActors and BubbleEffects are created here.
124 * Create the geometry of a mesh.
125 * @param[in] numOfPatch The triangle number in the mesh is 2*numOfPatch; two triangles for each bubble.
126 * @return The mesh geometry.
128 Geometry CreateGeometry( unsigned int numOfPatch );
131 * Callback function of the finished signal of off-screen render task.
132 * @param[in] source The render task used to create the color adjusted background image.
134 void OnRenderFinished(RenderTask& source);
137 * Callback function from Stage to tell us if the context has been regained.
139 void OnContextRegained();
142 * Set the uniform values to the shader effect to emit a bubble
143 * @param[in] bubbleActor The BubbleActor to render the current bubble
144 * @param[in] curUniform The index of the uniform array in the shader
145 * @param[in] emitPosition The start position of the bubble movement.
146 * @param[in] direction The direction used to constrain the bubble to move in an adjacent direction around it.
147 * @param[in] displacement The displacement used to bound the moving distance of the bubble.
149 void SetBubbleParameter( BubbleActorPtr bubbleActor, unsigned int curUniform,
150 const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement );
154 Actor mBubbleRoot; ///<The bubble root actor. Need to add it to stage to get the bubbles rendered.
155 Image mShapeImage; ///< The alpha channnel of this texture defines the bubble shape.
156 Image mBackgroundImage; ///< The original background image
157 FrameBufferImage mEffectImage; ///< The image stores the adjusted color of the background image.The bubbles pick color from this image.
158 CameraActor mCameraActor; ///< The render task views the scene from the perspective of this actor.
160 Geometry mMeshGeometry; ///< The mesh geometry which contains the vertices and indices data
161 Material mMaterial; ///< The material which controls the bubble display
162 std::vector<BubbleActorPtr> mBubbleActors; ///< The meshActor vector, its size is mNumShader.
164 Vector2 mMovementArea; ///< The size of the bubble moving area, usually the same size as the background image actor.
165 Vector2 mBubbleSizeRange; ///< The size range of the bubbles; x component is the low bound, and y component is the up bound.
166 Vector3 mHSVDelta; ///< The HSV difference used to adjust the background image color.
168 unsigned int mNumBubblePerActor; ///< How many bubbles for each BubbleActor.
169 unsigned int mNumActor; ///< How many BubbleActors are used.
170 unsigned int mDensity; ///< How many bubbles will emit at each time, they are controlled by same uniforms in the shader.
171 unsigned int mTotalNumOfBubble; ///< mNumBubblePerShader*mNumShader.
172 unsigned int mCurrentBubble; ///< Keep track of the index for the newly emitted bubble
173 unsigned int mRandomSeed; ///< Seed to generate random number.
175 bool mRenderTaskRunning; ///< If the background render task is currently running
179 } // namespace Internal
181 // Helpers for public-api forwarding methods
182 inline Internal::BubbleEmitter& GetImpl(Dali::Toolkit::BubbleEmitter& obj)
184 DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
185 Dali::RefObject& handle = obj.GetImplementation();
186 return static_cast<Toolkit::Internal::BubbleEmitter&>(handle);
189 inline const Internal::BubbleEmitter& GetImpl(const Dali::Toolkit::BubbleEmitter& obj)
191 DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
192 const Dali::RefObject& handle = obj.GetImplementation();
193 return static_cast<const Toolkit::Internal::BubbleEmitter&>(handle);
196 } // namespace Toolkit
200 #endif /* __DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H__ */