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
00027
00028
00033 #ifndef PG_RECT_H
00034 #define PG_RECT_H
00035
00036 #include "pgpoint.h"
00037
00038 class PG_Widget;
00039
00045 class DECLSPEC PG_Rect : public SDL_Rect {
00046 public:
00047
00057 PG_Rect(Sint16 x = 0, Sint16 y = 0, Uint16 w = 0, Uint16 h = 0);
00058
00065 PG_Rect(const PG_Rect& src);
00066
00073 PG_Rect(const SDL_Rect& src);
00074
00075 virtual ~PG_Rect();
00076
00085 inline void SetRect(Sint16 nx, Sint16 ny, Uint16 nw, Uint16 nh) {
00086 x = nx;
00087 y = ny;
00088 w = nw;
00089 h = nh;
00090 }
00091
00094 PG_Rect& operator =(const SDL_Rect& src);
00095
00096 PG_Rect& operator =(const PG_Rect& src);
00097
00100 PG_Rect operator / ( const PG_Rect& b) const ;
00101
00102 inline bool operator ==(const PG_Rect& r) const {
00103 return (x == r.x) && (y == r.y) && (r.w == w) && (r.h == h);
00104 }
00105
00106 inline bool operator !=(const PG_Rect& r) const {
00107 return !((x == r.x) && (y == r.y) && (r.w == w) && (r.h == h));
00108 }
00116 inline static bool IsInside(const PG_Point& p, PG_Rect& r) {
00117 return r.IsInside(p);
00118 }
00119
00126 inline bool IsInside(const PG_Point& p) const {
00127 return ( (x <= p.x) && (p.x <= x + w) && (y <= p.y) && (p.y <= y + h) );
00128 }
00129
00136 static PG_Rect IntersectRect(const PG_Rect& p, const PG_Rect& c);
00137
00143 PG_Rect IntersectRect(const PG_Rect& p) const;
00144
00149 inline Uint16 Width() const {
00150 return w;
00151 }
00152
00157 inline Uint16 Height() const {
00158 return h;
00159 }
00160
00161 inline bool IsNull() const {
00162 return (!Width() && !Height());
00163 }
00164
00166
00170 inline bool OverlapRect(const PG_Rect& p, const PG_Rect& c) const {
00171 return !( (p.x + p.w < c.x) || (p.x > c.x + c.w) || (p.y + p.h < c.y) || (p.y > c.y + c.h) || (p.IntersectRect(c).IsNull()) );
00172 }
00173
00175
00179 inline bool OverlapRect(const PG_Rect& p) const {
00180 return OverlapRect(p, *this);
00181 }
00182
00184
00188 inline bool OverlapRect(PG_Rect* p) {
00189 return OverlapRect(*p, *this);
00190 }
00191
00196 inline PG_Widget* next() {
00197 return my_next;
00198 }
00199
00204 inline PG_Widget* prev() {
00205 return my_prev;
00206 }
00207
00208 Sint16& my_xpos;
00209
00210 Sint16& my_ypos;
00211
00212 Uint16& my_width;
00213
00214 Uint16& my_height;
00215
00216 Uint32 index;
00217
00218 static PG_Rect null;
00219
00220 protected:
00221
00222 PG_Widget* my_next;
00223
00224 PG_Widget* my_prev;
00225
00226 friend class PG_RectList;
00227 };
00228
00229 #endif // PG_RECT_H