BitmapText: line wrap automatically
This commit is contained in:
@@ -230,7 +230,7 @@ void BitmapText::DrawChars()
|
|||||||
/* sText is UTF-8. If not all of the characters in sText are available in the
|
/* sText is UTF-8. If not all of the characters in sText are available in the
|
||||||
* font, sAlternateText will be used instead. If there are unavailable characters
|
* font, sAlternateText will be used instead. If there are unavailable characters
|
||||||
* in sAlternateText, too, just use sText. */
|
* in sAlternateText, too, just use sText. */
|
||||||
void BitmapText::SetText( CString sText, CString sAlternateText )
|
void BitmapText::SetText( CString sText, CString sAlternateText, int iWrapWidthPixels )
|
||||||
{
|
{
|
||||||
ASSERT( m_pFont );
|
ASSERT( m_pFont );
|
||||||
|
|
||||||
@@ -239,12 +239,60 @@ void BitmapText::SetText( CString sText, CString sAlternateText )
|
|||||||
|
|
||||||
if(m_szText == sText)
|
if(m_szText == sText)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_szText = sText;
|
m_szText = sText;
|
||||||
|
|
||||||
/* Break the string into lines. */
|
|
||||||
|
// Break the string into lines.
|
||||||
|
//
|
||||||
m_szTextLines.clear();
|
m_szTextLines.clear();
|
||||||
split(CStringToWstring(m_szText), L"\n", m_szTextLines, false);
|
|
||||||
|
if( iWrapWidthPixels == -1 )
|
||||||
|
{
|
||||||
|
split( CStringToWstring(sText), L"\n", m_szTextLines, false );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Break sText into lines that don't exceed iWrapWidthPixels
|
||||||
|
// (if only one word fits on the line, it may be larger than iWrapWidthPixels ).
|
||||||
|
//
|
||||||
|
// TODO: Investigate whether this works in all languages
|
||||||
|
// TODO: Move this wrapping logic into Font
|
||||||
|
CStringArray asWords;
|
||||||
|
split( sText, " ", asWords );
|
||||||
|
|
||||||
|
CString sCurLine;
|
||||||
|
int iCurLineWidth = 0;
|
||||||
|
|
||||||
|
for( int i=0; i<asWords.size(); i++ )
|
||||||
|
{
|
||||||
|
CString sWord = asWords[i];
|
||||||
|
int iWidthWord = m_pFont->GetLineWidthInSourcePixels( CStringToWstring(sWord) );
|
||||||
|
|
||||||
|
if( sCurLine.empty() )
|
||||||
|
{
|
||||||
|
sCurLine = sWord;
|
||||||
|
iCurLineWidth = iWidthWord;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CString sToAdd = " " + sWord;
|
||||||
|
int iWidthToAdd = m_pFont->GetLineWidthInSourcePixels(L" ") + iWidthWord;
|
||||||
|
if( iCurLineWidth + iWidthToAdd <= iWrapWidthPixels ) // will fit on current line
|
||||||
|
{
|
||||||
|
sCurLine += sToAdd;
|
||||||
|
iCurLineWidth += iWidthToAdd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_szTextLines.push_back( CStringToWstring(sCurLine) );
|
||||||
|
sCurLine = sWord;
|
||||||
|
iCurLineWidth = iWidthWord;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_szTextLines.push_back( CStringToWstring(sCurLine) );
|
||||||
|
}
|
||||||
|
|
||||||
BuildChars();
|
BuildChars();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public:
|
|||||||
bool LoadFromFont( CString sFontName );
|
bool LoadFromFont( CString sFontName );
|
||||||
bool LoadFromNumbers( CString sTexturePath ) { return LoadFromTextureAndChars(sTexturePath,"0123456789%. :x"); };
|
bool LoadFromNumbers( CString sTexturePath ) { return LoadFromTextureAndChars(sTexturePath,"0123456789%. :x"); };
|
||||||
bool LoadFromTextureAndChars( CString sTexturePath, CString sChars );
|
bool LoadFromTextureAndChars( CString sTexturePath, CString sChars );
|
||||||
void SetText( CString sText, CString sAlternateText = "" );
|
void SetText( CString sText, CString sAlternateText = "", int iWrapWidthPixels = -1 );
|
||||||
void SetTextMaxWidth( float MaxWidth, const CString &text, const CString &alttext = "" );
|
void SetTextMaxWidth( float MaxWidth, const CString &text, const CString &alttext = "" );
|
||||||
|
|
||||||
int GetWidestLineWidthInSourcePixels() { return m_iWidestLineWidth; };
|
int GetWidestLineWidthInSourcePixels() { return m_iWidestLineWidth; };
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ ScreenEdit::ScreenEdit( CString sName ) : Screen( sName )
|
|||||||
m_Clipboard.SetNumTracks( m_NoteFieldEdit.GetNumTracks() );
|
m_Clipboard.SetNumTracks( m_NoteFieldEdit.GetNumTracks() );
|
||||||
|
|
||||||
|
|
||||||
|
GAMESTATE->m_PlayerOptions[PLAYER_1].Init(); // don't allow weird options in editor. It doesn't handle reverse well.
|
||||||
GAMESTATE->m_PlayerOptions[PLAYER_1].m_sNoteSkin = "default"; // change noteskin back to default before loading player
|
GAMESTATE->m_PlayerOptions[PLAYER_1].m_sNoteSkin = "default"; // change noteskin back to default before loading player
|
||||||
GAMESTATE->ResetNoteSkins();
|
GAMESTATE->ResetNoteSkins();
|
||||||
|
|
||||||
|
|||||||
@@ -791,7 +791,7 @@ void ScreenOptions::OnChange()
|
|||||||
sLineName.Replace("\n-","");
|
sLineName.Replace("\n-","");
|
||||||
sLineName.Replace("\n","");
|
sLineName.Replace("\n","");
|
||||||
sLineName.Replace(" ","");
|
sLineName.Replace(" ","");
|
||||||
pText->SetText( THEME->GetMetric(m_sName,sLineName) );
|
pText->SetText( THEME->GetMetric(m_sName,sLineName), "", 800 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user