1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/signals/callback.h>
26 #include <dali-toolkit/public-api/particle-system/particle-types.h>
28 namespace Dali::Toolkit::ParticleSystem::Internal
33 namespace Dali::Toolkit::ParticleSystem
35 class ParticleEmitter;
41 class ParticleModifier;
43 class ParticleRenderer;
46 * @brief Interface to override as a particle source
48 * ParticleSourceInterace allows altering behaviour for
49 * generating new particles.
51 class DALI_TOOLKIT_API ParticleSourceInterface
55 * @brief Adds new particles
56 * @param[in] outList List to write back
57 * @param[in] count Requested particles count
59 * @return Function should return a Number of emitted particles
61 virtual uint32_t Update(ParticleList& outList, uint32_t count) = 0;
64 * @brief Called when source is added to the emitter
66 virtual void Init() = 0;
70 * @class ParticleSource
72 * ParticleSource defines a logic associated with particles emission.
73 * The emitter will use ParticleSource in order to spawn new particles.
75 * ParticleSource manages how, where and how many particles to emit.
77 * ParticleSource uses an implementation of ParticleSourceInterface when
78 * emitting new particles.
80 class DALI_TOOLKIT_API ParticleSource : public Dali::BaseHandle
86 ParticleSource() = default;
91 ~ParticleSource() = default;
94 * @brief Creates a new instance of ParticleSource
96 * New instance is given an ownership over valid implementation
97 * of a ParticleSourceInferface.
99 * @param[in] particleSourceCallback Valid implementation of ParticleSourceInterface
101 * @return New ParticleSource object handle
103 static ParticleSource New(std::unique_ptr<ParticleSourceInterface>&& particleSourceCallback);
106 * @brief Creates new ParticleSource with given source callback and arguments
108 * The function creates a ParticleSource of a given class (T) and constructor
111 * @return New ParticleSource object handle
113 template<class T, class... Args>
114 static ParticleSource New(Args... args)
116 return New(std::move(std::make_unique<T>(args...)));
120 * @brief Downcasts a handle to ParticleSource handle.
122 * If handle points to an ParticleSource object, the downcast produces valid handle.
123 * If not, the returned handle is left uninitialized.
125 * @param[in] handle to An object
126 * @return handle to a ParticleSource object or an uninitialized handle
128 static ParticleSource DownCast(BaseHandle handle);
131 * @brief Returns associated particle source callback
133 * @return Valid reference to associated callback
135 [[nodiscard]] ParticleSourceInterface& GetSourceCallback() const;
140 * @brief This constructor is used by ParticleSource::New() methods.
142 * @param [in] impl A pointer to a newly allocated implementation
144 ParticleSource(Internal::ParticleSource* impl);
147 } // namespace Dali::Toolkit::ParticleSystem
149 #endif // DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_SOURCE_H