00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_I_CROPPED_RECTANGLE_H__
00024 #define __MYGUI_I_CROPPED_RECTANGLE_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Common.h"
00028 #include "MyGUI_Align.h"
00029
00030 namespace MyGUI
00031 {
00032
00033 class MYGUI_EXPORT ICroppedRectangle
00034 {
00035 public:
00036 ICroppedRectangle() :
00037 mIsMargin(false),
00038 mCroppedParent(nullptr),
00039 mVisible(true),
00040 mAlign(Align::Default)
00041 { }
00042
00043 virtual ~ICroppedRectangle() { }
00044
00046 ICroppedRectangle * getCroppedParent() { return mCroppedParent; }
00047
00049 virtual void setCoord(const IntCoord& _value) { mCoord = _value; }
00051 const IntCoord& getCoord() { return mCoord; }
00052
00054 virtual void setPosition(const IntPoint& _value) { mCoord.left = _value.left; mCoord.top = _value.top; }
00056 IntPoint getPosition() { return mCoord.point(); }
00057
00059 virtual void setSize(const IntSize& _value) { mCoord.width = _value.width; mCoord.height = _value.height; }
00061 IntSize getSize() { return mCoord.size(); }
00062
00064 virtual void setVisible(bool _value) { mVisible = _value; }
00066 bool isVisible() { return mVisible; }
00067
00069 const IntPoint& getAbsolutePosition() { return mAbsolutePosition; }
00071 IntRect getAbsoluteRect() { return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left+mCoord.width, mAbsolutePosition.top+mCoord.height); }
00073 IntCoord getAbsoluteCoord() { return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height); }
00074
00076 int getAbsoluteLeft() { return mAbsolutePosition.left; }
00078 int getAbsoluteTop() { return mAbsolutePosition.top; }
00079
00081 virtual void setAlign(Align _value) { mAlign = _value; }
00083 Align getAlign() { return mAlign; }
00084
00086 int getLeft() { return mCoord.left; }
00088 int getRight() { return mCoord.right(); }
00090 int getTop() { return mCoord.top; }
00092 int getBottom() { return mCoord.bottom(); }
00094 int getWidth() { return mCoord.width; }
00096 int getHeight() { return mCoord.height; }
00097
00098
00099
00101 bool _isMargin() { return mIsMargin; }
00102
00103
00104 int _getViewLeft() { return mCoord.left + mMargin.left; }
00105 int _getViewRight() { return mCoord.right() - mMargin.right; }
00106 int _getViewTop() { return mCoord.top + mMargin.top; }
00107 int _getViewBottom() { return mCoord.bottom() - mMargin.bottom; }
00108 int _getViewWidth() { return mCoord.width - mMargin.left - mMargin.right; }
00109 int _getViewHeight() { return mCoord.height - mMargin.top - mMargin.bottom; }
00110
00111 virtual void _updateView() { }
00112 virtual void _correctView() { }
00113 virtual void _setAlign(const IntSize& _oldsize, bool _update) { }
00114 virtual void _setAlign(const IntCoord& _oldcoord, bool _update) { }
00115
00116 void _setCroppedParent(ICroppedRectangle* _parent) { mCroppedParent = _parent; }
00117
00118 const IntRect& _getMargin() { return mMargin; }
00119 int _getMarginLeft() { return mMargin.left; }
00120 int _getMarginRight() { return mMargin.right; }
00121 int _getMarginTop() { return mMargin.top; }
00122 int _getMarginBottom() { return mMargin.bottom; }
00123
00124
00125 #ifndef MYGUI_DONT_USE_OBSOLETE
00126
00127 MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
00128 void show() { setVisible(true); }
00129 MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
00130 void hide() { setVisible(false); }
00131 MYGUI_OBSOLETE("use : bool ICroppedRectangle::isVisible()")
00132 bool isShow() { return isVisible(); }
00133
00134 #endif // MYGUI_DONT_USE_OBSOLETE
00135
00136 protected:
00137 bool _checkPoint(int _left, int _top)
00138 {
00139 return ! ((_getViewLeft() > _left) || (_getViewTop() > _top) || (_getViewRight() < _left) || (_getViewBottom() < _top));
00140 }
00141
00142 bool _checkMargin()
00143 {
00144 bool margin = false;
00145
00146 if (getLeft() < mCroppedParent->mMargin.left)
00147 {
00148 mMargin.left = mCroppedParent->mMargin.left - getLeft();
00149 margin = true;
00150 }
00151 else
00152 {
00153 mMargin.left = 0;
00154 }
00155
00156
00157 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
00158 {
00159 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
00160 margin = true;
00161 }
00162 else
00163 {
00164 mMargin.right = 0;
00165 }
00166
00167
00168 if (getTop() < mCroppedParent->mMargin.top)
00169 {
00170 mMargin.top = mCroppedParent->mMargin.top - getTop();
00171 margin = true;
00172 }
00173 else
00174 {
00175 mMargin.top = 0;
00176 }
00177
00178
00179 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
00180 {
00181 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
00182 margin = true;
00183 }
00184 else
00185 {
00186 mMargin.bottom = 0;
00187 }
00188
00189 return margin;
00190 }
00191
00192 bool _checkOutside()
00193 {
00194 return ( (getRight() < mCroppedParent->mMargin.left ) ||
00195 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) ||
00196 (getBottom() < mCroppedParent->mMargin.top ) ||
00197 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) );
00198 }
00199
00200 protected:
00201 bool mIsMargin;
00202 IntRect mMargin;
00203 IntCoord mCoord;
00204 IntPoint mAbsolutePosition;
00205
00206 ICroppedRectangle * mCroppedParent;
00207 bool mVisible;
00208 Align mAlign;
00209
00210 };
00211
00212 }
00213
00214 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__