00001 00002 00003 #ifndef SkSize_DEFINED 00004 #define SkSize_DEFINED 00005 00006 template <typename T> struct SkTSize { 00007 T fWidth; 00008 T fHeight; 00009 00010 void set(T w, T h) { 00011 fWidth = w; 00012 fHeight = h; 00013 } 00014 00017 bool isZero() const { 00018 return 0 == fWidth && 0 == fHeight; 00019 } 00020 00022 bool isEmpty() const { 00023 return fWidth <= 0 || fHeight <= 0; 00024 } 00025 00027 void setEmpty() { 00028 fWidth = fHeight = 0; 00029 } 00030 00031 T width() const { return fWidth; } 00032 T height() const { return fHeight; } 00033 00035 void clampNegToZero() { 00036 if (fWidth < 0) { 00037 fWidth = 0; 00038 } 00039 if (fHeight < 0) { 00040 fHeight = 0; 00041 } 00042 } 00043 00044 bool equals(T w, T h) const { 00045 return fWidth == w && fHeight == h; 00046 } 00047 }; 00048 00049 template <typename T> 00050 static inline bool operator==(const SkTSize<T>& a, const SkTSize<T>& b) { 00051 return a.fWidth == b.fWidth && a.fHeight == b.fHeight; 00052 } 00053 00054 template <typename T> 00055 static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) { 00056 return !(a == b); 00057 } 00058 00060 00061 struct SkISize : public SkTSize<int32_t> {}; 00062 00063 #include "SkScalar.h" 00064 00065 struct SkSize : public SkTSize<SkScalar> { 00066 SkSize& operator=(const SkISize& src) { 00067 this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)); 00068 return *this; 00069 } 00070 00071 SkISize round() const { 00072 SkISize s; 00073 s.set(SkScalarRound(fWidth), SkScalarRound(fHeight)); 00074 return s; 00075 } 00076 00077 SkISize ceil() const { 00078 SkISize s; 00079 s.set(SkScalarCeil(fWidth), SkScalarCeil(fHeight)); 00080 return s; 00081 } 00082 00083 SkISize floor() const { 00084 SkISize s; 00085 s.set(SkScalarFloor(fWidth), SkScalarFloor(fHeight)); 00086 return s; 00087 } 00088 }; 00089 00090 #endif