Files
itgmania212121/stepmania/src/RageTexture.cpp
T

106 lines
3.1 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.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
-----------------------------------------------------------------------------
*/
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "RageTexture.h"
#include "RageUtil.h"
2002-05-27 18:36:01 +00:00
#include <string.h>
2001-11-03 10:52:42 +00:00
2001-11-03 10:52:42 +00:00
//-----------------------------------------------------------------------------
// RageTexture constructor
//-----------------------------------------------------------------------------
RageTexture::RageTexture( CString sFilePath, RageTexturePrefs prefs )
2001-11-03 10:52:42 +00:00
{
// LOG->Trace( "RageTexture::RageTexture()" );
2001-11-03 10:52:42 +00:00
m_sFilePath = sFilePath;
m_prefs = prefs;
2001-11-03 10:52:42 +00:00
m_iRefCount = 1;
m_iSourceWidth = m_iSourceHeight = 0;
m_iTextureWidth = m_iTextureHeight = 0;
m_iImageWidth = m_iImageHeight = 0;
m_iFramesWide = m_iFramesHigh = 0;
2001-11-03 10:52:42 +00:00
}
RageTexture::~RageTexture()
{
}
void RageTexture::CreateFrameRects()
2001-11-03 10:52:42 +00:00
{
GetFrameDimensionsFromFileName( m_sFilePath, &m_iFramesWide, &m_iFramesHigh );
2001-11-25 04:31:44 +00:00
2001-11-03 10:52:42 +00:00
///////////////////////////////////
// Fill in the m_FrameRects with the bounds of each frame in the animation.
///////////////////////////////////
2002-10-24 20:15:24 +00:00
m_TextureCoordRects.clear();
2002-05-28 20:01:22 +00:00
for( int j=0; j<m_iFramesHigh; j++ ) // traverse along Y
2001-11-03 10:52:42 +00:00
{
for( int i=0; i<m_iFramesWide; i++ ) // traverse along X (important that this is the inner loop)
2001-11-03 10:52:42 +00:00
{
2002-10-31 06:00:30 +00:00
RectF frect( (i+0)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth, // these will all be between 0.0 and 1.0
(j+0)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight,
(i+1)/(float)m_iFramesWide*m_iImageWidth /(float)m_iTextureWidth,
(j+1)/(float)m_iFramesHigh*m_iImageHeight/(float)m_iTextureHeight );
2002-10-31 04:23:39 +00:00
m_TextureCoordRects.push_back( frect ); // the index of this array element will be (i + j*m_iFramesWide)
2001-11-03 10:52:42 +00:00
//LOG->Trace( "Adding frect%d %f %f %f %f", (i + j*m_iFramesWide), frect.left, frect.top, frect.right, frect.bottom );
2001-11-03 10:52:42 +00:00
}
}
}
void RageTexture::GetFrameDimensionsFromFileName( CString sPath, int* piFramesWide, int* piFramesHigh ) const
2001-11-03 10:52:42 +00:00
{
*piFramesWide = *piFramesHigh = 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
for( unsigned i=0; i<arrayBits.size(); i++ )
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 );
2001-12-28 10:15:59 +00:00
if( arrayDimensionsBits.size() != 2 )
2002-01-28 21:24:17 +00:00
continue;
else if( !IsAnInt(arrayDimensionsBits[0]) || !IsAnInt(arrayDimensionsBits[1]) )
continue;
2001-12-28 10:15:59 +00:00
*piFramesWide = atoi(arrayDimensionsBits[0]);
*piFramesHigh = atoi(arrayDimensionsBits[1]);
2001-12-28 10:15:59 +00:00
return;
}
2002-05-27 08:23:27 +00:00
}
const RectF *RageTexture::GetTextureCoordRect( int frameNo ) const
{
return &m_TextureCoordRects[frameNo];
}