Fix colors when unicode characters are in chat box (Online).
This is just hanubeki's patch which calculates accurate widths of characters so colors don't get offset. Signed-off-by: Sandon Van Ness <[email protected]>
This commit is contained in:
+17
-14
@@ -103,7 +103,7 @@ bool ScreenNetSelectBase::Input( const InputEventPlus &input )
|
|||||||
wchar_t c;
|
wchar_t c;
|
||||||
c = INPUTMAN->DeviceInputToChar(input.DeviceI, true);
|
c = INPUTMAN->DeviceInputToChar(input.DeviceI, true);
|
||||||
|
|
||||||
if( (c >= ' ') && (!bHoldingCtrl) )
|
if( (c >= L' ') && (!bHoldingCtrl) )
|
||||||
{
|
{
|
||||||
m_sTextInput += WStringToRString(wstring()+c);
|
m_sTextInput += WStringToRString(wstring()+c);
|
||||||
UpdateTextInput();
|
UpdateTextInput();
|
||||||
@@ -169,7 +169,7 @@ void ScreenNetSelectBase::UpdateUsers()
|
|||||||
|
|
||||||
for( unsigned i=0; i < NSMAN->m_ActivePlayer.size(); i++)
|
for( unsigned i=0; i < NSMAN->m_ActivePlayer.size(); i++)
|
||||||
{
|
{
|
||||||
m_textUsers[i].LoadFromFont( THEME->GetPathF(m_sName,"users") );
|
m_textUsers[i].LoadFromFont( THEME->GetPathF(m_sName,"chat") );
|
||||||
m_textUsers[i].SetHorizAlign( align_center );
|
m_textUsers[i].SetHorizAlign( align_center );
|
||||||
m_textUsers[i].SetVertAlign( align_top );
|
m_textUsers[i].SetVertAlign( align_top );
|
||||||
m_textUsers[i].SetShadowLength( 0 );
|
m_textUsers[i].SetShadowLength( 0 );
|
||||||
@@ -250,21 +250,24 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char curChar = m_sText[i];
|
int iCharLength = min( utf8_get_char_len(m_sText[i]), iCharsLeft + 1 );
|
||||||
int iCharLen = m_pFont->GetLineWidthInSourcePixels( wstring(1, curChar) );
|
RString curCharStr = m_sText.substr( i, iCharLength );
|
||||||
|
wchar_t curChar = utf8_get_char( curCharStr );
|
||||||
|
i += iCharLength - 1;
|
||||||
|
int iCharWidth = m_pFont->GetLineWidthInSourcePixels( wstring() + curChar );
|
||||||
|
|
||||||
switch( curChar )
|
switch( curChar )
|
||||||
{
|
{
|
||||||
case ' ':
|
case L' ':
|
||||||
if( /* iLineWidth == 0 &&*/ iWordWidth == 0 )
|
if( /* iLineWidth == 0 &&*/ iWordWidth == 0 )
|
||||||
break;
|
break;
|
||||||
sCurrentLine += sCurrentWord + " ";
|
sCurrentLine += sCurrentWord + " ";
|
||||||
iLineWidth += iWordWidth + iCharLen;
|
iLineWidth += iWordWidth + iCharWidth;
|
||||||
sCurrentWord = "";
|
sCurrentWord = "";
|
||||||
iWordWidth = 0;
|
iWordWidth = 0;
|
||||||
iGlyphsSoFar++;
|
iGlyphsSoFar++;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case L'\n':
|
||||||
if( iLineWidth + iWordWidth > iWrapWidthPixels )
|
if( iLineWidth + iWordWidth > iWrapWidthPixels )
|
||||||
{
|
{
|
||||||
SimpleAddLine( sCurrentLine, iLineWidth );
|
SimpleAddLine( sCurrentLine, iLineWidth );
|
||||||
@@ -284,23 +287,23 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if( iWordWidth + iCharLen > iWrapWidthPixels && iLineWidth == 0 )
|
if( iWordWidth + iCharWidth > iWrapWidthPixels && iLineWidth == 0 )
|
||||||
{
|
{
|
||||||
SimpleAddLine( sCurrentWord, iWordWidth );
|
SimpleAddLine( sCurrentWord, iWordWidth );
|
||||||
sCurrentWord = curChar; iWordWidth = iCharLen;
|
sCurrentWord = curCharStr; iWordWidth = iCharWidth;
|
||||||
}
|
}
|
||||||
else if( iWordWidth + iLineWidth + iCharLen > iWrapWidthPixels )
|
else if( iWordWidth + iLineWidth + iCharWidth > iWrapWidthPixels )
|
||||||
{
|
{
|
||||||
SimpleAddLine( sCurrentLine, iLineWidth );
|
SimpleAddLine( sCurrentLine, iLineWidth );
|
||||||
sCurrentLine = "";
|
sCurrentLine = "";
|
||||||
iLineWidth = 0;
|
iLineWidth = 0;
|
||||||
sCurrentWord += curChar;
|
sCurrentWord += curCharStr;
|
||||||
iWordWidth += iCharLen;
|
iWordWidth += iCharWidth;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sCurrentWord += curChar;
|
sCurrentWord += curCharStr;
|
||||||
iWordWidth += iCharLen;
|
iWordWidth += iCharWidth;
|
||||||
}
|
}
|
||||||
iGlyphsSoFar++;
|
iGlyphsSoFar++;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user