Updated all files to new format
[platform/core/uifw/dali-demo.git] / examples / particles / particle-view.h
1 #ifndef PARTICLES_PARTICLE_VIEW_H_
2 #define PARTICLES_PARTICLE_VIEW_H_
3 /*
4  * Copyright (c) 2021 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 #include <functional>
21 #include <vector>
22 #include "dali/public-api/actors/camera-actor.h"
23 #include "dali/public-api/animation/animation.h"
24 #include "dali/public-api/object/weak-handle.h"
25 #include "dali/public-api/rendering/shader.h"
26 #include "particle-field.h"
27
28 struct ColorRange
29 {
30   Dali::Vector3 rgb0;
31   Dali::Vector3 rgb1;
32 };
33
34 class ParticleView : public Dali::ConnectionTracker
35 {
36 public:
37   ParticleView(const ParticleField& field, Dali::Actor world, Dali::CameraActor camera, Dali::Geometry particleGeom = Dali::Geometry());
38   ~ParticleView();
39
40   void SetColorRange(const ColorRange& range);
41
42   void SetPopulation(float percentage);
43   void SetFocalLength(float f);
44   void SetAperture(float a);
45   void SetAlphaTestRefValue(float rv);
46   void SetFadeRange(float near, float far);
47   void SetAngularVelocity(float v);
48   void SetLinearVelocity(float v);
49
50   ///@brief Starts a scatter & regroup animation, cancelling any previously played animation
51   /// of the same kind. Bigger particles, and those further away from the Z axis are affected
52   /// less.
53   ///@param radius the normalised radius, within which particles are affected.
54   ///@param amount the amount of displacement applied to particles at the peak of the animation.
55   ///@param durationOut the duration of scattering, in seconds.
56   ///@param durationIn the duration of regrouping, in seconds.
57   void Scatter(float radius, float amount, float durationOut, float durationIn);
58
59   void SetScatterRay(Dali::Vector3 rayDir);
60
61   ///@brief Starts an animation to change the opacity of the particles to @a target.
62   ///@param duration Number of seconds to complete transition in.
63   ///@param target Target opacity in the 0..1.f range.
64   void Fade(float duration, float target, Dali::AlphaFunction alphaFn = Dali::AlphaFunction::DEFAULT, std::function<void(Dali::Animation&)> onFinished = nullptr);
65
66   ///@brief Starts an animation to change the opacity of the particles to @a target.
67   ///@param duration Number of seconds to complete transition in.
68   ///@param target Target opacity in the 0..1.f range.
69   ///@param from The value to set the opacity to prior to the animation.
70   void Fade(float duration, float target, float from, Dali::AlphaFunction alphaFn = Dali::AlphaFunction::DEFAULT, std::function<void(Dali::Animation&)> onFinished = nullptr);
71
72 private: // DATA
73   struct ScatterProps
74   {
75     Dali::Property::Index mPropRadius;
76     Dali::Property::Index mPropAmount;
77     Dali::Property::Index mPropRay;
78
79     Dali::Animation mAnim;
80   };
81
82   Dali::WeakHandle<Dali::Actor> mWorld;
83   Dali::Vector3                 mParticleBoxSize;
84
85   Dali::Shader          mParticleShader;
86   Dali::Property::Index mPropPopulation;
87   Dali::Property::Index mPropFocalLength;
88   Dali::Property::Index mPropAperture;
89   Dali::Property::Index mPropAlphaTestRefValue;
90   Dali::Property::Index mPropFadeRange;
91
92   ScatterProps mScatterProps[6];
93   int          mActiveScatter = 0;
94
95   Dali::Actor           mMasterParticles;
96   Dali::Property::Index mPropSecondaryColor;
97
98   Dali::Actor mSlaveParticles;
99
100   Dali::Animation mAngularAnim;
101   Dali::Animation mLinearAnim;
102   Dali::Animation mFadeAnim;
103 };
104
105 #endif //PARTICLES_PARTICLE_VIEW_H_