MyGUI 3.2.2

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

- File List
- Globals

MyGUI_ScrollView.cpp
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 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_ScrollView.h"
9 #include "MyGUI_SkinManager.h"
10 #include "MyGUI_ISubWidgetText.h"
11 #include "MyGUI_ScrollBar.h"
12
13 namespace MyGUI
14 {
15
16 const int SCROLL_VIEW_MOUSE_WHEEL = 50; // колличество пикселей для колеса мыши
17 const int SCROLL_VIEW_SCROLL_PAGE = 16; // колличество пикселей для кнопок скрола
18
19 ScrollView::ScrollView() :
20 mContentAlign(Align::Center),
21 mRealClient(nullptr)
22 {
23 mChangeContentByResize = false;
24 }
25
26 void ScrollView::initialiseOverride()
27 {
28 Base::initialiseOverride();
29
30 // FIXME нам нужен фокус клавы
31 setNeedKeyFocus(true);
32
34 assignWidget(mClient, "Client");
35 MyGUI::Widget* realClientOwner = this;
36 if (mClient != nullptr)
37 {
38 mClient->eventMouseWheel += newDelegate(this, &ScrollView::notifyMouseWheel);
39 realClientOwner = mClient;
40 }
41
42 // создаем холcт, реальный владелец детей
43 mRealClient = realClientOwner->createWidget<Widget>("Default", IntCoord(), Align::Default);
44 mRealClient->eventMouseWheel += newDelegate(this, &ScrollView::notifyMouseWheel);
45 setWidgetClient(mRealClient);
46
48 assignWidget(mVScroll, "VScroll");
49 if (mVScroll != nullptr)
50 {
51 mVScroll->eventScrollChangePosition += newDelegate(this, &ScrollView::notifyScrollChangePosition);
52 }
53
55 assignWidget(mHScroll, "HScroll");
56 if (mHScroll != nullptr)
57 {
58 mHScroll->eventScrollChangePosition += newDelegate(this, &ScrollView::notifyScrollChangePosition);
59 }
60
61 updateView();
62 }
63
64 void ScrollView::shutdownOverride()
65 {
66 mVScroll = nullptr;
67 mHScroll = nullptr;
68 mClient = nullptr;
69 mRealClient = nullptr;
70
71 Base::shutdownOverride();
72 }
73
74 void ScrollView::setPosition(const IntPoint& _point)
75 {
76 Base::setPosition(_point);
77 }
78
79 void ScrollView::setSize(const IntSize& _size)
80 {
81 Base::setSize(_size);
82
83 updateView();
84 }
85
86 void ScrollView::setCoord(const IntCoord& _coord)
87 {
88 Base::setCoord(_coord);
89
90 updateView();
91 }
92
93 void ScrollView::notifyScrollChangePosition(ScrollBar* _sender, size_t _position)
94 {
95 if (mRealClient == nullptr)
96 return;
97
98 if (_sender == mVScroll)
99 {
100 IntPoint point = mRealClient->getPosition();
101 point.top = -(int)_position;
102 mRealClient->setPosition(point);
103 }
104 else if (_sender == mHScroll)
105 {
106 IntPoint point = mRealClient->getPosition();
107 point.left = -(int)_position;
108 mRealClient->setPosition(point);
109 }
110 }
111
112 void ScrollView::notifyMouseWheel(Widget* _sender, int _rel)
113 {
114 if (mRealClient == nullptr)
115 return;
116
117 if (mVRange != 0)
118 {
119 IntPoint point = mRealClient->getPosition();
120 int offset = -point.top;
121 if (_rel < 0) offset += SCROLL_VIEW_MOUSE_WHEEL;
122 else offset -= SCROLL_VIEW_MOUSE_WHEEL;
123
124 if (offset < 0) offset = 0;
125 else if (offset > (int)mVRange) offset = mVRange;
126
127 if (offset != point.top)
128 {
129 point.top = -offset;
130 if (mVScroll != nullptr)
131 {
132 mVScroll->setScrollPosition(offset);
133 }
134 mRealClient->setPosition(point);
135 }
136 }
137 else if (mHRange != 0)
138 {
139 IntPoint point = mRealClient->getPosition();
140 int offset = -point.left;
141 if (_rel < 0) offset += SCROLL_VIEW_MOUSE_WHEEL;
142 else offset -= SCROLL_VIEW_MOUSE_WHEEL;
143
144 if (offset < 0) offset = 0;
145 else if (offset > (int)mHRange) offset = mHRange;
146
147 if (offset != point.left)
148 {
149 point.left = -offset;
150 if (mHScroll != nullptr)
151 {
152 mHScroll->setScrollPosition(offset);
153 }
154 mRealClient->setPosition(point);
155 }
156 }
157 }
158
159 IntSize ScrollView::getContentSize()
160 {
161 return mRealClient == nullptr ? IntSize() : mRealClient->getSize();
162 }
163
164 IntPoint ScrollView::getContentPosition()
165 {
166 return mRealClient == nullptr ? IntPoint() : (IntPoint() - mRealClient->getPosition());
167 }
168
169 void ScrollView::setContentPosition(const IntPoint& _point)
170 {
171 if (mRealClient != nullptr)
172 mRealClient->setPosition(IntPoint() - _point);
173 }
174
175 IntSize ScrollView::getViewSize()
176 {
177 return mClient == nullptr ? getSize() : mClient->getSize();
178 }
179
180 size_t ScrollView::getVScrollPage()
181 {
182 return SCROLL_VIEW_SCROLL_PAGE;
183 }
184
185 size_t ScrollView::getHScrollPage()
186 {
187 return SCROLL_VIEW_SCROLL_PAGE;
188 }
189
190 void ScrollView::updateView()
191 {
192 updateScrollSize();
193 updateScrollPosition();
194 }
195
196 void ScrollView::setVisibleVScroll(bool _value)
197 {
198 mVisibleVScroll = _value;
199 updateView();
200 }
201
202 void ScrollView::setVisibleHScroll(bool _value)
203 {
204 mVisibleHScroll = _value;
205 updateView();
206 }
207
208 void ScrollView::setCanvasAlign(Align _value)
209 {
210 mContentAlign = _value;
211 updateView();
212 }
213
214 void ScrollView::setCanvasSize(const IntSize& _value)
215 {
216 if (mRealClient != nullptr)
217 mRealClient->setSize(_value);
218 updateView();
219 }
220
221 IntSize ScrollView::getCanvasSize()
222 {
223 return mRealClient == nullptr ? IntSize() : mRealClient->getSize();
224 }
225
226 void ScrollView::setPropertyOverride(const std::string& _key, const std::string& _value)
227 {
229 if (_key == "VisibleVScroll")
230 setVisibleVScroll(utility::parseValue<bool>(_value));
231
233 else if (_key == "VisibleHScroll")
234 setVisibleHScroll(utility::parseValue<bool>(_value));
235
237 else if (_key == "CanvasAlign")
238 setCanvasAlign(utility::parseValue<Align>(_value));
239
241 else if (_key == "CanvasSize")
242 setCanvasSize(utility::parseValue<IntSize>(_value));
243
244 else
245 {
246 Base::setPropertyOverride(_key, _value);
247 return;
248 }
249
250 eventChangeProperty(this, _key, _value);
251 }
252
253 void ScrollView::setPosition(int _left, int _top)
254 {
255 setPosition(IntPoint(_left, _top));
256 }
257
258 void ScrollView::setSize(int _width, int _height)
259 {
260 setSize(IntSize(_width, _height));
261 }
262
263 void ScrollView::setCoord(int _left, int _top, int _width, int _height)
264 {
265 setCoord(IntCoord(_left, _top, _width, _height));
266 }
267
268 bool ScrollView::isVisibleVScroll() const
269 {
270 return mVisibleVScroll;
271 }
272
273 bool ScrollView::isVisibleHScroll() const
274 {
275 return mVisibleHScroll;
276 }
277
278 Align ScrollView::getCanvasAlign() const
279 {
280 return mContentAlign;
281 }
282
283 void ScrollView::setCanvasSize(int _width, int _height)
284 {
285 setCanvasSize(IntSize(_width, _height));
286 }
287
288 Align ScrollView::getContentAlign()
289 {
290 return mContentAlign;
291 }
292
293 void ScrollView::setViewOffset(const IntPoint& _value)
294 {
295 IntPoint value = _value;
296 IntPoint currentOffset = mRealClient->getPosition();
297
298 if (mHRange != 0)
299 {
300 if (value.left > 0)
301 value.left = 0;
302 else if (value.left < -(int)mHRange)
303 value.left = -(int)mHRange;
304 }
305 else
306 {
307 value.left = currentOffset.left;
308 }
309
310 if (mVRange != 0)
311 {
312 if (value.top > 0)
313 value.top = 0;
314 else if (value.top < -(int)mVRange)
315 value.top = -(int)mVRange;
316 }
317 else
318 {
319 value.top = currentOffset.top;
320 }
321
322 if (mHScroll != nullptr)
323 mHScroll->setScrollPosition(-value.left);
324
325 if (mVScroll != nullptr)
326 mVScroll->setScrollPosition(-value.top);
327
328 mRealClient->setPosition(value);
329 }
330
331 IntPoint ScrollView::getViewOffset() const
332 {
333 return mRealClient->getPosition();
334 }
335
336 IntCoord ScrollView::getViewCoord() const
337 {
338 return mClient == nullptr ? getCoord() : mClient->getCoord();
339 }
340
341 ScrollBar* ScrollView::getVScroll()
342 {
343 return mVScroll;
344 }
345
346 } // namespace MyGUI
MyGUI::ScrollView::mContentAlign
Align mContentAlign
Definition: MyGUI_ScrollView.h:105
MyGUI::ScrollView::setVisibleVScroll
void setVisibleVScroll(bool _value)
Definition: MyGUI_ScrollView.cpp:196
MyGUI::WidgetInput::eventMouseWheel
EventHandle_WidgetInt eventMouseWheel
Definition: MyGUI_WidgetInput.h:145
MyGUI::types::TCoord< int >
MyGUI::ScrollView::setPropertyOverride
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
Definition: MyGUI_ScrollView.cpp:226
MyGUI::ScrollViewBase::updateScrollSize
void updateScrollSize()
Definition: MyGUI_ScrollViewBase.cpp:30
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::ScrollView::notifyMouseWheel
void notifyMouseWheel(Widget *_sender, int _rel)
Definition: MyGUI_ScrollView.cpp:112
MyGUI::ScrollView::shutdownOverride
virtual void shutdownOverride()
Definition: MyGUI_ScrollView.cpp:64
MyGUI::ScrollView::getViewCoord
IntCoord getViewCoord() const
Definition: MyGUI_ScrollView.cpp:336
MyGUI::ScrollBar::eventScrollChangePosition
EventHandle_ScrollBarPtrSizeT eventScrollChangePosition
Definition: MyGUI_ScrollBar.h:130
MyGUI::ScrollViewBase::mHRange
size_t mHRange
Definition: MyGUI_ScrollViewBase.h:52
MyGUI::types::TPoint< int >
MyGUI::ScrollView::initialiseOverride
virtual void initialiseOverride()
Definition: MyGUI_ScrollView.cpp:26
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:61
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
MyGUI::ScrollView::setViewOffset
void setViewOffset(const IntPoint &_value)
Definition: MyGUI_ScrollView.cpp:293
MyGUI_Precompiled.h
MyGUI::ScrollView::setPosition
virtual void setPosition(const IntPoint &_value)
Definition: MyGUI_ScrollView.cpp:74
MyGUI::ScrollView::getViewOffset
IntPoint getViewOffset() const
Definition: MyGUI_ScrollView.cpp:331
MyGUI::ScrollViewBase::mHScroll
ScrollBar * mHScroll
Definition: MyGUI_ScrollViewBase.h:45
MyGUI::ScrollView::setVisibleHScroll
void setVisibleHScroll(bool _value)
Definition: MyGUI_ScrollView.cpp:202
MyGUI::types::TSize< int >
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:118
MyGUI::ScrollView::getCanvasSize
IntSize getCanvasSize()
Definition: MyGUI_ScrollView.cpp:221
MyGUI::ScrollViewBase::mChangeContentByResize
bool mChangeContentByResize
Definition: MyGUI_ScrollViewBase.h:55
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:328
MyGUI::ScrollView::notifyScrollChangePosition
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
Definition: MyGUI_ScrollView.cpp:93
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:21
MyGUI::ScrollViewBase::mVScroll
ScrollBar * mVScroll
Definition: MyGUI_ScrollViewBase.h:44
MyGUI::ScrollView::isVisibleHScroll
bool isVisibleHScroll() const
Definition: MyGUI_ScrollView.cpp:273
MyGUI::Widget::setSize
virtual void setSize(const IntSize &_value)
Definition: MyGUI_Widget.cpp:652
MyGUI::ScrollView::updateView
void updateView()
Definition: MyGUI_ScrollView.cpp:190
MyGUI::ScrollViewBase::mVisibleHScroll
bool mVisibleHScroll
Definition: MyGUI_ScrollViewBase.h:48
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
MyGUI::Align::Default
Definition: MyGUI_Align.h:36
MyGUI::ScrollView::setCoord
virtual void setCoord(const IntCoord &_value)
Definition: MyGUI_ScrollView.cpp:86
MyGUI::Widget::setPosition
virtual void setPosition(const IntPoint &_value)
Definition: MyGUI_Widget.cpp:635
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::ScrollView::mRealClient
Widget * mRealClient
Definition: MyGUI_ScrollView.h:106
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:266
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:20
MyGUI::ScrollView::isVisibleVScroll
bool isVisibleVScroll() const
Definition: MyGUI_ScrollView.cpp:268
MyGUI::ScrollViewBase::mVisibleVScroll
bool mVisibleVScroll
Definition: MyGUI_ScrollViewBase.h:49
MyGUI_ScrollBar.h
MyGUI_ScrollView.h
MyGUI::ScrollViewBase::updateScrollPosition
void updateScrollPosition()
Definition: MyGUI_ScrollViewBase.cpp:234
MyGUI::Widget::setWidgetClient
void setWidgetClient(Widget *_widget)
Definition: MyGUI_Widget.cpp:1134
MyGUI::Widget::createWidget
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:67
MyGUI::ScrollView::getCanvasAlign
Align getCanvasAlign() const
Definition: MyGUI_ScrollView.cpp:278
MyGUI::ScrollView::ScrollView
ScrollView()
Definition: MyGUI_ScrollView.cpp:19
MyGUI::ScrollView::setCanvasSize
void setCanvasSize(const IntSize &_value)
Definition: MyGUI_ScrollView.cpp:214
MyGUI::ScrollView::setSize
virtual void setSize(const IntSize &_value)
Definition: MyGUI_ScrollView.cpp:79
MyGUI::Align
Definition: MyGUI_Align.h:19
MyGUI::ICroppedRectangle::getPosition
IntPoint getPosition() const
Definition: MyGUI_ICroppedRectangle.h:51
MyGUI::SCROLL_VIEW_MOUSE_WHEEL
const int SCROLL_VIEW_MOUSE_WHEEL
Definition: MyGUI_ScrollView.cpp:16
MyGUI::ScrollView::setCanvasAlign
void setCanvasAlign(Align _value)
Definition: MyGUI_ScrollView.cpp:208
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition: MyGUI_WidgetInput.cpp:156
MyGUI::SCROLL_VIEW_SCROLL_PAGE
const int SCROLL_VIEW_SCROLL_PAGE
Definition: MyGUI_ScrollView.cpp:17
MyGUI::ScrollBar
ScrollBar properties. ScrollBar_skin_childs Skin childs. ScrollBar widget description should be here...
Definition: MyGUI_ScrollBar.h:23
MyGUI_SkinManager.h
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition: MyGUI_ICroppedRectangle.h:56
MyGUI::ScrollViewBase::mClient
Widget * mClient
Definition: MyGUI_ScrollViewBase.h:46
MyGUI_ISubWidgetText.h
MyGUI::ScrollView::getVScroll
ScrollBar * getVScroll()
Definition: MyGUI_ScrollView.cpp:341
MyGUI::ScrollBar::setScrollPosition
void setScrollPosition(size_t _value)
Definition: MyGUI_ScrollBar.cpp:347
MyGUI::ScrollViewBase::mVRange
size_t mVRange
Definition: MyGUI_ScrollViewBase.h:51
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26