MyGUI: MyGUI_ICroppedRectangle.h Source File

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
16 class MYGUI_EXPORT ICroppedRectangle
17 {
18 public:
19 virtual ~ICroppedRectangle() = default;
20
22 ICroppedRectangle* getCroppedParent()
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 }
33
34 virtual void setSize(const IntSize& _value)
35 {
36 mCoord.width = _value.width;
37 mCoord.height = _value.height;
38 }
39
40 virtual void setCoord(const IntCoord& _value)
41 {
42 mCoord = _value;
43 }
44
46 IntPoint getPosition() const
47 {
48 return mCoord.point();
49 }
50
51 IntSize getSize() const
52 {
53 return mCoord.size();
54 }
55
56 const IntCoord& getCoord() const
57 {
58 return mCoord;
59 }
60
62 const IntPoint& getAbsolutePosition() const
63 {
64 return mAbsolutePosition;
65 }
66
67 IntRect getAbsoluteRect() const
68 {
69 return {
70 mAbsolutePosition.left,
71 mAbsolutePosition.top,
72 mAbsolutePosition.left + mCoord.width,
73 mAbsolutePosition.top + mCoord.height};
74 }
75
76 IntCoord getAbsoluteCoord() const
77 {
78 return {mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height};
79 }
80
82 int getAbsoluteLeft() const
83 {
84 return mAbsolutePosition.left;
85 }
86
87 int getAbsoluteTop() const
88 {
89 return mAbsolutePosition.top;
90 }
91
93 int getLeft() const
94 {
95 return mCoord.left;
96 }
97
98 int getRight() const
99 {
100 return mCoord.right();
101 }
102
103 int getTop() const
104 {
105 return mCoord.top;
106 }
107
108 int getBottom() const
109 {
110 return mCoord.bottom();
111 }
112
113 int getWidth() const
114 {
115 return mCoord.width;
116 }
117
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
157 void _setCroppedParent(ICroppedRectangle* _parent)
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 }
178 int _getMarginBottom() const
179 {
180 return mMargin.bottom;
181 }
182
183 protected:
184 bool _checkMargin()
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_
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition MyGUI_Platform.h:77
MyGUI_Prerequest.h
MyGUI_Types.h
MyGUI::ICroppedRectangle
Definition MyGUI_ICroppedRectangle.h:17
MyGUI::ICroppedRectangle::~ICroppedRectangle
virtual ~ICroppedRectangle()=default
MyGUI::ICroppedRectangle::_getMarginBottom
int _getMarginBottom() const
Definition MyGUI_ICroppedRectangle.h:178
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition MyGUI_ICroppedRectangle.h:248
MyGUI::ICroppedRectangle::setPosition
virtual void setPosition(const IntPoint &_value)
Definition MyGUI_ICroppedRectangle.h:28
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition MyGUI_ICroppedRectangle.h:245
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition MyGUI_ICroppedRectangle.h:244
MyGUI::ICroppedRectangle::getTop
int getTop() const
Definition MyGUI_ICroppedRectangle.h:103
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition MyGUI_ICroppedRectangle.h:40
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition MyGUI_ICroppedRectangle.h:82
MyGUI::ICroppedRectangle::getAbsolutePosition
const IntPoint & getAbsolutePosition() const
Definition MyGUI_ICroppedRectangle.h:62
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition MyGUI_ICroppedRectangle.h:184
MyGUI::ICroppedRectangle::_isMargin
bool _isMargin() const
Definition MyGUI_ICroppedRectangle.h:126
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition MyGUI_ICroppedRectangle.h:46
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition MyGUI_ICroppedRectangle.h:113
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition MyGUI_ICroppedRectangle.h:234
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition MyGUI_ICroppedRectangle.h:118
MyGUI::ICroppedRectangle::_getMarginRight
int _getMarginRight() const
Definition MyGUI_ICroppedRectangle.h:170
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition MyGUI_ICroppedRectangle.h:249
MyGUI::ICroppedRectangle::_getMarginLeft
int _getMarginLeft() const
Definition MyGUI_ICroppedRectangle.h:166
MyGUI::ICroppedRectangle::_getMargin
const IntRect & _getMargin() const
Definition MyGUI_ICroppedRectangle.h:162
MyGUI::ICroppedRectangle::mAbsolutePosition
IntPoint mAbsolutePosition
Definition MyGUI_ICroppedRectangle.h:246
MyGUI::ICroppedRectangle::_getMarginTop
int _getMarginTop() const
Definition MyGUI_ICroppedRectangle.h:174
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ICroppedRectangle::getCroppedParent
ICroppedRectangle * getCroppedParent()
Definition MyGUI_ICroppedRectangle.h:22
MyGUI::ICroppedRectangle::getAbsoluteRect
IntRect getAbsoluteRect() const
Definition MyGUI_ICroppedRectangle.h:67
MyGUI::ICroppedRectangle::getRight
int getRight() const
Definition MyGUI_ICroppedRectangle.h:98
MyGUI::ICroppedRectangle::getAbsoluteCoord
IntCoord getAbsoluteCoord() const
Definition MyGUI_ICroppedRectangle.h:76
MyGUI::ICroppedRectangle::getLeft
int getLeft() const
Definition MyGUI_ICroppedRectangle.h:93
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition MyGUI_ICroppedRectangle.h:157
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
MyGUI::ICroppedRectangle::setSize
virtual void setSize(const IntSize &_value)
Definition MyGUI_ICroppedRectangle.h:34
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition MyGUI_ICroppedRectangle.h:87
MyGUI::ICroppedRectangle::getBottom
int getBottom() const
Definition MyGUI_ICroppedRectangle.h:108
MyGUI::ICroppedRectangle::_getViewRight
int _getViewRight() const
Definition MyGUI_ICroppedRectangle.h:136
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition MyGUI_ICroppedRectangle.h:148
MyGUI::ICroppedRectangle::_getViewLeft
int _getViewLeft() const
Definition MyGUI_ICroppedRectangle.h:132
MyGUI::ICroppedRectangle::_getViewTop
int _getViewTop() const
Definition MyGUI_ICroppedRectangle.h:140
MyGUI::ICroppedRectangle::_getViewBottom
int _getViewBottom() const
Definition MyGUI_ICroppedRectangle.h:144
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition MyGUI_ICroppedRectangle.h:152
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntRect
types::TRect< int > IntRect
Definition MyGUI_Types.h:33
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20