MyGUI 3.5.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
16 class MYGUI_EXPORT ICroppedRectangle
17 {
18 public:
19 virtual ~ICroppedRectangle() = default;
20
22 ICroppedRectangle* getCroppedParent()
23 {
24 return mCroppedParent;
25 }
26 const ICroppedRectangle* getCroppedParent() const
27 {
28 return mCroppedParent;
29 }
30
32 virtual void setPosition(const IntPoint& _value)
33 {
34 mCoord.left = _value.left;
35 mCoord.top = _value.top;
36 }
38 virtual void setSize(const IntSize& _value)
39 {
40 mCoord.width = _value.width;
41 mCoord.height = _value.height;
42 }
44 virtual void setCoord(const IntCoord& _value)
45 {
46 mCoord = _value;
47 }
48
50 IntPoint getPosition() const
51 {
52 return mCoord.point();
53 }
55 IntSize getSize() const
56 {
57 return mCoord.size();
58 }
60 const IntCoord& getCoord() const
61 {
62 return mCoord;
63 }
64
66 const IntPoint& getAbsolutePosition() const
67 {
68 return mAbsolutePosition;
69 }
71 IntRect getAbsoluteRect() const
72 {
73 return {
74 mAbsolutePosition.left,
75 mAbsolutePosition.top,
76 mAbsolutePosition.left + mCoord.width,
77 mAbsolutePosition.top + mCoord.height};
78 }
80 IntCoord getAbsoluteCoord() const
81 {
82 return {mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height};
83 }
84
86 int getAbsoluteLeft() const
87 {
88 return mAbsolutePosition.left;
89 }
91 int getAbsoluteTop() const
92 {
93 return mAbsolutePosition.top;
94 }
95
97 int getLeft() const
98 {
99 return mCoord.left;
100 }
102 int getRight() const
103 {
104 return mCoord.right();
105 }
107 int getTop() const
108 {
109 return mCoord.top;
110 }
112 int getBottom() const
113 {
114 return mCoord.bottom();
115 }
117 int getWidth() const
118 {
119 return mCoord.width;
120 }
122 int getHeight() const
123 {
124 return mCoord.height;
125 }
126
127
128 /*internal:*/
130 bool _isMargin() const
131 {
132 return mIsMargin;
133 }
134 virtual bool _hasRotation() const
135 {
136 return false;
137 }
138
139 // Get cropped by parent rectangle coordinates
140 int _getViewLeft() const
141 {
142 return mCoord.left + mMargin.left;
143 }
144 int _getViewRight() const
145 {
146 return mCoord.right() - mMargin.right;
147 }
148 int _getViewTop() const
149 {
150 return mCoord.top + mMargin.top;
151 }
152 int _getViewBottom() const
153 {
154 return mCoord.bottom() - mMargin.bottom;
155 }
156 int _getViewWidth() const
157 {
158 return mCoord.width - mMargin.left - mMargin.right;
159 }
160 int _getViewHeight() const
161 {
162 return mCoord.height - mMargin.top - mMargin.bottom;
163 }
164
165 void _setCroppedParent(ICroppedRectangle* _parent)
166 {
167 mCroppedParent = _parent;
168 }
169
170 const IntRect& _getMargin() const
171 {
172 return mMargin;
173 }
174 int _getMarginLeft() const
175 {
176 return mMargin.left;
177 }
178 int _getMarginRight() const
179 {
180 return mMargin.right;
181 }
182 int _getMarginTop() const
183 {
184 return mMargin.top;
185 }
186 int _getMarginBottom() const
187 {
188 return mMargin.bottom;
189 }
190
191 protected:
192 bool _checkMargin()
193 {
194 // Rotated geometry is clipped after its vertices have been transformed
195 if (_hasRotation() || mCroppedParent->_hasRotation())
196 {
197 mMargin.clear();
198 return false;
199 }
200 bool margin = false;
201 // Check if clipped on the left
202 if (getLeft() < mCroppedParent->mMargin.left)
203 {
204 mMargin.left = mCroppedParent->mMargin.left - getLeft();
205 margin = true;
206 }
207 else
208 {
209 mMargin.left = 0;
210 }
211
212 // Check if clipped on the right
213 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
214 {
215 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
216 margin = true;
217 }
218 else
219 {
220 mMargin.right = 0;
221 }
222
223 // Check if clipped on the top
224 if (getTop() < mCroppedParent->mMargin.top)
225 {
226 mMargin.top = mCroppedParent->mMargin.top - getTop();
227 margin = true;
228 }
229 else
230 {
231 mMargin.top = 0;
232 }
233
234 // Check if clipped on the bottom
235 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
236 {
237 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
238 margin = true;
239 }
240 else
241 {
242 mMargin.bottom = 0;
243 }
244
245 return margin;
246 }
247
248 // Check if completely outside parent bounds
249 bool _checkOutside() const
250 {
251 if (_hasRotation() || mCroppedParent->_hasRotation())
252 return false;
253 return _checkOutsideUnrotated();
254 }
255
256 // A successful _checkMargin() already establishes that neither rectangle is rotated.
257 bool _checkOutsideUnrotated() const
258 {
259 return (
260 (getRight() < mCroppedParent->mMargin.left) ||
261 (getLeft() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right) ||
262 (getBottom() < mCroppedParent->mMargin.top) ||
263 (getTop() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom));
264 }
265
266 protected:
267 IntRect mMargin;
268 IntCoord mCoord;
269 IntPoint mAbsolutePosition;
270
271 bool mIsMargin{false};
272 ICroppedRectangle* mCroppedParent{nullptr};
273 };
274
275} // namespace MyGUI
276
277#endif // MYGUI_I_CROPPED_RECTANGLE_H_
#define MYGUI_EXPORT
types::TRect< int > IntRect
Definition MyGUI_Types.h:32
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:26
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29