MyGUI: MyGUI_ScrollView.cpp Source File

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