[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / particle-system / particle-source.h
1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/signals/callback.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/particle-system/particle-types.h>
27
28 namespace Dali::Toolkit::ParticleSystem::Internal
29 {
30 class ParticleSource;
31 }
32
33 namespace Dali::Toolkit::ParticleSystem
34 {
35 class ParticleEmitter;
36
37 class ParticleList;
38
39 class ParticleDomain;
40
41 class ParticleModifier;
42
43 class ParticleRenderer;
44
45 /**
46  * @brief Interface to override as a particle source
47  *
48  * ParticleSourceInterace allows altering behaviour for
49  * generating new particles.
50  */
51 class DALI_TOOLKIT_API ParticleSourceInterface
52 {
53 public:
54   /**
55    * @brief Adds new particles
56    * @param[in] outList List to write back
57    * @param[in] count Requested particles count
58    *
59    * @return Function should return a Number of emitted particles
60    */
61   virtual uint32_t Update(ParticleList& outList, uint32_t count) = 0;
62
63   /**
64    * @brief Called when source is added to the emitter
65    */
66   virtual void Init() = 0;
67 };
68
69 /**
70  * @class ParticleSource
71  *
72  * ParticleSource defines a logic associated with particles emission.
73  * The emitter will use ParticleSource in order to spawn new particles.
74  *
75  * ParticleSource manages how, where and how many particles to emit.
76  *
77  * ParticleSource uses an implementation of ParticleSourceInterface when
78  * emitting new particles.
79  */
80 class DALI_TOOLKIT_API ParticleSource : public Dali::BaseHandle
81 {
82 public:
83   /**
84    * @brief Constructor
85    */
86   ParticleSource() = default;
87
88   /**
89    * @brief Destructor
90    */
91   ~ParticleSource() = default;
92
93   /**
94    * @brief Creates a new instance of ParticleSource
95    *
96    * New instance is given an ownership over valid implementation
97    * of a ParticleSourceInferface.
98    *
99    * @param[in] particleSourceCallback Valid implementation of ParticleSourceInterface
100    *
101    * @return New ParticleSource object handle
102    */
103   static ParticleSource New(std::unique_ptr<ParticleSourceInterface>&& particleSourceCallback);
104
105   /**
106    * @brief Creates new ParticleSource with given source callback and arguments
107    *
108    * The function creates a ParticleSource of a given class (T) and constructor
109    * arguments.
110    *
111    * @return New ParticleSource object handle
112    */
113   template<class T, class... Args>
114   static ParticleSource New(Args... args)
115   {
116     return New(std::move(std::make_unique<T>(args...)));
117   }
118
119   /**
120    * @brief Downcasts a handle to ParticleSource handle.
121    *
122    * If handle points to an ParticleSource object, the downcast produces valid handle.
123    * If not, the returned handle is left uninitialized.
124    *
125    * @param[in] handle to An object
126    * @return handle to a ParticleSource object or an uninitialized handle
127    */
128   static ParticleSource DownCast(BaseHandle handle);
129
130   /**
131    * @brief Returns associated particle source callback
132    *
133    * @return Valid reference to associated callback
134    */
135   [[nodiscard]] ParticleSourceInterface& GetSourceCallback() const;
136
137 private:
138   /// @cond internal
139   /**
140    * @brief This constructor is used by ParticleSource::New() methods.
141    *
142    * @param [in] impl A pointer to a newly allocated implementation
143    */
144   ParticleSource(Internal::ParticleSource* impl);
145   /// @endcond
146 };
147 } // namespace Dali::Toolkit::ParticleSystem
148
149 #endif // DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H