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
00029 #include "pgrect.h"
00030
00031 PG_Rect PG_Rect::null;
00032
00033 PG_Rect::PG_Rect(Sint16 xv, Sint16 yv, Uint16 wv, Uint16 hv) :
00034 my_xpos(x),
00035 my_ypos(y),
00036 my_width(w),
00037 my_height(h),
00038 index(0),
00039 my_next(NULL),
00040 my_prev(NULL) {
00041 SetRect(xv, yv, wv, hv);
00042 }
00043
00044 PG_Rect::PG_Rect(const PG_Rect& src) :
00045 my_xpos(x),
00046 my_ypos(y),
00047 my_width(w),
00048 my_height(h),
00049 my_next(NULL),
00050 my_prev(NULL) {
00051 *this = src;
00052 }
00053
00054 PG_Rect::PG_Rect(const SDL_Rect& src) :
00055 my_xpos(x),
00056 my_ypos(y),
00057 my_width(w),
00058 my_height(h),
00059 my_next(NULL),
00060 my_prev(NULL) {
00061 *this = src;
00062 }
00063
00064 PG_Rect::~PG_Rect() {}
00065
00066 PG_Rect PG_Rect::IntersectRect(const PG_Rect& p, const PG_Rect& c) {
00067 static int px0,py0,px1,py1;
00068 static int cx0,cy0,cx1,cy1;
00069 static int rx0,ry0,rx1,ry1;
00070
00071
00072 PG_Rect result;
00073
00074
00075 px0 = p.my_xpos;
00076 py0 = p.my_ypos;
00077 px1 = p.my_xpos + p.my_width - 1;
00078 py1 = p.my_ypos + p.my_height - 1;
00079
00080 cx0 = c.my_xpos;
00081 cy0 = c.my_ypos;
00082 cx1 = c.my_xpos + c.my_width - 1;
00083 cy1 = c.my_ypos + c.my_height - 1;
00084
00085
00086 if((cx1 < px0) || (cx0 > px1) || (cy1 < py0) || (cy0 > py1))
00087 return result;
00088
00089
00090 if(cx0 <= px0)
00091 rx0 = px0;
00092 else
00093 rx0 = cx0;
00094
00095 if(cx1 >= px1)
00096 rx1 = px1;
00097 else
00098 rx1 = cx1;
00099
00100
00101 if(cy0 <= py0)
00102 ry0 = py0;
00103 else
00104 ry0 = cy0;
00105
00106 if(cy1 >= py1)
00107 ry1 = py1;
00108 else
00109 ry1 = cy1;
00110
00111
00112 result.SetRect(
00113 rx0,
00114 ry0,
00115 (rx1-rx0)+1,
00116 (ry1-ry0)+1);
00117
00118 return result;
00119 }
00120
00121 PG_Rect PG_Rect::IntersectRect(const PG_Rect& p) const {
00122 return IntersectRect(p, *this);
00123 }
00124
00125 PG_Rect& PG_Rect::operator =(const PG_Rect& src) {
00126 SetRect(src.x, src.y, src.w, src.h);
00127 my_next = NULL;
00128 my_prev = NULL;
00129 return *this;
00130 }
00131
00132 PG_Rect PG_Rect::operator / ( const PG_Rect& b) const {
00133 return IntersectRect(b);
00134 }
00135
00136 PG_Rect& PG_Rect::operator =(const SDL_Rect& src) {
00137 x = src.x;
00138 y = src.y;
00139 w = src.w;
00140 h = src.h;
00141 return *this;
00142 }