2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: ScrollBar
|
|
|
|
|
|
|
|
|
|
Desc: See header.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-05-01 19:14:55 +00:00
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ScrollBar.h"
|
2002-07-23 01:41:40 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "GameConstantsAndTypes.h"
|
2002-11-11 04:53:31 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
#include "ThemeManager.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
ScrollBar::ScrollBar()
|
|
|
|
|
{
|
2003-04-12 17:39:27 +00:00
|
|
|
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 );
|
2002-09-02 21:59:58 +00:00
|
|
|
this->AddChild( &m_sprBackground );
|
2002-05-01 19:14:55 +00:00
|
|
|
|
2003-04-12 17:39:27 +00:00
|
|
|
m_sprScrollThumbPart1.Load( THEME->GetPathToG("ScrollBar thumb") );
|
2002-08-26 05:53:48 +00:00
|
|
|
m_sprScrollThumbPart1.StopAnimating();
|
2002-09-02 21:59:58 +00:00
|
|
|
this->AddChild( &m_sprScrollThumbPart1 );
|
2002-08-26 05:53:48 +00:00
|
|
|
|
2003-04-12 17:39:27 +00:00
|
|
|
m_sprScrollThumbPart2.Load( THEME->GetPathToG("ScrollBar thumb") );
|
2002-08-26 05:53:48 +00:00
|
|
|
m_sprScrollThumbPart2.StopAnimating();
|
2002-09-02 21:59:58 +00:00
|
|
|
this->AddChild( &m_sprScrollThumbPart2 );
|
2002-08-26 05:53:48 +00:00
|
|
|
|
2003-04-12 17:39:27 +00:00
|
|
|
m_sprTopButton.Load( THEME->GetPathToG("ScrollBar parts 1x3") );
|
2002-05-01 19:14:55 +00:00
|
|
|
m_sprTopButton.StopAnimating();
|
|
|
|
|
m_sprTopButton.SetState( 0 );
|
2002-09-02 21:59:58 +00:00
|
|
|
this->AddChild( &m_sprTopButton );
|
2002-05-01 19:14:55 +00:00
|
|
|
|
2003-04-12 17:39:27 +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 );
|
2002-09-02 21:59:58 +00:00
|
|
|
this->AddChild( &m_sprBottomButton );
|
2002-05-01 19:14:55 +00:00
|
|
|
|
2002-08-26 05:53:48 +00:00
|
|
|
SetBarHeight( 100 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScrollBar::SetBarHeight( int iHeight )
|
|
|
|
|
{
|
|
|
|
|
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 );
|
2002-05-01 19:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-26 05:53:48 +00:00
|
|
|
void ScrollBar::SetPercentage( float fStartPercent, float fEndPercent )
|
2002-05-01 19:14:55 +00:00
|
|
|
{
|
2002-08-26 05:53:48 +00:00
|
|
|
const int k_iBarContentHeight = m_iBarHeight - int( m_sprTopButton.GetUnzoomedHeight()/2 + m_sprBottomButton.GetUnzoomedHeight()/2 );
|
|
|
|
|
|
|
|
|
|
// make sure the percent numbers are between 0 and 1
|
|
|
|
|
fStartPercent = fmodf( fStartPercent+1, 1 );
|
|
|
|
|
fEndPercent = fmodf( fEndPercent+1, 1 );
|
|
|
|
|
|
|
|
|
|
int iPart1TopY, iPart1BottomY, iPart2TopY, iPart2BottomY;
|
|
|
|
|
|
|
|
|
|
if( fStartPercent < fEndPercent ) // we only need to one 1 thumb part
|
|
|
|
|
{
|
|
|
|
|
iPart1TopY = (int)SCALE( fStartPercent,0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
iPart1BottomY = (int)SCALE( fEndPercent, 0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
iPart2TopY = -1;
|
|
|
|
|
iPart2BottomY = -1;
|
|
|
|
|
}
|
|
|
|
|
else // we need two thumb parts
|
|
|
|
|
{
|
|
|
|
|
iPart1TopY = (int)SCALE( 0.0f, 0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
iPart1BottomY = (int)SCALE( fEndPercent, 0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
iPart2TopY = (int)SCALE( fStartPercent,0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
iPart2BottomY = (int)SCALE( 1.0f, 0.0f, 1.0f, -k_iBarContentHeight/2.0f, +k_iBarContentHeight/2.0f );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-10-31 05:52:12 +00:00
|
|
|
m_sprScrollThumbPart1.StretchTo( RectI(
|
2002-08-26 05:53:48 +00:00
|
|
|
(int)-m_sprScrollThumbPart1.GetUnzoomedWidth()/2,
|
|
|
|
|
iPart1TopY,
|
|
|
|
|
(int)+m_sprScrollThumbPart1.GetUnzoomedWidth()/2,
|
|
|
|
|
iPart1BottomY
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
if( iPart2TopY != -1 )
|
|
|
|
|
{
|
2002-10-31 05:52:12 +00:00
|
|
|
m_sprScrollThumbPart2.StretchTo( RectI(
|
2002-08-26 05:53:48 +00:00
|
|
|
(int)-m_sprScrollThumbPart2.GetUnzoomedWidth()/2,
|
|
|
|
|
iPart2TopY,
|
|
|
|
|
(int)+m_sprScrollThumbPart2.GetUnzoomedWidth()/2,
|
|
|
|
|
iPart2BottomY
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_sprScrollThumbPart2.SetZoomY( 0 );
|
|
|
|
|
}
|
2002-05-01 19:14:55 +00:00
|
|
|
}
|