From 27e393e1c6e96fc2456120661b1866c27a7f0312 Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Tue, 11 Mar 2014 22:06:19 -0700 Subject: [PATCH 1/2] 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 --- src/ScreenNetSelectBase.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ScreenNetSelectBase.cpp b/src/ScreenNetSelectBase.cpp index fbff7476a6..7aea5af0cf 100644 --- a/src/ScreenNetSelectBase.cpp +++ b/src/ScreenNetSelectBase.cpp @@ -103,7 +103,7 @@ bool ScreenNetSelectBase::Input( const InputEventPlus &input ) wchar_t c; c = INPUTMAN->DeviceInputToChar(input.DeviceI, true); - if( (c >= ' ') && (!bHoldingCtrl) ) + if( (c >= L' ') && (!bHoldingCtrl) ) { m_sTextInput += WStringToRString(wstring()+c); UpdateTextInput(); @@ -169,7 +169,7 @@ void ScreenNetSelectBase::UpdateUsers() 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].SetVertAlign( align_top ); m_textUsers[i].SetShadowLength( 0 ); @@ -250,21 +250,24 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate } } - char curChar = m_sText[i]; - int iCharLen = m_pFont->GetLineWidthInSourcePixels( wstring(1, curChar) ); + int iCharLength = min( utf8_get_char_len(m_sText[i]), iCharsLeft + 1 ); + 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 ) { - case ' ': + case L' ': if( /* iLineWidth == 0 &&*/ iWordWidth == 0 ) break; sCurrentLine += sCurrentWord + " "; - iLineWidth += iWordWidth + iCharLen; + iLineWidth += iWordWidth + iCharWidth; sCurrentWord = ""; iWordWidth = 0; iGlyphsSoFar++; break; - case '\n': + case L'\n': if( iLineWidth + iWordWidth > iWrapWidthPixels ) { SimpleAddLine( sCurrentLine, iLineWidth ); @@ -284,23 +287,23 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate } break; default: - if( iWordWidth + iCharLen > iWrapWidthPixels && iLineWidth == 0 ) + if( iWordWidth + iCharWidth > iWrapWidthPixels && iLineWidth == 0 ) { 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 ); sCurrentLine = ""; iLineWidth = 0; - sCurrentWord += curChar; - iWordWidth += iCharLen; + sCurrentWord += curCharStr; + iWordWidth += iCharWidth; } else { - sCurrentWord += curChar; - iWordWidth += iCharLen; + sCurrentWord += curCharStr; + iWordWidth += iCharWidth; } iGlyphsSoFar++; break; From 5c588087f0d658de0ac152e7b5c195dba3102322 Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Fri, 14 Mar 2014 12:24:42 -0700 Subject: [PATCH 2/2] Fixed indention. Fixed revert. Signed-off-by: Sandon Van Ness --- src/ScreenNetSelectBase.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ScreenNetSelectBase.cpp b/src/ScreenNetSelectBase.cpp index 7aea5af0cf..54a8e239c9 100644 --- a/src/ScreenNetSelectBase.cpp +++ b/src/ScreenNetSelectBase.cpp @@ -103,7 +103,7 @@ bool ScreenNetSelectBase::Input( const InputEventPlus &input ) wchar_t c; c = INPUTMAN->DeviceInputToChar(input.DeviceI, true); - if( (c >= L' ') && (!bHoldingCtrl) ) + if( (c >= L' ') && (!bHoldingCtrl) ) { m_sTextInput += WStringToRString(wstring()+c); UpdateTextInput(); @@ -169,7 +169,7 @@ void ScreenNetSelectBase::UpdateUsers() for( unsigned i=0; i < NSMAN->m_ActivePlayer.size(); i++) { - m_textUsers[i].LoadFromFont( THEME->GetPathF(m_sName,"chat") ); + m_textUsers[i].LoadFromFont( THEME->GetPathF(m_sName,"users") ); m_textUsers[i].SetHorizAlign( align_center ); m_textUsers[i].SetVertAlign( align_top ); m_textUsers[i].SetShadowLength( 0 ); @@ -250,11 +250,11 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate } } - int iCharLength = min( utf8_get_char_len(m_sText[i]), iCharsLeft + 1 ); - RString curCharStr = m_sText.substr( i, iCharLength ); - wchar_t curChar = utf8_get_char( curCharStr ); - i += iCharLength - 1; - int iCharWidth = m_pFont->GetLineWidthInSourcePixels( wstring() + curChar ); + int iCharLength = min( utf8_get_char_len(m_sText[i]), iCharsLeft + 1 ); + 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 ) { @@ -262,7 +262,7 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate if( /* iLineWidth == 0 &&*/ iWordWidth == 0 ) break; sCurrentLine += sCurrentWord + " "; - iLineWidth += iWordWidth + iCharWidth; + iLineWidth += iWordWidth + iCharWidth; sCurrentWord = ""; iWordWidth = 0; iGlyphsSoFar++; @@ -287,23 +287,23 @@ void ColorBitmapText::SetText( const RString& _sText, const RString& _sAlternate } break; default: - if( iWordWidth + iCharWidth > iWrapWidthPixels && iLineWidth == 0 ) + if( iWordWidth + iCharWidth > iWrapWidthPixels && iLineWidth == 0 ) { SimpleAddLine( sCurrentWord, iWordWidth ); - sCurrentWord = curCharStr; iWordWidth = iCharWidth; + sCurrentWord = curCharStr; iWordWidth = iCharWidth; } - else if( iWordWidth + iLineWidth + iCharWidth > iWrapWidthPixels ) + else if( iWordWidth + iLineWidth + iCharWidth > iWrapWidthPixels ) { SimpleAddLine( sCurrentLine, iLineWidth ); sCurrentLine = ""; iLineWidth = 0; - sCurrentWord += curCharStr; - iWordWidth += iCharWidth; + sCurrentWord += curCharStr; + iWordWidth += iCharWidth; } else { - sCurrentWord += curCharStr; - iWordWidth += iCharWidth; + sCurrentWord += curCharStr; + iWordWidth += iCharWidth; } iGlyphsSoFar++; break;