MyGUI  3.2.1
MyGUI_ICroppedRectangle.h
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #ifndef __MYGUI_I_CROPPED_RECTANGLE_H__
00008 #define __MYGUI_I_CROPPED_RECTANGLE_H__
00009 
00010 #include "MyGUI_Prerequest.h"
00011 #include "MyGUI_Types.h"
00012 
00013 namespace MyGUI
00014 {
00015 
00016     class MYGUI_EXPORT ICroppedRectangle
00017     {
00018     public:
00019         ICroppedRectangle() :
00020             mIsMargin(false),
00021             mCroppedParent(nullptr)
00022         { }
00023 
00024         virtual ~ICroppedRectangle() { }
00025 
00027         ICroppedRectangle* getCroppedParent()
00028         {
00029             return mCroppedParent;
00030         }
00031 
00033         virtual void setPosition(const IntPoint& _value)
00034         {
00035             mCoord.left = _value.left;
00036             mCoord.top = _value.top;
00037         }
00039         virtual void setSize(const IntSize& _value)
00040         {
00041             mCoord.width = _value.width;
00042             mCoord.height = _value.height;
00043         }
00045         virtual void setCoord(const IntCoord& _value)
00046         {
00047             mCoord = _value;
00048         }
00049 
00051         IntPoint getPosition() const
00052         {
00053             return mCoord.point();
00054         }
00056         IntSize getSize() const
00057         {
00058             return mCoord.size();
00059         }
00061         const IntCoord& getCoord() const
00062         {
00063             return mCoord;
00064         }
00065 
00067         const IntPoint& getAbsolutePosition() const
00068         {
00069             return mAbsolutePosition;
00070         }
00072         IntRect getAbsoluteRect() const
00073         {
00074             return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left + mCoord.width, mAbsolutePosition.top + mCoord.height);
00075         }
00077         IntCoord getAbsoluteCoord() const
00078         {
00079             return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height);
00080         }
00081 
00083         int getAbsoluteLeft() const
00084         {
00085             return mAbsolutePosition.left;
00086         }
00088         int getAbsoluteTop() const
00089         {
00090             return mAbsolutePosition.top;
00091         }
00092 
00094         int getLeft() const
00095         {
00096             return mCoord.left;
00097         }
00099         int getRight() const
00100         {
00101             return mCoord.right();
00102         }
00104         int getTop() const
00105         {
00106             return mCoord.top;
00107         }
00109         int getBottom() const
00110         {
00111             return mCoord.bottom();
00112         }
00114         int getWidth() const
00115         {
00116             return mCoord.width;
00117         }
00119         int getHeight() const
00120         {
00121             return mCoord.height;
00122         }
00123 
00124 
00125         /*internal:*/
00127         bool _isMargin() const
00128         {
00129             return mIsMargin;
00130         }
00131 
00132         // Get cropped by parent rectangle coordinates
00133         int _getViewLeft() const
00134         {
00135             return mCoord.left + mMargin.left;
00136         }
00137         int _getViewRight() const
00138         {
00139             return mCoord.right() - mMargin.right;
00140         }
00141         int _getViewTop() const
00142         {
00143             return mCoord.top + mMargin.top;
00144         }
00145         int _getViewBottom() const
00146         {
00147             return mCoord.bottom() - mMargin.bottom;
00148         }
00149         int _getViewWidth() const
00150         {
00151             return mCoord.width - mMargin.left - mMargin.right;
00152         }
00153         int _getViewHeight() const
00154         {
00155             return mCoord.height - mMargin.top - mMargin.bottom;
00156         }
00157 
00158         void _setCroppedParent(ICroppedRectangle* _parent)
00159         {
00160             mCroppedParent = _parent;
00161         }
00162 
00163         const IntRect& _getMargin() const
00164         {
00165             return mMargin;
00166         }
00167         int _getMarginLeft() const
00168         {
00169             return mMargin.left;
00170         }
00171         int _getMarginRight() const
00172         {
00173             return mMargin.right;
00174         }
00175         int _getMarginTop() const
00176         {
00177             return mMargin.top;
00178         }
00179         int _getMarginBottom() const
00180         {
00181             return mMargin.bottom;
00182         }
00183 
00184     protected:
00185         bool _checkMargin()
00186         {
00187             bool margin = false;
00188             //вылезли ли налево
00189             if (getLeft() < mCroppedParent->mMargin.left)
00190             {
00191                 mMargin.left = mCroppedParent->mMargin.left - getLeft();
00192                 margin = true;
00193             }
00194             else
00195             {
00196                 mMargin.left = 0;
00197             }
00198 
00199             //вылезли ли направо
00200             if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
00201             {
00202                 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
00203                 margin = true;
00204             }
00205             else
00206             {
00207                 mMargin.right = 0;
00208             }
00209 
00210             //вылезли ли вверх
00211             if (getTop() < mCroppedParent->mMargin.top)
00212             {
00213                 mMargin.top = mCroppedParent->mMargin.top - getTop();
00214                 margin = true;
00215             }
00216             else
00217             {
00218                 mMargin.top = 0;
00219             }
00220 
00221             //вылезли ли вниз
00222             if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
00223             {
00224                 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
00225                 margin = true;
00226             }
00227             else
00228             {
00229                 mMargin.bottom = 0;
00230             }
00231 
00232             return margin;
00233         }
00234 
00235         bool _checkOutside() const // проверка на полный выход за границу
00236         {
00237             return ( (getRight() < mCroppedParent->mMargin.left ) || // совсем уехали налево
00238                 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) || // совсем уехали направо
00239                 (getBottom() < mCroppedParent->mMargin.top  ) || // совсем уехали вверх
00240                 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) );  // совсем уехали вниз
00241         }
00242 
00243     protected:
00244         IntRect mMargin; // перекрытие
00245         IntCoord mCoord; // координаты
00246         IntPoint mAbsolutePosition; // обсолютные координаты
00247 
00248         bool mIsMargin;
00249         ICroppedRectangle* mCroppedParent;
00250     };
00251 
00252 } // namespace MyGUI
00253 
00254 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__