00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _COMPRECT_H
00027 #define _COMPRECT_H
00028
00033 class CompRect {
00034
00035 public:
00036 CompRect ();
00037 CompRect (int x, int y, int width, int height);
00038 CompRect (const CompRect&);
00039 CompRect (const XRectangle);
00040
00041 int x () const;
00042 int y () const;
00043 CompPoint pos () const;
00044
00045 int width () const;
00046 int height () const;
00047
00048 int x1 () const;
00049 int y1 () const;
00050 int x2 () const;
00051 int y2 () const;
00052
00053 int left () const;
00054 int right () const;
00055 int top () const;
00056 int bottom () const;
00057
00058 int centerX () const;
00059 int centerY () const;
00060 CompPoint center () const;
00061
00062 int area () const;
00063
00067 const Region region () const;
00068
00069 void setGeometry (int x, int y,
00070 int width, int height);
00071
00072 void setX (int);
00073 void setY (int);
00074 void setWidth (int);
00075 void setHeight (int);
00076
00077 void setPos (const CompPoint&);
00078 void setSize (const CompSize&);
00079
00086 void setLeft (int);
00093 void setTop (int);
00100 void setRight (int);
00107 void setBottom (int);
00108
00109 bool contains (const CompPoint &) const;
00110 bool contains (const CompRect &) const;
00111 bool intersects (const CompRect &) const;
00112 bool isEmpty () const;
00113
00114 bool operator== (const CompRect &) const;
00115 bool operator!= (const CompRect &) const;
00116
00117 CompRect operator& (const CompRect &) const;
00118 CompRect& operator&= (const CompRect &);
00119 CompRect& operator= (const CompRect &);
00120
00121 typedef std::vector<CompRect> vector;
00122 typedef std::vector<CompRect *> ptrVector;
00123 typedef std::list<CompRect *> ptrList;
00124
00125 private:
00126 REGION mRegion;
00127 };
00128
00129
00130 inline int
00131 CompRect::x () const
00132 {
00133 return mRegion.extents.x1;
00134 }
00135
00136 inline int
00137 CompRect::y () const
00138 {
00139 return mRegion.extents.y1;
00140 }
00141
00142 inline CompPoint
00143 CompRect::pos () const
00144 {
00145 return CompPoint (x (), y ());
00146 }
00147
00148 inline int
00149 CompRect::width () const
00150 {
00151 return mRegion.extents.x2 - mRegion.extents.x1;
00152 }
00153
00154 inline int
00155 CompRect::height () const
00156 {
00157 return mRegion.extents.y2 - mRegion.extents.y1;
00158 }
00159
00160 inline int
00161 CompRect::x1 () const
00162 {
00163 return mRegion.extents.x1;
00164 }
00165
00166 inline int
00167 CompRect::y1 () const
00168 {
00169 return mRegion.extents.y1;
00170 }
00171
00172 inline int
00173 CompRect::x2 () const
00174 {
00175 return mRegion.extents.x2;
00176 }
00177
00178 inline int
00179 CompRect::y2 () const
00180 {
00181 return mRegion.extents.y2;
00182 }
00183
00184 inline int
00185 CompRect::left () const
00186 {
00187 return mRegion.extents.x1;
00188 }
00189
00190 inline int
00191 CompRect::right () const
00192 {
00193 return mRegion.extents.x2;
00194 }
00195
00196 inline int
00197 CompRect::top () const
00198 {
00199 return mRegion.extents.y1;
00200 }
00201
00202
00203 inline int
00204 CompRect::bottom () const
00205 {
00206 return mRegion.extents.y2;
00207 }
00208
00209 inline int
00210 CompRect::centerX () const
00211 {
00212 return x () + width () / 2;
00213 }
00214
00215 inline int
00216 CompRect::centerY () const
00217 {
00218 return y () + height () / 2;
00219 }
00220
00221 inline CompPoint
00222 CompRect::center () const
00223 {
00224 return CompPoint (centerX (), centerY ());
00225 }
00226
00227 #endif