00001 // This interface is based on the one in the file region.h in gtk+. 00002 // That file didn't contain license info, so is presumably under the 00003 // same LGPL license as the rest of that library. 00004 00005 // Stolen from Gtk+ and C++-ized by Ron Steinke, January 2003 00006 // Heavily C++-ized with copy on write semantics by Vassilis Virvilis March 2006 00007 00008 #ifndef WT_REGION_H 00009 #define WT_REGION_H 00010 00011 #include <boost/shared_ptr.hpp> 00012 00013 #include <wt/rect.h> 00014 00015 namespace Wt { 00016 00017 /// Region specifies a 'working area' of the screen 00018 /*! pixels outside the region are always ignored */ 00019 class Region { 00020 public: 00021 //! \name Contructors 00022 //@{ 00023 /// Create a new empty region 00024 Region(); 00025 00026 /// Region from rectangle 00027 Region(const Rect& rect); 00028 00029 /// Region from point 00030 Region(const Point& p); 00031 //@} 00032 00033 /*! \note the defauly copy constructor, assignment operator 00034 and destructor should be ok 00035 */ 00036 00037 /// true if region empty 00038 bool isEmpty() const { 00039 return rects_->size() == 0; 00040 } 00041 00042 /// check if a region contains a point 00043 bool contains(const Point& p) const; 00044 00045 /// Check if a region contains/overlaps a rectangle 00046 bool contains(const Rect& r) const; 00047 00048 /// Move a region by dx, dy 00049 void translate(int dx, int dy); 00050 00051 Region unite(const Region& r) const; 00052 Region intersect( const Region& r) const; 00053 Region subtract(const Region& r) const; 00054 Region eor(const Region& r) const; 00055 00056 // returns the bounding rect 00057 const Rect& boundingRect() const { 00058 return extents; 00059 } 00060 00061 /// returns the array of rectangles composing the region 00062 const RectArray& rects() const { 00063 return *rects_; 00064 } 00065 00066 Region operator|(const Region& r) const; 00067 Region operator+(const Region& r) const; 00068 Region operator&(const Region& r) const; 00069 Region operator-(const Region& r) const; 00070 Region operator^(const Region& r) const; 00071 00072 Region& operator|=(const Region& r); 00073 Region& operator+=(const Region& r); 00074 Region& operator&=(const Region& r); 00075 Region& operator-=(const Region& r); 00076 Region& operator^=(const Region& r); 00077 00078 /// compare two regions 00079 bool operator==(const Region& r) const; 00080 /// compare two regions 00081 bool operator!=(const Region& r) const { 00082 return !operator==(r); 00083 } 00084 00085 protected: 00086 void detach(); 00087 00088 private: 00089 typedef boost::shared_ptr<RectArray> RectArrayPtr; 00090 RectArrayPtr rects_; 00091 Rect extents; 00092 00093 private: 00094 typedef void (Region::*overlapFunc)(const RectArray& ra1, int start1, int end1, 00095 const RectArray& ra2, int start2, int end2, 00096 int y1, int y2); 00097 typedef void (Region::*nonOverlapFunc)(const RectArray& ra, 00098 int start, int end, int y1, int y2); 00099 void merge_rect(const RectArray& ra, int index, int y1, int y2); 00100 void calc_extents(); 00101 int coalesce(int prevStart, int curStart); 00102 00103 void regionOp(const Region& other, overlapFunc overlapFn, 00104 nonOverlapFunc nonOverlap1Fn, nonOverlapFunc nonOverlap2Fn); 00105 00106 void unionNonO(const RectArray& ra, int start, int end, int y1, int y2); 00107 void unionO(const RectArray& ra1, int start1, int end1, 00108 const RectArray& ra2, int start2, int end2, 00109 int y1, int y2); 00110 00111 void intersectO(const RectArray& ra1, int start1, int end1, 00112 const RectArray& ra2, int start2, int end2, 00113 int y1, int y2); 00114 00115 void subtractNonO(const RectArray& ra, int start, int end, int y1, int y2); 00116 void subtractO(const RectArray& ra1, int start1, int end1, 00117 const RectArray& ra2, int start2, int end2, 00118 int y1, int y2); 00119 }; 00120 00121 /// stream region output for debugging 00122 std::ostream& operator<<(std::ostream& s, const Region& r); 00123 00124 } // namespace 00125 00126 #endif // WT_REGION_H
This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.