MyGUI 3.0.1
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #include "MyGUI_Precompiled.h" 00024 #include "MyGUI_HScroll.h" 00025 #include "MyGUI_InputManager.h" 00026 #include "MyGUI_Button.h" 00027 #include "MyGUI_ResourceSkin.h" 00028 00029 namespace MyGUI 00030 { 00031 00032 HScroll::HScroll() 00033 { 00034 } 00035 00036 void HScroll::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) 00037 { 00038 Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name); 00039 00040 initialiseWidgetSkin(_info); 00041 } 00042 00043 HScroll::~HScroll() 00044 { 00045 shutdownWidgetSkin(); 00046 } 00047 00048 void HScroll::baseChangeWidgetSkin(ResourceSkin* _info) 00049 { 00050 shutdownWidgetSkin(); 00051 Base::baseChangeWidgetSkin(_info); 00052 initialiseWidgetSkin(_info); 00053 } 00054 00055 void HScroll::initialiseWidgetSkin(ResourceSkin* _info) 00056 { 00057 } 00058 00059 void HScroll::shutdownWidgetSkin() 00060 { 00061 } 00062 00063 void HScroll::updateTrack() 00064 { 00065 if (mWidgetTrack == nullptr) 00066 return; 00067 00068 _forcePeek(mWidgetTrack); 00069 // размер диапазана в пикселях 00070 int pos = getLineSize(); 00071 00072 // скрываем если диапазан маленький или места мало 00073 if ((mScrollRange < 2) || (pos <= mWidgetTrack->getWidth())) 00074 { 00075 mWidgetTrack->setVisible(false); 00076 if ( nullptr != mWidgetFirstPart ) mWidgetFirstPart->setSize(pos/2, mWidgetFirstPart->getHeight()); 00077 if ( nullptr != mWidgetSecondPart ) mWidgetSecondPart->setCoord(pos/2 + mSkinRangeStart, mWidgetSecondPart->getTop(), pos - pos/2, mWidgetSecondPart->getHeight()); 00078 return; 00079 } 00080 // если скрыт то покажем 00081 if (!mWidgetTrack->isVisible()) 00082 { 00083 mWidgetTrack->setVisible(true); 00084 } 00085 00086 // и обновляем позицию 00087 pos = (int)(((size_t)(pos-getTrackSize()) * mScrollPosition) / (mScrollRange-1) + mSkinRangeStart); 00088 00089 mWidgetTrack->setPosition(pos, mWidgetTrack->getTop()); 00090 if ( nullptr != mWidgetFirstPart ) 00091 { 00092 int height = pos + mWidgetTrack->getWidth()/2 - mWidgetFirstPart->getLeft(); 00093 mWidgetFirstPart->setSize(height, mWidgetFirstPart->getHeight()); 00094 } 00095 if ( nullptr != mWidgetSecondPart ) 00096 { 00097 int top = pos + mWidgetTrack->getWidth()/2; 00098 int height = mWidgetSecondPart->getWidth() + mWidgetSecondPart->getLeft() - top; 00099 mWidgetSecondPart->setCoord(top, mWidgetSecondPart->getTop(), height, mWidgetSecondPart->getHeight()); 00100 } 00101 } 00102 00103 void HScroll::TrackMove(int _left, int _top) 00104 { 00105 if (mWidgetTrack == nullptr) 00106 return; 00107 00108 const IntPoint& point = InputManager::getInstance().getLastLeftPressed(); 00109 00110 // расчитываем позицию виджета 00111 int start = mPreActionOffset.left + (_left - point.left); 00112 if (start < (int)mSkinRangeStart) start = (int)mSkinRangeStart; 00113 else if (start > (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth())) start = (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth()); 00114 if (mWidgetTrack->getLeft() != start) mWidgetTrack->setPosition(IntPoint(start, mWidgetTrack->getTop())); 00115 00116 // расчитываем положение соответствующее позиции 00117 // плюс пол позиции 00118 int pos = start - (int)mSkinRangeStart + (getLineSize() - getTrackSize()) / (((int)mScrollRange-1) * 2); 00119 // высчитываем ближайшее значение и обновляем 00120 pos = pos * (int)(mScrollRange-1) / (getLineSize() - getTrackSize()); 00121 00122 // проверяем на выходы и изменения 00123 if (pos < 0) pos = 0; 00124 else if (pos >= (int)mScrollRange) pos = (int)mScrollRange - 1; 00125 if (pos == (int)mScrollPosition) return; 00126 00127 mScrollPosition = pos; 00128 // отсылаем событие 00129 eventScrollChangePosition(this, (int)mScrollPosition); 00130 } 00131 00132 void HScroll::setTrackSize(int _size) 00133 { 00134 if (mWidgetTrack != nullptr) 00135 mWidgetTrack->setSize(((int)_size < (int)mMinTrackSize)? (int)mMinTrackSize : (int)_size, mWidgetTrack->getHeight()); 00136 updateTrack(); 00137 } 00138 00139 int HScroll::getTrackSize() 00140 { 00141 return mWidgetTrack == nullptr ? 1 : mWidgetTrack->getWidth(); 00142 } 00143 00144 int HScroll::getLineSize() 00145 { 00146 return mCoord.width - (int)(mSkinRangeStart + mSkinRangeEnd); 00147 } 00148 00149 } // namespace MyGUI