MyGUI  3.2.0
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 
35  mContentAlign(Align::Center),
36  mRealClient(nullptr)
37  {
38  mChangeContentByResize = false;
40  }
41 
43  {
45 
46  // FIXME нам нужен фокус клавы
47  setNeedKeyFocus(true);
48 
49  assignWidget(mClient, "Client");
50  MyGUI::Widget* realClientOwner = this;
51  if (mClient != nullptr)
52  {
54  realClientOwner = mClient;
55  }
56 
57  // создаем холcт, реальный владелец детей
58  mRealClient = realClientOwner->createWidget<Widget>("Default", IntCoord(), Align::Default);
61 
62  assignWidget(mVScroll, "VScroll");
63  if (mVScroll != nullptr)
64  {
66  }
67 
68  assignWidget(mHScroll, "HScroll");
69  if (mHScroll != nullptr)
70  {
72  }
73 
74  updateView();
75  }
76 
78  {
79  mVScroll = nullptr;
80  mHScroll = nullptr;
81  mClient = nullptr;
82  mRealClient = nullptr;
83 
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  {
196  }
197 
198  size_t ScrollView::getHScrollPage()
199  {
201  }
202 
204  {
207  }
208 
210  {
211  mVisibleVScroll = _value;
212  updateView();
213  }
214 
216  {
217  mVisibleHScroll = _value;
218  updateView();
219  }
220 
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 
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 
273  {
274  return mVisibleVScroll;
275  }
276 
278  {
279  return mVisibleHScroll;
280  }
281 
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 
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)
328 
329  if (mVScroll != nullptr)
330  mVScroll->setScrollPosition(-value.top);
331 
332  mRealClient->setPosition(value);
333  }
334 
336  {
337  return mRealClient->getPosition();
338  }
339 
341  {
342  return mClient == nullptr ? getCoord() : mClient->getCoord();
343  }
344 
346  {
347  return mVScroll;
348  }
349 
350 } // namespace MyGUI