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 = -1, 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 SetWidth(float width); 32 inline void SetHeight(float height); 33 34 inline int32 IntegerWidth() const; 35 inline int32 IntegerHeight() const; 36 37 inline bool IsWidthSet() const; 38 inline bool IsHeightSet() const; 39 40 inline bool operator==(const BSize& other) const; 41 inline bool operator!=(const BSize& other) const; 42 43 inline BSize& operator=(const BSize& other); 44 }; 45 46 47 // constructor 48 inline 49 BSize::BSize() 50 : width(B_SIZE_UNSET), 51 height(B_SIZE_UNSET) 52 { 53 } 54 55 56 // copy constructor 57 inline 58 BSize::BSize(const BSize& other) 59 : width(other.width), 60 height(other.height) 61 { 62 } 63 64 65 // constructor 66 inline 67 BSize::BSize(float width, float height) 68 : width(width), 69 height(height) 70 { 71 } 72 73 74 // Width 75 inline float 76 BSize::Width() const 77 { 78 return width; 79 } 80 81 82 // Height 83 inline float 84 BSize::Height() const 85 { 86 return height; 87 } 88 89 90 // SetWidth 91 inline void 92 BSize::SetWidth(float width) 93 { 94 this->width = width; 95 } 96 97 98 // SetHeight 99 inline void 100 BSize::SetHeight(float height) 101 { 102 this->height = height; 103 } 104 105 106 // IntegerWidth 107 inline int32 108 BSize::IntegerWidth() const 109 { 110 return (int32)width; 111 } 112 113 114 // IntegerHeight 115 inline int32 116 BSize::IntegerHeight() const 117 { 118 return (int32)height; 119 } 120 121 122 // IsWidthSet 123 inline bool 124 BSize::IsWidthSet() const 125 { 126 return width != B_SIZE_UNSET; 127 } 128 129 130 // IsHeightSet 131 inline bool 132 BSize::IsHeightSet() const 133 { 134 return height != B_SIZE_UNSET; 135 } 136 137 138 // == 139 inline bool 140 BSize::operator==(const BSize& other) const 141 { 142 return (width == other.width && height == other.height); 143 } 144 145 146 // != 147 inline bool 148 BSize::operator!=(const BSize& other) const 149 { 150 return !(*this == other); 151 } 152 153 154 // = 155 inline BSize& 156 BSize::operator=(const BSize& other) 157 { 158 width = other.width; 159 height = other.height; 160 return *this; 161 } 162 163 #endif // _SIZE_H 164