[SDL] Polskie znaki - rozwiązanie probemu
Ostatnio zmodyfikowano 2011-06-24 16:54
programista12 Temat założony przez niniejszego użytkownika |
[SDL] Polskie znaki - rozwiązanie probemu » 2011-06-24 16:54:06 W internecie na pewno jest dużo rozwiązań problemów z polskimi znakami w SDLu. Wielu z nich próbowałem, ale żaden nie okazał się skuteczny. Gdzieś w internecie przeczytałem, że trzeba użyć klasy wstring. Jednak większość z Was używa zwykłego stringa, a jego konwersja na wstring sprawia problemy i polskie znaki nie działają. Mi udało się rozwikłać ten problem. Funkcja zamieniająca string na wstring: std::wstring StrToWstr( const std::string & s ) { std::wstring tmp; for( unsigned i = 0; i < s.length(); i++ ) { if( s[ i ] == 'ą' ) tmp += L"ą"; else if( s[ i ] == 'ć' ) tmp += L"ć"; else if( s[ i ] == 'ę' ) tmp += L"ę"; else if( s[ i ] == 'ł' ) tmp += L"ł"; else if( s[ i ] == 'ń' ) tmp += L"ń"; else if( s[ i ] == 'ó' ) tmp += L"ó"; else if( s[ i ] == 'ś' ) tmp += L"ś"; else if( s[ i ] == 'ź' ) tmp += L"ź"; else if( s[ i ] == 'ż' ) tmp += L"ż"; else if( s[ i ] == 'Ą' ) tmp += L"Ą"; else if( s[ i ] == 'Ć' ) tmp += L"Ć"; else if( s[ i ] == 'Ę' ) tmp += L"Ę"; else if( s[ i ] == 'Ł' ) tmp += L"Ł"; else if( s[ i ] == 'Ń' ) tmp += L"Ń"; else if( s[ i ] == 'Ó' ) tmp += L"Ó"; else if( s[ i ] == 'Ś' ) tmp += L"Ś"; else if( s[ i ] == 'Ź' ) tmp += L"Ź"; else if( s[ i ] == 'Ż' ) tmp += L"Ż"; else tmp += s[ i ]; } return tmp; }
I funkcja wyświetlająca tekst: void ShowText( int x, int y, std::string s, TTF_Font * f, SDL_Color c, SDL_Surface * dst ) { std::wstring s1 = StrToWstr( s ); SDL_Surface * txt = TTF_RenderUNICODE_Blended( f,(( Uint16 * ) s1.data() ), c ); ShowImage( x, y, txt, dst, NULL ); SDL_FreeSurface( txt ); }
Wiem, że to może nie być zbyt odkrywcze, ale dla osób początkujących na pewno się przyda. |
|
« 1 » |