• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TRIANGLE_RENDER_TRIANGLE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRIANGLE_RENDER_TRIANGLE_H
18 
19 #include "base/geometry/arc.h"
20 #include "core/gestures/click_recognizer.h"
21 #include "core/pipeline/base/render_node.h"
22 
23 namespace OHOS::Ace {
24 
25 class TriangleRotationCalculator {
26 
27 public:
SetPointOne(double x,double y)28     void SetPointOne(double x, double y)
29     {
30         x1_ = x;
31         y1_ = y;
32     }
33 
SetPointTwo(double x,double y)34     void SetPointTwo(double x, double y)
35     {
36         x2_ = x;
37         y2_ = y;
38     }
39 
SetPointThree(double x,double y)40     void SetPointThree(double x, double y)
41     {
42         x3_ = x;
43         y3_ = y;
44     }
45 
SetAngle(double value)46     void SetAngle(double value)
47     {
48         angle_ = value;
49     }
50 
SetRadius(double value)51     void SetRadius(double value)
52     {
53         radius_ = value;
54     }
55 
56     bool Calculate(double xOffset, double yOffset);
57 
58     bool IsDown() const;
59 
GetOutArc1()60     const Arc& GetOutArc1()
61     {
62         return outArc1_;
63     }
64 
GetOutArc2()65     const Arc& GetOutArc2()
66     {
67         return outArc2_;
68     }
69 
GetOutArc3()70     const Arc& GetOutArc3()
71     {
72         return outArc3_;
73     }
74 
75 private:
76     // point one
77     double x1_ = 0.0;
78     double y1_ = 0.0;
79     // point two
80     double x2_ = 0.0;
81     double y2_ = 0.0;
82     // point three
83     double x3_ = 0.0;
84     double y3_ = 0.0;
85     // rotate angle
86     double angle_ = 0.0;
87     // radius value
88     double radius_ = 0.0;
89     // out arc 1
90     Arc outArc1_;
91     // out arc 2
92     Arc outArc2_;
93     // out arc 3
94     Arc outArc3_;
95 };
96 
97 class RenderTriangle : public RenderNode {
98     DECLARE_ACE_TYPE(RenderTriangle, RenderNode);
99 
100 public:
101     static RefPtr<RenderNode> Create();
102 
103     void Update(const RefPtr<Component>& component) override;
104     void PerformLayout() override;
105 
GetOnClick()106     const std::function<void(bool)>& GetOnClick() const
107     {
108         return onClick_;
109     }
SetOnClick(const std::function<void (bool)> & value)110     void SetOnClick(const std::function<void(bool)>& value)
111     {
112         onClick_ = value;
113     }
114 
UpdateAngle(double value)115     void UpdateAngle(double value)
116     {
117         data_.SetAngle(value);
118         MarkNeedRender();
119     }
120 
121     void OnTouchTestHit(const Offset&, const TouchRestrict&, TouchTestResult& result) override;
122 
123 protected:
124     void CalculateTrianglePoints();
125     void HandleClick();
126 
127     Dimension width_;
128     Dimension height_;
129     Dimension padding_;
130     Color color_;
131 
132     TriangleRotationCalculator data_;
133 
134 private:
135     RefPtr<ClickRecognizer> click_;
136     std::function<void(bool)> onClick_;
137 };
138 
139 } // namespace OHOS::Ace
140 
141 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRIANGLE_RENDER_TRIANGLE_H
142