MyGUI  3.0.1
MyGUI_ICroppedRectangle.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_I_CROPPED_RECTANGLE_H__
24 #define __MYGUI_I_CROPPED_RECTANGLE_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Types.h"
28 
29 namespace MyGUI
30 {
31 
33  {
34  public:
36  mIsMargin(false),
37  mCroppedParent(nullptr),
38  mVisible(true),
39  mAlign(Align::Default)
40  { }
41 
42  virtual ~ICroppedRectangle() { }
43 
45  ICroppedRectangle * getCroppedParent() { return mCroppedParent; }
46 
48  virtual void setCoord(const IntCoord& _value) { mCoord = _value; }
50  const IntCoord& getCoord() const { return mCoord; }
51 
53  virtual void setPosition(const IntPoint& _value) { mCoord.left = _value.left; mCoord.top = _value.top; }
55  IntPoint getPosition() const { return mCoord.point(); }
56 
58  virtual void setSize(const IntSize& _value) { mCoord.width = _value.width; mCoord.height = _value.height; }
60  IntSize getSize() const { return mCoord.size(); }
61 
63  virtual void setVisible(bool _value) { mVisible = _value; }
65  bool isVisible() const { return mVisible; }
66 
68  const IntPoint& getAbsolutePosition() const { return mAbsolutePosition; }
70  IntRect getAbsoluteRect() const { return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left+mCoord.width, mAbsolutePosition.top+mCoord.height); }
72  IntCoord getAbsoluteCoord() const { return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height); }
73 
75  int getAbsoluteLeft() const { return mAbsolutePosition.left; }
77  int getAbsoluteTop() const { return mAbsolutePosition.top; }
78 
80  virtual void setAlign(Align _value) { mAlign = _value; }
82  Align getAlign() const { return mAlign; }
83 
85  int getLeft() const { return mCoord.left; }
87  int getRight() const { return mCoord.right(); }
89  int getTop() const { return mCoord.top; }
91  int getBottom() const { return mCoord.bottom(); }
93  int getWidth() const { return mCoord.width; }
95  int getHeight() const { return mCoord.height; }
96 
97 
98  /*internal:*/
100  bool _isMargin() const { return mIsMargin; }
101 
102  // Get cropped by parent rectangle coordinates
103  int _getViewLeft() const { return mCoord.left + mMargin.left; }
104  int _getViewRight() const { return mCoord.right() - mMargin.right; }
105  int _getViewTop() const { return mCoord.top + mMargin.top; }
106  int _getViewBottom() const { return mCoord.bottom() - mMargin.bottom; }
107  int _getViewWidth() const { return mCoord.width - mMargin.left - mMargin.right; }
108  int _getViewHeight() const { return mCoord.height - mMargin.top - mMargin.bottom; }
109 
110  virtual void _updateView() { }
111  virtual void _correctView() { }
112  virtual void _setAlign(const IntSize& _oldsize, bool _update) { }
113  virtual void _setAlign(const IntCoord& _oldcoord, bool _update) { }
114 
115  void _setCroppedParent(ICroppedRectangle* _parent) { mCroppedParent = _parent; }
116 
117  const IntRect& _getMargin() const { return mMargin; }
118  int _getMarginLeft() const { return mMargin.left; }
119  int _getMarginRight() const { return mMargin.right; }
120  int _getMarginTop() const { return mMargin.top; }
121  int _getMarginBottom() const { return mMargin.bottom; }
122 
123  /*obsolete:*/
124 #ifndef MYGUI_DONT_USE_OBSOLETE
125 
126  MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
127  void show() { setVisible(true); }
128  MYGUI_OBSOLETE("use : void ICroppedRectangle::setVisible(bool _visible)")
129  void hide() { setVisible(false); }
130  MYGUI_OBSOLETE("use : bool ICroppedRectangle::isVisible()")
131  bool isShow() { return isVisible(); }
132 
133 #endif // MYGUI_DONT_USE_OBSOLETE
134 
135  protected:
136  bool _checkPoint(int _left, int _top)
137  {
138  return ! ((_getViewLeft() > _left) || (_getViewTop() > _top) || (_getViewRight() < _left) || (_getViewBottom() < _top));
139  }
140 
141  bool _checkMargin()
142  {
143  bool margin = false;
144  //вылезли ли налево
145  if (getLeft() < mCroppedParent->mMargin.left)
146  {
147  mMargin.left = mCroppedParent->mMargin.left - getLeft();
148  margin = true;
149  }
150  else
151  {
152  mMargin.left = 0;
153  }
154 
155  //вылезли ли направо
156  if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
157  {
158  mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
159  margin = true;
160  }
161  else
162  {
163  mMargin.right = 0;
164  }
165 
166  //вылезли ли вверх
167  if (getTop() < mCroppedParent->mMargin.top)
168  {
169  mMargin.top = mCroppedParent->mMargin.top - getTop();
170  margin = true;
171  }
172  else
173  {
174  mMargin.top = 0;
175  }
176 
177  //вылезли ли вниз
178  if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
179  {
180  mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
181  margin = true;
182  }
183  else
184  {
185  mMargin.bottom = 0;
186  }
187 
188  return margin;
189  }
190 
191  bool _checkOutside() // проверка на полный выход за границу
192  {
193  return ( (getRight() < mCroppedParent->mMargin.left ) || // совсем уехали налево
194  (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) || // совсем уехали направо
195  (getBottom() < mCroppedParent->mMargin.top ) || // совсем уехали вверх
196  (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) ); // совсем уехали вниз
197  }
198 
199  protected:
200  bool mIsMargin;
201  IntRect mMargin; // перекрытие
202  IntCoord mCoord; // координаты
203  IntPoint mAbsolutePosition; // обсолютные координаты
204 
206  bool mVisible;
208 
209  };
210 
211 } // namespace MyGUI
212 
213 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__