1 /* 2 * Copyright (c) 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_NG_VIEWBOX_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_VIEWBOX_H 18 19 #include "base/geometry/dimension.h" 20 21 namespace OHOS::Ace::NG { 22 23 class ShapeViewBox final { 24 public: 25 ShapeViewBox() = default; 26 ShapeViewBox(const Dimension& x, const Dimension& y, const Dimension& width, const Dimension& height); 27 ~ShapeViewBox() = default; 28 Left()29 const Dimension& Left() const 30 { 31 return x_; 32 } 33 Top()34 const Dimension& Top() const 35 { 36 return y_; 37 } 38 Width()39 const Dimension& Width() const 40 { 41 return width_; 42 } 43 Height()44 const Dimension& Height() const 45 { 46 return height_; 47 } 48 SetLeft(const Dimension & left)49 void SetLeft(const Dimension& left) 50 { 51 x_ = left; 52 } 53 SetTop(const Dimension & top)54 void SetTop(const Dimension& top) 55 { 56 y_ = top; 57 } 58 SetWidth(const Dimension & width)59 void SetWidth(const Dimension& width) 60 { 61 width_ = width; 62 } 63 SetHeight(const Dimension & height)64 void SetHeight(const Dimension& height) 65 { 66 height_ = height; 67 } IsValid()68 bool IsValid() const 69 { 70 return width_.Value() > 0.0 && height_.Value() > 0.0; 71 } 72 73 ShapeViewBox& operator=(const ShapeViewBox& shapeViewBox) 74 { 75 x_ = shapeViewBox.x_; 76 y_ = shapeViewBox.y_; 77 width_ = shapeViewBox.width_; 78 height_ = shapeViewBox.height_; 79 return *this; 80 } 81 82 bool operator==(const ShapeViewBox& shapeViewBox) const 83 { 84 return (x_ == shapeViewBox.x_) && (y_ == shapeViewBox.y_) && (width_ == shapeViewBox.width_) && 85 (height_ == shapeViewBox.height_); 86 } 87 88 bool operator!=(const ShapeViewBox& shapeViewBox) const 89 { 90 return (x_ != shapeViewBox.x_) || (y_ != shapeViewBox.y_) || (width_ != shapeViewBox.width_) || 91 (height_ != shapeViewBox.height_); 92 } 93 94 private: 95 Dimension x_ = Dimension(-1.0); 96 Dimension y_ = Dimension(-1.0); 97 Dimension width_ = Dimension(-1.0); 98 Dimension height_ = Dimension(-1.0); 99 }; 100 101 } // namespace OHOS::Ace::NG 102 103 #endif 104