MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_I_CROPPED_RECTANGLE_H__ 00023 #define __MYGUI_I_CROPPED_RECTANGLE_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Types.h" 00027 00028 namespace MyGUI 00029 { 00030 00031 class MYGUI_EXPORT ICroppedRectangle 00032 { 00033 public: 00034 ICroppedRectangle() : 00035 mIsMargin(false), 00036 mCroppedParent(nullptr) 00037 { } 00038 00039 virtual ~ICroppedRectangle() { } 00040 00042 ICroppedRectangle* getCroppedParent() 00043 { 00044 return mCroppedParent; 00045 } 00046 00048 virtual void setPosition(const IntPoint& _value) 00049 { 00050 mCoord.left = _value.left; 00051 mCoord.top = _value.top; 00052 } 00054 virtual void setSize(const IntSize& _value) 00055 { 00056 mCoord.width = _value.width; 00057 mCoord.height = _value.height; 00058 } 00060 virtual void setCoord(const IntCoord& _value) 00061 { 00062 mCoord = _value; 00063 } 00064 00066 IntPoint getPosition() const 00067 { 00068 return mCoord.point(); 00069 } 00071 IntSize getSize() const 00072 { 00073 return mCoord.size(); 00074 } 00076 const IntCoord& getCoord() const 00077 { 00078 return mCoord; 00079 } 00080 00082 const IntPoint& getAbsolutePosition() const 00083 { 00084 return mAbsolutePosition; 00085 } 00087 IntRect getAbsoluteRect() const 00088 { 00089 return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left + mCoord.width, mAbsolutePosition.top + mCoord.height); 00090 } 00092 IntCoord getAbsoluteCoord() const 00093 { 00094 return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height); 00095 } 00096 00098 int getAbsoluteLeft() const 00099 { 00100 return mAbsolutePosition.left; 00101 } 00103 int getAbsoluteTop() const 00104 { 00105 return mAbsolutePosition.top; 00106 } 00107 00109 int getLeft() const 00110 { 00111 return mCoord.left; 00112 } 00114 int getRight() const 00115 { 00116 return mCoord.right(); 00117 } 00119 int getTop() const 00120 { 00121 return mCoord.top; 00122 } 00124 int getBottom() const 00125 { 00126 return mCoord.bottom(); 00127 } 00129 int getWidth() const 00130 { 00131 return mCoord.width; 00132 } 00134 int getHeight() const 00135 { 00136 return mCoord.height; 00137 } 00138 00139 00140 /*internal:*/ 00142 bool _isMargin() const 00143 { 00144 return mIsMargin; 00145 } 00146 00147 // Get cropped by parent rectangle coordinates 00148 int _getViewLeft() const 00149 { 00150 return mCoord.left + mMargin.left; 00151 } 00152 int _getViewRight() const 00153 { 00154 return mCoord.right() - mMargin.right; 00155 } 00156 int _getViewTop() const 00157 { 00158 return mCoord.top + mMargin.top; 00159 } 00160 int _getViewBottom() const 00161 { 00162 return mCoord.bottom() - mMargin.bottom; 00163 } 00164 int _getViewWidth() const 00165 { 00166 return mCoord.width - mMargin.left - mMargin.right; 00167 } 00168 int _getViewHeight() const 00169 { 00170 return mCoord.height - mMargin.top - mMargin.bottom; 00171 } 00172 00173 void _setCroppedParent(ICroppedRectangle* _parent) 00174 { 00175 mCroppedParent = _parent; 00176 } 00177 00178 const IntRect& _getMargin() const 00179 { 00180 return mMargin; 00181 } 00182 int _getMarginLeft() const 00183 { 00184 return mMargin.left; 00185 } 00186 int _getMarginRight() const 00187 { 00188 return mMargin.right; 00189 } 00190 int _getMarginTop() const 00191 { 00192 return mMargin.top; 00193 } 00194 int _getMarginBottom() const 00195 { 00196 return mMargin.bottom; 00197 } 00198 00199 protected: 00200 bool _checkMargin() 00201 { 00202 bool margin = false; 00203 //вылезли ли налево 00204 if (getLeft() < mCroppedParent->mMargin.left) 00205 { 00206 mMargin.left = mCroppedParent->mMargin.left - getLeft(); 00207 margin = true; 00208 } 00209 else 00210 { 00211 mMargin.left = 0; 00212 } 00213 00214 //вылезли ли направо 00215 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right) 00216 { 00217 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right); 00218 margin = true; 00219 } 00220 else 00221 { 00222 mMargin.right = 0; 00223 } 00224 00225 //вылезли ли вверх 00226 if (getTop() < mCroppedParent->mMargin.top) 00227 { 00228 mMargin.top = mCroppedParent->mMargin.top - getTop(); 00229 margin = true; 00230 } 00231 else 00232 { 00233 mMargin.top = 0; 00234 } 00235 00236 //вылезли ли вниз 00237 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom) 00238 { 00239 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom); 00240 margin = true; 00241 } 00242 else 00243 { 00244 mMargin.bottom = 0; 00245 } 00246 00247 return margin; 00248 } 00249 00250 bool _checkOutside() const // проверка на полный выход за границу 00251 { 00252 return ( (getRight() < mCroppedParent->mMargin.left ) || // совсем уехали налево 00253 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) || // совсем уехали направо 00254 (getBottom() < mCroppedParent->mMargin.top ) || // совсем уехали вверх 00255 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) ); // совсем уехали вниз 00256 } 00257 00258 protected: 00259 IntRect mMargin; // перекрытие 00260 IntCoord mCoord; // координаты 00261 IntPoint mAbsolutePosition; // обсолютные координаты 00262 00263 bool mIsMargin; 00264 ICroppedRectangle* mCroppedParent; 00265 }; 00266 00267 } // namespace MyGUI 00268 00269 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__