// magic hurr // This code should either be removed or refactored in the future -aj void Sprite::CropTo( float fWidth, float fHeight ) { m_fRememberedClipWidth = fWidth; m_fRememberedClipHeight = fHeight; if( !m_pTexture ) return; // save the original X&Y. We're going to restore them later. float fOriginalX = GetX(); float fOriginalY = GetY(); if( fWidth != -1 && fHeight != -1 ) { // this is probably a background graphic or something not intended to be a CroppedSprite Sprite::StopUsingCustomCoords(); // first find the correct zoom Sprite::ScaleToCover( RectF(0, 0, fWidth, fHeight) ); // find which dimension is larger bool bXDimNeedsToBeCropped = GetZoomedWidth() > fWidth+0.01; if( bXDimNeedsToBeCropped ) // crop X { float fPercentageToCutOff = (this->GetZoomedWidth() - fWidth) / this->GetZoomedWidth(); float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates RectF fCustomImageRect( fPercentageToCutOffEachSide, 0, 1 - fPercentageToCutOffEachSide, 1 ); SetCustomImageRect( fCustomImageRect ); } else // crop Y { float fPercentageToCutOff = (this->GetZoomedHeight() - fHeight) / this->GetZoomedHeight(); float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates RectF fCustomImageRect( 0, fPercentageToCutOffEachSide, 1, 1 - fPercentageToCutOffEachSide ); SetCustomImageRect( fCustomImageRect ); } m_size = RageVector2( fWidth, fHeight ); SetZoom( 1 ); } // restore original XY SetXY( fOriginalX, fOriginalY ); }
void Sprite::ScaleToClipped( float fWidth, float fHeight ) { m_fRememberedClipWidth = fWidth; m_fRememberedClipHeight = fHeight; if( !m_pTexture ) return; 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( IsDiagonalBanner(iSourceWidth, iSourceHeight) ) // this is a SSR/DWI CroppedSprite { float fCustomImageCoords[8] = { 0.02f, 0.78f, // top left 0.22f, 0.98f, // bottom left 0.98f, 0.22f, // bottom right 0.78f, 0.02f, // top right }; Sprite::SetCustomImageCoords( fCustomImageCoords ); if( fWidth != -1 && fHeight != -1) m_size = RageVector2( fWidth, fHeight ); 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); } SetZoom( 1 ); } else if( m_pTexture->GetID().filename.find( "(was rotated)" ) != m_pTexture->GetID().filename.npos && fWidth != -1 && fHeight != -1 ) { /* Dumb hack. Normally, we crop all sprites except for diagonal banners, * which are stretched. Low-res versions of banners need to do the same * thing as their full resolution counterpart, so the crossfade looks right. * However, low-res diagonal banners are un-rotated, to save space. BannerCache * drops the above text into the "filename" (which is otherwise unused for * these banners) to tell us this. */ Sprite::StopUsingCustomCoords(); m_size = RageVector2( fWidth, fHeight ); SetZoom( 1 ); } else if( fWidth != -1 && fHeight != -1 ) { // this is probably a background graphic or something not intended to be a CroppedSprite Sprite::StopUsingCustomCoords(); // first find the correct zoom Sprite::ScaleToCover( RectF(0,0,fWidth,fHeight) ); // find which dimension is larger bool bXDimNeedsToBeCropped = GetZoomedWidth() > fWidth+0.01; if( bXDimNeedsToBeCropped ) // crop X { float fPercentageToCutOff = (this->GetZoomedWidth() - fWidth) / this->GetZoomedWidth(); float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates RectF fCustomImageRect( fPercentageToCutOffEachSide, 0, 1 - fPercentageToCutOffEachSide, 1 ); SetCustomImageRect( fCustomImageRect ); } else // crop Y { float fPercentageToCutOff = (this->GetZoomedHeight() - fHeight) / this->GetZoomedHeight(); float fPercentageToCutOffEachSide = fPercentageToCutOff / 2; // generate a rectangle with new texture coordinates RectF fCustomImageRect( 0, fPercentageToCutOffEachSide, 1, 1 - fPercentageToCutOffEachSide ); SetCustomImageRect( fCustomImageRect ); } m_size = RageVector2( fWidth, fHeight ); SetZoom( 1 ); } // restore original XY SetXY( fOriginalX, fOriginalY ); }