Files
itgmania212121/stepmania/src/RageTexture.cpp
T

107 lines
3.0 KiB
C++
Raw Normal View History

2001-11-03 10:52:42 +00:00
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: RageTexture.h
Desc: Abstract class for a texture with metadata.
Copyright (c) 2001 Chris Danford. All rights reserved.
-----------------------------------------------------------------------------
*/
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "RageTexture.h"
#include "RageUtil.h"
//-----------------------------------------------------------------------------
// RageTexture constructor
//-----------------------------------------------------------------------------
RageTexture::RageTexture( LPRageScreen pScreen, CString sFilePath ) :
2001-11-25 04:31:44 +00:00
m_uSourceWidth( 0 ),
m_uSourceHeight( 0 ),
2001-11-03 10:52:42 +00:00
m_uTextureWidth( 0 ),
m_uTextureHeight( 0 ),
m_uFramesWide( 1 ),
m_uFramesHigh( 1 ),
2001-11-25 04:31:44 +00:00
m_uSourceFrameWidth( 0 ),
m_uSourceFrameHeight( 0 )
2001-11-03 10:52:42 +00:00
{
// RageLog( "RageTexture::RageTexture()" );
// save a pointer to the D3D device
m_pd3dDevice = pScreen->GetDevice();
assert( m_pd3dDevice != NULL );
// save the file path
m_sFilePath = sFilePath;
2001-12-19 01:50:57 +00:00
// m_pd3dTexture = NULL;
2001-11-03 10:52:42 +00:00
m_iRefCount = 1;
}
RageTexture::~RageTexture()
{
}
void RageTexture::CreateFrameRects()
2001-11-03 10:52:42 +00:00
{
2001-11-25 04:31:44 +00:00
GetFrameDimensionsFromFileName( m_sFilePath, &m_uFramesWide, &m_uFramesHigh );
2001-11-03 10:52:42 +00:00
///////////////////////////////////
// Fill in the m_FrameRects with the bounds of each frame in the animation.
///////////////////////////////////
2001-11-25 04:31:44 +00:00
for( UINT j=0; j<m_uFramesHigh; j++ ) // traverse along Y
2001-11-03 10:52:42 +00:00
{
2001-11-25 04:31:44 +00:00
for( UINT i=0; i<m_uFramesWide; i++ ) // traverse along X (important that this is the inner loop)
2001-11-03 10:52:42 +00:00
{
2001-11-25 04:31:44 +00:00
FRECT frect( (i+0)/(float)m_uFramesWide, // these will all be between 0.0 and 1.0
(j+0)/(float)m_uFramesHigh,
(i+1)/(float)m_uFramesWide,
(j+1)/(float)m_uFramesHigh );
m_TextureCoordRects.Add( frect ); // the index of this array element will be (i + j*m_uFramesWide)
2001-11-03 10:52:42 +00:00
2001-11-25 04:31:44 +00:00
//RageLog( "Adding frect%d %f %f %f %f", (i + j*m_uFramesWide), frect.left, frect.top, frect.right, frect.bottom );
2001-11-03 10:52:42 +00:00
}
}
}
#include "string.h"
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, UINT* puFramesWide, UINT* puFramesHigh ) const
2001-11-03 10:52:42 +00:00
{
2002-01-28 21:24:17 +00:00
*puFramesWide = *puFramesHigh = 1; // set default values in case we don't find the dimension in the file name
2001-12-28 10:15:59 +00:00
sPath.MakeLower();
CString sDir, sFName, sExt;
splitrelpath( sPath, sDir, sFName, sExt);
2002-01-28 21:24:17 +00:00
CStringArray arrayBits;
split( sFName, " ", arrayBits, false );
2001-12-28 10:15:59 +00:00
2002-01-28 21:24:17 +00:00
for( int i=0; i<arrayBits.GetSize(); i++ )
2001-12-28 10:15:59 +00:00
{
2002-01-28 21:24:17 +00:00
CString &sBit = arrayBits[ i ];
// Test to see if it looks like "%ux%u" (e.g. 16x8)
2001-12-28 10:15:59 +00:00
2002-01-28 21:24:17 +00:00
CStringArray arrayDimensionsBits;
split( sBit, "x", arrayDimensionsBits, false );
if( arrayDimensionsBits.GetSize() != 2 )
continue;
else if( !IsAnInt(arrayDimensionsBits[0]) || !IsAnInt(arrayDimensionsBits[1]) )
continue;
*puFramesWide = atoi(arrayDimensionsBits[0]);
*puFramesHigh = atoi(arrayDimensionsBits[1]);
2001-12-28 10:15:59 +00:00
return;
}
2001-11-03 10:52:42 +00:00
}