MyGUI  3.0.1
MyGUI_HScroll.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_HScroll.h"
25 #include "MyGUI_InputManager.h"
26 #include "MyGUI_Button.h"
27 #include "MyGUI_ResourceSkin.h"
28 
29 namespace MyGUI
30 {
31 
33  {
34  }
35 
36  void HScroll::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
37  {
38  Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
39 
40  initialiseWidgetSkin(_info);
41  }
42 
44  {
45  shutdownWidgetSkin();
46  }
47 
49  {
50  shutdownWidgetSkin();
52  initialiseWidgetSkin(_info);
53  }
54 
55  void HScroll::initialiseWidgetSkin(ResourceSkin* _info)
56  {
57  }
58 
59  void HScroll::shutdownWidgetSkin()
60  {
61  }
62 
63  void HScroll::updateTrack()
64  {
65  if (mWidgetTrack == nullptr)
66  return;
67 
69  // размер диапазана в пикселях
70  int pos = getLineSize();
71 
72  // скрываем если диапазан маленький или места мало
73  if ((mScrollRange < 2) || (pos <= mWidgetTrack->getWidth()))
74  {
75  mWidgetTrack->setVisible(false);
78  return;
79  }
80  // если скрыт то покажем
81  if (!mWidgetTrack->isVisible())
82  {
83  mWidgetTrack->setVisible(true);
84  }
85 
86  // и обновляем позицию
87  pos = (int)(((size_t)(pos-getTrackSize()) * mScrollPosition) / (mScrollRange-1) + mSkinRangeStart);
88 
90  if ( nullptr != mWidgetFirstPart )
91  {
92  int height = pos + mWidgetTrack->getWidth()/2 - mWidgetFirstPart->getLeft();
94  }
95  if ( nullptr != mWidgetSecondPart )
96  {
97  int top = pos + mWidgetTrack->getWidth()/2;
98  int height = mWidgetSecondPart->getWidth() + mWidgetSecondPart->getLeft() - top;
100  }
101  }
102 
103  void HScroll::TrackMove(int _left, int _top)
104  {
105  if (mWidgetTrack == nullptr)
106  return;
107 
109 
110  // расчитываем позицию виджета
111  int start = mPreActionOffset.left + (_left - point.left);
112  if (start < (int)mSkinRangeStart) start = (int)mSkinRangeStart;
113  else if (start > (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth())) start = (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth());
115 
116  // расчитываем положение соответствующее позиции
117  // плюс пол позиции
118  int pos = start - (int)mSkinRangeStart + (getLineSize() - getTrackSize()) / (((int)mScrollRange-1) * 2);
119  // высчитываем ближайшее значение и обновляем
120  pos = pos * (int)(mScrollRange-1) / (getLineSize() - getTrackSize());
121 
122  // проверяем на выходы и изменения
123  if (pos < 0) pos = 0;
124  else if (pos >= (int)mScrollRange) pos = (int)mScrollRange - 1;
125  if (pos == (int)mScrollPosition) return;
126 
127  mScrollPosition = pos;
128  // отсылаем событие
130  }
131 
132  void HScroll::setTrackSize(int _size)
133  {
134  if (mWidgetTrack != nullptr)
135  mWidgetTrack->setSize(((int)_size < (int)mMinTrackSize)? (int)mMinTrackSize : (int)_size, mWidgetTrack->getHeight());
136  updateTrack();
137  }
138 
140  {
141  return mWidgetTrack == nullptr ? 1 : mWidgetTrack->getWidth();
142  }
143 
145  {
146  return mCoord.width - (int)(mSkinRangeStart + mSkinRangeEnd);
147  }
148 
149 } // namespace MyGUI