1 /* 2 * Copyright (c) 2021-2022 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_COMMON_PROPERTIES_RADIUS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_RADIUS_H 18 #include "base/geometry/animatable_dimension.h" 19 #include "base/utils/utils.h" 20 #include "frameworks/base/geometry/dimension.h" 21 namespace OHOS::Ace { 22 // A radius for shapes like rect and etc. 23 class Radius final { 24 public: 25 Radius() = default; Radius(double value)26 explicit Radius(double value) : Radius(value, value) {} Radius(const Dimension & value)27 explicit Radius(const Dimension& value) : Radius(value, value) {} Radius(double x,double y)28 Radius(double x, double y) : x_(Dimension(x)), y_(Dimension(y)) {} Radius(const Dimension & x,const Dimension & y)29 Radius(const Dimension& x, const Dimension& y) : x_(x), y_(y) {} 30 ~Radius() = default; 31 SetContextAndCallback(const WeakPtr<PipelineBase> & context,const RenderNodeAnimationCallback & callback)32 void SetContextAndCallback(const WeakPtr<PipelineBase>& context, const RenderNodeAnimationCallback& callback) 33 { 34 } 35 ApplyScaleAndRound(double scale)36 void ApplyScaleAndRound(double scale) 37 { 38 x_.SetValue(round(x_.Value() * scale)); 39 y_.SetValue(round(y_.Value() * scale)); 40 } 41 IsValid()42 bool IsValid() const 43 { 44 return x_.IsValid() && y_.IsValid(); 45 } 46 HasValue()47 bool HasValue() const 48 { 49 return x_.IsValid() || y_.IsValid(); 50 } 51 GetX()52 const Dimension& GetX() const 53 { 54 return x_; 55 } 56 GetY()57 const Dimension& GetY() const 58 { 59 return y_; 60 } 61 SetX(const Dimension & x,const AnimationOption & option)62 void SetX(const Dimension& x, const AnimationOption& option) 63 { 64 x_ = x; 65 } 66 SetY(const Dimension & y,const AnimationOption & option)67 void SetY(const Dimension& y, const AnimationOption& option) 68 { 69 y_ = y; 70 } 71 SetX(const Dimension & x)72 void SetX(const Dimension& x) 73 { 74 x_ = x; 75 } 76 SetY(const Dimension & y)77 void SetY(const Dimension& y) 78 { 79 y_ = y; 80 } 81 82 Radius operator+(const Radius& radius) const 83 { 84 return Radius(x_ + radius.GetX(), y_ + radius.GetY()); 85 } 86 87 Radius operator-(const Radius& radius) const 88 { 89 return Radius(x_ - radius.GetX(), y_ - radius.GetY()); 90 } 91 92 Radius operator*(double scale) const 93 { 94 return Radius(x_ * scale, y_ * scale); 95 } 96 97 bool operator==(const Radius& radius) const 98 { 99 return (radius.GetX() == x_) && (radius.GetY() == y_); 100 } 101 ToString()102 std::string ToString() const 103 { 104 return std::string("x:").append(x_.ToString()).append(", y:").append(y_.ToString()); 105 } 106 107 private: 108 Dimension x_; 109 Dimension y_; 110 }; 111 112 } // namespace OHOS::Ace 113 114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_RADIUS_H 115