Files
itgmania212121/stepmania/src/ScrollBar.cpp
T

125 lines
4.3 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-01 19:14:55 +00:00
#include "ScrollBar.h"
#include "GameConstantsAndTypes.h"
#include "ThemeManager.h"
2004-06-08 00:45:30 +00:00
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
ScrollBar::ScrollBar()
{
m_sprBackground.Load( THEME->GetPathToG("ScrollBar parts 1x3") );
2002-05-01 19:14:55 +00:00
m_sprBackground.StopAnimating();
2002-07-23 01:41:40 +00:00
m_sprBackground.SetState( 1 );
this->AddChild( &m_sprBackground );
2002-05-01 19:14:55 +00:00
m_sprScrollThumbPart1.Load( THEME->GetPathToG("ScrollBar thumb") );
m_sprScrollThumbPart1.StopAnimating();
this->AddChild( &m_sprScrollThumbPart1 );
m_sprScrollThumbPart2.Load( THEME->GetPathToG("ScrollBar thumb") );
m_sprScrollThumbPart2.StopAnimating();
this->AddChild( &m_sprScrollThumbPart2 );
m_sprTopButton.Load( THEME->GetPathToG("ScrollBar parts 1x3") );
2002-05-01 19:14:55 +00:00
m_sprTopButton.StopAnimating();
m_sprTopButton.SetState( 0 );
this->AddChild( &m_sprTopButton );
2002-05-01 19:14:55 +00:00
m_sprBottomButton.Load( THEME->GetPathToG("ScrollBar parts 1x3") );
2002-05-01 19:14:55 +00:00
m_sprBottomButton.StopAnimating();
2002-07-23 01:41:40 +00:00
m_sprBottomButton.SetState( 2 );
this->AddChild( &m_sprBottomButton );
2002-05-01 19:14:55 +00:00
SetBarHeight( 100 );
2002-05-01 19:14:55 +00:00
}
void ScrollBar::SetBarHeight( int iHeight )
2002-05-01 19:14:55 +00:00
{
m_iBarHeight = iHeight;
m_sprBackground.SetZoomY( m_iBarHeight/m_sprBackground.GetUnzoomedHeight() );
m_sprTopButton.SetY( -m_iBarHeight/2.0f );
m_sprBottomButton.SetY( +m_iBarHeight/2.0f );
m_sprScrollThumbPart1.SetY( 0 );
m_sprScrollThumbPart2.SetY( 0 );
}
void ScrollBar::SetPercentage( float fStartPercent, float fEndPercent )
{
2003-09-15 06:51:45 +00:00
CHECKPOINT;
const int iBarContentHeight = m_iBarHeight - int( m_sprTopButton.GetUnzoomedHeight()/2 + m_sprBottomButton.GetUnzoomedHeight()/2 );
ASSERT( iBarContentHeight != 0 );
CHECKPOINT;
// make sure the percent numbers are between 0 and 1
fStartPercent = fmodf( fStartPercent+1, 1 );
fEndPercent = fmodf( fEndPercent+1, 1 );
CHECKPOINT;
int iPart1TopY, iPart1BottomY, iPart2TopY, iPart2BottomY;
if( fStartPercent < fEndPercent ) // we only need to one 1 thumb part
{
iPart1TopY = (int)SCALE( fStartPercent,0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
iPart1BottomY = (int)SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
iPart2TopY = -1;
iPart2BottomY = -1;
}
else // we need two thumb parts
{
iPart1TopY = (int)SCALE( 0.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
iPart1BottomY = (int)SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
iPart2TopY = (int)SCALE( fStartPercent,0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
iPart2BottomY = (int)SCALE( 1.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
}
CHECKPOINT;
2002-10-31 05:52:12 +00:00
m_sprScrollThumbPart1.StretchTo( RectI(
(int)-m_sprScrollThumbPart1.GetUnzoomedWidth()/2,
iPart1TopY,
(int)+m_sprScrollThumbPart1.GetUnzoomedWidth()/2,
iPart1BottomY
) );
CHECKPOINT;
if( iPart2TopY != -1 )
{
2002-10-31 05:52:12 +00:00
m_sprScrollThumbPart2.StretchTo( RectI(
(int)-m_sprScrollThumbPart2.GetUnzoomedWidth()/2,
iPart2TopY,
(int)+m_sprScrollThumbPart2.GetUnzoomedWidth()/2,
iPart2BottomY
) );
}
else
{
m_sprScrollThumbPart2.SetZoomY( 0 );
}
2003-09-15 06:51:45 +00:00
CHECKPOINT;
2002-05-01 19:14:55 +00:00
}
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-2003 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/