1 #ifndef PARTICLES_PARTICLE_VIEW_H_
2 #define PARTICLES_PARTICLE_VIEW_H_
4 * Copyright (c) 2020 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.
20 #include "particle-field.h"
21 #include "dali/public-api/actors/camera-actor.h"
22 #include "dali/public-api/animation/animation.h"
23 #include "dali/public-api/object/weak-handle.h"
24 #include "dali/public-api/rendering/shader.h"
34 class ParticleView: public Dali::ConnectionTracker
37 ParticleView(const ParticleField& field, Dali::Actor world, Dali::CameraActor camera,
38 Dali::Geometry particleGeom = Dali::Geometry());
41 void SetColorRange(const ColorRange& range);
43 void SetPopulation(float percentage);
44 void SetFocalLength(float f);
45 void SetAperture(float a);
46 void SetAlphaTestRefValue(float rv);
47 void SetFadeRange(float near, float far);
48 void SetAngularVelocity(float v);
49 void SetLinearVelocity(float v);
51 ///@brief Starts a scatter & regroup animation, cancelling any previously played animation
52 /// of the same kind. Bigger particles, and those further away from the Z axis are affected
54 ///@param radius the normalised radius, within which particles are affected.
55 ///@param amount the amount of displacement applied to particles at the peak of the animation.
56 ///@param durationOut the duration of scattering, in seconds.
57 ///@param durationIn the duration of regrouping, in seconds.
58 void Scatter(float radius, float amount, float durationOut, float durationIn);
60 void SetScatterRay(Dali::Vector3 rayDir);
62 ///@brief Starts an animation to change the opacity of the particles to @a target.
63 ///@param duration Number of seconds to complete transition in.
64 ///@param target Target opacity in the 0..1.f range.
65 void Fade(float duration, float target, Dali::AlphaFunction alphaFn = Dali::AlphaFunction::DEFAULT,
66 std::function<void(Dali::Animation&)> onFinished = nullptr);
68 ///@brief Starts an animation to change the opacity of the particles to @a target.
69 ///@param duration Number of seconds to complete transition in.
70 ///@param target Target opacity in the 0..1.f range.
71 ///@param from The value to set the opacity to prior to the animation.
72 void Fade(float duration, float target, float from, Dali::AlphaFunction alphaFn = Dali::AlphaFunction::DEFAULT,
73 std::function<void(Dali::Animation&)> onFinished = nullptr);
78 Dali::Property::Index mPropRadius;
79 Dali::Property::Index mPropAmount;
80 Dali::Property::Index mPropRay;
82 Dali::Animation mAnim;
85 Dali::WeakHandle<Dali::Actor> mWorld;
86 Dali::Vector3 mParticleBoxSize;
88 Dali::Shader mParticleShader;
89 Dali::Property::Index mPropPopulation;
90 Dali::Property::Index mPropFocalLength;
91 Dali::Property::Index mPropAperture;
92 Dali::Property::Index mPropAlphaTestRefValue;
93 Dali::Property::Index mPropFadeRange;
95 ScatterProps mScatterProps[6];
96 int mActiveScatter = 0;
98 Dali::Actor mMasterParticles;
99 Dali::Property::Index mPropSecondaryColor;
101 Dali::Actor mSlaveParticles;
103 Dali::Animation mAngularAnim;
104 Dali::Animation mLinearAnim;
105 Dali::Animation mFadeAnim;
108 #endif //PARTICLES_PARTICLE_VIEW_H_