Files
itgmania212121/stepmania/src/ListDisplay.cpp
T

175 lines
5.3 KiB
C++
Raw Normal View History

2003-12-28 08:20:48 +00:00
#include "global.h"
#include "ListDisplay.h"
#include "RageUtil.h"
#include "GameConstantsAndTypes.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "PrefsManager.h"
#include "Course.h"
#include "SongManager.h"
#include "ThemeManager.h"
#include "Steps.h"
#include "GameState.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
2003-12-28 08:20:48 +00:00
#include "RageTexture.h"
2005-02-28 18:49:17 +00:00
//
// TODO: Merge this with ActorScroller
//
2003-12-28 08:20:48 +00:00
ListDisplay::ListDisplay()
{
m_iNumItemsToShow = 0;
m_fItemWidth = 0;
m_fItemHeight = 0;
2005-02-28 18:49:17 +00:00
m_fCurrentItemAtTopOfList = 0;
m_fDestinationItemAtTopOfList = 0;
2003-12-28 08:20:48 +00:00
m_quadMask.SetBlendMode( BLEND_NO_EFFECT ); // don't change color values
m_quadMask.SetUseZBuffer( true ); // we want to write to the Zbuffer
}
void ListDisplay::Load(
const vector<Actor*> &m_vpItems,
int iNumItemsToShow,
float fItemWidth,
float fItemHeight,
bool bLoop,
float fSecondsPerItem,
float fSecondsPauseBetweenItems,
bool bSlide )
{
2003-12-31 07:20:05 +00:00
CLAMP( iNumItemsToShow, 1, 10000 );
CLAMP( fItemWidth, 1, 10000 );
CLAMP( fItemHeight, 1, 10000 );
CLAMP( fSecondsPerItem, 0.01f, 10000 );
CLAMP( fSecondsPauseBetweenItems, 0, 10000 );
2003-12-28 08:20:48 +00:00
m_SubActors = m_vpItems;
m_iNumItemsToShow = iNumItemsToShow;
m_fItemWidth = fItemWidth;
m_fItemHeight = fItemHeight;
m_bLoop = bLoop;
m_fSecondsPerItem = fSecondsPerItem;
m_fSecondsPauseBetweenItems = fSecondsPauseBetweenItems;
m_bSlide = bSlide;
2005-02-28 18:49:17 +00:00
m_fCurrentItemAtTopOfList = m_bLoop ? 0 : (float)-m_iNumItemsToShow;
2005-03-01 15:54:13 +00:00
m_fDestinationItemAtTopOfList = (float)(m_vpItems.size()+1);
2003-12-28 08:20:48 +00:00
m_fSecondsPauseCountdown = 0;
RectF rectBarSize(-m_fItemWidth/2, -m_fItemHeight/2,
m_fItemWidth/2, m_fItemHeight/2);
m_quadMask.StretchTo( rectBarSize );
m_quadMask.SetZ( 1 );
}
float ListDisplay::GetSecondsForCompleteScrollThrough()
{
2003-12-28 23:23:43 +00:00
int fTotalItems = m_iNumItemsToShow + m_SubActors.size();
2003-12-28 08:20:48 +00:00
return fTotalItems * (m_fSecondsPerItem + m_fSecondsPauseBetweenItems );
}
void ListDisplay::Update( float fDeltaTime )
{
ActorFrame::Update( fDeltaTime );
2003-12-29 01:10:16 +00:00
/* If we have no children, the code below will busy loop. */
if( !m_SubActors.size() )
return;
2005-02-28 18:49:17 +00:00
// handle pause
if( fDeltaTime > m_fSecondsPauseCountdown )
2003-12-28 08:20:48 +00:00
{
2005-02-28 18:49:17 +00:00
fDeltaTime -= m_fSecondsPauseCountdown;
m_fSecondsPauseCountdown = 0;
}
else
{
m_fSecondsPauseCountdown -= fDeltaTime;
fDeltaTime = 0;
return;
}
2003-12-28 08:20:48 +00:00
2005-02-28 18:49:17 +00:00
if( m_fCurrentItemAtTopOfList == m_fDestinationItemAtTopOfList )
return; // done scrolling
2003-12-28 08:20:48 +00:00
2005-02-28 18:49:17 +00:00
float fOldItemAtTop = m_fCurrentItemAtTopOfList;
fapproach( m_fCurrentItemAtTopOfList, m_fDestinationItemAtTopOfList, fDeltaTime/m_fSecondsPerItem );
// if items changed, then pause
if( (int)fOldItemAtTop != (int)m_fCurrentItemAtTopOfList )
m_fSecondsPauseCountdown = m_fSecondsPauseBetweenItems;
if( m_bLoop )
wrap( m_fCurrentItemAtTopOfList, (float) m_SubActors.size() );
2003-12-28 08:20:48 +00:00
}
void ListDisplay::DrawPrimitives()
{
if( m_SubActors.empty() )
return;
// write to z buffer so that top and bottom are clipped
float fIndexFullyOnScreenTop = -(m_iNumItemsToShow-1)/2.f;
float fIndexFullyOnScreenBottom = (m_iNumItemsToShow-1)/2.f;
float fIndexCompletelyOffScreenTop = fIndexFullyOnScreenTop - 1;
float fIndexCompletelyOffScreenBottom = fIndexFullyOnScreenBottom + 1;
m_quadMask.SetY( fIndexCompletelyOffScreenTop * m_fItemHeight );
m_quadMask.Draw();
m_quadMask.SetY( fIndexCompletelyOffScreenBottom * m_fItemHeight );
m_quadMask.Draw();
2005-02-28 18:49:17 +00:00
int iItemToDraw = (int)m_fCurrentItemAtTopOfList;
float fRemainder = m_fCurrentItemAtTopOfList - (int)m_fCurrentItemAtTopOfList;
2003-12-28 08:20:48 +00:00
float fIndex = fIndexFullyOnScreenTop - fRemainder;
float fY = (fIndex)*m_fItemHeight;
for( int i=0; i<m_iNumItemsToShow+1; i++ )
{
2003-12-28 23:23:43 +00:00
if( iItemToDraw >= 0 && iItemToDraw < (int) m_SubActors.size() )
2003-12-28 08:20:48 +00:00
{
float fX = 0;
if( m_bSlide && fIndex>fIndexFullyOnScreenBottom-1 )
fX = SCALE( fIndex, fIndexFullyOnScreenBottom, fIndexFullyOnScreenBottom-1.f, 640.f, 0.f );
m_SubActors[iItemToDraw]->SetXY( roundf(fX), roundf(fY) );
m_SubActors[iItemToDraw]->Draw();
}
iItemToDraw++;
if( m_bLoop )
wrap( iItemToDraw, m_SubActors.size() );
fY += m_fItemHeight;
fIndex += 1;
}
}
2004-06-07 21:14:03 +00:00
/*
* (c) 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.
*/