2001-11-03 10:52:42 +00:00
|
|
|
#include "stdafx.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
File: Banner.h
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-04 19:34:28 +00:00
|
|
|
Desc: The song's banner displayed in SelectSong.
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-04 19:34:28 +00:00
|
|
|
Copyright (c) 2001 Chris Danford. All rights reserved.
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
#include "RageUtil.h"
|
|
|
|
|
|
|
|
|
|
#include "Banner.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOL Banner::LoadFromSong( Song &song )
|
|
|
|
|
{
|
|
|
|
|
BOOL bResult = Sprite::LoadFromTexture( song.GetBannerPath() );
|
|
|
|
|
if( bResult )
|
|
|
|
|
{
|
|
|
|
|
int iImageWidth = this->GetZoomedWidth();
|
|
|
|
|
int iImageHeight = this->GetZoomedHeight();
|
|
|
|
|
|
2001-11-21 03:21:00 +00:00
|
|
|
int iCorrectedBannerWidth = BANNER_WIDTH / m_pTexture->GetWidthCorrectionRatio();
|
|
|
|
|
int iCorrectedBannerHeight = BANNER_HEIGHT / m_pTexture->GetHeightCorrectionRatio();
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2001-11-21 03:21:00 +00:00
|
|
|
// first find the correct zoom
|
|
|
|
|
Sprite::ScaleToCover( CRect(0, 0,
|
|
|
|
|
iCorrectedBannerWidth,
|
|
|
|
|
iCorrectedBannerHeight )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FLOAT fFinalZoom = this->GetZoom();
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
// find which dimension is larger
|
2001-11-21 03:21:00 +00:00
|
|
|
BOOL bYDimIsLarger = this->GetZoomedHeight() > iCorrectedBannerHeight;
|
|
|
|
|
// BOOL bYDimIsLarger = this->GetZoomedHeight() > BANNER_HEIGHT;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
// now crop it
|
|
|
|
|
if( !bYDimIsLarger ) // crop X
|
|
|
|
|
{
|
2001-11-21 03:21:00 +00:00
|
|
|
int iScreenPixelsToCrop = (this->GetZoomedWidth() - iCorrectedBannerWidth) / 2;
|
2001-11-03 10:52:42 +00:00
|
|
|
int iImagePixelsToCrop = roundf( iScreenPixelsToCrop / fFinalZoom );
|
|
|
|
|
RECT rectNewSrc;
|
|
|
|
|
::SetRect( &rectNewSrc, iImagePixelsToCrop,
|
|
|
|
|
0,
|
|
|
|
|
iImageWidth - iImagePixelsToCrop,
|
|
|
|
|
iImageHeight );
|
|
|
|
|
Sprite::SetCustomSrcRect( rectNewSrc );
|
|
|
|
|
}
|
|
|
|
|
else // crop Y
|
|
|
|
|
{
|
2001-11-21 03:21:00 +00:00
|
|
|
int iScreenPixelsToCrop = (this->GetZoomedHeight() - iCorrectedBannerHeight) / 2;
|
2001-11-03 10:52:42 +00:00
|
|
|
int iImagePixelsToCrop = roundf( iScreenPixelsToCrop / fFinalZoom );
|
|
|
|
|
RECT rectNewSrc;
|
|
|
|
|
::SetRect( &rectNewSrc, 0,
|
|
|
|
|
iImagePixelsToCrop,
|
|
|
|
|
iImageWidth,
|
|
|
|
|
iImageHeight - iImagePixelsToCrop );
|
|
|
|
|
Sprite::SetCustomSrcRect( rectNewSrc );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|