MyGUI 3.4.3
MyGUI_ICroppedRectangle.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_I_CROPPED_RECTANGLE_H_
8#define MYGUI_I_CROPPED_RECTANGLE_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_Types.h"
12
13namespace MyGUI
14{
15
17 {
18 public:
19 virtual ~ICroppedRectangle() = default;
20
23 {
24 return mCroppedParent;
25 }
26
28 virtual void setPosition(const IntPoint& _value)
29 {
30 mCoord.left = _value.left;
31 mCoord.top = _value.top;
32 }
34 virtual void setSize(const IntSize& _value)
35 {
36 mCoord.width = _value.width;
37 mCoord.height = _value.height;
38 }
40 virtual void setCoord(const IntCoord& _value)
41 {
42 mCoord = _value;
43 }
44
47 {
48 return mCoord.point();
49 }
52 {
53 return mCoord.size();
54 }
56 const IntCoord& getCoord() const
57 {
58 return mCoord;
59 }
60
63 {
64 return mAbsolutePosition;
65 }
68 {
69 return {
70 mAbsolutePosition.left,
71 mAbsolutePosition.top,
72 mAbsolutePosition.left + mCoord.width,
73 mAbsolutePosition.top + mCoord.height};
74 }
77 {
78 return {mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height};
79 }
80
82 int getAbsoluteLeft() const
83 {
84 return mAbsolutePosition.left;
85 }
87 int getAbsoluteTop() const
88 {
89 return mAbsolutePosition.top;
90 }
91
93 int getLeft() const
94 {
95 return mCoord.left;
96 }
98 int getRight() const
99 {
100 return mCoord.right();
101 }
103 int getTop() const
104 {
105 return mCoord.top;
106 }
108 int getBottom() const
109 {
110 return mCoord.bottom();
111 }
113 int getWidth() const
114 {
115 return mCoord.width;
116 }
118 int getHeight() const
119 {
120 return mCoord.height;
121 }
122
123
124 /*internal:*/
126 bool _isMargin() const
127 {
128 return mIsMargin;
129 }
130
131 // Get cropped by parent rectangle coordinates
132 int _getViewLeft() const
133 {
134 return mCoord.left + mMargin.left;
135 }
136 int _getViewRight() const
137 {
138 return mCoord.right() - mMargin.right;
139 }
140 int _getViewTop() const
141 {
142 return mCoord.top + mMargin.top;
143 }
144 int _getViewBottom() const
145 {
146 return mCoord.bottom() - mMargin.bottom;
147 }
148 int _getViewWidth() const
149 {
150 return mCoord.width - mMargin.left - mMargin.right;
151 }
152 int _getViewHeight() const
153 {
154 return mCoord.height - mMargin.top - mMargin.bottom;
155 }
156
158 {
159 mCroppedParent = _parent;
160 }
161
162 const IntRect& _getMargin() const
163 {
164 return mMargin;
165 }
166 int _getMarginLeft() const
167 {
168 return mMargin.left;
169 }
170 int _getMarginRight() const
171 {
172 return mMargin.right;
173 }
174 int _getMarginTop() const
175 {
176 return mMargin.top;
177 }
179 {
180 return mMargin.bottom;
181 }
182
183 protected:
185 {
186 bool margin = false;
187 //вылезли ли налево
188 if (getLeft() < mCroppedParent->mMargin.left)
189 {
190 mMargin.left = mCroppedParent->mMargin.left - getLeft();
191 margin = true;
192 }
193 else
194 {
195 mMargin.left = 0;
196 }
197
198 //вылезли ли направо
199 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
200 {
201 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
202 margin = true;
203 }
204 else
205 {
206 mMargin.right = 0;
207 }
208
209 //вылезли ли вверх
210 if (getTop() < mCroppedParent->mMargin.top)
211 {
212 mMargin.top = mCroppedParent->mMargin.top - getTop();
213 margin = true;
214 }
215 else
216 {
217 mMargin.top = 0;
218 }
219
220 //вылезли ли вниз
221 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
222 {
223 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
224 margin = true;
225 }
226 else
227 {
228 mMargin.bottom = 0;
229 }
230
231 return margin;
232 }
233
234 bool _checkOutside() const // проверка на полный выход за границу
235 {
236 return (
237 (getRight() < mCroppedParent->mMargin.left) || // совсем уехали налево
238 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right) || // совсем уехали направо
239 (getBottom() < mCroppedParent->mMargin.top) || // совсем уехали вверх
240 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)); // совсем уехали вниз
241 }
242
243 protected:
244 IntRect mMargin; // перекрытие
245 IntCoord mCoord; // координаты
246 IntPoint mAbsolutePosition; // обсолютные координаты
247
248 bool mIsMargin{false};
249 ICroppedRectangle* mCroppedParent{nullptr};
250 };
251
252} // namespace MyGUI
253
254#endif // MYGUI_I_CROPPED_RECTANGLE_H_
#define MYGUI_EXPORT
virtual ~ICroppedRectangle()=default
virtual void setPosition(const IntPoint &_value)
virtual void setCoord(const IntCoord &_value)
const IntPoint & getAbsolutePosition() const
const IntRect & _getMargin() const
const IntCoord & getCoord() const
ICroppedRectangle * getCroppedParent()
void _setCroppedParent(ICroppedRectangle *_parent)
virtual void setSize(const IntSize &_value)