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 )
|
|
|
|
|
{
|
|
|
|
|
RECT r;
|
|
|
|
|
int iImageWidth = this->GetZoomedWidth();
|
|
|
|
|
int iImageHeight = this->GetZoomedHeight();
|
|
|
|
|
|
|
|
|
|
// first find the correct zoom
|
|
|
|
|
::SetRect( &r, 0, 0, BANNER_WIDTH, BANNER_HEIGHT );
|
|
|
|
|
Sprite::ScaleToCover( &r );
|
|
|
|
|
FLOAT fFinalZoom = this->GetZoom();
|
|
|
|
|
|
|
|
|
|
// find which dimension is larger
|
|
|
|
|
BOOL bYDimIsLarger = this->GetZoomedHeight() > BANNER_HEIGHT;
|
|
|
|
|
|
|
|
|
|
// now crop it
|
|
|
|
|
if( !bYDimIsLarger ) // crop X
|
|
|
|
|
{
|
|
|
|
|
int iScreenPixelsToCrop = (this->GetZoomedWidth() - BANNER_WIDTH) / 2;
|
|
|
|
|
int iImagePixelsToCrop = roundf( iScreenPixelsToCrop / fFinalZoom );
|
|
|
|
|
RECT rectNewSrc;
|
|
|
|
|
::SetRect( &rectNewSrc, iImagePixelsToCrop,
|
|
|
|
|
0,
|
|
|
|
|
iImageWidth - iImagePixelsToCrop,
|
|
|
|
|
iImageHeight );
|
|
|
|
|
Sprite::SetCustomSrcRect( rectNewSrc );
|
|
|
|
|
}
|
|
|
|
|
else // crop Y
|
|
|
|
|
{
|
|
|
|
|
int iScreenPixelsToCrop = (this->GetZoomedHeight() - BANNER_HEIGHT) / 2;
|
|
|
|
|
int iImagePixelsToCrop = roundf( iScreenPixelsToCrop / fFinalZoom );
|
|
|
|
|
RECT rectNewSrc;
|
|
|
|
|
::SetRect( &rectNewSrc, 0,
|
|
|
|
|
iImagePixelsToCrop,
|
|
|
|
|
iImageWidth,
|
|
|
|
|
iImageHeight - iImagePixelsToCrop );
|
|
|
|
|
Sprite::SetCustomSrcRect( rectNewSrc );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|