Fix: Don't let BitmapText spill outside it's wrap area. Is this a good way to do it? anyone have a better idea?

This commit is contained in:
Charles Lohr
2005-04-19 02:14:43 +00:00
parent 814878efba
commit 3b84c9024b
3 changed files with 61 additions and 6 deletions
+58 -4
View File
@@ -409,12 +409,28 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText,
}
else
{
m_wTextLines.push_back( CStringToWstring(sCurLine) );
sCurLine = sWord;
iCurLineWidth = iWidthWord;
AddLine( sCurLine, iCurLineWidth );
if ( sCurLine.length() != 0 )
{
sCurLine += " " + sWord;
iCurLineWidth += iWidthWord;
}
else
{
sCurLine = sWord;
iCurLineWidth = iWidthWord;
}
}
}
m_wTextLines.push_back( CStringToWstring(sCurLine) );
int LastWidth = iCurLineWidth;
while ( sCurLine.length() > 0 )
{
AddLine( sCurLine, iCurLineWidth );
if ( LastWidth < iCurLineWidth )
break; //Something's wrong (infinite loop)
else
LastWidth = iCurLineWidth;
}
}
}
@@ -422,6 +438,44 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText,
UpdateBaseZoom();
}
/* This will get called only if the sAddition is already somewhat
broken down into lines. This is in place only to handle single
words that are too wide for the line. */
void BitmapText::AddLine( CString &sAddition, int & iWidthPixels )
{
if ( ( iWidthPixels < m_iWrapWidthPixels ) || ( sAddition.length() == 0 ) )
{
m_wTextLines.push_back( CStringToWstring( sAddition ) );
sAddition = "";
iWidthPixels = 0;
}
else
{
CString sCurrentLine;
int iCurrentLineWidth;
for ( unsigned i = 0; i < sAddition.length(); i++ )
{
CString sCurrentChar = sAddition.substr( i, 1 );
int iCurrentCharWidth = m_pFont->GetLineWidthInSourcePixels( CStringToWstring( sCurrentChar ) );
if ( iCurrentLineWidth + iCurrentCharWidth > m_iWrapWidthPixels )
{
if ( sCurrentLine.length() != 0 )
m_wTextLines.push_back( CStringToWstring( sCurrentLine ) );
sCurrentLine = sCurrentChar;
iCurrentLineWidth = iCurrentCharWidth;
}
else
{
sCurrentLine += sCurrentChar;
iCurrentLineWidth += iCurrentCharWidth;
}
}
sAddition = sCurrentLine;
iWidthPixels = iCurrentLineWidth;
}
}
void BitmapText::SetMaxWidth( float fMaxWidth )
{
m_fMaxWidth = fMaxWidth;
+1
View File
@@ -86,6 +86,7 @@ protected:
vector<RageSpriteVertex> verts;
vector<RageTexture *> tex;
void AddLine( CString & sAddition, int & iWidthPixels );
void BuildChars();
void DrawChars();
void UpdateBaseZoom();
+2 -2
View File
@@ -79,7 +79,7 @@ void ScreenNetSelectBase::Init()
vector <wstring> wLines;
m_textOutHidden.GetLines( wLines );
m_actualText = "";
for (unsigned i = max(int(wLines.size()) - SHOW_CHAT_LINES, 0 ) ; i < wLines.size() ; ++i)
for (unsigned i = max(int(wLines.size()) - SHOW_CHAT_LINES + 1, 0 ) ; i < wLines.size() ; ++i)
m_actualText += WStringToCString( wLines[i] )+'\n';
m_textChatOutput.SetText( m_actualText );
@@ -201,7 +201,7 @@ void ScreenNetSelectBase::HandleScreenMessage( const ScreenMessage SM )
vector <wstring> wLines;
m_textOutHidden.GetLines( wLines );
m_actualText = "";
for (unsigned i = max(int(wLines.size()) - SHOW_CHAT_LINES, 0 ) ; i < wLines.size() ; ++i)
for (unsigned i = max(int(wLines.size()) - SHOW_CHAT_LINES + 1, 0 ) ; i < wLines.size() ; ++i)
m_actualText += WStringToCString( wLines[i] )+'\n';
m_textChatOutput.SetText( m_actualText );
}