Files
itgmania212121/stepmania/src/CroppedSprite.cpp
T

126 lines
3.3 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-04-16 17:31:00 +00:00
/*
-----------------------------------------------------------------------------
File: CroppedSprite.h
Desc: The song's CroppedSprite displayed in SelectSong.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-04-16 17:31:00 +00:00
-----------------------------------------------------------------------------
*/
#include "RageUtil.h"
#include "CroppedSprite.h"
2002-07-23 01:41:40 +00:00
#include "PrefsManager.h"
2002-04-16 17:31:00 +00:00
#include "RageBitmapTexture.h"
2003-04-22 22:39:51 +00:00
#include <math.h>
2002-04-16 17:31:00 +00:00
CroppedSprite::CroppedSprite()
{
2003-04-22 22:39:51 +00:00
/* By default, crop to the size of the image. */
m_fCropWidth = m_fCropHeight = -1;
}
bool CroppedSprite::Load( RageTextureID ID )
{
Sprite::Load( ID );
CropToSize( m_fCropWidth, m_fCropHeight );
return true;
}
void CroppedSprite::SetWH(float fWidth, float fHeight)
{
Sprite::SetWidth(fWidth);
Sprite::SetHeight(fWidth);
}
void CroppedSprite::SetCroppedSize( float fWidth, float fHeight )
{
m_fCropWidth = fWidth;
m_fCropHeight = fHeight;
}
2002-04-16 17:31:00 +00:00
void CroppedSprite::CropToSize( float fWidth, float fHeight )
{
m_fCropWidth = fWidth;
m_fCropHeight = fHeight;
int iSourceWidth = m_pTexture->GetSourceWidth();
int iSourceHeight = m_pTexture->GetSourceHeight();
// save the original X&Y. We're going to resore them later.
float fOriginalX = GetX();
float fOriginalY = GetY();
if( iSourceWidth == iSourceHeight ) // this is a SSR/DWI CroppedSprite
{
float fCustomImageCoords[8] = {
0.02f, 0.78f, // top left
2003-04-21 01:53:48 +00:00
0.22f, 0.98f, // bottom left
2002-04-16 17:31:00 +00:00
0.98f, 0.22f, // bottom right
0.78f, 0.02f, // top right
};
Sprite::SetCustomImageCoords( fCustomImageCoords );
2003-04-22 22:39:51 +00:00
if( m_fCropWidth != -1 && m_fCropHeight != -1)
m_size = RageVector2( m_fCropWidth, m_fCropHeight );
else
{
/* If no crop size is set, then we're only being used to crop diagonal
* banners so they look like regular ones. We don't actually care about
* the size of the image, only that it has an aspect ratio of 4:1. */
m_size = RageVector2(256, 64);
}
2002-04-16 17:31:00 +00:00
SetZoom( 1 );
}
2003-04-22 22:39:51 +00:00
else if( m_fCropWidth != -1 && m_fCropHeight != -1)
2002-04-16 17:31:00 +00:00
{
2003-04-22 22:39:51 +00:00
// this is probably a background graphic or something not intended to be a CroppedSprite
2002-04-16 17:31:00 +00:00
Sprite::StopUsingCustomCoords();
// first find the correct zoom
2002-10-31 05:52:12 +00:00
Sprite::ScaleToCover( RectI(0, 0,
2002-04-16 17:31:00 +00:00
(int)m_fCropWidth,
(int)m_fCropHeight )
);
// find which dimension is larger
2002-07-11 19:02:26 +00:00
bool bXDimNeedsToBeCropped = GetZoomedWidth() > m_fCropWidth+0.01;
2002-04-16 17:31:00 +00:00
if( bXDimNeedsToBeCropped ) // crop X
{
float fPercentageToCutOff = (this->GetZoomedWidth() - m_fCropWidth) / this->GetZoomedWidth();
float fPercentageToCutOffEachSide = fPercentageToCutOff / 2;
// generate a rectangle with new texture coordinates
2002-10-31 06:00:30 +00:00
RectF fCustomImageCoords(
2002-04-16 17:31:00 +00:00
fPercentageToCutOffEachSide,
0,
1 - fPercentageToCutOffEachSide,
1 );
SetCustomImageRect( fCustomImageCoords );
}
else // crop Y
{
float fPercentageToCutOff = (this->GetZoomedHeight() - m_fCropHeight) / this->GetZoomedHeight();
float fPercentageToCutOffEachSide = fPercentageToCutOff / 2;
// generate a rectangle with new texture coordinates
2002-10-31 06:00:30 +00:00
RectF fCustomImageCoords(
2002-04-16 17:31:00 +00:00
0,
fPercentageToCutOffEachSide,
1,
1 - fPercentageToCutOffEachSide );
SetCustomImageRect( fCustomImageCoords );
}
m_size = RageVector2( m_fCropWidth, m_fCropHeight );
2002-04-16 17:31:00 +00:00
SetZoom( 1 );
}
// restore original XY
SetXY( fOriginalX, fOriginalY );
}