remove operator= and use more standard copy constructor, add stroke texture support

This commit is contained in:
Chris Danford
2008-02-15 09:31:54 +00:00
parent 456faed1b7
commit 95dad9ff4b
2 changed files with 41 additions and 21 deletions
+33 -18
View File
@@ -54,6 +54,8 @@ BitmapText::BitmapText()
m_iVertSpacing = 0; m_iVertSpacing = 0;
m_bHasGlowAttribute = false; m_bHasGlowAttribute = false;
m_StrokeColor = RageColor(1,1,1,1);
SetShadowLength( 4 ); SetShadowLength( 4 );
} }
@@ -67,11 +69,7 @@ BitmapText::BitmapText( const BitmapText &cpy ):
Actor( cpy ) Actor( cpy )
{ {
m_pFont = NULL; m_pFont = NULL;
*this = cpy;
}
BitmapText &BitmapText::operator =( const BitmapText &cpy )
{
#define CPY(a) a = cpy.a #define CPY(a) a = cpy.a
CPY( m_sText ); CPY( m_sText );
CPY( m_wTextLines ); CPY( m_wTextLines );
@@ -83,9 +81,10 @@ BitmapText &BitmapText::operator =( const BitmapText &cpy )
CPY( m_bJitter ); CPY( m_bJitter );
CPY( m_iVertSpacing ); CPY( m_iVertSpacing );
CPY( m_aVertices ); CPY( m_aVertices );
CPY( m_pTextures ); CPY( m_vpFontPageTextures );
CPY( m_bHasGlowAttribute );
CPY( m_mAttributes ); CPY( m_mAttributes );
CPY( m_bHasGlowAttribute );
CPY( m_StrokeColor );
#undef CPY #undef CPY
if( m_pFont ) if( m_pFont )
@@ -95,8 +94,6 @@ BitmapText &BitmapText::operator =( const BitmapText &cpy )
m_pFont = FONT->CopyFont( cpy.m_pFont ); m_pFont = FONT->CopyFont( cpy.m_pFont );
else else
m_pFont = NULL; m_pFont = NULL;
return *this;
} }
void BitmapText::LoadFromNode( const XNode* pNode ) void BitmapText::LoadFromNode( const XNode* pNode )
@@ -181,7 +178,7 @@ void BitmapText::BuildChars()
m_size.x = QuantizeUp( m_size.x, 2.0f ); m_size.x = QuantizeUp( m_size.x, 2.0f );
m_aVertices.clear(); m_aVertices.clear();
m_pTextures.clear(); m_vpFontPageTextures.clear();
if( m_wTextLines.empty() ) if( m_wTextLines.empty() )
return; return;
@@ -234,7 +231,7 @@ void BitmapText::BuildChars()
v[3].t = RageVector2( g.m_TexRect.right, g.m_TexRect.top ); v[3].t = RageVector2( g.m_TexRect.right, g.m_TexRect.top );
m_aVertices.insert( m_aVertices.end(), &v[0], &v[4] ); m_aVertices.insert( m_aVertices.end(), &v[0], &v[4] );
m_pTextures.push_back( g.GetTexture() ); m_vpFontPageTextures.push_back( g.GetFontPageTextures() );
} }
/* The amount of padding a line needs: */ /* The amount of padding a line needs: */
@@ -242,14 +239,14 @@ void BitmapText::BuildChars()
} }
} }
void BitmapText::DrawChars() void BitmapText::DrawChars( bool bUseStrokeTexture )
{ {
// bail if cropped all the way // bail if cropped all the way
if( m_pTempState->crop.left + m_pTempState->crop.right >= 1 || if( m_pTempState->crop.left + m_pTempState->crop.right >= 1 ||
m_pTempState->crop.top + m_pTempState->crop.bottom >= 1 ) m_pTempState->crop.top + m_pTempState->crop.bottom >= 1 )
return; return;
const int iNumGlyphs = m_pTextures.size(); const int iNumGlyphs = m_vpFontPageTextures.size();
int iStartGlyph = lrintf( SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) iNumGlyphs ) ); int iStartGlyph = lrintf( SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) iNumGlyphs ) );
int iEndGlyph = lrintf( SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) iNumGlyphs, 0 ) ); int iEndGlyph = lrintf( SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) iNumGlyphs, 0 ) );
iStartGlyph = clamp( iStartGlyph, 0, iNumGlyphs ); iStartGlyph = clamp( iStartGlyph, 0, iNumGlyphs );
@@ -319,10 +316,13 @@ void BitmapText::DrawChars()
for( int start = iStartGlyph; start < iEndGlyph; ) for( int start = iStartGlyph; start < iEndGlyph; )
{ {
int end = start; int end = start;
while( end < iEndGlyph && m_pTextures[end] == m_pTextures[start] ) while( end < iEndGlyph && m_vpFontPageTextures[end] == m_vpFontPageTextures[start] )
end++; end++;
DISPLAY->ClearAllTextures(); DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( TextureUnit_1, m_pTextures[start]->GetTexHandle() ); if( bUseStrokeTexture && m_vpFontPageTextures[start]->m_pTextureStroke )
DISPLAY->SetTexture( TextureUnit_1, m_vpFontPageTextures[start]->m_pTextureStroke->GetTexHandle() );
else
DISPLAY->SetTexture( TextureUnit_1, m_vpFontPageTextures[start]->m_pTextureMain->GetTexHandle() );
/* Don't bother setting texture render states for text. We never go outside of 0..1. /* /* Don't bother setting texture render states for text. We never go outside of 0..1. /*
/* We should call SetTextureRenderStates because it does more than just setting /* We should call SetTextureRenderStates because it does more than just setting
@@ -531,17 +531,30 @@ void BitmapText::DrawPrimitives()
if( m_fShadowLengthX != 0 || m_fShadowLengthY != 0 ) if( m_fShadowLengthX != 0 || m_fShadowLengthY != 0 )
{ {
DISPLAY->PushMatrix(); DISPLAY->PushMatrix();
DISPLAY->TranslateWorld( m_fShadowLengthX, m_fShadowLengthY, 0 ); // shift by 5 units DISPLAY->TranslateWorld( m_fShadowLengthX, m_fShadowLengthY, 0 );
RageColor c = m_ShadowColor; RageColor c = m_ShadowColor;
c.a *= m_pTempState->diffuse[0].a; c.a *= m_pTempState->diffuse[0].a;
for( unsigned i=0; i<m_aVertices.size(); i++ ) for( unsigned i=0; i<m_aVertices.size(); i++ )
m_aVertices[i].c = c; m_aVertices[i].c = c;
DrawChars(); DrawChars( false );
DISPLAY->PopMatrix(); DISPLAY->PopMatrix();
} }
//
// render the stroke
//
bool bUsingStrokeTexture = !!m_vpFontPageTextures[0]->m_pTextureStroke;
if( bUsingStrokeTexture && m_StrokeColor.a > 0 )
{
RageColor c = m_StrokeColor;
c.a *= m_pTempState->diffuse[0].a;
for( unsigned i=0; i<m_aVertices.size(); i++ )
m_aVertices[i].c = c;
DrawChars( true );
}
// //
// render the diffuse pass // render the diffuse pass
// //
@@ -612,7 +625,7 @@ void BitmapText::DrawPrimitives()
} }
} }
DrawChars(); DrawChars( false );
// undo jitter to verts // undo jitter to verts
if( m_bJitter ) if( m_bJitter )
@@ -657,7 +670,7 @@ void BitmapText::DrawPrimitives()
for( ; i < iEnd; ++i ) for( ; i < iEnd; ++i )
m_aVertices[i].c = attr.glow; m_aVertices[i].c = attr.glow;
} }
DrawChars(); DrawChars( false );
} }
} }
@@ -798,6 +811,7 @@ public:
return 0; return 0;
} }
static int ClearAttributes( T* p, lua_State *L ) { p->ClearAttributes(); return 0; } static int ClearAttributes( T* p, lua_State *L ) { p->ClearAttributes(); return 0; }
static int strokecolor( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetStrokeColor( c ); return 0; }
LunaBitmapText() LunaBitmapText()
{ {
@@ -811,6 +825,7 @@ public:
ADD_METHOD( GetText ); ADD_METHOD( GetText );
ADD_METHOD( AddAttribute ); ADD_METHOD( AddAttribute );
ADD_METHOD( ClearAttributes ); ADD_METHOD( ClearAttributes );
ADD_METHOD( strokecolor );
} }
}; };
+8 -3
View File
@@ -8,13 +8,13 @@
class RageTexture; class RageTexture;
class Font; class Font;
struct FontPageTextures;
class BitmapText : public Actor class BitmapText : public Actor
{ {
public: public:
BitmapText(); BitmapText();
BitmapText( const BitmapText &cpy ); BitmapText( const BitmapText &cpy );
BitmapText &operator =( const BitmapText &cpy );
virtual ~BitmapText(); virtual ~BitmapText();
virtual void LoadFromNode( const XNode* pNode ); virtual void LoadFromNode( const XNode* pNode );
@@ -37,6 +37,8 @@ public:
void SetHorizAlign( float f ); void SetHorizAlign( float f );
void SetStrokeColor( RageColor c ) { m_StrokeColor = c; }
void GetLines( vector<wstring> &wTextLines ) const { wTextLines = m_wTextLines; } void GetLines( vector<wstring> &wTextLines ) const { wTextLines = m_wTextLines; }
const vector<wstring> &GetLines() const { return m_wTextLines; } const vector<wstring> &GetLines() const { return m_wTextLines; }
@@ -76,13 +78,16 @@ protected:
int m_iVertSpacing; int m_iVertSpacing;
vector<RageSpriteVertex> m_aVertices; vector<RageSpriteVertex> m_aVertices;
vector<RageTexture *> m_pTextures;
vector<FontPageTextures*> m_vpFontPageTextures;
map<size_t, Attribute> m_mAttributes; map<size_t, Attribute> m_mAttributes;
bool m_bHasGlowAttribute; bool m_bHasGlowAttribute;
RageColor m_StrokeColor;
// recalculate the items in SetText() // recalculate the items in SetText()
void BuildChars(); void BuildChars();
void DrawChars(); void DrawChars( bool bUseStrokeTexture );
void UpdateBaseZoom(); void UpdateBaseZoom();
private: private: