MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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
31 class MYGUI_EXPORT ICroppedRectangle
32 {
33 public:
34 ICroppedRectangle() :
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;
264 ICroppedRectangle* mCroppedParent;
265 };
266
267 } // namespace MyGUI
268
269 #endif // __MYGUI_I_CROPPED_RECTANGLE_H__
MyGUI::ICroppedRectangle::getAbsoluteLeft
int getAbsoluteLeft() const
Definition: MyGUI_ICroppedRectangle.h:98
MyGUI::types::TCoord< int >
MyGUI::ICroppedRectangle::setSize
virtual void setSize(const IntSize &_value)
Definition: MyGUI_ICroppedRectangle.h:54
MyGUI::IntRect
types::TRect< int > IntRect
Definition: MyGUI_Types.h:47
MyGUI::types::TPoint< int >
MyGUI_Prerequest.h
MyGUI::ICroppedRectangle::~ICroppedRectangle
virtual ~ICroppedRectangle()
Definition: MyGUI_ICroppedRectangle.h:39
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:76
MyGUI::ICroppedRectangle::_getViewHeight
int _getViewHeight() const
Definition: MyGUI_ICroppedRectangle.h:168
MyGUI::ICroppedRectangle::mIsMargin
bool mIsMargin
Definition: MyGUI_ICroppedRectangle.h:263
MyGUI::ICroppedRectangle::_getMarginRight
int _getMarginRight() const
Definition: MyGUI_ICroppedRectangle.h:186
MyGUI::ICroppedRectangle::getHeight
int getHeight() const
Definition: MyGUI_ICroppedRectangle.h:134
MyGUI::types::TSize< int >
MyGUI::ICroppedRectangle::getRight
int getRight() const
Definition: MyGUI_ICroppedRectangle.h:114
MyGUI::ICroppedRectangle::_getMarginLeft
int _getMarginLeft() const
Definition: MyGUI_ICroppedRectangle.h:182
MyGUI::ICroppedRectangle::mAbsolutePosition
IntPoint mAbsolutePosition
Definition: MyGUI_ICroppedRectangle.h:261
MyGUI::ICroppedRectangle::getLeft
int getLeft() const
Definition: MyGUI_ICroppedRectangle.h:109
MyGUI::ICroppedRectangle::mCroppedParent
ICroppedRectangle * mCroppedParent
Definition: MyGUI_ICroppedRectangle.h:264
MyGUI::ICroppedRectangle::getAbsoluteTop
int getAbsoluteTop() const
Definition: MyGUI_ICroppedRectangle.h:103
MyGUI::ICroppedRectangle::_getMarginBottom
int _getMarginBottom() const
Definition: MyGUI_ICroppedRectangle.h:194
MyGUI::ICroppedRectangle::_getMargin
const IntRect & _getMargin() const
Definition: MyGUI_ICroppedRectangle.h:178
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:36
MyGUI::ICroppedRectangle::getBottom
int getBottom() const
Definition: MyGUI_ICroppedRectangle.h:124
MyGUI_Types.h
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
MyGUI::ICroppedRectangle::getAbsoluteRect
IntRect getAbsoluteRect() const
Definition: MyGUI_ICroppedRectangle.h:87
MyGUI::ICroppedRectangle::mCoord
IntCoord mCoord
Definition: MyGUI_ICroppedRectangle.h:260
MyGUI::ICroppedRectangle::_getViewLeft
int _getViewLeft() const
Definition: MyGUI_ICroppedRectangle.h:148
MyGUI::ICroppedRectangle::getCroppedParent
ICroppedRectangle * getCroppedParent()
Definition: MyGUI_ICroppedRectangle.h:42
MyGUI::ICroppedRectangle::mMargin
IntRect mMargin
Definition: MyGUI_ICroppedRectangle.h:259
MyGUI::ICroppedRectangle::_setCroppedParent
void _setCroppedParent(ICroppedRectangle *_parent)
Definition: MyGUI_ICroppedRectangle.h:173
MyGUI::ICroppedRectangle::_isMargin
bool _isMargin() const
Definition: MyGUI_ICroppedRectangle.h:142
MyGUI::ICroppedRectangle::setCoord
virtual void setCoord(const IntCoord &_value)
Definition: MyGUI_ICroppedRectangle.h:60
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:35
MyGUI::ICroppedRectangle::getWidth
int getWidth() const
Definition: MyGUI_ICroppedRectangle.h:129
MyGUI::ICroppedRectangle::_getMarginTop
int _getMarginTop() const
Definition: MyGUI_ICroppedRectangle.h:190
MyGUI::ICroppedRectangle::getAbsolutePosition
const IntPoint & getAbsolutePosition() const
Definition: MyGUI_ICroppedRectangle.h:82
MyGUI::types::TRect< int >
MyGUI::ICroppedRectangle::_getViewWidth
int _getViewWidth() const
Definition: MyGUI_ICroppedRectangle.h:164
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:35
MyGUI::ICroppedRectangle::_checkOutside
bool _checkOutside() const
Definition: MyGUI_ICroppedRectangle.h:250
MyGUI::ICroppedRectangle::_getViewBottom
int _getViewBottom() const
Definition: MyGUI_ICroppedRectangle.h:160
MyGUI::ICroppedRectangle::_getViewTop
int _getViewTop() const
Definition: MyGUI_ICroppedRectangle.h:156
MyGUI::ICroppedRectangle::getAbsoluteCoord
IntCoord getAbsoluteCoord() const
Definition: MyGUI_ICroppedRectangle.h:92
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:31
MyGUI::ICroppedRectangle::getTop
int getTop() const
Definition: MyGUI_ICroppedRectangle.h:119
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition: MyGUI_ICroppedRectangle.h:66
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:36
MyGUI::ICroppedRectangle::ICroppedRectangle
ICroppedRectangle()
Definition: MyGUI_ICroppedRectangle.h:34
MyGUI::ICroppedRectangle::_getViewRight
int _getViewRight() const
Definition: MyGUI_ICroppedRectangle.h:152
MyGUI::ICroppedRectangle::_checkMargin
bool _checkMargin()
Definition: MyGUI_ICroppedRectangle.h:200
MyGUI::ICroppedRectangle::setPosition
virtual void setPosition(const IntPoint &_value)
Definition: MyGUI_ICroppedRectangle.h:48
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition: MyGUI_ICroppedRectangle.h:71