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 #include "CEGUIRect.h"
00027
00028
00029 namespace CEGUI
00030 {
00031
00032
00033
00034 Rect::Rect(float left, float top, float right, float bottom) :
00035 d_top(top),
00036 d_bottom(bottom),
00037 d_left(left),
00038 d_right(right)
00039 {
00040 }
00041
00042 Rect::Rect(Point pos, Size sz) :
00043 d_top(pos.d_y),
00044 d_bottom(pos.d_y + sz.d_height),
00045 d_left(pos.d_x),
00046 d_right(pos.d_x + sz.d_width)
00047 {
00048 }
00049
00050
00051
00052
00053
00054 Rect Rect::getIntersection(const Rect& rect) const
00055 {
00056
00057 if ((d_right > rect.d_left) &&
00058 (d_left < rect.d_right) &&
00059 (d_bottom > rect.d_top) &&
00060 (d_top < rect.d_bottom))
00061 {
00062 Rect temp;
00063
00064
00065 temp.d_left = (d_left > rect.d_left) ? d_left : rect.d_left;
00066 temp.d_right = (d_right < rect.d_right) ? d_right : rect.d_right;
00067 temp.d_top = (d_top > rect.d_top) ? d_top : rect.d_top;
00068 temp.d_bottom = (d_bottom < rect.d_bottom) ? d_bottom : rect.d_bottom;
00069
00070 return temp;
00071 }
00072 else
00073 {
00074 return Rect(0.0f, 0.0f, 0.0f, 0.0f);
00075 }
00076
00077 }
00078
00079
00080
00081
00082 Rect& Rect::offset(const Point& pt)
00083 {
00084 d_left += pt.d_x;
00085 d_right += pt.d_x;
00086 d_top += pt.d_y;
00087 d_bottom += pt.d_y;
00088 return *this;
00089 }
00090
00091
00092
00093
00094
00095 bool Rect::isPointInRect(const Point& pt) const
00096 {
00097 if ((d_left > pt.d_x) ||
00098 (d_right <= pt.d_x) ||
00099 (d_top > pt.d_y) ||
00100 (d_bottom <= pt.d_y))
00101 {
00102 return false;
00103 }
00104
00105 return true;
00106 }
00107
00108
00109
00110
00111 void Rect::setPosition(const Point& pt)
00112 {
00113 Size sz(getSize());
00114
00115 d_left = pt.d_x;
00116 d_top = pt.d_y;
00117 setSize(sz);
00118 }
00119
00120
00121
00122
00123
00124
00125 Rect& Rect::constrainSizeMax(const Size& sz)
00126 {
00127 if (getWidth() > sz.d_width)
00128 {
00129 setWidth(sz.d_width);
00130 }
00131
00132 if (getHeight() > sz.d_height)
00133 {
00134 setHeight(sz.d_height);
00135 }
00136
00137 return *this;
00138 }
00139
00140
00141
00142
00143
00144
00145 Rect& Rect::constrainSizeMin(const Size& sz)
00146 {
00147 if (getWidth() < sz.d_width)
00148 {
00149 setWidth(sz.d_width);
00150 }
00151
00152 if (getHeight() < sz.d_height)
00153 {
00154 setHeight(sz.d_height);
00155 }
00156
00157 return *this;
00158 }
00159
00160
00161
00162
00163
00164
00165 Rect& Rect::constrainSize(const Size& max_sz, const Size& min_sz)
00166 {
00167 Size curr_sz(getSize());
00168
00169 if (curr_sz.d_width > max_sz.d_width)
00170 {
00171 setWidth(max_sz.d_width);
00172 }
00173 else if (curr_sz.d_width < min_sz.d_width)
00174 {
00175 setWidth(min_sz.d_width);
00176 }
00177
00178 if (curr_sz.d_height > max_sz.d_height)
00179 {
00180 setHeight(max_sz.d_height);
00181 }
00182 else if (curr_sz.d_height < min_sz.d_height)
00183 {
00184 setHeight(min_sz.d_height);
00185 }
00186
00187 return *this;
00188 }
00189
00190 Rect& Rect::operator=(const Rect& rhs)
00191 {
00192 d_left = rhs.d_left;
00193 d_top = rhs.d_top;
00194 d_right = rhs.d_right;
00195 d_bottom = rhs.d_bottom;
00196
00197 return *this;
00198 }
00199
00200 }