MyGUI  3.4.1
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 
20  mContentAlign(Align::Center)
21  {
22  mChangeContentByResize = false;
23  }
24 
26  {
27  Base::initialiseOverride();
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  {
48  }
49 
51  assignWidget(mHScroll, "HScroll");
52  if (mHScroll != nullptr)
53  {
55  }
56 
57  updateView();
58  }
59 
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  {
93  point.top = -(int)_position;
94  getClientWidget()->setPosition(point);
95  }
96  else if (_sender == mHScroll)
97  {
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  {
171  }
172 
173  size_t ScrollView::getHScrollPage() const
174  {
176  }
177 
179  {
182  }
183 
185  {
186  mVisibleVScroll = _value;
187  updateView();
188  }
189 
191  {
192  mVisibleHScroll = _value;
193  updateView();
194  }
195 
197  {
198  mContentAlign = _value;
199  updateView();
200  }
201 
202  void ScrollView::setCanvasSize(const IntSize& _value)
203  {
204  getClientWidget()->setSize(_value);
205  updateView();
206  }
207 
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 
241  {
242  return mVisibleVScroll;
243  }
244 
246  {
247  return mVisibleHScroll;
248  }
249 
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 
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)
296 
297  if (mVScroll != nullptr)
298  mVScroll->setScrollPosition(-value.top);
299 
300  getClientWidget()->setPosition(value);
301  }
302 
304  {
305  return getClientWidget()->getPosition();
306  }
307 
309  {
310  return mScrollViewClient == nullptr ? getCoord() : mScrollViewClient->getCoord();
311  }
312 
314  {
315  return mVScroll;
316  }
317 
318 } // namespace MyGUI
const IntCoord & getCoord() const
widget description should be here.
EventHandle_ScrollBarPtrSizeT eventScrollChangePosition
void setScrollPosition(size_t _value)
void setVisibleHScroll(bool _value)
IntCoord getViewCoord() const
void setCoord(const IntCoord &_value) override
IntSize getCanvasSize() const
void setVisibleVScroll(bool _value)
void initialiseOverride() override
void setViewOffset(const IntPoint &_value)
bool isVisibleHScroll() const
ScrollBar * getVScroll() const
void setPosition(const IntPoint &_value) override
void setSize(const IntSize &_value) override
bool isVisibleVScroll() const
void shutdownOverride() override
void setCanvasAlign(Align _value)
Align getCanvasAlign() const
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void setCanvasSize(const IntSize &_value)
IntPoint getViewOffset() const
void notifyMouseWheel(Widget *_sender, int _rel)
void notifyScrollChangePosition(ScrollBar *_sender, size_t _position)
widget description should be here.
Definition: MyGUI_Widget.h:37
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:267
void assignWidget(T *&_widget, const std::string &_name)
Definition: MyGUI_Widget.h:335
void setPosition(const IntPoint &_value) override
void setSize(const IntSize &_value) override
Widget * getClientWidget()
void setWidgetClient(Widget *_widget)
T * createWidget(const std::string &_skin, const IntCoord &_coord, Align _align, const std::string &_name="")
Definition: MyGUI_Widget.h:67
Widget * _getClientWidget()
If there is client widget return it, otherwise return this.
void setNeedKeyFocus(bool _value)
EventHandle_WidgetInt eventMouseWheel
const int SCROLL_VIEW_MOUSE_WHEEL
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
const int SCROLL_VIEW_SCROLL_PAGE
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
types::TPoint< int > IntPoint
Definition: MyGUI_Types.h:26