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_Types.h"
00028
00029 namespace MyGUI
00030 {
00031
00032 class MYGUI_EXPORT ICroppedRectangle
00033 {
00034 public:
00035 ICroppedRectangle() :
00036 mIsMargin(false),
00037 mCroppedParent(nullptr),
00038 mVisible(true),
00039 mAlign(Align::Default)
00040 { }
00041
00042 virtual ~ICroppedRectangle() { }
00043
00045 ICroppedRectangle * getCroppedParent() { return mCroppedParent; }
00046
00048 virtual void setCoord(const IntCoord& _value) { mCoord = _value; }
00050 const IntCoord& getCoord() const { return mCoord; }
00051
00053 virtual void setPosition(const IntPoint& _value) { mCoord.left = _value.left; mCoord.top = _value.top; }
00055 IntPoint getPosition() const { return mCoord.point(); }
00056
00058 virtual void setSize(const IntSize& _value) { mCoord.width = _value.width; mCoord.height = _value.height; }
00060 IntSize getSize() const { return mCoord.size(); }
00061
00063 virtual void setVisible(bool _value) { mVisible = _value; }
00065 bool isVisible() const { return mVisible; }
00066
00068 const IntPoint& getAbsolutePosition() const { return mAbsolutePosition; }
00070 IntRect getAbsoluteRect() const { return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left+mCoord.width, mAbsolutePosition.top+mCoord.height); }
00072 IntCoord getAbsoluteCoord() const { return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height); }
00073
00075 int getAbsoluteLeft() const { return mAbsolutePosition.left; }
00077 int getAbsoluteTop() const { return mAbsolutePosition.top; }
00078
00080 virtual void setAlign(Align _value) { mAlign = _value; }
00082 Align getAlign() const { return mAlign; }
00083
00085 int getLeft() const { return mCoord.left; }
00087 int getRight() const { return mCoord.right(); }
00089 int getTop() const { return mCoord.top; }
00091 int getBottom() const { return mCoord.bottom(); }
00093 int getWidth() const { return mCoord.width; }
00095 int getHeight() const { return mCoord.height; }
00096
00097
00098
00100 bool _isMargin() const { return mIsMargin; }
00101
00102
00103 int _getViewLeft() const { return mCoord.left + mMargin.left; }
00104 int _getViewRight() const { return mCoord.right() - mMargin.right; }
00105 int _getViewTop() const { return mCoord.top + mMargin.top; }
00106 int _getViewBottom() const { return mCoord.bottom() - mMargin.bottom; }
00107 int _getViewWidth() const { return mCoord.width - mMargin.left - mMargin.right; }
00108 int _getViewHeight() const { return mCoord.height - mMargin.top - mMargin.bottom; }
00109
00110 virtual void _updateView() { }
00111 virtual void _correctView() { }
00112 virtual void _setAlign(const IntSize& _oldsize, bool _update) { }
00113 virtual void _setAlign(const IntCoord& _oldcoord, bool _update) { }
00114
00115 void _setCroppedParent(ICroppedRectangle* _parent) { mCroppedParent = _parent; }
00116
00117 const IntRect& _getMargin() const { return mMargin; }
00118 int _getMarginLeft() const { return mMargin.left; }
00119 int _getMarginRight() const { return mMargin.right; }
00120 int _getMarginTop() const { return mMargin.top; }
00121 int _getMarginBottom() const { return mMargin.bottom; }
00122
00123
00124 #ifndef MYGUI_DONT_USE_OBSOLETE
00125
00126 MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
00127 void show() { setVisible(true); }
00128 MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
00129 void hide() { setVisible(false); }
00130 MYGUI_OBSOLETE("use : bool ICroppedRectangle::isVisible()")
00131 bool isShow() { return isVisible(); }
00132
00133 #endif // MYGUI_DONT_USE_OBSOLETE
00134
00135 protected:
00136 bool _checkPoint(int _left, int _top)
00137 {
00138 return ! ((_getViewLeft() > _left) || (_getViewTop() > _top) || (_getViewRight() < _left) || (_getViewBottom() < _top));
00139 }
00140
00141 bool _checkMargin()
00142 {
00143 bool margin = false;
00144
00145 if (getLeft() < mCroppedParent->mMargin.left)
00146 {
00147 mMargin.left = mCroppedParent->mMargin.left - getLeft();
00148 margin = true;
00149 }
00150 else
00151 {
00152 mMargin.left = 0;
00153 }
00154
00155
00156 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
00157 {
00158 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
00159 margin = true;
00160 }
00161 else
00162 {
00163 mMargin.right = 0;
00164 }
00165
00166
00167 if (getTop() < mCroppedParent->mMargin.top)
00168 {
00169 mMargin.top = mCroppedParent->mMargin.top - getTop();
00170 margin = true;
00171 }
00172 else
00173 {
00174 mMargin.top = 0;
00175 }
00176
00177
00178 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
00179 {
00180 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
00181 margin = true;
00182 }
00183 else
00184 {
00185 mMargin.bottom = 0;
00186 }
00187
00188 return margin;
00189 }
00190
00191 bool _checkOutside()
00192 {
00193 return ( (getRight() < mCroppedParent->mMargin.left ) ||
00194 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) ||
00195 (getBottom() < mCroppedParent->mMargin.top ) ||
00196 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) );
00197 }
00198
00199 protected:
00200 bool mIsMargin;
00201 IntRect mMargin;
00202 IntCoord mCoord;
00203 IntPoint mAbsolutePosition;
00204
00205 ICroppedRectangle * mCroppedParent;
00206 bool mVisible;
00207 Align mAlign;
00208
00209 };
00210
00211 }
00212
00213 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__