1 /*
2  * Copyright (c) 2021 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_PROGRESS_LOADING_PROGRESS_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_LOADING_PROGRESS_COMPONENT_H
18 
19 #include "base/geometry/dimension.h"
20 #include "base/geometry/offset.h"
21 #include "core/components/common/properties/color.h"
22 #include "core/pipeline/base/render_component.h"
23 
24 namespace OHOS::Ace {
25 
26 constexpr int32_t COMET_COUNT = 20;
27 constexpr double MOVE_RATIO = 0.06; // The Ratio to the Ring diameter.
28 constexpr double COMET_TAIL_LEN = 60.0;
29 const Dimension RING_RADIUS = 10.5_vp;
30 const Dimension ORBIT_RADIUS = 17.0_vp;
31 const Color PROGRESS_COLOR = Color(0xff666666);
32 const Color PROGRESS_COLOR_DARK = Color(0x99ffffff);
33 
34 class ACE_EXPORT LoadingProgressComponent : public RenderComponent {
35     DECLARE_ACE_TYPE(LoadingProgressComponent, RenderComponent);
36 
37 public:
38     LoadingProgressComponent() = default;
LoadingProgressComponent(double diameter)39     explicit LoadingProgressComponent(double diameter) : diameter_(diameter) {};
40     ~LoadingProgressComponent() override = default;
41 
42     RefPtr<RenderNode> CreateRenderNode() override;
43     RefPtr<Element> CreateElement() override;
44 
GetDiameter()45     const Dimension& GetDiameter() const
46     {
47         return diameter_;
48     }
49 
SetDiameter(const Dimension & diameter)50     void SetDiameter(const Dimension& diameter)
51     {
52         diameter_ = diameter;
53     }
54 
SetProgressColor(const Color & color)55     void SetProgressColor(const Color& color)
56     {
57         progressColor_ = color;
58     }
59 
GetProgressColor()60     const Color& GetProgressColor() const
61     {
62         return progressColor_;
63     }
64 
SetMoveRatio(double ratio)65     void SetMoveRatio(double ratio)
66     {
67         moveRatio_ = ratio;
68     }
69 
GetMoveRatio()70     double GetMoveRatio() const
71     {
72         return moveRatio_;
73     }
74 
SetRingRadius(const Dimension & radius)75     void SetRingRadius(const Dimension& radius)
76     {
77         ringRadius_ = radius;
78     }
79 
GetRingRadius()80     const Dimension& GetRingRadius() const
81     {
82         return ringRadius_;
83     }
84 
SetOrbitRadius(const Dimension & radius)85     void SetOrbitRadius(const Dimension& radius)
86     {
87         orbitRadius_ = radius;
88     }
89 
GetOrbitRadius()90     const Dimension& GetOrbitRadius() const
91     {
92         return orbitRadius_;
93     }
94 
SetCometTailLen(double len)95     void SetCometTailLen(double len)
96     {
97         cometTailLen_ = len;
98     }
99 
GetCometTailLen()100     double GetCometTailLen() const
101     {
102         return cometTailLen_;
103     }
104 
105 private:
106     Dimension diameter_;
107     double cometTailLen_ = COMET_TAIL_LEN; // Degrees.
108     double moveRatio_ = MOVE_RATIO; // The Ratio to the Ring diameter.
109     Dimension ringRadius_ = RING_RADIUS;
110     Dimension orbitRadius_ = ORBIT_RADIUS;
111     Color progressColor_ = PROGRESS_COLOR;
112 };
113 
114 } // namespace OHOS::Ace
115 
116 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_LOADING_PROGRESS_COMPONENT_H
117