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:
@@ -409,12 +409,28 @@ void BitmapText::SetText( const CString& _sText, const CString& _sAlternateText,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_wTextLines.push_back( CStringToWstring(sCurLine) );
|
AddLine( sCurLine, iCurLineWidth );
|
||||||
|
if ( sCurLine.length() != 0 )
|
||||||
|
{
|
||||||
|
sCurLine += " " + sWord;
|
||||||
|
iCurLineWidth += iWidthWord;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sCurLine = sWord;
|
sCurLine = sWord;
|
||||||
iCurLineWidth = iWidthWord;
|
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();
|
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 )
|
void BitmapText::SetMaxWidth( float fMaxWidth )
|
||||||
{
|
{
|
||||||
m_fMaxWidth = fMaxWidth;
|
m_fMaxWidth = fMaxWidth;
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ protected:
|
|||||||
vector<RageSpriteVertex> verts;
|
vector<RageSpriteVertex> verts;
|
||||||
vector<RageTexture *> tex;
|
vector<RageTexture *> tex;
|
||||||
|
|
||||||
|
void AddLine( CString & sAddition, int & iWidthPixels );
|
||||||
void BuildChars();
|
void BuildChars();
|
||||||
void DrawChars();
|
void DrawChars();
|
||||||
void UpdateBaseZoom();
|
void UpdateBaseZoom();
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ void ScreenNetSelectBase::Init()
|
|||||||
vector <wstring> wLines;
|
vector <wstring> wLines;
|
||||||
m_textOutHidden.GetLines( wLines );
|
m_textOutHidden.GetLines( wLines );
|
||||||
m_actualText = "";
|
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_actualText += WStringToCString( wLines[i] )+'\n';
|
||||||
m_textChatOutput.SetText( m_actualText );
|
m_textChatOutput.SetText( m_actualText );
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ void ScreenNetSelectBase::HandleScreenMessage( const ScreenMessage SM )
|
|||||||
vector <wstring> wLines;
|
vector <wstring> wLines;
|
||||||
m_textOutHidden.GetLines( wLines );
|
m_textOutHidden.GetLines( wLines );
|
||||||
m_actualText = "";
|
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_actualText += WStringToCString( wLines[i] )+'\n';
|
||||||
m_textChatOutput.SetText( m_actualText );
|
m_textChatOutput.SetText( m_actualText );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user