FEATURE: Allow BitmapTexts to on-the-fly change color mid-text depending on the text

This feature can be used by enabling the coloration by using the .SetDynamicColor( true )
function.  Once this is done, the syntax for color changing is: |c0RRGGBB where RR = red
in hex, GG = green in hex and BB = blue in hex.  |c0 is the token to note the
beginning of a text change.  This was discussed on the StepMania development
list.
This commit is contained in:
Charles Lohr
2005-05-03 03:37:52 +00:00
parent b6944ab340
commit 348c6f6f5a
3 changed files with 76 additions and 0 deletions
+63
View File
@@ -77,6 +77,8 @@ BitmapText::BitmapText()
m_fMaxHeight = 0;
SetShadowLength( 4 );
m_vColors.clear();
}
BitmapText::~BitmapText()
@@ -143,6 +145,8 @@ bool BitmapText::LoadFromFont( const CString& sFontFilePath )
BuildChars();
m_bColored = false;
return true;
}
@@ -207,6 +211,7 @@ void BitmapText::BuildChars()
for( unsigned i=0; i<m_wTextLines.size(); i++ ) // foreach line
{
iY += m_pFont->GetHeight();
const wstring &szLine = m_wTextLines[i];
const int iLineWidth = m_iLineWidths[i];
@@ -356,9 +361,41 @@ 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 < m_sText.length() )
i = m_sText.Find( CString("|c0"), last );
else
i = -1;
}
if ( last < m_sText.length() )
sEndText += m_sText.substr( last, m_sText.length()-last );
m_sText = sEndText;
}
// Break the string into lines.
//
m_wTextLines.clear();
if( iWrapWidthPixels == -1 )
@@ -434,6 +471,13 @@ 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();
}
@@ -602,6 +646,25 @@ 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<verts.size(); i+=4 )
{
loc++;
if ( cur < m_vColors.size() )
if ( loc > 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<verts.size(); i+=4 )
+10
View File
@@ -59,6 +59,8 @@ public:
void GetLines( vector<wstring> &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;
@@ -83,6 +85,14 @@ protected:
bool m_bRainbow;
bool m_bColored;
struct ColorChange
{
RageColor c; //Color to change to
int l; //Change Location
};
vector<ColorChange> m_vColors;
vector<RageSpriteVertex> verts;
vector<RageTexture *> tex;
+3
View File
@@ -55,6 +55,7 @@ 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 );
@@ -67,6 +68,7 @@ void ScreenNetSelectBase::Init()
m_textOutHidden.SetWrapWidthPixels( (int)(CHATOUTPUT_WIDTH * 2) );
m_textChatOutput.LoadFromFont( THEME->GetPathF(m_sName,"chat") );
m_textChatOutput.SetDynamicColor( true );
m_textChatOutput.SetHorizAlign( align_left );
m_textChatOutput.SetVertAlign( align_bottom );
m_textChatOutput.SetShadowLength( 0 );
@@ -75,6 +77,7 @@ void ScreenNetSelectBase::Init()
this->AddChild( &m_textChatOutput );
//Display updated chat (maybe this should be a function)?
m_textOutHidden.SetDynamicColor( false );
m_textOutHidden.SetText( NSMAN->m_sChatText );
vector <wstring> wLines;
m_textOutHidden.GetLines( wLines );