Files
itgmania212121/stepmania/src/Banner.cpp
T

93 lines
2.4 KiB
C++
Raw Normal View History

2001-11-03 10:52:42 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: Banner.h
2001-11-03 10:52:42 +00:00
Desc: The song's banner displayed in SelectSong.
2001-11-03 10:52:42 +00:00
Copyright (c) 2001 Chris Danford. All rights reserved.
-----------------------------------------------------------------------------
*/
2001-11-03 10:52:42 +00:00
#include "RageUtil.h"
#include "Banner.h"
2002-01-16 10:01:32 +00:00
#include "ThemeManager.h"
2001-11-03 10:52:42 +00:00
2001-12-28 10:15:59 +00:00
2001-11-03 10:52:42 +00:00
2001-11-25 04:31:44 +00:00
bool Banner::LoadFromSong( Song &song )
2001-11-03 10:52:42 +00:00
{
2001-12-28 10:15:59 +00:00
if( song.HasBanner() )
Sprite::LoadFromTexture( song.GetBannerPath() );
2002-01-16 10:01:32 +00:00
else if( song.HasBackground() )
2001-12-28 10:15:59 +00:00
Sprite::LoadFromTexture( song.GetBackgroundPath() );
else
2002-01-16 10:01:32 +00:00
Sprite::LoadFromTexture( THEME->GetPathTo(GRAPHIC_FALLBACK_BANNER) );
2001-12-19 01:50:57 +00:00
//Sprite::TurnShadowOff();
2001-11-03 10:52:42 +00:00
2001-12-28 10:15:59 +00:00
int iSourceWidth = m_pTexture->GetSourceWidth();
int iSourceHeight = m_pTexture->GetSourceHeight();
2001-11-21 03:21:00 +00:00
2001-12-28 10:15:59 +00:00
if( iSourceWidth == iSourceHeight ) // this is a SSR/DWI style banner
2001-11-25 04:31:44 +00:00
{
2001-12-28 10:15:59 +00:00
float fCustomTexCoords[8] = {
0.22f, 0.98f, // bottom left
0.02f, 0.78f, // top left
0.98f, 0.22f, // bottom right
0.78f, 0.02f, // top right
};
Sprite::SetCustomTexCoords( fCustomTexCoords );
2001-11-21 03:21:00 +00:00
2001-12-28 10:15:59 +00:00
SetWidth( BANNER_WIDTH );
SetHeight( BANNER_HEIGHT );
2001-11-25 04:31:44 +00:00
}
2001-12-28 10:15:59 +00:00
else // this is a normal sized banner
2001-11-25 04:31:44 +00:00
{
2001-12-28 10:15:59 +00:00
// first find the correct zoom
Sprite::ScaleToCover( CRect(0, 0,
(int)BANNER_WIDTH,
(int)BANNER_HEIGHT )
);
float fFinalZoom = this->GetZoom();
// find which dimension is larger
bool bXDimNeedsToBeCropped = GetZoomedWidth() > BANNER_WIDTH;
2001-11-03 10:52:42 +00:00
2001-12-28 10:15:59 +00:00
if( bXDimNeedsToBeCropped ) // crop X
{
float fPercentageToCutOff = (this->GetZoomedWidth() - BANNER_WIDTH) / this->GetZoomedWidth();
float fPercentageToCutOffEachSide = fPercentageToCutOff / 2;
// generate a rectangle with new texture coordinates
FRECT frectNewSrc( fPercentageToCutOffEachSide,
0,
1 - fPercentageToCutOffEachSide,
1 );
Sprite::SetCustomSrcRect( frectNewSrc );
}
else // crop Y
{
float fPercentageToCutOff = (this->GetZoomedHeight() - BANNER_HEIGHT) / this->GetZoomedHeight();
float fPercentageToCutOffEachSide = fPercentageToCutOff / 2;
// generate a rectangle with new texture coordinates
FRECT frectNewSrc( 0,
fPercentageToCutOffEachSide,
1,
1 - fPercentageToCutOffEachSide );
Sprite::SetCustomSrcRect( frectNewSrc );
}
SetWidth( BANNER_WIDTH );
SetHeight( BANNER_HEIGHT );
SetZoom( 1 );
2001-11-03 10:52:42 +00:00
}
2001-11-25 04:31:44 +00:00
return true;
2001-11-03 10:52:42 +00:00
}