diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 56124739c9..cae7a61a5e 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -71,15 +71,12 @@ BitmapText::BitmapText() m_pFont = NULL; m_bRainbow = false; - m_bColored = false; m_iWrapWidthPixels = -1; m_fMaxWidth = 0; m_fMaxHeight = 0; SetShadowLength( 4 ); - - m_vColors.clear(); } BitmapText::~BitmapText() @@ -360,38 +357,6 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText, m_sText = sNewText; m_iWrapWidthPixels = iWrapWidthPixels; - //Split out color commands if text is colored. - if ( m_bColored ) - { - CString sEndText; - m_vColors.clear(); - - int i = m_sText.Find( "|c0", 0 ); - int last = 0; - while ( ( i > -1 ) && ( i < ( int( m_sText.length() ) - 9 ) ) ) - { - sEndText += m_sText.substr( last, i-last ); - ColorChange change; - int k; - sscanf( m_sText.substr( i+3, 2 ).c_str(), "%x", &k ); change.c.r = float( k ) / 255.0f; - sscanf( m_sText.substr( i+5, 2 ).c_str(), "%x", &k ); change.c.g = 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.l = sEndText.length(); - m_vColors.push_back( change ); - last = i+9; - if ( last < (int)m_sText.length() ) - i = m_sText.Find( CString("|c0"), last ); - else - i = -1; - } - - if ( last < (int)m_sText.length() ) - sEndText += m_sText.substr( last, m_sText.length()-last ); - - m_sText = sEndText; - } - // Break the string into lines. // @@ -473,9 +438,6 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText, //XXX: YUCK! This is horrible... but basically, in order to make sure we are //in sync with all of the color changes, we have to add bogus spaces at the end //of all lines. - if ( m_bColored ) - for ( unsigned int i = 0; i < m_wTextLines.size(); i++ ) - m_wTextLines[i] = CStringToWstring( WStringToCString( m_wTextLines[i] ) + CString( " " ) ); BuildChars(); UpdateBaseZoom(); @@ -645,25 +607,6 @@ void BitmapText::DrawPrimitives() color_index = (color_index+1)%NUM_RAINBOW_COLORS; } } - else if ( m_bColored ) - { - int loc = 0, cur = 0; - RageColor c = m_pTempState->diffuse[0]; - - for( unsigned i=0; i m_vColors[cur].l ) - { - c = m_vColors[cur].c; - cur++; - } - - for ( unsigned j=0; j<4; j++ ) - verts[i+j].c = c; - } - } else { for( unsigned i=0; i 8 ) ) + { + ColorChange change; + int k; + sscanf( m_sText.substr( i+3, 2 ).c_str(), "%x", &k ); change.c.r = float( k ) / 255.0f; + sscanf( m_sText.substr( i+5, 2 ).c_str(), "%x", &k ); change.c.g = 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.l = iGlyphsSoFar; + m_vColors.push_back( change ); + i+=8; + continue; + } + + CString curCStr = m_sText.substr( i, 1 ); + char curChar = curCStr.c_str()[0]; + int iCharLen = m_pFont->GetLineWidthInSourcePixels( CStringToWstring( curCStr ) ); + + switch ( curChar ) + { + case ' ': + if ( /*( iLineWidth == 0 ) &&*/ ( iWordWidth == 0 ) ) + break; + sCurrentLine += sCurrentWord + " "; + iLineWidth += iWordWidth + iCharLen; + sCurrentWord = ""; + iWordWidth = 0; + iGlyphsSoFar++; + break; + case '\n': + if ( iLineWidth + iWordWidth > iWrapWidthPixels ) + { + SimpleAddLine( sCurrentLine, iLineWidth ); + if ( iWordWidth > 0 ) + iLineWidth = iWordWidth + //Add the width of a space + m_pFont->GetLineWidthInSourcePixels( CStringToWstring( " " ) ); + sCurrentLine = sCurrentWord + " "; + iWordWidth = 0; + sCurrentWord = ""; + iGlyphsSoFar++; + } + else + { + SimpleAddLine( sCurrentLine + sCurrentWord, iLineWidth + iWordWidth ); + sCurrentLine = ""; iLineWidth = 0; + sCurrentWord = ""; iWordWidth = 0; + } + break; + default: + if ( ( iWordWidth + iCharLen > iWrapWidthPixels ) && ( iLineWidth == 0 ) ) + { + SimpleAddLine( sCurrentWord, iWordWidth ); + sCurrentWord = curChar; iWordWidth = iCharLen; + } + else if ( iWordWidth + iLineWidth + iCharLen > iWrapWidthPixels ) + { + SimpleAddLine( sCurrentLine, iLineWidth ); + sCurrentLine = ""; + iLineWidth = 0; + sCurrentWord += curChar; + iWordWidth += iCharLen; + } + else + { + sCurrentWord += curChar; + iWordWidth += iCharLen; + } + iGlyphsSoFar++; + break; + } + } + + if ( iWordWidth > 0 ) + { + sCurrentLine += sCurrentWord; + iLineWidth += iWordWidth; + } + + if ( iLineWidth > 0 ) + SimpleAddLine( sCurrentLine, iLineWidth ); + + BuildChars(); + UpdateBaseZoom(); +} + +void ColorBitmapText::SimpleAddLine( const CString &sAddition, const int iWidthPixels) +{ + m_wTextLines.push_back( CStringToWstring( sAddition ) ); + m_iLineWidths.push_back( iWidthPixels ); +} + +void ColorBitmapText::DrawPrimitives( ) +{ + Actor::SetGlobalRenderStates(); // set Actor-specified render states + DISPLAY->SetTextureModeModulate(); + + /* Draw if we're not fully transparent or the zbuffer is enabled */ + if( m_pTempState->diffuse[0].a != 0 ) + { + ////////////////////// + // render the shadow + ////////////////////// + if( m_fShadowLength != 0 ) + { + DISPLAY->PushMatrix(); + DISPLAY->TranslateWorld( m_fShadowLength, m_fShadowLength, 0 ); // shift by 5 units + + RageColor dim(0,0,0,0.5f*m_pTempState->diffuse[0].a); // semi-transparent black + + for( unsigned i=0; iPopMatrix(); + } + + ////////////////////// + // render the diffuse pass + ////////////////////// + int loc = 0, cur = 0; + RageColor c = m_pTempState->diffuse[0]; + + for( unsigned i=0; i m_vColors[cur].l ) + { + c = m_vColors[cur].c; + cur++; + } + for ( unsigned j=0; j<4; j++ ) + verts[i+j].c = c; + } + + DrawChars(); + } + + /* render the glow pass */ + if( m_pTempState->glow.a > 0.0001f ) + { + DISPLAY->SetTextureModeGlow(); + + for( unsigned i=0; iglow; + DrawChars(); + } + Actor::DrawPrimitives(); +} + /* - * (c) 2003-2004 Chris Danford + * (c) 2003-2004 Chris Danford, Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index f324761f32..a2fe8056d5 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -60,8 +60,6 @@ public: void GetLines( vector &wTextLines ) { wTextLines = m_wTextLines; } - void SetDynamicColor( bool coloration ) { m_bColored = coloration; } - CString GetText() const { return m_sText; } /* Return true if the string 's' will use an alternate string, if available. */ bool StringWillUseAlternate(const CString& sText, const CString& sAlternateText) const; @@ -86,14 +84,6 @@ protected: bool m_bRainbow; - bool m_bColored; - - struct ColorChange - { - RageColor c; //Color to change to - int l; //Change Location - }; - vector m_vColors; vector verts; vector tex; @@ -103,11 +93,29 @@ protected: void UpdateBaseZoom(); }; +class ColorBitmapText : public BitmapText +{ +public: + ColorBitmapText(); +// virtual ~ColorBitmapText(); + void SetText( const CString &sText, const CString &sAlternateText = "", int iWrapWidthPixels = -1 ); + void DrawPrimitives( ); + void SetMaxLines( int iLines, bool bCutBottom = true ); //if bCutBottom = false then, it will crop the top + void SimpleAddLine ( const CString &sAddition, int iWidthPixels ); +protected: + struct ColorChange + { + RageColor c; //Color to change to + int l; //Change Location + }; + vector m_vColors; +}; + #endif /* - * (c) 2001-2004 Chris Danford + * (c) 2001-2004 Chris Danford, Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a diff --git a/stepmania/src/ScreenNetSelectBase.cpp b/stepmania/src/ScreenNetSelectBase.cpp index ffbcfe2f4f..5d7a401f47 100644 --- a/stepmania/src/ScreenNetSelectBase.cpp +++ b/stepmania/src/ScreenNetSelectBase.cpp @@ -55,7 +55,6 @@ void ScreenNetSelectBase::Init() this->AddChild( &m_sprChatOutputBox ); m_textChatInput.LoadFromFont( THEME->GetPathF(m_sName,"chat") ); - m_textChatInput.SetDynamicColor( true ); m_textChatInput.SetHorizAlign( align_left ); m_textChatInput.SetVertAlign( align_top ); m_textChatInput.SetShadowLength( 0 ); @@ -66,7 +65,6 @@ void ScreenNetSelectBase::Init() m_textChatOutput.LoadFromFont( THEME->GetPathF(m_sName,"chat") ); m_textChatOutput.SetWrapWidthPixels( (int)(CHATOUTPUT_WIDTH * 2) ); - m_textChatOutput.SetDynamicColor( true ); m_textChatOutput.SetHorizAlign( align_left ); m_textChatOutput.SetVertAlign( align_bottom ); m_textChatOutput.SetShadowLength( 0 ); diff --git a/stepmania/src/ScreenNetSelectBase.h b/stepmania/src/ScreenNetSelectBase.h index a833d35bc7..8650a36a1a 100644 --- a/stepmania/src/ScreenNetSelectBase.h +++ b/stepmania/src/ScreenNetSelectBase.h @@ -24,8 +24,8 @@ public: void UpdateTextInput(); private: //Chatting - BitmapText m_textChatInput; - BitmapText m_textChatOutput; + ColorBitmapText m_textChatInput; + ColorBitmapText m_textChatOutput; Sprite m_sprChatInputBox; Sprite m_sprChatOutputBox; CString m_sTextInput;