MyGUI 3.2.0

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

- File List
- Globals

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