• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_HScroll.cpp

Go to the documentation of this file.
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, WidgetPtr _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         _forcePeek(mWidgetTrack);
00066         // размер диапазана в пикселях
00067         int pos = getLineSize();
00068 
00069         // скрываем если диапазан маленький или места мало
00070         if ((mScrollRange < 2) || (pos <= mWidgetTrack->getWidth())) {
00071             mWidgetTrack->setVisible(false);
00072             if ( nullptr != mWidgetFirstPart ) mWidgetFirstPart->setSize(pos/2, mWidgetFirstPart->getHeight());
00073             if ( nullptr != mWidgetSecondPart ) mWidgetSecondPart->setCoord(pos/2 + mSkinRangeStart, mWidgetSecondPart->getTop(), pos - pos/2, mWidgetSecondPart->getHeight());
00074             return;
00075         }
00076         // если скрыт то покажем
00077         if (false == mWidgetTrack->isVisible())
00078         {
00079             mWidgetTrack->setVisible(true);
00080         }
00081 
00082         // и обновляем позицию
00083         pos = (int)(((size_t)(pos-getTrackSize()) * mScrollPosition) / (mScrollRange-1) + mSkinRangeStart);
00084 
00085         mWidgetTrack->setPosition(pos, mWidgetTrack->getTop());
00086         if ( nullptr != mWidgetFirstPart )
00087         {
00088             int height = pos + mWidgetTrack->getWidth()/2 - mWidgetFirstPart->getLeft();
00089             mWidgetFirstPart->setSize(height, mWidgetFirstPart->getHeight());
00090         }
00091         if ( nullptr != mWidgetSecondPart )
00092         {
00093             int top = pos + mWidgetTrack->getWidth()/2;
00094             int height = mWidgetSecondPart->getWidth() + mWidgetSecondPart->getLeft() - top;
00095             mWidgetSecondPart->setCoord(top, mWidgetSecondPart->getTop(), height, mWidgetSecondPart->getHeight());
00096         }
00097     }
00098 
00099     void HScroll::TrackMove(int _left, int _top)
00100     {
00101         const IntPoint& point = InputManager::getInstance().getLastLeftPressed();
00102 
00103         // расчитываем позицию виджета
00104         int start = mPreActionOffset.left + (_left - point.left);
00105         if (start < (int)mSkinRangeStart) start = (int)mSkinRangeStart;
00106         else if (start > (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth())) start = (mCoord.width - (int)mSkinRangeEnd - mWidgetTrack->getWidth());
00107         if (mWidgetTrack->getLeft() != start) mWidgetTrack->setPosition(IntPoint(start, mWidgetTrack->getTop()));
00108 
00109         // расчитываем положение соответствующее позиции
00110         // плюс пол позиции
00111         int pos = start - (int)mSkinRangeStart + (getLineSize() - getTrackSize()) / (((int)mScrollRange-1) * 2);
00112         // высчитываем ближайшее значение и обновляем
00113         pos = pos * (int)(mScrollRange-1) / (getLineSize() - getTrackSize());
00114 
00115         // проверяем на выходы и изменения
00116         if (pos < 0) pos = 0;
00117         else if (pos >= (int)mScrollRange) pos = (int)mScrollRange - 1;
00118         if (pos == (int)mScrollPosition) return;
00119 
00120         mScrollPosition = pos;
00121         // отсылаем событие
00122         eventScrollChangePosition(this, (int)mScrollPosition);
00123     }
00124 
00125     void HScroll::setTrackSize(int _size)
00126     {
00127         mWidgetTrack->setSize(((int)_size < (int)mMinTrackSize)? (int)mMinTrackSize : (int)_size, mWidgetTrack->getHeight());
00128         updateTrack();
00129     }
00130 
00131     int HScroll::getTrackSize()
00132     {
00133         return mWidgetTrack->getWidth();
00134     }
00135 
00136     int HScroll::getLineSize()
00137     {
00138         return mCoord.width - (int)(mSkinRangeStart + mSkinRangeEnd);
00139     }
00140 
00141 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1