WCHAR* g_wszTestText = L"{0}가\r\n{1}나다{2}라마{4}바사아자{3}차카타파{1}하{4}ABCDEGG{2}吳宗法";
D3DCOLOR d3dTextColor[10] =
{
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) }, ///깜장
{ D3DCOLOR_ARGB( 2255, 255, 0, 0 ) }, ///빨강
{ D3DCOLOR_ARGB( 2255, 0, 255, 0 ) }, ///녹색
{ D3DCOLOR_ARGB( 2255, 0, 0, 255 ) }, ///파랑
{ D3DCOLOR_ARGB( 2255, 255, 255, 0 ) },
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) },
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) },
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) },
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) },
{ D3DCOLOR_ARGB( 2255, 0, 0, 0 ) },
};
void SetMultiColorText( CGuiWindow* pModifyWindow, WCHAR* wModifyText )
{
if( pModifyWindow )
ZeroMemory( pModifyWindow->m_sMultiColorText, sizeof( pModifyWindow->m_sMultiColorText ) );
SIZE size;
HDC hdc = pModifyWindow->GetFont()->GetDC();
///#############################
///########## Issue ##########
///#############################
/// 1. 컬러 코드 단위로 (구조체로)묶여야 함.
/// 2. 자동 행넘김이 되어야 하면 묶여야 함.
/// Parsing
///1. '{'를 찾고 '}'까지의 칼라값을 알아온다.
///2. '}'부터 다음 '{'까지의 텍스트를 하나씩 가져오면서. 자동 행넘김을 해야 하는 상황이면 묶는다.
int nArray = 0;
int nLastText = wcslen( wModifyText );
int nStructArray = -1;
CGuiRect rtGui;
pModifyWindow->GetWindowRect( rtGui );
for( int i = nArray; i < nLastText; i++ )
{
if( wModifyText[i] == '{' )
{
nStructArray++;
wstring wstrColorCode;
wstrColorCode.clear();
int nColor = 0;
/// 칼라값이 1자리 경우
if( wModifyText[ i + 2 ] == '}')
{
wstrColorCode += wModifyText[ i + 1 ];
nArray = i + 3;
}
///칼라값이 2자리 경우
else if( wModifyText[ i + 3 ] == '}')
{
wstrColorCode += wModifyText[ i + 1 ];
wstrColorCode += wModifyText[ i + 2 ];
nArray = i + 4;
}
i = nArray;
/// 칼라값 세팅
nColor = _wtoi( wstrColorCode.c_str() );
pModifyWindow->m_sMultiColorText[nStructArray].d3dColor = d3dTextColor[nColor];
}
nArray = i;
pModifyWindow->m_sMultiColorText[nStructArray].wstrText += wModifyText[i];
/// 문자열 Rect 세팅
if( wModifyText[i + 1] == '{' || i == nLastText - 1 || (wModifyText[i + 1] == '\r' && wModifyText[i + 2] == '\n') )
{
SMultiColorText* pMultiColor = &pModifyWindow->m_sMultiColorText[nStructArray];
if( nStructArray == 0 )
{
GetTextExtentPoint32( hdc, pModifyWindow->m_sMultiColorText[nStructArray].wstrText.c_str(), pModifyWindow->m_sMultiColorText[nStructArray].wstrText.size(), &size);
rtGui.right = rtGui.left + size.cx;
rtGui.bottom = rtGui.top + size.cy;
pMultiColor->rtText.left = rtGui.left;
pMultiColor->rtText.top = rtGui.top;
pMultiColor->rtText.right = rtGui.left + size.cx ;
pMultiColor->rtText.bottom = rtGui.top + size.cy;
}
else
{
rtGui.left = pModifyWindow->m_sMultiColorText[nStructArray - 1].rtText.right;
rtGui.top = pModifyWindow->m_sMultiColorText[nStructArray - 1].rtText.top;
pMultiColor->rtText.left = rtGui.left;
pMultiColor->rtText.top = rtGui.top;
GetTextExtentPoint32( hdc,pMultiColor->wstrText.c_str(), pMultiColor->wstrText.size(), &size);
rtGui.right = rtGui.left + size.cx;
rtGui.bottom = rtGui.top + size.cy;
pMultiColor->rtText.right = rtGui.left + size.cx ;
pMultiColor->rtText.bottom = rtGui.top + size.cy;
}
/// 행넘김
if( i + 2 < nLastText )
{
if( wModifyText[i + 1] == '\r' && wModifyText[i + 2] == '\n' )
{
rtGui.left = 0;
rtGui.top = rtGui.top + rtGui.bottom;
rtGui.right = 0;
rtGui.bottom = rtGui.bottom + size.cy;
}
}
}
}
}