Region.h (1251B)
1 #ifndef _REGION_H 2 #define _REGION_H 3 4 #include "Rect.h" 5 #include "assert.h" 6 7 const int COORD_MAX = 0x7ffffff0; 8 9 class Region { 10 public: 11 12 Region(); 13 ~Region(); 14 Region(const Region&); 15 Region& Clear(); 16 Region& Include(const Rect&); 17 Region& Include(const Region&); 18 Region& Exclude(const Rect&); 19 Region& Exclude(const Region&); 20 Region& Invert(); 21 Region& Intersect(const Region&); 22 Region& Translate(int x, int y); 23 Region& ConstrainTo(const Rect&); 24 Region& SetTo(const Region&); 25 Region& operator=(const Region&); 26 27 const bool FindRect(int x, int y, Rect &outRect) const; 28 29 Rect Bounds() const; 30 inline bool Valid() const; 31 inline int CountRects() const; 32 const Rect& RectAt(int index) const; 33 34 void Dump() const; 35 36 private: 37 38 void AddRect(const Rect&); 39 void RemoveRect(int index); 40 void Consolidate(); 41 42 // Assumes there are no overlaps 43 void AddRegionRects(const Region&); 44 45 void AllocSpace(int numRects); 46 47 void BeginOperation(); 48 void EndOperation(); 49 50 Rect *fRects; 51 int fNumRects; 52 int fOpLevel; 53 }; 54 55 inline int Region::CountRects() const 56 { 57 return fNumRects; 58 } 59 60 inline const Rect& Region::RectAt(int index) const 61 { 62 ASSERT(index < fNumRects); 63 return fRects[index]; 64 } 65 66 67 inline bool Region::Valid() const 68 { 69 return fNumRects > 0; 70 } 71 72 73 #endif