xref: /haiku/headers/os/interface/Size.h (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright 2006, Haiku Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_SIZE_H
6 #define	_SIZE_H
7 
8 #include <limits.h>
9 
10 #include <SupportDefs.h>
11 
12 
13 enum {
14 	B_SIZE_UNSET		= -2,
15 	B_SIZE_UNLIMITED	= 1024 * 1024 * 1024,
16 };
17 
18 
19 class BSize {
20 public:
21 			float				width;
22 			float				height;
23 
24 	inline						BSize();
25 	inline						BSize(const BSize& other);
26 	inline						BSize(float width, float height);
27 
28 	inline	float				Width() const;
29 	inline	float				Height() const;
30 
31 	inline	void				Set(float width, float height);
32 	inline	void				SetWidth(float width);
33 	inline	void				SetHeight(float height);
34 
35 	inline	int32				IntegerWidth() const;
36 	inline	int32				IntegerHeight() const;
37 
38 	inline	bool				IsWidthSet() const;
39 	inline	bool				IsHeightSet() const;
40 
41 	inline	bool				operator==(const BSize& other) const;
42 	inline	bool				operator!=(const BSize& other) const;
43 
44 	inline	BSize&				operator=(const BSize& other);
45 };
46 
47 
48 // constructor
49 inline
50 BSize::BSize()
51 	: width(B_SIZE_UNSET),
52 	  height(B_SIZE_UNSET)
53 {
54 }
55 
56 
57 // copy constructor
58 inline
59 BSize::BSize(const BSize& other)
60 	: width(other.width),
61 	  height(other.height)
62 {
63 }
64 
65 
66 // constructor
67 inline
68 BSize::BSize(float width, float height)
69 	: width(width),
70 	  height(height)
71 {
72 }
73 
74 
75 // Width
76 inline float
77 BSize::Width() const
78 {
79 	return width;
80 }
81 
82 
83 // Height
84 inline float
85 BSize::Height() const
86 {
87 	return height;
88 }
89 
90 
91 // Set
92 inline void
93 BSize::Set(float width, float height)
94 {
95 	this->width = width;
96 	this->height = height;
97 }
98 
99 
100 // SetWidth
101 inline void
102 BSize::SetWidth(float width)
103 {
104 	this->width = width;
105 }
106 
107 
108 // SetHeight
109 inline void
110 BSize::SetHeight(float height)
111 {
112 	this->height = height;
113 }
114 
115 
116 // IntegerWidth
117 inline int32
118 BSize::IntegerWidth() const
119 {
120 	return (int32)width;
121 }
122 
123 
124 // IntegerHeight
125 inline int32
126 BSize::IntegerHeight() const
127 {
128 	return (int32)height;
129 }
130 
131 
132 // IsWidthSet
133 inline bool
134 BSize::IsWidthSet() const
135 {
136 	return width != B_SIZE_UNSET;
137 }
138 
139 
140 // IsHeightSet
141 inline bool
142 BSize::IsHeightSet() const
143 {
144 	return height != B_SIZE_UNSET;
145 }
146 
147 
148 // ==
149 inline bool
150 BSize::operator==(const BSize& other) const
151 {
152 	return (width == other.width && height == other.height);
153 }
154 
155 
156 // !=
157 inline bool
158 BSize::operator!=(const BSize& other) const
159 {
160 	return !(*this == other);
161 }
162 
163 
164 // =
165 inline BSize&
166 BSize::operator=(const BSize& other)
167 {
168 	width = other.width;
169 	height = other.height;
170 	return *this;
171 }
172 
173 #endif	// _SIZE_H
174