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 SIZE_H
17 #define SIZE_H
18 
19 #include "utils/drawing_macros.h"
20 #include "utils/scalar.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 class SizeF;
26 typedef SizeF Size;
27 
28 class DRAWING_API SizeF {
29 public:
30     inline SizeF() noexcept;
31     inline SizeF(const SizeF& s) noexcept;
32     inline SizeF(scalar w, scalar h) noexcept;
33     inline ~SizeF() noexcept;
34 
35     inline bool IsZero() const;
36     inline bool IsEmpty() const;
37 
38     inline scalar Width() const;
39     inline scalar Height() const;
40 
41     inline void SetWidth(scalar w);
42     inline void SetHeight(scalar h);
43 
44     friend inline bool operator==(const SizeF& s1, const SizeF& s2);
45     friend inline bool operator!=(const SizeF& s1, const SizeF& s2);
46 
47 private:
48     scalar width_;
49     scalar height_;
50 };
51 
SizeF()52 inline SizeF::SizeF() noexcept : width_(0.0), height_(0.0) {}
53 
SizeF(const SizeF & s)54 inline SizeF::SizeF(const SizeF& s) noexcept : width_(s.Width()), height_(s.Height()) {}
55 
SizeF(scalar w,scalar h)56 inline SizeF::SizeF(scalar w, scalar h) noexcept : width_(w), height_(h) {}
57 
~SizeF()58 inline SizeF::~SizeF() noexcept {}
59 
IsZero()60 inline bool SizeF::IsZero() const
61 {
62     return width_ == 0 && height_ == 0;
63 }
64 
IsEmpty()65 inline bool SizeF::IsEmpty() const
66 {
67     return width_ <= 0 || height_ <= 0;
68 }
69 
Width()70 inline scalar SizeF::Width() const
71 {
72     return width_;
73 }
74 
Height()75 inline scalar SizeF::Height() const
76 {
77     return height_;
78 }
79 
SetWidth(scalar w)80 inline void SizeF::SetWidth(scalar w)
81 {
82     width_ = w;
83 }
84 
SetHeight(scalar h)85 inline void SizeF::SetHeight(scalar h)
86 {
87     height_ = h;
88 }
89 
90 inline bool operator==(const SizeF& s1, const SizeF& s2)
91 {
92     return s1.width_ == s2.width_ && s1.height_ == s2.height_;
93 }
94 
95 inline bool operator!=(const SizeF& s1, const SizeF& s2)
96 {
97     return s1.width_ != s2.width_ || s1.height_ != s2.height_;
98 }
99 
100 class DRAWING_API SizeI {
101 public:
102     inline SizeI() noexcept;
103     inline SizeI(const SizeI& s) noexcept;
104     inline SizeI(int w, int h) noexcept;
105     inline ~SizeI() noexcept;
106 
107     inline bool IsZero() const;
108     inline bool IsEmpty() const;
109 
110     inline int Width() const;
111     inline int Height() const;
112 
113     inline void SetWidth(int w);
114     inline void SetHeight(int h);
115 
116     friend inline bool operator==(const SizeI& s1, const SizeI& s2);
117     friend inline bool operator!=(const SizeI& s1, const SizeI& s2);
118 
119 private:
120     int width_;
121     int height_;
122 };
123 
SizeI()124 inline SizeI::SizeI() noexcept : width_(0.0), height_(0.0) {}
125 
SizeI(const SizeI & s)126 inline SizeI::SizeI(const SizeI& s) noexcept : width_(s.Width()), height_(s.Height()) {}
127 
SizeI(int w,int h)128 inline SizeI::SizeI(int w, int h) noexcept : width_(w), height_(h) {}
129 
~SizeI()130 inline SizeI::~SizeI() noexcept {}
131 
IsZero()132 inline bool SizeI::IsZero() const
133 {
134     return width_ == 0 && height_ == 0;
135 }
136 
IsEmpty()137 inline bool SizeI::IsEmpty() const
138 {
139     return width_ <= 0 || height_ <= 0;
140 }
141 
Width()142 inline int SizeI::Width() const
143 {
144     return width_;
145 }
146 
Height()147 inline int SizeI::Height() const
148 {
149     return height_;
150 }
151 
SetWidth(int w)152 inline void SizeI::SetWidth(int w)
153 {
154     width_ = w;
155 }
156 
SetHeight(int h)157 inline void SizeI::SetHeight(int h)
158 {
159     height_ = h;
160 }
161 
162 inline bool operator==(const SizeI& s1, const SizeI& s2)
163 {
164     return s1.width_ == s2.width_ && s1.height_ == s2.height_;
165 }
166 
167 inline bool operator!=(const SizeI& s1, const SizeI& s2)
168 {
169     return s1.width_ != s2.width_ || s1.height_ != s2.height_;
170 }
171 } // namespace Drawing
172 } // namespace Rosen
173 } // namespace OHOS
174 #endif