cleanup. (hate this fade logic ...)

This commit is contained in:
Glenn Maynard
2005-08-25 00:47:10 +00:00
parent b4482a42a7
commit a774629f4e
+49 -47
View File
@@ -280,18 +280,18 @@ void BitmapText::DrawChars()
/* We fade from 0 to LeftColor, then from RightColor to 0. (We won't fade all the way to /* We fade from 0 to LeftColor, then from RightColor to 0. (We won't fade all the way to
* 0 if the crop is beyond the outer edge.) */ * 0 if the crop is beyond the outer edge.) */
const float RightAlpha = SCALE( FadeSize.right, FadeDist.right, 0, 1, 0 ); const float fRightAlpha = SCALE( FadeSize.right, FadeDist.right, 0, 1, 0 );
const float LeftAlpha = SCALE( FadeSize.left, FadeDist.left, 0, 1, 0 ); const float fLeftAlpha = SCALE( FadeSize.left, FadeDist.left, 0, 1, 0 );
const float StartFadeLeftPercent = m_pTempState->crop.left; const float fStartFadeLeftPercent = m_pTempState->crop.left;
const float StopFadeLeftPercent = m_pTempState->crop.left + FadeSize.left; const float fStopFadeLeftPercent = m_pTempState->crop.left + FadeSize.left;
const float fLeftFadeStartGlyph = SCALE( StartFadeLeftPercent, 0.f, 1.f, 0, (float) iNumGlyphs ); const float fLeftFadeStartGlyph = SCALE( fStartFadeLeftPercent, 0.f, 1.f, 0, (float) iNumGlyphs );
const float fLeftFadeStopGlyph = SCALE( StopFadeLeftPercent, 0.f, 1.f, 0, (float) iNumGlyphs ); const float fLeftFadeStopGlyph = SCALE( fStopFadeLeftPercent, 0.f, 1.f, 0, (float) iNumGlyphs );
const float StartFadeRightPercent = 1-(m_pTempState->crop.right + FadeSize.right); const float fStartFadeRightPercent = 1-(m_pTempState->crop.right + FadeSize.right);
const float StopFadeRightPercent = 1-(m_pTempState->crop.right); const float fStopFadeRightPercent = 1-(m_pTempState->crop.right);
const float fRightFadeStartGlyph = SCALE( StartFadeRightPercent, 0.f, 1.f, 0, (float) iNumGlyphs ); const float fRightFadeStartGlyph = SCALE( fStartFadeRightPercent, 0.f, 1.f, 0, (float) iNumGlyphs );
const float fRightFadeStopGlyph = SCALE( StopFadeRightPercent, 0.f, 1.f, 0, (float) iNumGlyphs ); const float fRightFadeStopGlyph = SCALE( fStopFadeRightPercent, 0.f, 1.f, 0, (float) iNumGlyphs );
for( int start = iStartGlyph; start < iEndGlyph; ++start ) for( int start = iStartGlyph; start < iEndGlyph; ++start )
{ {
@@ -303,14 +303,14 @@ void BitmapText::DrawChars()
/* Add .5, so we fade wrt. the center of the vert, not the left side. */ /* Add .5, so we fade wrt. the center of the vert, not the left side. */
float fPercent = SCALE( start+0.5f, fLeftFadeStartGlyph, fLeftFadeStopGlyph, 0.0f, 1.0f ); float fPercent = SCALE( start+0.5f, fLeftFadeStartGlyph, fLeftFadeStopGlyph, 0.0f, 1.0f );
fPercent = clamp( fPercent, 0.0f, 1.0f ); fPercent = clamp( fPercent, 0.0f, 1.0f );
fAlpha *= fPercent * LeftAlpha; fAlpha *= fPercent * fLeftAlpha;
} }
if( FadeSize.right > 0.001f ) if( FadeSize.right > 0.001f )
{ {
float fPercent = SCALE( start+0.5f, fRightFadeStartGlyph, fRightFadeStopGlyph, 1.0f, 0.0f ); float fPercent = SCALE( start+0.5f, fRightFadeStartGlyph, fRightFadeStopGlyph, 1.0f, 0.0f );
fPercent = clamp( fPercent, 0.0f, 1.0f ); fPercent = clamp( fPercent, 0.0f, 1.0f );
fAlpha *= fPercent * RightAlpha; fAlpha *= fPercent * fRightAlpha;
} }
for( int j = 0; j < 4; ++j ) for( int j = 0; j < 4; ++j )
@@ -510,9 +510,9 @@ void BitmapText::DrawPrimitives()
/* Draw if we're not fully transparent or the zbuffer is enabled */ /* Draw if we're not fully transparent or the zbuffer is enabled */
if( m_pTempState->diffuse[0].a != 0 ) if( m_pTempState->diffuse[0].a != 0 )
{ {
////////////////////// //
// render the shadow // render the shadow
////////////////////// //
if( m_fShadowLength != 0 ) if( m_fShadowLength != 0 )
{ {
DISPLAY->PushMatrix(); DISPLAY->PushMatrix();
@@ -527,9 +527,9 @@ void BitmapText::DrawPrimitives()
DISPLAY->PopMatrix(); DISPLAY->PopMatrix();
} }
////////////////////// //
// render the diffuse pass // render the diffuse pass
////////////////////// //
if( m_bRainbow ) if( m_bRainbow )
{ {
int color_index = int(RageTimer::GetTimeSinceStartFast() / 0.200) % NUM_RAINBOW_COLORS; int color_index = int(RageTimer::GetTimeSinceStartFast() / 0.200) % NUM_RAINBOW_COLORS;
@@ -611,7 +611,7 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
m_sText = sNewText; m_sText = sNewText;
m_iWrapWidthPixels = iWrapWidthPixels; m_iWrapWidthPixels = iWrapWidthPixels;
//Set up the first color. // Set up the first color.
m_vColors.clear(); m_vColors.clear();
ColorChange change; ColorChange change;
change.c = RageColor ( 1, 1, 1, 1 ); change.c = RageColor ( 1, 1, 1, 1 );
@@ -627,14 +627,14 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
int iWordWidth = 0; int iWordWidth = 0;
int iGlyphsSoFar = 0; int iGlyphsSoFar = 0;
for ( unsigned i = 0; i < m_sText.length(); i++ ) for( unsigned i = 0; i < m_sText.length(); i++ )
{ {
int iCharsLeft = m_sText.length() - i - 1; int iCharsLeft = m_sText.length() - i - 1;
//First: Check for the special (color) case. // First: Check for the special (color) case.
CString FirstThree = m_sText.substr( i, 3 ); CString FirstThree = m_sText.substr( i, 3 );
if ( ( FirstThree.CompareNoCase( "|c0" ) == 0 ) && ( iCharsLeft > 8 ) ) if( FirstThree.CompareNoCase("|c0") == 0 && iCharsLeft > 8 )
{ {
ColorChange change; ColorChange change;
int k; int k;
@@ -643,7 +643,7 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
sscanf( m_sText.substr( i+7, 2 ).c_str(), "%x", &k ); change.c.b = float( k ) / 255.0f; sscanf( m_sText.substr( i+7, 2 ).c_str(), "%x", &k ); change.c.b = float( k ) / 255.0f;
change.c.a = 1; change.c.a = 1;
change.l = iGlyphsSoFar; change.l = iGlyphsSoFar;
if ( iGlyphsSoFar == 0 ) if( iGlyphsSoFar == 0 )
m_vColors[0] = change; m_vColors[0] = change;
else else
m_vColors.push_back( change ); m_vColors.push_back( change );
@@ -655,10 +655,10 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
char curChar = curCStr.c_str()[0]; char curChar = curCStr.c_str()[0];
int iCharLen = m_pFont->GetLineWidthInSourcePixels( CStringToWstring( curCStr ) ); int iCharLen = m_pFont->GetLineWidthInSourcePixels( CStringToWstring( curCStr ) );
switch ( curChar ) switch( curChar )
{ {
case ' ': case ' ':
if ( /*( iLineWidth == 0 ) &&*/ ( iWordWidth == 0 ) ) if( /* iLineWidth == 0 &&*/ iWordWidth == 0 )
break; break;
sCurrentLine += sCurrentWord + " "; sCurrentLine += sCurrentWord + " ";
iLineWidth += iWordWidth + iCharLen; iLineWidth += iWordWidth + iCharLen;
@@ -667,12 +667,12 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
iGlyphsSoFar++; iGlyphsSoFar++;
break; break;
case '\n': case '\n':
if ( iLineWidth + iWordWidth > iWrapWidthPixels ) if( iLineWidth + iWordWidth > iWrapWidthPixels )
{ {
SimpleAddLine( sCurrentLine, iLineWidth ); SimpleAddLine( sCurrentLine, iLineWidth );
if ( iWordWidth > 0 ) if( iWordWidth > 0 )
iLineWidth = iWordWidth + //Add the width of a space iLineWidth = iWordWidth + //Add the width of a space
m_pFont->GetLineWidthInSourcePixels( CStringToWstring( " " ) ); m_pFont->GetLineWidthInSourcePixels( CStringToWstring( " " ) );
sCurrentLine = sCurrentWord + " "; sCurrentLine = sCurrentWord + " ";
iWordWidth = 0; iWordWidth = 0;
sCurrentWord = ""; sCurrentWord = "";
@@ -686,12 +686,12 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
} }
break; break;
default: default:
if ( ( iWordWidth + iCharLen > iWrapWidthPixels ) && ( iLineWidth == 0 ) ) if( iWordWidth + iCharLen > iWrapWidthPixels && iLineWidth == 0 )
{ {
SimpleAddLine( sCurrentWord, iWordWidth ); SimpleAddLine( sCurrentWord, iWordWidth );
sCurrentWord = curChar; iWordWidth = iCharLen; sCurrentWord = curChar; iWordWidth = iCharLen;
} }
else if ( iWordWidth + iLineWidth + iCharLen > iWrapWidthPixels ) else if( iWordWidth + iLineWidth + iCharLen > iWrapWidthPixels )
{ {
SimpleAddLine( sCurrentLine, iLineWidth ); SimpleAddLine( sCurrentLine, iLineWidth );
sCurrentLine = ""; sCurrentLine = "";
@@ -709,13 +709,13 @@ void ColorBitmapText::SetText( const CString& _sText, const CString& _sAlternate
} }
} }
if ( iWordWidth > 0 ) if( iWordWidth > 0 )
{ {
sCurrentLine += sCurrentWord; sCurrentLine += sCurrentWord;
iLineWidth += iWordWidth; iLineWidth += iWordWidth;
} }
if ( iLineWidth > 0 ) if( iLineWidth > 0 )
SimpleAddLine( sCurrentLine, iLineWidth ); SimpleAddLine( sCurrentLine, iLineWidth );
BuildChars(); BuildChars();
@@ -736,9 +736,9 @@ void ColorBitmapText::DrawPrimitives( )
/* Draw if we're not fully transparent or the zbuffer is enabled */ /* Draw if we're not fully transparent or the zbuffer is enabled */
if( m_pTempState->diffuse[0].a != 0 ) if( m_pTempState->diffuse[0].a != 0 )
{ {
////////////////////// //
// render the shadow // render the shadow
////////////////////// //
if( m_fShadowLength != 0 ) if( m_fShadowLength != 0 )
{ {
DISPLAY->PushMatrix(); DISPLAY->PushMatrix();
@@ -753,22 +753,24 @@ void ColorBitmapText::DrawPrimitives( )
DISPLAY->PopMatrix(); DISPLAY->PopMatrix();
} }
////////////////////// //
// render the diffuse pass // render the diffuse pass
////////////////////// //
int loc = 0, cur = 0; int loc = 0, cur = 0;
RageColor c = m_pTempState->diffuse[0]; RageColor c = m_pTempState->diffuse[0];
for( unsigned i=0; i<m_aVertices.size(); i+=4 ) for( unsigned i=0; i<m_aVertices.size(); i+=4 )
{ {
loc++; loc++;
if ( cur < (int)m_vColors.size() ) if( cur < (int)m_vColors.size() )
{
if ( loc > m_vColors[cur].l ) if ( loc > m_vColors[cur].l )
{ {
c = m_vColors[cur].c; c = m_vColors[cur].c;
cur++; cur++;
} }
for ( unsigned j=0; j<4; j++ ) }
for( unsigned j=0; j<4; j++ )
m_aVertices[i+j].c = c; m_aVertices[i+j].c = c;
} }
@@ -799,21 +801,21 @@ void ColorBitmapText::SetMaxLines( int iNumLines, int iDirection )
} }
else else
{ {
//Because colors are relative to the beginning, we have to crop them back // Because colors are relative to the beginning, we have to crop them back
unsigned shift = 0; unsigned shift = 0;
for ( unsigned i = 0; i < m_wTextLines.size() - iNumLines; i++ ) for( unsigned i = 0; i < m_wTextLines.size() - iNumLines; i++ )
shift += m_wTextLines[i].length(); shift += m_wTextLines[i].length();
//When we're cutting out text, we need to maintain the last // When we're cutting out text, we need to maintain the last
//color, so our text at the top doesn't become colorless. // color, so our text at the top doesn't become colorless.
RageColor LastColor; RageColor LastColor;
for ( unsigned i = 0; i < m_vColors.size(); i++ ) for( unsigned i = 0; i < m_vColors.size(); i++ )
{ {
m_vColors[i].l -= shift; m_vColors[i].l -= shift;
if ( m_vColors[i].l < 0 ) if( m_vColors[i].l < 0 )
{ {
LastColor = m_vColors[i].c; LastColor = m_vColors[i].c;
m_vColors.erase( m_vColors.begin() + i ); m_vColors.erase( m_vColors.begin() + i );
@@ -821,9 +823,9 @@ void ColorBitmapText::SetMaxLines( int iNumLines, int iDirection )
} }
} }
//If we already have a color set for the first char // If we already have a color set for the first char
//do not override it. // do not override it.
if ( ( m_vColors.size() > 0 ) && ( m_vColors[0].l > 0 ) ) if( m_vColors.size() > 0 && m_vColors[0].l > 0 )
{ {
ColorChange tmp; ColorChange tmp;
tmp.c = LastColor; tmp.c = LastColor;