Files
itgmania212121/stepmania/src/Banner.cpp
T

62 lines
1.6 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"
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;
}