have separate tick thumb and stretch thumb elements

This commit is contained in:
Chris Danford
2008-02-15 09:19:56 +00:00
parent 47e475a89f
commit acc5c7e7d5
2 changed files with 66 additions and 59 deletions
+59 -52
View File
@@ -6,28 +6,27 @@
ScrollBar::ScrollBar() ScrollBar::ScrollBar()
{ {
m_sprBackground.Load( THEME->GetPathG("ScrollBar","parts 1x3") ); RString sMetricsGroup = "ScrollBar";
m_sprBackground->StopAnimating();
m_sprBackground->SetState( 1 );
this->AddChild( m_sprBackground );
m_sprScrollThumbPart1.Load( THEME->GetPathG("ScrollBar","thumb") ); m_sprMiddle.Load( THEME->GetPathG(sMetricsGroup,"middle") );
m_sprScrollThumbPart1->StopAnimating(); this->AddChild( m_sprMiddle );
this->AddChild( m_sprScrollThumbPart1 );
m_sprScrollThumbPart2.Load( THEME->GetPathG("ScrollBar","thumb") ); m_sprTop.Load( THEME->GetPathG(sMetricsGroup,"top") );
m_sprScrollThumbPart2->StopAnimating(); m_sprTop->SetVertAlign( VertAlign_Bottom );
this->AddChild( m_sprScrollThumbPart2 ); this->AddChild( m_sprTop );
m_sprTopButton.Load( THEME->GetPathG("ScrollBar","parts 1x3") ); m_sprBottom.Load( THEME->GetPathG(sMetricsGroup,"bottom") );
m_sprTopButton->StopAnimating(); m_sprBottom->SetVertAlign( VertAlign_Top );
m_sprTopButton->SetState( 0 ); this->AddChild( m_sprBottom );
this->AddChild( m_sprTopButton );
m_sprBottomButton.Load( THEME->GetPathG("ScrollBar","parts 1x3") ); m_sprScrollTickThumb.Load( THEME->GetPathG(sMetricsGroup,"TickThumb") );
m_sprBottomButton->StopAnimating(); this->AddChild( m_sprScrollTickThumb );
m_sprBottomButton->SetState( 2 );
this->AddChild( m_sprBottomButton ); for( int i=0; i<ARRAYLEN(m_sprScrollStretchThumb); i++ )
{
m_sprScrollStretchThumb[i].Load( THEME->GetPathG(sMetricsGroup,"StretchThumb") );
this->AddChild( m_sprScrollStretchThumb[i] );
}
SetBarHeight( 100 ); SetBarHeight( 100 );
} }
@@ -35,58 +34,66 @@ ScrollBar::ScrollBar()
void ScrollBar::SetBarHeight( int iHeight ) void ScrollBar::SetBarHeight( int iHeight )
{ {
m_iBarHeight = iHeight; m_iBarHeight = iHeight;
m_sprBackground->SetZoomY( m_iBarHeight/m_sprBackground->GetUnzoomedHeight() ); m_sprMiddle->SetZoomY( m_iBarHeight/m_sprMiddle->GetUnzoomedHeight() );
m_sprTopButton->SetY( -m_iBarHeight/2.0f ); m_sprTop->SetY( -m_iBarHeight/2.0f );
m_sprBottomButton->SetY( +m_iBarHeight/2.0f ); m_sprBottom->SetY( +m_iBarHeight/2.0f );
m_sprScrollThumbPart1->SetY( 0 ); m_sprScrollTickThumb->SetY( 0 );
m_sprScrollThumbPart2->SetY( 0 ); for( int i=0; i<ARRAYLEN(m_sprScrollStretchThumb); i++ )
m_sprScrollStretchThumb[i]->SetY( 0 );
} }
void ScrollBar::SetPercentage( float fStartPercent, float fEndPercent ) void ScrollBar::SetPercentage( float fCenterPercent, float fSizePercent )
{ {
CHECKPOINT; wrap( fCenterPercent, 1.0f );
const int iBarContentHeight = m_iBarHeight - int( m_sprTopButton->GetUnzoomedHeight()/2 + m_sprBottomButton->GetUnzoomedHeight()/2 );
const int iBarContentHeight = m_sprMiddle->GetZoomedHeight();
ASSERT( iBarContentHeight != 0 ); ASSERT( iBarContentHeight != 0 );
CHECKPOINT;
/* Set tick thumb */
{
float fY = SCALE( fCenterPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, iBarContentHeight/2.0f );
fY = roundf( fY );
m_sprScrollTickThumb->SetY( fY );
}
/* Set stretch thumb */
float fStartPercent = fCenterPercent - fSizePercent;
float fEndPercent = fCenterPercent + fSizePercent;
// make sure the percent numbers are between 0 and 1 // make sure the percent numbers are between 0 and 1
fStartPercent = fmodf( fStartPercent+1, 1 ); fStartPercent = fmodf( fStartPercent+1, 1 );
fEndPercent = fmodf( fEndPercent+1, 1 ); fEndPercent = fmodf( fEndPercent+1, 1 );
CHECKPOINT; CHECKPOINT;
float fPart1TopY, fPart1BottomY, fPart2TopY, fPart2BottomY; float fPartTopY[2], fPartBottomY[2];
if( fStartPercent < fEndPercent ) // we only need to one 1 thumb part if( fStartPercent < fEndPercent ) // we only need to one 1 stretch thumb part
{ {
fPart1TopY = SCALE( fStartPercent,0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartTopY[0] = SCALE( fStartPercent,0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
fPart1BottomY = SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartBottomY[0] = SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
fPart2TopY = 0; fPartTopY[1] = 0;
fPart2BottomY = 0; fPartBottomY[1] = 0;
} }
else // we need two thumb parts else // we need two stretch thumb parts
{ {
fPart1TopY = SCALE( 0.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartTopY[0] = SCALE( 0.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
fPart1BottomY = SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartBottomY[0] = SCALE( fEndPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
fPart2TopY = SCALE( fStartPercent,0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartTopY[1] = SCALE( fStartPercent, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
fPart2BottomY = SCALE( 1.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f ); fPartBottomY[1] = SCALE( 1.0f, 0.0f, 1.0f, -iBarContentHeight/2.0f, +iBarContentHeight/2.0f );
} }
CHECKPOINT; CHECKPOINT;
m_sprScrollThumbPart1->StretchTo( RectF( for( int i=0; i<ARRAYLEN(m_sprScrollStretchThumb); i++ )
-m_sprScrollThumbPart1->GetUnzoomedWidth()/2, {
fPart1TopY, RectF rect(
+m_sprScrollThumbPart1->GetUnzoomedWidth()/2, -m_sprScrollStretchThumb[i]->GetUnzoomedWidth()/2,
fPart1BottomY fPartTopY[i],
) ); +m_sprScrollStretchThumb[i]->GetUnzoomedWidth()/2,
fPartBottomY[i]
CHECKPOINT; );
m_sprScrollThumbPart2->StretchTo( RectF( m_sprScrollStretchThumb[i]->StretchTo( rect );
-m_sprScrollThumbPart2->GetUnzoomedWidth()/2, }
fPart2TopY,
+m_sprScrollThumbPart2->GetUnzoomedWidth()/2,
fPart2BottomY
) );
CHECKPOINT; CHECKPOINT;
} }
+6 -6
View File
@@ -13,17 +13,17 @@ public:
ScrollBar(); ScrollBar();
void SetBarHeight( int iHeight ); void SetBarHeight( int iHeight );
void SetPercentage( float fStartPercent, float fEndPercent); void SetPercentage( float fCenterPercent, float fSizePercent );
protected: protected:
int m_iBarHeight; int m_iBarHeight;
AutoActor m_sprTopButton; AutoActor m_sprMiddle;
AutoActor m_sprBottomButton; AutoActor m_sprTop;
AutoActor m_sprBackground; AutoActor m_sprBottom;
AutoActor m_sprScrollThumbPart1; AutoActor m_sprScrollTickThumb;
AutoActor m_sprScrollThumbPart2; AutoActor m_sprScrollStretchThumb[2];
}; };
#endif #endif