MyGUI: MyGUI_ScrollView.cpp Source File

MyGUI 3.4.3

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)
111 offset += SCROLL_VIEW_MOUSE_WHEEL;
112 else
113 offset -= SCROLL_VIEW_MOUSE_WHEEL;
114
115 if (offset < 0)
116 offset = 0;
117 else if (offset > (int)mVRange)
118 offset = mVRange;
119
120 if (offset != point.top)
121 {
122 point.top = -offset;
123 if (mVScroll != nullptr)
124 {
125 mVScroll->setScrollPosition(offset);
126 }
127 getClientWidget()->setPosition(point);
128 }
129 }
130 else if (mHRange != 0)
131 {
132 IntPoint point = getClientWidget()->getPosition();
133 int offset = -point.left;
134 if (_rel < 0)
135 offset += SCROLL_VIEW_MOUSE_WHEEL;
136 else
137 offset -= SCROLL_VIEW_MOUSE_WHEEL;
138
139 if (offset < 0)
140 offset = 0;
141 else if (offset > (int)mHRange)
142 offset = mHRange;
143
144 if (offset != point.left)
145 {
146 point.left = -offset;
147 if (mHScroll != nullptr)
148 {
149 mHScroll->setScrollPosition(offset);
150 }
151 getClientWidget()->setPosition(point);
152 }
153 }
154 }
155
156 IntSize ScrollView::getContentSize() const
157 {
158 return getClientWidget()->getSize();
159 }
160
161 IntPoint ScrollView::getContentPosition() const
162 {
163 return IntPoint() - getClientWidget()->getPosition();
164 }
165
166 void ScrollView::setContentPosition(const IntPoint& _point)
167 {
168 getClientWidget()->setPosition(IntPoint() - _point);
169 }
170
171 IntSize ScrollView::getViewSize() const
172 {
173 return mScrollViewClient == nullptr ? getSize() : mScrollViewClient->getSize();
174 }
175
176 size_t ScrollView::getVScrollPage() const
177 {
178 return SCROLL_VIEW_SCROLL_PAGE;
179 }
180
181 size_t ScrollView::getHScrollPage() const
182 {
183 return SCROLL_VIEW_SCROLL_PAGE;
184 }
185
186 void ScrollView::updateView()
187 {
188 updateScrollSize();
189 updateScrollPosition();
190 }
191
192 void ScrollView::setVisibleVScroll(bool _value)
193 {
194 mVisibleVScroll = _value;
195 updateView();
196 }
197
198 void ScrollView::setVisibleHScroll(bool _value)
199 {
200 mVisibleHScroll = _value;
201 updateView();
202 }
203
204 void ScrollView::setCanvasAlign(Align _value)
205 {
206 mContentAlign = _value;
207 updateView();
208 }
209
210 void ScrollView::setCanvasSize(const IntSize& _value)
211 {
212 getClientWidget()->setSize(_value);
213 updateView();
214 }
215
216 IntSize ScrollView::getCanvasSize() const
217 {
218 return getClientWidget()->getSize();
219 }
220
221 void ScrollView::setPropertyOverride(std::string_view _key, std::string_view _value)
222 {
224 if (_key == "VisibleVScroll")
225 setVisibleVScroll(utility::parseValue<bool>(_value));
226
228 else if (_key == "VisibleHScroll")
229 setVisibleHScroll(utility::parseValue<bool>(_value));
230
232 else if (_key == "CanvasAlign")
233 setCanvasAlign(utility::parseValue<Align>(_value));
234
236 else if (_key == "CanvasSize")
237 setCanvasSize(utility::parseValue<IntSize>(_value));
238
239 else
240 {
241 Base::setPropertyOverride(_key, _value);
242 return;
243 }
244
245 eventChangeProperty(this, _key, _value);
246 }
247
248 bool ScrollView::isVisibleVScroll() const
249 {
250 return mVisibleVScroll;
251 }
252
253 bool ScrollView::isVisibleHScroll() const
254 {
255 return mVisibleHScroll;
256 }
257
258 Align ScrollView::getCanvasAlign() const
259 {
260 return mContentAlign;
261 }
262
263 void ScrollView::setCanvasSize(int _width, int _height)
264 {
265 setCanvasSize(IntSize(_width, _height));
266 }
267
268 Align ScrollView::getContentAlign() const
269 {
270 return mContentAlign;
271 }
272
273 void ScrollView::setViewOffset(const IntPoint& _value)
274 {
275 IntPoint value = _value;
276 IntPoint currentOffset = getClientWidget()->getPosition();
277
278 if (mHRange != 0)
279 {
280 if (value.left > 0)
281 value.left = 0;
282 else if (value.left < -(int)mHRange)
283 value.left = -(int)mHRange;
284 }
285 else
286 {
287 value.left = currentOffset.left;
288 }
289
290 if (mVRange != 0)
291 {
292 if (value.top > 0)
293 value.top = 0;
294 else if (value.top < -(int)mVRange)
295 value.top = -(int)mVRange;
296 }
297 else
298 {
299 value.top = currentOffset.top;
300 }
301
302 if (mHScroll != nullptr)
303 mHScroll->setScrollPosition(-value.left);
304
305 if (mVScroll != nullptr)
306 mVScroll->setScrollPosition(-value.top);
307
308 getClientWidget()->setPosition(value);
309 }
310
311 IntPoint ScrollView::getViewOffset() const
312 {
313 return getClientWidget()->getPosition();
314 }
315
316 IntCoord ScrollView::getViewCoord() const
317 {
318 return mScrollViewClient == nullptr ? getCoord() : mScrollViewClient->getCoord();
319 }
320
321 ScrollBar* ScrollView::getVScroll() const
322 {
323 return mVScroll;
324 }
325
326} // 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:46
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ICroppedRectangle::getSize
IntSize getSize() const
Definition MyGUI_ICroppedRectangle.h:51
MyGUI::ScrollBar
widget description should be here.
Definition MyGUI_ScrollBar.h:24
MyGUI::ScrollViewBase::getViewSize
virtual IntSize getViewSize() const
Definition MyGUI_ScrollViewBase.cpp:329
MyGUI::ScrollViewBase::mHScroll
ScrollBar * mHScroll
Definition MyGUI_ScrollViewBase.h:44
MyGUI::ScrollViewBase::mVRange
size_t mVRange
Definition MyGUI_ScrollViewBase.h:50
MyGUI::ScrollViewBase::getHScrollPage
virtual size_t getHScrollPage() const
Definition MyGUI_ScrollViewBase.cpp:334
MyGUI::ScrollViewBase::updateScrollPosition
void updateScrollPosition()
Definition MyGUI_ScrollViewBase.cpp:234
MyGUI::ScrollViewBase::mHRange
size_t mHRange
Definition MyGUI_ScrollViewBase.h:51
MyGUI::ScrollViewBase::mScrollViewClient
Widget * mScrollViewClient
Definition MyGUI_ScrollViewBase.h:45
MyGUI::ScrollViewBase::mVisibleVScroll
bool mVisibleVScroll
Definition MyGUI_ScrollViewBase.h:48
MyGUI::ScrollViewBase::getContentPosition
virtual IntPoint getContentPosition() const
Definition MyGUI_ScrollViewBase.cpp:320
MyGUI::ScrollViewBase::mChangeContentByResize
bool mChangeContentByResize
Definition MyGUI_ScrollViewBase.h:54
MyGUI::ScrollViewBase::mVisibleHScroll
bool mVisibleHScroll
Definition MyGUI_ScrollViewBase.h:47
MyGUI::ScrollViewBase::getContentAlign
virtual Align getContentAlign() const
Definition MyGUI_ScrollViewBase.cpp:344
MyGUI::ScrollViewBase::getContentSize
virtual IntSize getContentSize() const
Definition MyGUI_ScrollViewBase.cpp:315
MyGUI::ScrollViewBase::updateScrollSize
void updateScrollSize()
Definition MyGUI_ScrollViewBase.cpp:14
MyGUI::ScrollViewBase::mVScroll
ScrollBar * mVScroll
Definition MyGUI_ScrollViewBase.h:43
MyGUI::ScrollViewBase::getVScrollPage
virtual size_t getVScrollPage() const
Definition MyGUI_ScrollViewBase.cpp:339
MyGUI::ScrollView::setVisibleHScroll
void setVisibleHScroll(bool _value)
Definition MyGUI_ScrollView.cpp:198
MyGUI::ScrollView::getViewCoord
IntCoord getViewCoord() const
Definition MyGUI_ScrollView.cpp:316
MyGUI::ScrollView::getCanvasSize
IntSize getCanvasSize() const
Definition MyGUI_ScrollView.cpp:216
MyGUI::ScrollView::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_ScrollView.cpp:69
MyGUI::ScrollView::setVisibleVScroll
void setVisibleVScroll(bool _value)
Definition MyGUI_ScrollView.cpp:192
MyGUI::ScrollView::initialiseOverride
void initialiseOverride() override
Definition MyGUI_ScrollView.cpp:25
MyGUI::ScrollView::setViewOffset
void setViewOffset(const IntPoint &_value)
Definition MyGUI_ScrollView.cpp:273
MyGUI::ScrollView::isVisibleHScroll
bool isVisibleHScroll() const
Definition MyGUI_ScrollView.cpp:253
MyGUI::ScrollView::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_ScrollView.cpp:221
MyGUI::ScrollView::getVScroll
ScrollBar * getVScroll() const
Definition MyGUI_ScrollView.cpp:321
MyGUI::ScrollView::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_ScrollView.cpp:74
MyGUI::ScrollView::isVisibleVScroll
bool isVisibleVScroll() const
Definition MyGUI_ScrollView.cpp:248
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:204
MyGUI::ScrollView::getCanvasAlign
Align getCanvasAlign() const
Definition MyGUI_ScrollView.cpp:258
MyGUI::ScrollView::updateView
void updateView()
Definition MyGUI_ScrollView.cpp:186
MyGUI::ScrollView::mContentAlign
Align mContentAlign
Definition MyGUI_ScrollView.h:96
MyGUI::ScrollView::setCanvasSize
void setCanvasSize(const IntSize &_value)
Definition MyGUI_ScrollView.cpp:210
MyGUI::ScrollView::getViewOffset
IntPoint getViewOffset() const
Definition MyGUI_ScrollView.cpp:311
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::ScrollView::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_ScrollView.cpp:81
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::getClientWidget
Widget * getClientWidget()
Definition MyGUI_Widget.cpp:1367
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::Widget::setWidgetClient
void setWidgetClient(Widget *_widget)
Definition MyGUI_Widget.cpp:1190
MyGUI::Widget::createWidget
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Definition MyGUI_Widget.h:94
MyGUI::Widget::_getClientWidget
Widget * _getClientWidget()
If there is client widget return it, otherwise return this.
Definition MyGUI_Widget.cpp:1196
MyGUI::WidgetInput::setNeedKeyFocus
void setNeedKeyFocus(bool _value)
Definition MyGUI_WidgetInput.cpp:142
MyGUI::WidgetInput::eventMouseWheel
EventHandle_WidgetInt eventMouseWheel
Definition MyGUI_WidgetInput.h:144
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
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:100
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::Align::Default
@ Default
Definition MyGUI_Align.h:36
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20