1 /* 2 * Copyright (c) 2021-2024 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_ROUND_FRAMEWORKS_BASE_GEOMETRY_ARC_H 17 #define FOUNDATION_ACE_ROUND_FRAMEWORKS_BASE_GEOMETRY_ARC_H 18 19 #include "base/geometry/point.h" 20 #include "base/utils/utils.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/common/layout/constants.h" 23 24 constexpr float ARC_ROUND_RADIUS_TO_DIAMETER = 2.0; 25 constexpr float HALF = 0.5; 26 constexpr float SQUARE = 2.0; 27 constexpr float ORG_HOTREGION = 24.0f; 28 constexpr float HALF_CIRCULARITY = 180; 29 constexpr float WHOLE_CIRCULARITY = 360; 30 31 namespace OHOS::Ace { 32 33 class ArcRound { 34 public: 35 ArcRound() = default; 36 ~ArcRound() = default; 37 38 ArcRound(const ArcRound& other); 39 ArcRound(Point centerPoint, float radius, float startAngle, float sweepAngle, float width); 40 ArcRound& operator=(const ArcRound& arc); 41 42 void Rotate(const Point& point, float angle); 43 void Move(float xOffset, float yOffset); 44 void GetPointByAngle(float angle, Point& out) const; 45 float GetPositionAngle(const Offset& position) const; 46 Point GetStartPoint() const; 47 Point GetEndPoint() const; 48 void SetOuterRadius(float outerRadius); 49 void SetWidth(float width); 50 double Get2PIRadians(double radian) const; 51 bool IsInRegion(const Point& point, float minHotRegion = ORG_HOTREGION) const; 52 GetCenterPoint()53 const Point& GetCenterPoint() const 54 { 55 return centerPoint_; 56 } 57 SetCenterPoint(const Point & point)58 void SetCenterPoint(const Point& point) 59 { 60 centerPoint_ = point; 61 } 62 GetRadius()63 float GetRadius() const 64 { 65 return radius_; 66 } 67 SetRadius(float radius)68 void SetRadius(float radius) 69 { 70 radius_ = radius; 71 } 72 GetStartAngle()73 float GetStartAngle() const 74 { 75 return startAngle_; 76 } 77 SetStartAngle(float angle)78 void SetStartAngle(float angle) 79 { 80 startAngle_ = angle; 81 } 82 GetStepAngle()83 float GetStepAngle() const 84 { 85 return stepAngle_; 86 } 87 SetStepAngle(float angle)88 void SetStepAngle(float angle) 89 { 90 stepAngle_ = angle; 91 } 92 GetEndAngle()93 float GetEndAngle() const 94 { 95 return endAngle_; 96 } 97 SetEndAngle(float angle)98 void SetEndAngle(float angle) 99 { 100 endAngle_ = angle; 101 } 102 GetStartPoint(Point & out)103 void GetStartPoint(Point& out) const 104 { 105 GetPointByAngle(startAngle_, out); 106 } 107 GetEndPoint(Point & out)108 void GetEndPoint(Point& out) const 109 { 110 GetPointByAngle(endAngle_, out); 111 } 112 GetLeft()113 float GetLeft() const 114 { 115 return centerPoint_.GetX() - radius_; 116 } 117 GetRight()118 float GetRight() const 119 { 120 return centerPoint_.GetX() + radius_; 121 } 122 GetTop()123 float GetTop() const 124 { 125 return centerPoint_.GetY() - radius_; 126 } 127 GetBottom()128 float GetBottom() const 129 { 130 return centerPoint_.GetY() + radius_; 131 } 132 GetOuterRadius()133 float GetOuterRadius() const 134 { 135 return outerRadius_; 136 } 137 GetWidth()138 float GetWidth() const 139 { 140 return width_; 141 } 142 GetSweepAngle()143 float GetSweepAngle() const 144 { 145 return sweepAngle_; 146 } 147 GetColor()148 Color GetColor() const 149 { 150 return color_; 151 } 152 SetSweepAngle(float sweepAngle)153 void SetSweepAngle(float sweepAngle) 154 { 155 sweepAngle_ = sweepAngle; 156 } 157 SetColor(const Color & color)158 void SetColor(const Color& color) 159 { 160 color_ = color; 161 } 162 IsAcrValid()163 bool IsAcrValid() const 164 { 165 return !NearZero(sweepAngle_); 166 } 167 IsArcShow()168 bool IsArcShow() const 169 { 170 return color_.GetAlpha() != 0; 171 } 172 GetShadowWidth()173 float GetShadowWidth() const 174 { 175 return shadowWidth_; 176 } 177 SetPositionMode(PositionMode positionMode)178 void SetPositionMode(PositionMode positionMode) 179 { 180 positionMode_ = positionMode; 181 } 182 183 private: 184 Point centerPoint_; 185 float radius_ = 0.0; 186 float startAngle_ = 0.0; 187 float endAngle_ = 0.0; 188 float stepAngle_ = 0.0; 189 190 float sweepAngle_ = 0.0; 191 float outerRadius_ = 0.0; 192 float width_ = 0.0; 193 Color color_ = Color::WHITE; 194 float shadowWidth_ = 0.0; 195 PositionMode positionMode_ = PositionMode::RIGHT; 196 }; 197 198 } // namespace OHOS::Ace 199 200 #endif // FOUNDATION_ACE_ROUND_FRAMEWORKS_BASE_GEOMETRY_ARC_H 201