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"
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
24
26 {
28
29 // FIXME нам нужен фокус клавы
30 setNeedKeyFocus(true);
31
33 if (getClientWidget() != nullptr)
34 {
36 }
37
38 // create widget that will be real parent for child widgets
39 Widget* realClient = _getClientWidget()->createWidget<Widget>("Default", IntCoord(), Align::Default);
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
61 {
62 mVScroll = nullptr;
63 mHScroll = nullptr;
64 mScrollViewClient = nullptr;
65
67 }
68
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 {
93 point.top = -(int)_position;
95 }
96 else if (_sender == mHScroll)
97 {
99 point.left = -(int)_position;
101 }
102 }
103
104 void ScrollView::notifyMouseWheel(Widget* _sender, int _rel)
105 {
106 if (mVRange != 0)
107 {
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 }
128 }
129 }
130 else if (mHRange != 0)
131 {
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 }
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 {
179 }
180
181 size_t ScrollView::getHScrollPage() const
182 {
184 }
185
191
193 {
194 mVisibleVScroll = _value;
195 updateView();
196 }
197
199 {
200 mVisibleHScroll = _value;
201 updateView();
202 }
203
205 {
206 mContentAlign = _value;
207 updateView();
208 }
209
211 {
212 getClientWidget()->setSize(_value);
213 updateView();
214 }
215
217 {
218 return getClientWidget()->getSize();
219 }
220
221 void ScrollView::setPropertyOverride(std::string_view _key, std::string_view _value)
222 {
224 if (_key == "VisibleVScroll")
226
228 else if (_key == "VisibleHScroll")
230
232 else if (_key == "CanvasAlign")
234
236 else if (_key == "CanvasSize")
238
239 else
240 {
241 Base::setPropertyOverride(_key, _value);
242 return;
243 }
244
245 eventChangeProperty(this, _key, _value);
246 }
247
249 {
250 return mVisibleVScroll;
251 }
252
254 {
255 return mVisibleHScroll;
256 }
257
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
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
309 }
310
312 {
313 return getClientWidget()->getPosition();
314 }
315
317 {
318 return mScrollViewClient == nullptr ? getCoord() : mScrollViewClient->getCoord();
319 }
320
322 {
323 return mVScroll;
324 }
325
326} // namespace MyGUI
const IntCoord & getCoord() const
widget description should be here.
void setVisibleHScroll(bool _value)
IntCoord getViewCoord() const
IntSize getCanvasSize() const
void setPosition(const IntPoint &_point) override
void setVisibleVScroll(bool _value)
void initialiseOverride() override
void setViewOffset(const IntPoint &_value)
bool isVisibleHScroll() const
void setPropertyOverride(std::string_view _key, std::string_view _value) override
ScrollBar * getVScroll() const
void setSize(const IntSize &_size) override
bool isVisibleVScroll() const
void shutdownOverride() override
void setCanvasAlign(Align _value)
Align getCanvasAlign() const
void setCanvasSize(const IntSize &_value)
IntPoint getViewOffset() const
void notifyMouseWheel(Widget *_sender, int _rel)
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
void setCoord(const IntCoord &_coord) override
widget description should be here.
void setSize(const IntSize &_size) override
EventHandle_WidgetStringString eventChangeProperty
void setPosition(const IntPoint &_point) override
Widget * getClientWidget()
void assignWidget(T *&_widget, std::string_view _name)
void setWidgetClient(Widget *_widget)
T * createWidget(std::string_view _skin, const IntCoord &_coord, Align _align, std::string_view _name={})
Widget * _getClientWidget()
If there is client widget return it, otherwise return this.
void setNeedKeyFocus(bool _value)
EventHandle_WidgetInt eventMouseWheel
T parseValue(std::string_view _value)
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
const int SCROLL_VIEW_MOUSE_WHEEL
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
const int SCROLL_VIEW_SCROLL_PAGE
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))