MyGUI: MyGUI_ICroppedRectangle.h Source File

MyGUI 3.2.2

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
13 namespace MyGUI
14 {
15
16 class MYGUI_EXPORT ICroppedRectangle
17 {
18 public:
19 ICroppedRectangle() :
20 mIsMargin(false),
21 mCroppedParent(nullptr)
22 { }
23
24 virtual ~ICroppedRectangle() { }
25
27 ICroppedRectangle* getCroppedParent()
28 {
29 return mCroppedParent;
30 }
31
33 virtual void setPosition(const IntPoint& _value)
34 {
35 mCoord.left = _value.left;
36 mCoord.top = _value.top;
37 }
39 virtual void setSize(const IntSize& _value)
40 {
41 mCoord.width = _value.width;
42 mCoord.height = _value.height;
43 }
45 virtual void setCoord(const IntCoord& _value)
46 {
47 mCoord = _value;
48 }
49
51 IntPoint getPosition() const
52 {
53 return mCoord.point();
54 }
56 IntSize getSize() const
57 {
58 return mCoord.size();
59 }
61 const IntCoord& getCoord() const
62 {
63 return mCoord;
64 }
65
67 const IntPoint& getAbsolutePosition() const
68 {
69 return mAbsolutePosition;
70 }
72 IntRect getAbsoluteRect() const
73 {
74 return IntRect(mAbsolutePosition.left, mAbsolutePosition.top, mAbsolutePosition.left + mCoord.width, mAbsolutePosition.top + mCoord.height);
75 }
77 IntCoord getAbsoluteCoord() const
78 {
79 return IntCoord(mAbsolutePosition.left, mAbsolutePosition.top, mCoord.width, mCoord.height);
80 }
81
83 int getAbsoluteLeft() const
84 {
85 return mAbsolutePosition.left;
86 }
88 int getAbsoluteTop() const
89 {
90 return mAbsolutePosition.top;
91 }
92
94 int getLeft() const
95 {
96 return mCoord.left;
97 }
99 int getRight() const
100 {
101 return mCoord.right();
102 }
104 int getTop() const
105 {
106 return mCoord.top;
107 }
109 int getBottom() const
110 {
111 return mCoord.bottom();
112 }
114 int getWidth() const
115 {
116 return mCoord.width;
117 }
119 int getHeight() const
120 {
121 return mCoord.height;
122 }
123
124
125 /*internal:*/
127 bool _isMargin() const
128 {
129 return mIsMargin;
130 }
131
132 // Get cropped by parent rectangle coordinates
133 int _getViewLeft() const
134 {
135 return mCoord.left + mMargin.left;
136 }
137 int _getViewRight() const
138 {
139 return mCoord.right() - mMargin.right;
140 }
141 int _getViewTop() const
142 {
143 return mCoord.top + mMargin.top;
144 }
145 int _getViewBottom() const
146 {
147 return mCoord.bottom() - mMargin.bottom;
148 }
149 int _getViewWidth() const
150 {
151 return mCoord.width - mMargin.left - mMargin.right;
152 }
153 int _getViewHeight() const
154 {
155 return mCoord.height - mMargin.top - mMargin.bottom;
156 }
157
158 void _setCroppedParent(ICroppedRectangle* _parent)
159 {
160 mCroppedParent = _parent;
161 }
162
163 const IntRect& _getMargin() const
164 {
165 return mMargin;
166 }
167 int _getMarginLeft() const
168 {
169 return mMargin.left;
170 }
171 int _getMarginRight() const
172 {
173 return mMargin.right;
174 }
175 int _getMarginTop() const
176 {
177 return mMargin.top;
178 }
179 int _getMarginBottom() const
180 {
181 return mMargin.bottom;
182 }
183
184 protected:
185 bool _checkMargin()
186 {
187 bool margin = false;
188 //вылезли ли налево
189 if (getLeft() < mCroppedParent->mMargin.left)
190 {
191 mMargin.left = mCroppedParent->mMargin.left - getLeft();
192 margin = true;
193 }
194 else
195 {
196 mMargin.left = 0;
197 }
198
199 //вылезли ли направо
200 if (getRight() > mCroppedParent->getWidth() - mCroppedParent->mMargin.right)
201 {
202 mMargin.right = getRight() - (mCroppedParent->getWidth() - mCroppedParent->mMargin.right);
203 margin = true;
204 }
205 else
206 {
207 mMargin.right = 0;
208 }
209
210 //вылезли ли вверх
211 if (getTop() < mCroppedParent->mMargin.top)
212 {
213 mMargin.top = mCroppedParent->mMargin.top - getTop();
214 margin = true;
215 }
216 else
217 {
218 mMargin.top = 0;
219 }
220
221 //вылезли ли вниз
222 if (getBottom() > mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom)
223 {
224 mMargin.bottom = getBottom() - (mCroppedParent->getHeight() - mCroppedParent->mMargin.bottom);
225 margin = true;
226 }
227 else
228 {
229 mMargin.bottom = 0;
230 }
231
232 return margin;
233 }
234
235 bool _checkOutside() const // проверка на полный выход за границу
236 {
237 return ( (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;
249 ICroppedRectangle* mCroppedParent;
250 };
251
252 } // namespace MyGUI
253
254 #endif // MYGUI_I_CROPPED_RECTANGLE_H_
MyGUI::ICroppedRectangle::_getViewTop
int _getViewTop() const
Definition: MyGUI_ICroppedRectangle.h:141
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:21
MyGUI::ICroppedRectangle::_getMarginTop
int _getMarginTop() const
Definition: MyGUI_ICroppedRectangle.h:175
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition: MyGUI_ICroppedRectangle.h:248
MyGUI::ICroppedRectangle::getAbsoluteCoord
IntCoord getAbsoluteCoord() const
Definition: MyGUI_ICroppedRectangle.h:77
MyGUI::ICroppedRectangle::getAbsolutePosition
const IntPoint & getAbsolutePosition() const
Definition: MyGUI_ICroppedRectangle.h:67
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:21
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition: MyGUI_ICroppedRectangle.h:153
MyGUI::ICroppedRectangle::ICroppedRectangle
ICroppedRectangle()
Definition: MyGUI_ICroppedRectangle.h:19
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition: MyGUI_ICroppedRectangle.h:88
MyGUI::types::TRect< int >
MyGUI::ICroppedRectangle::_isMargin
bool _isMargin() const
Definition: MyGUI_ICroppedRectangle.h:127
MyGUI::ICroppedRectangle::_getMarginRight
int _getMarginRight() const
Definition: MyGUI_ICroppedRectangle.h:171
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition: MyGUI_ICroppedRectangle.h:83
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition: MyGUI_ICroppedRectangle.h:244
MyGUI::types::TPoint< int >
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:20
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition: MyGUI_ICroppedRectangle.h:51
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition: MyGUI_ICroppedRectangle.h:235
MyGUI::ICroppedRectangle::setSize
virtual void setSize(const IntSize &_value)
Definition: MyGUI_ICroppedRectangle.h:39
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition: MyGUI_ICroppedRectangle.h:249
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition: MyGUI_ICroppedRectangle.h:245
MyGUI_Prerequest.h
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:20
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:61
MyGUI::ICroppedRectangle::_getViewLeft
int _getViewLeft() const
Definition: MyGUI_ICroppedRectangle.h:133
MyGUI::ICroppedRectangle::~ICroppedRectangle
virtual ~ICroppedRectangle()
Definition: MyGUI_ICroppedRectangle.h:24
MyGUI::ICroppedRectangle::_getViewRight
int _getViewRight() const
Definition: MyGUI_ICroppedRectangle.h:137
MyGUI::types::TSize< int >
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:16
MyGUI::ICroppedRectangle::_getMargin
const IntRect & _getMargin() const
Definition: MyGUI_ICroppedRectangle.h:163
MyGUI::ICroppedRectangle::setPosition
virtual void setPosition(const IntPoint &_value)
Definition: MyGUI_ICroppedRectangle.h:33
MyGUI::ICroppedRectangle::_getMarginBottom
int _getMarginBottom() const
Definition: MyGUI_ICroppedRectangle.h:179
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition: MyGUI_ICroppedRectangle.h:45
MyGUI::ICroppedRectangle::getBottom
int getBottom() const
Definition: MyGUI_ICroppedRectangle.h:109
MyGUI::ICroppedRectangle::mAbsolutePosition
IntPoint mAbsolutePosition
Definition: MyGUI_ICroppedRectangle.h:246
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI_Types.h
MyGUI::ICroppedRectangle::_getMarginLeft
int _getMarginLeft() const
Definition: MyGUI_ICroppedRectangle.h:167
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition: MyGUI_ICroppedRectangle.h:185
MyGUI::ICroppedRectangle::getTop
int getTop() const
Definition: MyGUI_ICroppedRectangle.h:104
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition: MyGUI_ICroppedRectangle.h:149
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition: MyGUI_ICroppedRectangle.h:119
MyGUI::ICroppedRectangle::_getViewBottom
int _getViewBottom() const
Definition: MyGUI_ICroppedRectangle.h:145
MyGUI::types::TCoord< int >
MyGUI::IntRect
types::TRect< int > IntRect
Definition: MyGUI_Types.h:32
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition: MyGUI_ICroppedRectangle.h:114
MyGUI::ICroppedRectangle::getRight
int getRight() const
Definition: MyGUI_ICroppedRectangle.h:99
MyGUI::ICroppedRectangle::getAbsoluteRect
IntRect getAbsoluteRect() const
Definition: MyGUI_ICroppedRectangle.h:72
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition: MyGUI_ICroppedRectangle.h:158
MyGUI::ICroppedRectangle::getLeft
int getLeft() const
Definition: MyGUI_ICroppedRectangle.h:94
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::ICroppedRectangle::getCroppedParent
ICroppedRectangle * getCroppedParent()
Definition: MyGUI_ICroppedRectangle.h:27
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition: MyGUI_ICroppedRectangle.h:56