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