• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PATTERNS_PARTICLE_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PATTERNS_PARTICLE_MODEL_H
18 #include <functional>
19 #include <list>
20 #include <memory>
21 #include <mutex>
22 
23 #include "base/geometry/ng/vector.h"
24 #include "base/utils/macros.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/property/particle_property.h"
27 namespace OHOS::Ace {
28 
29 enum class ParticleDisturbanceShapeType :uint32_t { RECT, CIRCLE, ELLIPSE };
30 const CalcDimension DEFAULT_CENTER_VALUE = CalcDimension(0.5, DimensionUnit::PERCENT);
31 constexpr float DEFAULT_RADIUS_VALUE = 0.0f;
32 constexpr float DEFAULT_START_ANGLE_VALUE = 0.0f;
33 constexpr float DEFAULT_END_ANGLE_VALUE = 360.0f;
34 
35 struct ParticleDisturbance {
36     float strength = 0.0f;
37     ParticleDisturbanceShapeType shape = ParticleDisturbanceShapeType::RECT;
38     int  size[2] = {0, 0};
39     int  position[2] = {0, 0};
40     int feather = 0;
41     float noiseScale = 1.0f;
42     float noiseFrequency = 1.0f;
43     float noiseAmplitude = 1.0f;
44 
45     bool operator!=(const ParticleDisturbance& data) const
46     {
47         return !(NearEqual(strength, data.strength) && shape == data.shape && size[0] == data.size[0] &&
48                  size[1] == data.size[1] && position[0] == data.position[0] && position[1] == data.position[1] &&
49                  feather == data.feather && NearEqual(noiseScale, data.noiseScale) &&
50                  NearEqual(noiseFrequency, data.noiseFrequency) && NearEqual(noiseAmplitude, data.noiseAmplitude));
51     }
52 };
53 
54 struct EmitterProperty {
55     uint32_t index = 0;
56     std::optional<NG::VectorF> position;
57     std::optional<NG::VectorF> size;
58     std::optional<uint32_t> emitRate;
59     std::optional<NG::ParticleAnnulusRegion> annulusRegion;
60 };
61 
62 class ACE_FORCE_EXPORT ParticleModel {
63 public:
64     static ParticleModel* GetInstance();
65     virtual ~ParticleModel() = default;
66     virtual void Create(std::list<NG::ParticleOption>& arrayValue) = 0;
67     virtual void DisturbanceField(const std::vector<ParticleDisturbance>& disturbanceArray) = 0;
68     virtual void updateEmitter(std::vector<EmitterProperty>& property) = 0;
69 
70 private:
71     static std::unique_ptr<ParticleModel> instance_;
72     static std::mutex mutex_;
73 };
74 } // namespace OHOS::Ace
75 #endif