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_ARC_RENDER_ARC_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ARC_RENDER_ARC_H
18 
19 #include "core/components/arc/arc_component.h"
20 #include "core/pipeline/base/render_node.h"
21 
22 namespace OHOS::Ace {
23 
24 constexpr double ARC_RADIUS_TO_DIAMETER = 2.0;
25 
26 class RenderArc : public RenderNode {
27     DECLARE_ACE_TYPE(RenderArc, RenderNode);
28 
29 public:
30     static RefPtr<RenderNode> Create();
31     void Update(const RefPtr<Component>& component) override;
32     void PerformLayout() override;
33 
34     double GetOuterRadius() const;
35 
36     double GetWidth() const;
37 
38     double GetStartAngle() const;
39 
40     double GetSweepAngle() const;
41 
42     Color GetColor() const;
43 
44     void SetOuterRadius(double outerRadius);
45 
46     void SetWidth(double width);
47 
48     void SetStartAngle(double startAngle);
49 
50     void SetSweepAngle(double sweepAngle);
51 
52     void SetColor(const Color& color);
53 
54     bool IsAcrValid() const;
55 
56     bool IsArcShow() const;
57 
58     double GetPositionAngle(const Offset& position, double correctOffset) const;
59 
60     bool IsInRegion(const Point& point) const;
61 
62     double GetShadowWidth() const;
63 
64 protected:
65     double outerRadius_ = 0.0;
66     double width_ = 0.0;
67     ArcFlex flex_ = ArcFlex::FLEX_X;
68 
69     double startAngle_ = 0.0;
70     double sweepAngle_ = 0.0;
71 
72     Color color_ = Color::BLACK;
73 
74     double arcRadiusX_ = 0.0;
75     double arcRadiusY_ = 0.0;
76     double arcWidth_ = 0.0;
77 
78     double shadowWidth_ = 0.0;
79 
80 private:
81     double GetDistance(const Point& point) const;
82 }; // class RenderArc
83 
84 } // namespace OHOS::Ace
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ARC_RENDER_ARC_H
87