MyGUI  3.2.0
MyGUI_ICroppedRectangle.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_I_CROPPED_RECTANGLE_H__
23 #define __MYGUI_I_CROPPED_RECTANGLE_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Types.h"
27 
28 namespace MyGUI
29 {
30 
32  {
33  public:
35  mIsMargin(false),
36  mCroppedParent(nullptr)
37  { }
38 
39  virtual ~ICroppedRectangle() { }
40 
42  ICroppedRectangle* getCroppedParent()
43  {
44  return mCroppedParent;
45  }
46 
48  virtual void setPosition(const IntPoint& _value)
49  {
50  mCoord.left = _value.left;
51  mCoord.top = _value.top;
52  }
54  virtual void setSize(const IntSize& _value)
55  {
56  mCoord.width = _value.width;
57  mCoord.height = _value.height;
58  }
60  virtual void setCoord(const IntCoord& _value)
61  {
62  mCoord = _value;
63  }
64 
66  IntPoint getPosition() const
67  {
68  return mCoord.point();
69  }
71  IntSize getSize() const
72  {
73  return mCoord.size();
74  }
76  const IntCoord& getCoord() const
77  {
78  return mCoord;
79  }
80 
82  const IntPoint& getAbsolutePosition() const
83  {
84  return mAbsolutePosition;
85  }
87  IntRect getAbsoluteRect() const
88  {
89  return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left + mCoord.width, mAbsolutePosition.top + mCoord.height);
90  }
92  IntCoord getAbsoluteCoord() const
93  {
94  return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height);
95  }
96 
98  int getAbsoluteLeft() const
99  {
100  return mAbsolutePosition.left;
101  }
103  int getAbsoluteTop() const
104  {
105  return mAbsolutePosition.top;
106  }
107 
109  int getLeft() const
110  {
111  return mCoord.left;
112  }
114  int getRight() const
115  {
116  return mCoord.right();
117  }
119  int getTop() const
120  {
121  return mCoord.top;
122  }
124  int getBottom() const
125  {
126  return mCoord.bottom();
127  }
129  int getWidth() const
130  {
131  return mCoord.width;
132  }
134  int getHeight() const
135  {
136  return mCoord.height;
137  }
138 
139 
140  /*internal:*/
142  bool _isMargin() const
143  {
144  return mIsMargin;
145  }
146 
147  // Get cropped by parent rectangle coordinates
148  int _getViewLeft() const
149  {
150  return mCoord.left + mMargin.left;
151  }
152  int _getViewRight() const
153  {
154  return mCoord.right() - mMargin.right;
155  }
156  int _getViewTop() const
157  {
158  return mCoord.top + mMargin.top;
159  }
160  int _getViewBottom() const
161  {
162  return mCoord.bottom() - mMargin.bottom;
163  }
164  int _getViewWidth() const
165  {
166  return mCoord.width - mMargin.left - mMargin.right;
167  }
168  int _getViewHeight() const
169  {
170  return mCoord.height - mMargin.top - mMargin.bottom;
171  }
172 
173  void _setCroppedParent(ICroppedRectangle* _parent)
174  {
175  mCroppedParent = _parent;
176  }
177 
178  const IntRect& _getMargin() const
179  {
180  return mMargin;
181  }
182  int _getMarginLeft() const
183  {
184  return mMargin.left;
185  }
186  int _getMarginRight() const
187  {
188  return mMargin.right;
189  }
190  int _getMarginTop() const
191  {
192  return mMargin.top;
193  }
194  int _getMarginBottom() const
195  {
196  return mMargin.bottom;
197  }
198 
199  protected:
200  bool _checkMargin()
201  {
202  bool margin = false;
203  //вылезли ли налево
204  if (getLeft() < mCroppedParent->mMargin.left)
205  {
206  mMargin.left = mCroppedParent->mMargin.left - getLeft();
207  margin = true;
208  }
209  else
210  {
211  mMargin.left = 0;
212  }
213 
214  //вылезли ли направо
215  if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
216  {
217  mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
218  margin = true;
219  }
220  else
221  {
222  mMargin.right = 0;
223  }
224 
225  //вылезли ли вверх
226  if (getTop() < mCroppedParent->mMargin.top)
227  {
228  mMargin.top = mCroppedParent->mMargin.top - getTop();
229  margin = true;
230  }
231  else
232  {
233  mMargin.top = 0;
234  }
235 
236  //вылезли ли вниз
237  if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
238  {
239  mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
240  margin = true;
241  }
242  else
243  {
244  mMargin.bottom = 0;
245  }
246 
247  return margin;
248  }
249 
250  bool _checkOutside() const // проверка на полный выход за границу
251  {
252  return ( (getRight() < mCroppedParent->mMargin.left ) || // совсем уехали налево
253  (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right ) || // совсем уехали направо
254  (getBottom() < mCroppedParent->mMargin.top ) || // совсем уехали вверх
255  (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom ) ); // совсем уехали вниз
256  }
257 
258  protected:
259  IntRect mMargin; // перекрытие
260  IntCoord mCoord; // координаты
261  IntPoint mAbsolutePosition; // обсолютные координаты
262 
263  bool mIsMargin;
265  };
266 
267 } // namespace MyGUI
268 
269 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__