From 0250c98ff8cb09755960270cd3a14c9e222c4e96 Mon Sep 17 00:00:00 2001 From: spartanj Date: Sun, 6 Mar 2011 02:37:54 -0300 Subject: [PATCH] Replaced wstrings with String internal class. Removed all the unnecessary wide-strings. Removed some wstring functions. --- src/base/string.cpp | 1389 +++++++++--------- src/base/string.hpp | 1257 ++++++++-------- src/ee.h | 1 - src/graphics/cconsole.cpp | 204 ++- src/graphics/cconsole.hpp | 55 +- src/graphics/cfont.cpp | 28 +- src/graphics/cfont.hpp | 32 +- src/graphics/ctextcache.cpp | 12 +- src/graphics/ctextcache.hpp | 12 +- src/helper/chipmunk/cpBBTree.c | 149 +- src/helper/chipmunk/cpSpaceHash.c | 137 +- src/test/eetest.cpp | 132 +- src/test/eetest.hpp | 4 +- src/ui/cuicomplexcontrol.cpp | 10 +- src/ui/cuicomplexcontrol.hpp | 8 +- src/ui/cuilistbox.cpp | 16 +- src/ui/cuilistbox.hpp | 14 +- src/ui/cuimenu.cpp | 16 +- src/ui/cuimenu.hpp | 16 +- src/ui/cuiprogressbar.cpp | 2 +- src/ui/cuipushbutton.cpp | 9 +- src/ui/cuipushbutton.hpp | 6 +- src/ui/cuispinbox.cpp | 10 +- src/ui/cuitextbox.cpp | 8 +- src/ui/cuitextbox.hpp | 6 +- src/ui/cuitextedit.cpp | 8 +- src/ui/cuitextedit.hpp | 8 +- src/ui/cuitextinput.cpp | 8 +- src/ui/cuitextinput.hpp | 6 +- src/ui/cuitooltip.cpp | 8 +- src/ui/cuitooltip.hpp | 6 +- src/ui/cuiwindow.cpp | 6 +- src/ui/cuiwindow.hpp | 4 +- src/utils/string.cpp | 37 +- src/utils/string.hpp | 36 +- src/utils/utils.cpp | 94 +- src/utils/utils.hpp | 12 +- src/window/backend/SDL/cclipboardsdl.cpp | 13 +- src/window/backend/SDL/cclipboardsdl.hpp | 6 +- src/window/backend/allegro5/cclipboardal.cpp | 6 +- src/window/backend/allegro5/cclipboardal.hpp | 6 +- src/window/backend/null/cclipboardnull.cpp | 6 +- src/window/backend/null/cclipboardnull.hpp | 6 +- src/window/cclipboard.hpp | 8 +- src/window/cinputtextbuffer.cpp | 10 +- src/window/cinputtextbuffer.hpp | 6 +- 46 files changed, 1855 insertions(+), 1978 deletions(-) diff --git a/src/base/string.cpp b/src/base/string.cpp index 91adbfc63..595f4007d 100644 --- a/src/base/string.cpp +++ b/src/base/string.cpp @@ -1,680 +1,709 @@ -#include "string.hpp" -#include "utf.hpp" -#include - -namespace EE { - -const std::size_t String::InvalidPos = StringType::npos; - -String::String() -{ -} - -String::String(char ansiChar) -{ - mString += Utf32::DecodeAnsi(ansiChar); -} - -String::String(char ansiChar, const std::locale& locale) -{ - mString += Utf32::DecodeAnsi(ansiChar, locale); -} - -String::String(wchar_t wideChar) -{ - mString += Utf32::DecodeWide(wideChar); -} - -String::String(StringBaseType utf32Char) -{ - mString += utf32Char; -} - -String::String(const char* ansiString) -{ - if (ansiString) - { - std::size_t length = strlen(ansiString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString)); - } - } -} - -String::String(const std::string& ansiString) -{ - mString.reserve(ansiString.length() + 1); - Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString)); -} - -String::String(const char* ansiString, const std::locale& locale) -{ - if (ansiString) - { - std::size_t length = strlen(ansiString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); - } - } -} - -String::String(const std::string& ansiString, const std::locale& locale) -{ - mString.reserve(ansiString.length() + 1); - Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); -} - -String::String(const wchar_t* wideString) -{ - if (wideString) - { - std::size_t length = std::wcslen(wideString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); - } - } -} - -String::String(const std::wstring& wideString) -{ - mString.reserve(wideString.length() + 1); - Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); -} - -String::String(const StringBaseType* utf32String) -{ - if (utf32String) - mString = utf32String; -} - -String::String(const StringType& utf32String) : -mString(utf32String) -{ -} - -String::String(const String& str) : -mString(str.mString) -{ -} - -String::operator std::string() const -{ - return ToAnsiString(); -} - -String::operator std::wstring() const -{ - return ToWideString(); -} - -std::string String::ToAnsiString() const -{ - // Prepare the output string - std::string output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0); - - return output; -} - -std::string String::ToAnsiString(const std::locale& locale) const -{ - // Prepare the output string - std::string output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); - - return output; -} - -std::wstring String::ToWideString() const -{ - // Prepare the output string - std::wstring output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); - - return output; -} - -String& String::operator =(const String& right) -{ - mString = right.mString; - return *this; -} - -String& String::operator +=(const String& right) -{ - mString += right.mString; - return *this; -} - -String::StringBaseType String::operator [](std::size_t index) const -{ - return mString[index]; -} - -String::StringBaseType& String::operator [](std::size_t index) -{ - return mString[index]; -} - -String::StringBaseType String::at( std::size_t index ) const -{ - return mString.at( index ); -} - -void String::push_back( StringBaseType c ) -{ - mString.push_back( c ); -} - -void String::swap ( String& str ) -{ - mString.swap( str.mString ); -} - -void String::clear() -{ - mString.clear(); -} - -std::size_t String::size() const -{ - return mString.size(); -} - -std::size_t String::length() const -{ - return mString.length(); -} - -bool String::empty() const -{ - return mString.empty(); -} - -void String::erase(std::size_t position, std::size_t count) -{ - mString.erase(position, count); -} - -String& String::insert(std::size_t position, const String& str) -{ - mString.insert(position, str.mString); - return *this; -} - -String& String::insert( std::size_t pos1, const String& str, std::size_t pos2, std::size_t n ) -{ - mString.insert( pos1, str.mString, pos2, n ); - return *this; -} - -String& String::insert ( size_t pos1, const char* s, size_t n ) -{ - String tmp( s ); - - mString.insert( pos1, tmp.data(), n ); - - return *this; -} - -String& String::insert ( size_t pos1, size_t n, char c ) -{ - mString.insert( pos1, n, c ); - return *this; -} - -String& String::insert ( size_t pos1, const char* s ) -{ - String tmp( s ); - - mString.insert( pos1, tmp.data() ); - - return *this; -} - -String::Iterator String::insert ( Iterator p, char c ) -{ - return mString.insert( p, c ); -} - -void String::insert ( Iterator p, size_t n, char c ) -{ - mString.insert( p, n, c ); -} - -const String::StringBaseType* String::c_str() const -{ - return mString.c_str(); -} - -const String::StringBaseType* String::data() const -{ - return mString.data(); -} - -String::Iterator String::begin() -{ - return mString.begin(); -} - -String::ConstIterator String::begin() const -{ - return mString.begin(); -} - -String::Iterator String::end() -{ - return mString.end(); -} - -String::ConstIterator String::end() const -{ - return mString.end(); -} - -String::ReverseIterator String::rbegin() -{ - return mString.rbegin(); -} - -String::ConstReverseIterator String::rbegin() const -{ - return mString.rbegin(); -} - -String::ReverseIterator String::rend() -{ - return mString.rend(); -} - -String::ConstReverseIterator String::rend() const -{ - return mString.rend(); -} - -void String::resize( std::size_t n, StringBaseType c ) -{ - mString.resize( n, c ); -} - -void String::resize( std::size_t n ) -{ - mString.resize( n ); -} - -std::size_t String::max_size() const -{ - return mString.max_size(); -} - -void String::reserve( size_t res_arg ) -{ - mString.reserve( res_arg ); -} - -std::size_t String::capacity() const -{ - return mString.capacity(); -} - -String& String::assign ( const String& str ) -{ - mString.assign( str.mString ); - return *this; -} - -String& String::assign ( const String& str, size_t pos, size_t n ) -{ - mString.assign( str.mString, pos, n ); - return *this; -} - -String& String::assign ( const char* s, size_t n ) -{ - String tmp( s ); - - mString.assign( tmp.mString ); - - return *this; -} - -String& String::assign ( const char* s ) -{ - String tmp( s ); - - mString.assign( tmp.mString ); - - return *this; -} - -String& String::assign ( size_t n, char c ) -{ - mString.assign( n, c ); - - return *this; -} - -String& String::append ( const String& str ) -{ - mString.append( str.mString ); - - return *this; -} - -String& String::append ( const String& str, size_t pos, size_t n ) -{ - mString.append( str.mString, pos, n ); - - return *this; -} - -String& String::append ( const char* s, size_t n ) -{ - String tmp( s ); - - mString.append( tmp.mString ); - - return *this; -} - -String& String::append ( const char* s ) -{ - String tmp( s ); - - mString.append( tmp.mString ); - - return *this; -} - -String& String::append ( size_t n, char c ) -{ - mString.append( n, c ); - - return *this; -} - -String& String::replace ( size_t pos1, size_t n1, const String& str ) -{ - mString.replace( pos1, n1, str.mString ); - - return *this; -} - -String& String::replace ( Iterator i1, Iterator i2, const String& str ) -{ - mString.replace( i1, i2, str.mString ); - - return *this; -} - -String& String::replace ( size_t pos1, size_t n1, const String& str, size_t pos2, size_t n2 ) -{ - mString.replace( pos1, n1, str.mString, pos2, n2 ); - - return *this; -} - -String& String::replace ( size_t pos1, size_t n1, const char* s, size_t n2 ) -{ - String tmp( s ); - - mString.replace( pos1, n1, tmp.data(), n2 ); - - return *this; -} - -String& String::replace ( Iterator i1, Iterator i2, const char* s, size_t n2 ) -{ - String tmp( s ); - - mString.replace( i1, i2, tmp.data(), n2 ); - - return *this; -} - -String& String::replace ( size_t pos1, size_t n1, const char* s ) -{ - String tmp( s ); - - mString.replace( pos1, n1, tmp.mString ); - - return *this; -} - -String& String::replace ( Iterator i1, Iterator i2, const char* s ) -{ - String tmp( s ); - - mString.replace( i1, i2, tmp.mString ); - - return *this; -} - -String& String::replace ( size_t pos1, size_t n1, size_t n2, char c ) -{ - mString.replace( pos1, n1, n2, (StringBaseType)c ); - - return *this; -} - -String& String::replace ( Iterator i1, Iterator i2, size_t n2, char c ) -{ - mString.replace( i1, i2, n2, (StringBaseType)c ); - - return *this; -} - -std::size_t String::find( const String& str, std::size_t start ) const -{ - return mString.find( str.mString, start ); -} - -std::size_t String::find ( const char* s, std::size_t pos, std::size_t n ) const -{ - return find( String( s ), pos ); -} - -std::size_t String::find ( const char* s, std::size_t pos ) const -{ - return find( String( s ), pos ); -} - -size_t String::find ( char c, std::size_t pos ) const -{ - return mString.find( (StringBaseType)c, pos ); -} - -std::size_t String::rfind ( const String& str, std::size_t pos ) const -{ - return mString.rfind( str.mString, pos ); -} - -std::size_t String::rfind ( const char* s, std::size_t pos, std::size_t n ) const -{ - return rfind( String( s ), pos ); -} - -std::size_t String::rfind ( const char* s, std::size_t pos ) const -{ - return rfind( String( s ), pos ); -} - -std::size_t String::rfind ( char c, std::size_t pos ) const -{ - return mString.rfind( c, pos ); -} - -std::size_t String::copy ( StringBaseType* s, std::size_t n, std::size_t pos ) const -{ - return mString.copy( s, n, pos ); -} - -String String::substr ( std::size_t pos, std::size_t n ) const -{ - return String( mString.substr( pos, n ) ); -} - -int String::compare ( const String& str ) const -{ - return mString.compare( str.mString ); -} - -int String::compare ( const char* s ) const -{ - return compare( String( s ) ); -} - -int String::compare ( std::size_t pos1, std::size_t n1, const String& str ) const -{ - return mString.compare( pos1, n1, str.mString ); -} - -int String::compare ( std::size_t pos1, std::size_t n1, const char* s) const -{ - return compare( pos1, n1, String( s ) ); -} - -int String::compare ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ) const -{ - return mString.compare( pos1, n1, str.mString, pos2, n2 ); -} - -int String::compare ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2) const -{ - return compare( pos1, n1, String( s ), 0, n2 ); -} - -std::size_t String::find_first_of ( const String& str, std::size_t pos ) const -{ - return mString.find_first_of( str.mString, pos ); -} - -std::size_t String::find_first_of ( const char* s, std::size_t pos, std::size_t n ) const -{ - return find_first_of( String( s ), pos ); -} - -std::size_t String::find_first_of ( const char* s, std::size_t pos ) const -{ - return find_first_of( String( s ), pos ); -} - -std::size_t String::find_first_of ( StringBaseType c, std::size_t pos ) const -{ - return mString.find_first_of( c, pos ); -} - -std::size_t String::find_last_of ( const String& str, std::size_t pos ) const -{ - return mString.find_last_of( str.mString, pos ); -} - -std::size_t String::find_last_of ( const char* s, std::size_t pos, std::size_t n ) const -{ - return find_last_of( String( s ), pos ); -} - -std::size_t String::find_last_of ( const char* s, std::size_t pos ) const -{ - return find_last_of( String( s ), pos ); -} - -std::size_t String::find_last_of ( StringBaseType c, std::size_t pos) const -{ - return mString.find_last_of( c, pos ); -} - -std::size_t String::find_first_not_of ( const String& str, std::size_t pos ) const -{ - return mString.find_first_not_of( str.mString, pos ); -} - -std::size_t String::find_first_not_of ( const char* s, std::size_t pos, std::size_t n ) const -{ - return find_first_not_of( String( s ), pos ); -} - -std::size_t String::find_first_not_of ( const char* s, std::size_t pos ) const -{ - return find_first_not_of( String( s ), pos ); -} - -std::size_t String::find_first_not_of ( StringBaseType c, std::size_t pos ) const -{ - return mString.find_first_not_of( c, pos ); -} - -std::size_t String::find_last_not_of ( const String& str, std::size_t pos ) const -{ - return mString.find_last_not_of( str.mString, pos ); -} - -std::size_t String::find_last_not_of ( const char* s, std::size_t pos, std::size_t n ) const -{ - return find_last_not_of( String( s ), pos ); -} - -std::size_t String::find_last_not_of ( const char* s, std::size_t pos ) const -{ - return find_last_not_of( String( s ), pos ); -} - -std::size_t String::find_last_not_of ( StringBaseType c, std::size_t pos ) const -{ - return mString.find_last_not_of( c, pos ); -} - -bool operator ==(const String& left, const String& right) -{ - return left.mString == right.mString; -} - -bool operator !=(const String& left, const String& right) -{ - return !(left == right); -} - -bool operator <(const String& left, const String& right) -{ - return left.mString < right.mString; -} - -bool operator >(const String& left, const String& right) -{ - return right < left; -} - -bool operator <=(const String& left, const String& right) -{ - return !(right < left); -} - -bool operator >=(const String& left, const String& right) -{ - return !(left < right); -} - -String operator +(const String& left, const String& right) -{ - String string = left; - string += right; - - return string; -} - -} +#include "string.hpp" +#include "utf.hpp" +#include + +namespace EE { + +const std::size_t String::InvalidPos = StringType::npos; + +String::String() +{ +} + +String::String(char ansiChar) +{ + mString += Utf32::DecodeAnsi(ansiChar); +} + +String::String(char ansiChar, const std::locale& locale) +{ + mString += Utf32::DecodeAnsi(ansiChar, locale); +} + +String::String(wchar_t wideChar) +{ + mString += Utf32::DecodeWide(wideChar); +} + +String::String(StringBaseType utf32Char) +{ + mString += utf32Char; +} + +String::String(const char* ansiString) +{ + if (ansiString) + { + std::size_t length = strlen(ansiString); + if (length > 0) + { + mString.reserve(length + 1); + Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString)); + } + } +} + +String::String(const std::string& ansiString) +{ + mString.reserve(ansiString.length() + 1); + Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString)); +} + +String::String(const char* ansiString, const std::locale& locale) +{ + if (ansiString) + { + std::size_t length = strlen(ansiString); + if (length > 0) + { + mString.reserve(length + 1); + Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); + } + } +} + +String::String(const std::string& ansiString, const std::locale& locale) +{ + mString.reserve(ansiString.length() + 1); + Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); +} + +String::String(const wchar_t* wideString) +{ + if (wideString) + { + std::size_t length = std::wcslen(wideString); + if (length > 0) + { + mString.reserve(length + 1); + Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); + } + } +} + +String::String(const std::wstring& wideString) +{ + mString.reserve(wideString.length() + 1); + Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); +} + +String::String(const StringBaseType* utf32String) +{ + if (utf32String) + mString = utf32String; +} + +String::String(const StringType& utf32String) : +mString(utf32String) +{ +} + +String::String(const String& str) : +mString(str.mString) +{ +} + +String String::FromUtf8( const std::string& utf8 ) +{ + String::StringType utf32; + + utf32.reserve( utf8.length() + 1 ); + + Utf8::ToUtf32( utf8.begin(), utf8.end(), std::back_inserter( utf32 ) ); + + return String( utf32 ); +} + +String::operator std::string() const +{ + return ToAnsiString(); +} + +String::operator std::wstring() const +{ + return ToWideString(); +} + +std::string String::ToAnsiString() const +{ + // Prepare the output string + std::string output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0); + + return output; +} + +std::string String::ToAnsiString(const std::locale& locale) const +{ + // Prepare the output string + std::string output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); + + return output; +} + +String String::ToWideString() const +{ + // Prepare the output string + std::wstring output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); + + return output; +} + +std::string String::ToUtf8() const { + // Prepare the output string + std::string output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output) ); + + return output; +} + +String& String::operator =(const String& right) +{ + mString = right.mString; + return *this; +} + +String& String::operator +=(const String& right) +{ + mString += right.mString; + return *this; +} + +String::StringBaseType String::operator [](std::size_t index) const +{ + return mString[index]; +} + +String::StringBaseType& String::operator [](std::size_t index) +{ + return mString[index]; +} + +String::StringBaseType String::at( std::size_t index ) const +{ + return mString.at( index ); +} + +void String::push_back( StringBaseType c ) +{ + mString.push_back( c ); +} + +void String::swap ( String& str ) +{ + mString.swap( str.mString ); +} + +void String::clear() +{ + mString.clear(); +} + +std::size_t String::size() const +{ + return mString.size(); +} + +std::size_t String::length() const +{ + return mString.length(); +} + +bool String::empty() const +{ + return mString.empty(); +} + +void String::erase(std::size_t position, std::size_t count) +{ + mString.erase(position, count); +} + +String& String::insert(std::size_t position, const String& str) +{ + mString.insert(position, str.mString); + return *this; +} + +String& String::insert( std::size_t pos1, const String& str, std::size_t pos2, std::size_t n ) +{ + mString.insert( pos1, str.mString, pos2, n ); + return *this; +} + +String& String::insert ( size_t pos1, const char* s, size_t n ) +{ + String tmp( s ); + + mString.insert( pos1, tmp.data(), n ); + + return *this; +} + +String& String::insert ( size_t pos1, size_t n, char c ) +{ + mString.insert( pos1, n, c ); + return *this; +} + +String& String::insert ( size_t pos1, const char* s ) +{ + String tmp( s ); + + mString.insert( pos1, tmp.data() ); + + return *this; +} + +String::Iterator String::insert ( Iterator p, char c ) +{ + return mString.insert( p, c ); +} + +void String::insert ( Iterator p, size_t n, char c ) +{ + mString.insert( p, n, c ); +} + +const String::StringBaseType* String::c_str() const +{ + return mString.c_str(); +} + +const String::StringBaseType* String::data() const +{ + return mString.data(); +} + +String::Iterator String::begin() +{ + return mString.begin(); +} + +String::ConstIterator String::begin() const +{ + return mString.begin(); +} + +String::Iterator String::end() +{ + return mString.end(); +} + +String::ConstIterator String::end() const +{ + return mString.end(); +} + +String::ReverseIterator String::rbegin() +{ + return mString.rbegin(); +} + +String::ConstReverseIterator String::rbegin() const +{ + return mString.rbegin(); +} + +String::ReverseIterator String::rend() +{ + return mString.rend(); +} + +String::ConstReverseIterator String::rend() const +{ + return mString.rend(); +} + +void String::resize( std::size_t n, StringBaseType c ) +{ + mString.resize( n, c ); +} + +void String::resize( std::size_t n ) +{ + mString.resize( n ); +} + +std::size_t String::max_size() const +{ + return mString.max_size(); +} + +void String::reserve( size_t res_arg ) +{ + mString.reserve( res_arg ); +} + +std::size_t String::capacity() const +{ + return mString.capacity(); +} + +String& String::assign ( const String& str ) +{ + mString.assign( str.mString ); + return *this; +} + +String& String::assign ( const String& str, size_t pos, size_t n ) +{ + mString.assign( str.mString, pos, n ); + return *this; +} + +String& String::assign ( const char* s, size_t n ) +{ + String tmp( s ); + + mString.assign( tmp.mString ); + + return *this; +} + +String& String::assign ( const char* s ) +{ + String tmp( s ); + + mString.assign( tmp.mString ); + + return *this; +} + +String& String::assign ( size_t n, char c ) +{ + mString.assign( n, c ); + + return *this; +} + +String& String::append ( const String& str ) +{ + mString.append( str.mString ); + + return *this; +} + +String& String::append ( const String& str, size_t pos, size_t n ) +{ + mString.append( str.mString, pos, n ); + + return *this; +} + +String& String::append ( const char* s, size_t n ) +{ + String tmp( s ); + + mString.append( tmp.mString ); + + return *this; +} + +String& String::append ( const char* s ) +{ + String tmp( s ); + + mString.append( tmp.mString ); + + return *this; +} + +String& String::append ( size_t n, char c ) +{ + mString.append( n, c ); + + return *this; +} + +String& String::append ( std::size_t n, StringBaseType c ) +{ + mString.append( n, c ); + + return *this; +} + +String& String::replace ( size_t pos1, size_t n1, const String& str ) +{ + mString.replace( pos1, n1, str.mString ); + + return *this; +} + +String& String::replace ( Iterator i1, Iterator i2, const String& str ) +{ + mString.replace( i1, i2, str.mString ); + + return *this; +} + +String& String::replace ( size_t pos1, size_t n1, const String& str, size_t pos2, size_t n2 ) +{ + mString.replace( pos1, n1, str.mString, pos2, n2 ); + + return *this; +} + +String& String::replace ( size_t pos1, size_t n1, const char* s, size_t n2 ) +{ + String tmp( s ); + + mString.replace( pos1, n1, tmp.data(), n2 ); + + return *this; +} + +String& String::replace ( Iterator i1, Iterator i2, const char* s, size_t n2 ) +{ + String tmp( s ); + + mString.replace( i1, i2, tmp.data(), n2 ); + + return *this; +} + +String& String::replace ( size_t pos1, size_t n1, const char* s ) +{ + String tmp( s ); + + mString.replace( pos1, n1, tmp.mString ); + + return *this; +} + +String& String::replace ( Iterator i1, Iterator i2, const char* s ) +{ + String tmp( s ); + + mString.replace( i1, i2, tmp.mString ); + + return *this; +} + +String& String::replace ( size_t pos1, size_t n1, size_t n2, char c ) +{ + mString.replace( pos1, n1, n2, (StringBaseType)c ); + + return *this; +} + +String& String::replace ( Iterator i1, Iterator i2, size_t n2, char c ) +{ + mString.replace( i1, i2, n2, (StringBaseType)c ); + + return *this; +} + +std::size_t String::find( const String& str, std::size_t start ) const +{ + return mString.find( str.mString, start ); +} + +std::size_t String::find ( const char* s, std::size_t pos, std::size_t n ) const +{ + return find( String( s ), pos ); +} + +std::size_t String::find ( const char* s, std::size_t pos ) const +{ + return find( String( s ), pos ); +} + +size_t String::find ( char c, std::size_t pos ) const +{ + return mString.find( (StringBaseType)c, pos ); +} + +std::size_t String::rfind ( const String& str, std::size_t pos ) const +{ + return mString.rfind( str.mString, pos ); +} + +std::size_t String::rfind ( const char* s, std::size_t pos, std::size_t n ) const +{ + return rfind( String( s ), pos ); +} + +std::size_t String::rfind ( const char* s, std::size_t pos ) const +{ + return rfind( String( s ), pos ); +} + +std::size_t String::rfind ( char c, std::size_t pos ) const +{ + return mString.rfind( c, pos ); +} + +std::size_t String::copy ( StringBaseType* s, std::size_t n, std::size_t pos ) const +{ + return mString.copy( s, n, pos ); +} + +String String::substr ( std::size_t pos, std::size_t n ) const +{ + return String( mString.substr( pos, n ) ); +} + +int String::compare ( const String& str ) const +{ + return mString.compare( str.mString ); +} + +int String::compare ( const char* s ) const +{ + return compare( String( s ) ); +} + +int String::compare ( std::size_t pos1, std::size_t n1, const String& str ) const +{ + return mString.compare( pos1, n1, str.mString ); +} + +int String::compare ( std::size_t pos1, std::size_t n1, const char* s) const +{ + return compare( pos1, n1, String( s ) ); +} + +int String::compare ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ) const +{ + return mString.compare( pos1, n1, str.mString, pos2, n2 ); +} + +int String::compare ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2) const +{ + return compare( pos1, n1, String( s ), 0, n2 ); +} + +std::size_t String::find_first_of ( const String& str, std::size_t pos ) const +{ + return mString.find_first_of( str.mString, pos ); +} + +std::size_t String::find_first_of ( const char* s, std::size_t pos, std::size_t n ) const +{ + return find_first_of( String( s ), pos ); +} + +std::size_t String::find_first_of ( const char* s, std::size_t pos ) const +{ + return find_first_of( String( s ), pos ); +} + +std::size_t String::find_first_of ( StringBaseType c, std::size_t pos ) const +{ + return mString.find_first_of( c, pos ); +} + +std::size_t String::find_last_of ( const String& str, std::size_t pos ) const +{ + return mString.find_last_of( str.mString, pos ); +} + +std::size_t String::find_last_of ( const char* s, std::size_t pos, std::size_t n ) const +{ + return find_last_of( String( s ), pos ); +} + +std::size_t String::find_last_of ( const char* s, std::size_t pos ) const +{ + return find_last_of( String( s ), pos ); +} + +std::size_t String::find_last_of ( StringBaseType c, std::size_t pos) const +{ + return mString.find_last_of( c, pos ); +} + +std::size_t String::find_first_not_of ( const String& str, std::size_t pos ) const +{ + return mString.find_first_not_of( str.mString, pos ); +} + +std::size_t String::find_first_not_of ( const char* s, std::size_t pos, std::size_t n ) const +{ + return find_first_not_of( String( s ), pos ); +} + +std::size_t String::find_first_not_of ( const char* s, std::size_t pos ) const +{ + return find_first_not_of( String( s ), pos ); +} + +std::size_t String::find_first_not_of ( StringBaseType c, std::size_t pos ) const +{ + return mString.find_first_not_of( c, pos ); +} + +std::size_t String::find_last_not_of ( const String& str, std::size_t pos ) const +{ + return mString.find_last_not_of( str.mString, pos ); +} + +std::size_t String::find_last_not_of ( const char* s, std::size_t pos, std::size_t n ) const +{ + return find_last_not_of( String( s ), pos ); +} + +std::size_t String::find_last_not_of ( const char* s, std::size_t pos ) const +{ + return find_last_not_of( String( s ), pos ); +} + +std::size_t String::find_last_not_of ( StringBaseType c, std::size_t pos ) const +{ + return mString.find_last_not_of( c, pos ); +} + +bool operator ==(const String& left, const String& right) +{ + return left.mString == right.mString; +} + +bool operator !=(const String& left, const String& right) +{ + return !(left == right); +} + +bool operator <(const String& left, const String& right) +{ + return left.mString < right.mString; +} + +bool operator >(const String& left, const String& right) +{ + return right < left; +} + +bool operator <=(const String& left, const String& right) +{ + return !(right < left); +} + +bool operator >=(const String& left, const String& right) +{ + return !(left < right); +} + +String operator +(const String& left, const String& right) +{ + String string = left; + string += right; + + return string; +} + +} diff --git a/src/base/string.hpp b/src/base/string.hpp index 9fac5b5dd..c2b136a21 100644 --- a/src/base/string.hpp +++ b/src/base/string.hpp @@ -1,627 +1,630 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// -/** NOTE: -** The class was modified to fit EEPP own needs. This is not the original implementation from SFML2. -** Functions and methods are the same that in std::string to facilitate portability. -**/ - -#ifndef EE_STRING_HPP -#define EE_STRING_HPP - -#include "../base.hpp" -#include - -namespace EE { - -/** @brief Utility string class that automatically handles conversions between types and encodings **/ -class EE_API String { - public : - typedef Uint32 StringBaseType; - typedef std::basic_string StringType; - typedef StringType::iterator Iterator; //! Iterator type - typedef StringType::const_iterator ConstIterator; //! Constant iterator type - typedef StringType::reverse_iterator ReverseIterator; //! Reverse Iterator type - typedef StringType::const_reverse_iterator ConstReverseIterator; //! Constant iterator type - - static const std::size_t InvalidPos; ///< Represents an invalid position in the string - - /** @brief Default constructor - ** This constructor creates an empty string. - **/ - String(); - - - /** @brief Construct from a single ANSI character - ** The source character is converted to UTF-32 according - ** to the current locale. See the other constructor for - ** explicitely passing the locale to use. - ** @param ansiChar ANSI character to convert - **/ - String( char ansiChar ); - - /** @brief Construct from a single ANSI character and a locale - ** The source character is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. - ** @param ansiChar ANSI character to convert - ** @param locale Locale to use for conversion - **/ - String( char ansiChar, const std::locale& locale ); - - /** @brief Construct from single wide character - ** @param wideChar Wide character to convert - **/ - String( wchar_t wideChar ); - - /** @brief Construct from single UTF-32 character - ** @param utf32Char UTF-32 character to convert - **/ - String( StringBaseType utf32Char ); - - /** @brief Construct from a null-terminated C-style ANSI string - ** The source string is converted to UTF-32 according - ** to the current locale. See the other constructor for - ** explicitely passing the locale to use. - ** @param ansiString ANSI string to convert - **/ - String( const char* ansiString ); - - /** @brief Construct from an ANSI string - ** The source string is converted to UTF-32 according - ** to the current global locale. See the other constructor for - ** explicitely passing the locale to use. - ** @param ansiString ANSI string to convert - **/ - String( const std::string& ansiString ); - - /** @brief Construct from a null-terminated C-style ANSI string and a locale - ** The source string is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. - ** @param ansiString ANSI string to convert - ** @param locale Locale to use for conversion - **/ - String( const char* ansiString, const std::locale& locale ); - - /** @brief Construct from an ANSI string and a locale - ** The source string is converted to UTF-32 according - ** to the given locale. If you want to use the current global - ** locale, rather use the other constructor. - ** @param ansiString ANSI string to convert - ** @param locale Locale to use for conversion - **/ - String( const std::string& ansiString, const std::locale& locale ); - - /** @brief Construct from null-terminated C-style wide string - ** @param wideString Wide string to convert - **/ - String( const wchar_t* wideString ); - - /** @brief Construct from a wide string - ** @param wideString Wide string to convert - **/ - String( const std::wstring& wideString ); - - /** @brief Construct from a null-terminated C-style UTF-32 string - ** @param utf32String UTF-32 string to assign - **/ - String( const StringBaseType* utf32String ); - - /** @brief Construct from an UTF-32 string - ** @param utf32String UTF-32 string to assign - **/ - String( const StringType& utf32String ); - - - /** @brief Copy constructor - ** @param str Instance to copy - **/ - String( const String& str ); - - /** @brief Implicit cast operator to std::string (ANSI string) - ** The current global locale is used for conversion. If you - ** want to explicitely specify a locale, see ToAnsiString. - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** This operator is defined for convenience, and is equivalent - ** to calling ToAnsiString(). - ** @return Converted ANSI string - ** @see ToAnsiString, operator std::wstring - **/ - operator std::string() const; - - - /** @brief Implicit cast operator to std::wstring (wide string) - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** This operator is defined for convenience, and is equivalent - ** to calling ToWideString(). - ** @return Converted wide string - ** @see ToWideString, operator std::string - **/ - operator std::wstring() const; - - - /** @brief Convert the unicode string to an ANSI string - ** The current global locale is used for conversion. If you - ** want to explicitely specify a locale, see the other overload - ** of ToAnsiString. - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** @return Converted ANSI string - ** @see ToWideString, operator std::string - **/ - std::string ToAnsiString() const; - - /** @brief Convert the unicode string to an ANSI string - ** The UTF-32 string is converted to an ANSI string in - ** the encoding defined by \a locale. If you want to use - ** the current global locale, see the other overload - ** of ToAnsiString. - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** @param locale Locale to use for conversion - ** @return Converted ANSI string - ** @see ToWideString, operator std::string - **/ - std::string ToAnsiString(const std::locale& locale) const; - - /** @brief Convert the unicode string to a wide string - ** Characters that do not fit in the target encoding are - ** discarded from the returned string. - ** @return Converted wide string - ** @see ToAnsiString, operator std::wstring - **/ - std::wstring ToWideString() const; - - /** @brief Overload of assignment operator - ** @param right Instance to assign - ** @return Reference to self - **/ - String& operator =(const String& right); - - /** @brief Overload of += operator to append an UTF-32 string - ** @param right String to append - ** @return Reference to self - **/ - String& operator +=(const String& right); - - - /** @brief Overload of [] operator to access a character by its position - ** This function provides read-only access to characters. - ** Note: this function doesn't throw if \a index is out of range. - ** @param index Index of the character to get - ** @return Character at position \a index - **/ - StringBaseType operator [](std::size_t index) const; - - /** @brief Overload of [] operator to access a character by its position - ** This function provides read and write access to characters. - ** Note: this function doesn't throw if \a index is out of range. - ** @param index Index of the character to get - ** @return Reference to the character at position \a index - **/ - - StringBaseType& operator [](std::size_t index); - - /** @brief Get character in string - ** Performs a range check, throwing an exception of type out_of_range in case that pos is not an actual position in the string. - ** @return The character at position pos in the string. - */ - StringBaseType at( std::size_t index ) const; - - /** @brief clear the string - ** This function removes all the characters from the string. - ** @see empty, erase - **/ - void clear(); - - /** @brief Get the size of the string - ** @return Number of characters in the string - ** @see empty - **/ - std::size_t size() const; - - /** @see size() */ - std::size_t length() const; - - /** @brief Check whether the string is empty or not - ** @return True if the string is empty (i.e. contains no character) - ** @see clear, size - **/ - bool empty() const; - - /** @brief Erase one or more characters from the string - ** This function removes a sequence of \a count characters - ** starting from \a position. - ** @param position Position of the first character to erase - ** @param count Number of characters to erase - **/ - void erase(std::size_t position, std::size_t count = 1); - - - /** @brief Insert one or more characters into the string - ** This function inserts the characters of \a str - ** into the string, starting from \a position. - ** @param position Position of insertion - ** @param str Characters to insert - **/ - String& insert(std::size_t position, const String& str); - - String& insert( std::size_t pos1, const String& str, std::size_t pos2, std::size_t n ); - - String& insert ( std::size_t pos1, const char* s, std::size_t n ); - - String& insert ( std::size_t pos1, const char* s ); - - String& insert ( std::size_t pos1, size_t n, char c ); - - Iterator insert ( Iterator p, char c ); - - void insert ( Iterator p, std::size_t n, char c ); - - template - void insert ( Iterator p, InputIterator first, InputIterator last ) - { - mString.insert( p, first, last ); - } - - /** @brief Find a sequence of one or more characters in the string - ** This function searches for the characters of \a str - ** into the string, starting from \a start. - ** @param str Characters to find - ** @param start Where to begin searching - ** @return Position of \a str in the string, or String::InvalidPos if not found - **/ - std::size_t find( const String& str, std::size_t start = 0 ) const; - - std::size_t find ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t find ( const char* s, std::size_t pos = 0 ) const; - - std::size_t find ( char c, std::size_t pos = 0 ) const; - - /** @brief Get a pointer to the C-style array of characters - ** This functions provides a read-only access to a - ** null-terminated C-style representation of the string. - ** The returned pointer is temporary and is meant only for - ** immediate use, thus it is not recommended to store it. - ** @return Read-only pointer to the array of characters - **/ - const StringBaseType* c_str() const; - - /** @brief Get string data - ** Notice that no terminating null character is appended (see member c_str for such a functionality). - ** The returned array points to an internal location which should not be modified directly in the program. - ** Its contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the string object. - ** @return Pointer to an internal array containing the same content as the string. - **/ - const StringBaseType* data() const; - - /** @brief Return an iterator to the beginning of the string - ** @return Read-write iterator to the beginning of the string characters - ** @see end - **/ - Iterator begin(); - - /** @brief Return an iterator to the beginning of the string - ** @return Read-only iterator to the beginning of the string characters - ** @see end - **/ - ConstIterator begin() const; - - /** @brief Return an iterator to the beginning of the string - ** The end iterator refers to 1 position past the last character; - ** thus it represents an invalid character and should never be - ** accessed. - ** @return Read-write iterator to the end of the string characters - ** @see begin - **/ - Iterator end(); - - /** @brief Return an iterator to the beginning of the string - ** The end iterator refers to 1 position past the last character; - ** thus it represents an invalid character and should never be - ** accessed. - ** @return Read-only iterator to the end of the string characters - ** @see begin - **/ - ConstIterator end() const; - - /** @brief Return an reverse iterator to the beginning of the string - ** @return Read-write reverse iterator to the beginning of the string characters - ** @see end - **/ - ReverseIterator rbegin(); - - /** @brief Return an reverse iterator to the beginning of the string - ** @return Read-only reverse iterator to the beginning of the string characters - ** @see end - **/ - ConstReverseIterator rbegin() const; - - /** @brief Return an reverse iterator to the beginning of the string - ** The end reverse iterator refers to 1 position past the last character; - ** thus it represents an invalid character and should never be - ** accessed. - ** @return Read-write reverse iterator to the end of the string characters - ** @see begin - **/ - ReverseIterator rend(); - - - /** @brief Return an reverse iterator to the beginning of the string - ** The end reverse iterator refers to 1 position past the last character; - ** thus it represents an invalid character and should never be - ** accessed. - ** @return Read-only reverse iterator to the end of the string characters - ** @see begin - **/ - ConstReverseIterator rend() const; - - /** @brief Resize String */ - void resize ( std::size_t n, StringBaseType c ); - - /** @brief Resize String */ - void resize ( std::size_t n ); - - /** @return Maximum size of string */ - std::size_t max_size() const; - - /** @brief Request a change in capacity */ - void reserve ( size_t res_arg=0 ); - - /** @return Size of allocated storage */ - std::size_t capacity() const; - - /** @brief Append character to string */ - void push_back( StringBaseType c ); - - /** @brief Swap contents with another string */ - void swap ( String& str ); - - String& assign ( const String& str ); - - String& assign ( const String& str, std::size_t pos, std::size_t n ); - - String& assign ( const char* s, std::size_t n ); - - String& assign ( const char* s ); - - String& assign ( std::size_t n, char c ); - - template - String& assign ( InputIterator first, InputIterator last ) - { - mString.assign( first, last ); - return *this; - } - - String& append ( const String& str ); - - String& append ( const String& str, std::size_t pos, std::size_t n ); - - String& append ( const char* s, std::size_t n ); - - String& append ( const char* s ); - - String& append ( std::size_t n, char c ); - - template - String& append ( InputIterator first, InputIterator last ) - { - mString.append( first, last ); - return *this; - } - - String& replace ( std::size_t pos1, std::size_t n1, const String& str ); - - String& replace ( Iterator i1, Iterator i2, const String& str ); - - String& replace ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ); - - String& replace ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2 ); - - String& replace ( Iterator i1, Iterator i2, const char* s, std::size_t n2 ); - - String& replace ( std::size_t pos1, std::size_t n1, const char* s ); - - String& replace ( Iterator i1, Iterator i2, const char* s ); - - String& replace ( std::size_t pos1, std::size_t n1, std::size_t n2, char c ); - - String& replace ( Iterator i1, Iterator i2, std::size_t n2, char c ); - - template - String& replace ( Iterator i1, Iterator i2, InputIterator j1, InputIterator j2 ) - { - mString.replace( i1, i2, j1, j2 ); - return *this; - } - - std::size_t rfind ( const String& str, std::size_t pos = StringType::npos ) const; - - std::size_t rfind ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t rfind ( const char* s, std::size_t pos = StringType::npos ) const; - - std::size_t rfind ( char c, std::size_t pos = StringType::npos ) const; - - String substr ( std::size_t pos = 0, std::size_t n = StringType::npos ) const; - - std::size_t copy ( StringBaseType* s, std::size_t n, std::size_t pos = 0 ) const; - - int compare ( const String& str ) const; - - int compare ( const char* s ) const; - - int compare ( std::size_t pos1, std::size_t n1, const String& str ) const; - - int compare ( std::size_t pos1, std::size_t n1, const char* s) const; - - int compare ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ) const; - - int compare ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2) const; - - std::size_t find_first_of ( const String& str, std::size_t pos = 0 ) const; - - std::size_t find_first_of ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t find_first_of ( const char* s, std::size_t pos = 0 ) const; - - std::size_t find_first_of ( StringBaseType c, std::size_t pos = 0 ) const; - - std::size_t find_last_of ( const String& str, std::size_t pos = StringType::npos ) const; - - std::size_t find_last_of ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t find_last_of ( const char* s, std::size_t pos = StringType::npos ) const; - - std::size_t find_last_of ( StringBaseType c, std::size_t pos = StringType::npos ) const; - - std::size_t find_first_not_of ( const String& str, std::size_t pos = 0 ) const; - - std::size_t find_first_not_of ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t find_first_not_of ( const char* s, std::size_t pos = 0 ) const; - - std::size_t find_first_not_of ( StringBaseType c, std::size_t pos = 0 ) const; - - std::size_t find_last_not_of ( const String& str, std::size_t pos = StringType::npos ) const; - - std::size_t find_last_not_of ( const char* s, std::size_t pos, std::size_t n ) const; - - std::size_t find_last_not_of ( const char* s, std::size_t pos = StringType::npos ) const; - - std::size_t find_last_not_of ( StringBaseType c, std::size_t pos = StringType::npos ) const; -private : - friend EE_API bool operator ==(const String& left, const String& right); - friend EE_API bool operator <(const String& left, const String& right); - - StringType mString; ///< Internal string of UTF-32 characters -}; - -/** @relates String -** @brief Overload of == operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if both strings are equal -**/ -EE_API bool operator ==(const String& left, const String& right); - -/** @relates String -** @brief Overload of != operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if both strings are different -**/ -EE_API bool operator !=(const String& left, const String& right); - -/** @relates String -** @brief Overload of < operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if \a left is alphabetically lesser than \a right -**/ -EE_API bool operator <(const String& left, const String& right); - -/** @relates String -** @brief Overload of > operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if \a left is alphabetically greater than \a right -**/ -EE_API bool operator >(const String& left, const String& right); - -/** @relates String -** @brief Overload of <= operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if \a left is alphabetically lesser or equal than \a right -**/ -EE_API bool operator <=(const String& left, const String& right); - -/** @relates String -** @brief Overload of >= operator to compare two UTF-32 strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return True if \a left is alphabetically greater or equal than \a right -**/ -EE_API bool operator >=(const String& left, const String& right); - -/** @relates String -** @brief Overload of binary + operator to concatenate two strings -** @param left Left operand (a string) -** @param right Right operand (a string) -** @return Concatenated string -**/ -EE_API String operator +( const String& left, const String& right ); - -} - -#endif - -/** @class EE::String -** @ingroup system -** EE::String is a utility string class defined mainly for -** convenience. It is a Unicode string (implemented using -** UTF-32), thus it can store any character in the world -** (european, chinese, arabic, hebrew, etc.). -** It automatically handles conversions from/to ANSI and -** wide strings, so that you can work with standard string -** classes and still be compatible with functions taking a -** EE::String. -** @code -** EE::String s; -** std::string s1 = s; // automatically converted to ANSI string -** std::wstring s2 = s; // automatically converted to wide string -** s = "hello"; // automatically converted from ANSI string -** s = L"hello"; // automatically converted from wide string -** s += 'a'; // automatically converted from ANSI string -** s += L'a'; // automatically converted from wide string -** @endcode -** Conversions involving ANSI strings use the default user locale. However -** it is possible to use a custom locale if necessary: -** @code -** std::locale locale; -** EE::String s; -** ... -** std::string s1 = s.ToAnsiString(locale); -** s = EE::String("hello", locale); -** @endcode -** -** EE::String defines the most important functions of the -** standard std::string class: removing, random access, iterating, -** appending, comparing, etc. However it is a simple class -** provided for convenience, and you may have to consider using -** a more optimized class if your program requires complex string -** handling. The automatic conversion functions will then take -** care of converting your string to EE::String whenever EE -** requires it. -** -** Please note that EE also defines a low-level, generic -** interface for Unicode handling, see the EE::Utf classes. -** -** All credits to Laurent Gomila, i just modified a little bit the implementation. -**/ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// +/** NOTE: +** The class was modified to fit EEPP own needs. This is not the original implementation from SFML2. +** Functions and methods are the same that in std::string to facilitate portability. +**/ + +#ifndef EE_STRING_HPP +#define EE_STRING_HPP + +#include "../base.hpp" +#include + +namespace EE { + +/** @brief Utility string class that automatically handles conversions between types and encodings **/ +class EE_API String { + public : + typedef Uint32 StringBaseType; + typedef std::basic_string StringType; + typedef StringType::iterator Iterator; //! Iterator type + typedef StringType::const_iterator ConstIterator; //! Constant iterator type + typedef StringType::reverse_iterator ReverseIterator; //! Reverse Iterator type + typedef StringType::const_reverse_iterator ConstReverseIterator; //! Constant iterator type + + static const std::size_t InvalidPos; ///< Represents an invalid position in the string + + static String FromUtf8( const std::string& utf8 ); + + /** @brief Default constructor + ** This constructor creates an empty string. + **/ + String(); + + /** @brief Construct from a single ANSI character + ** The source character is converted to UTF-32 according + ** to the current locale. See the other constructor for + ** explicitely passing the locale to use. + ** @param ansiChar ANSI character to convert + **/ + String( char ansiChar ); + + /** @brief Construct from a single ANSI character and a locale + ** The source character is converted to UTF-32 according + ** to the given locale. If you want to use the current global + ** locale, rather use the other constructor. + ** @param ansiChar ANSI character to convert + ** @param locale Locale to use for conversion + **/ + String( char ansiChar, const std::locale& locale ); + + /** @brief Construct from single wide character + ** @param wideChar Wide character to convert + **/ + String( wchar_t wideChar ); + + /** @brief Construct from single UTF-32 character + ** @param utf32Char UTF-32 character to convert + **/ + String( StringBaseType utf32Char ); + + /** @brief Construct from a null-terminated C-style ANSI string + ** The source string is converted to UTF-32 according + ** to the current locale. See the other constructor for + ** explicitely passing the locale to use. + ** @param ansiString ANSI string to convert + **/ + String( const char* ansiString ); + + /** @brief Construct from an ANSI string + ** The source string is converted to UTF-32 according + ** to the current global locale. See the other constructor for + ** explicitely passing the locale to use. + ** @param ansiString ANSI string to convert + **/ + String( const std::string& ansiString ); + + /** @brief Construct from a null-terminated C-style ANSI string and a locale + ** The source string is converted to UTF-32 according + ** to the given locale. If you want to use the current global + ** locale, rather use the other constructor. + ** @param ansiString ANSI string to convert + ** @param locale Locale to use for conversion + **/ + String( const char* ansiString, const std::locale& locale ); + + /** @brief Construct from an ANSI string and a locale + ** The source string is converted to UTF-32 according + ** to the given locale. If you want to use the current global + ** locale, rather use the other constructor. + ** @param ansiString ANSI string to convert + ** @param locale Locale to use for conversion + **/ + String( const std::string& ansiString, const std::locale& locale ); + + /** @brief Construct from null-terminated C-style wide string + ** @param wideString Wide string to convert + **/ + String( const wchar_t* wideString ); + + /** @brief Construct from a wide string + ** @param wideString Wide string to convert + **/ + String( const std::wstring& wideString ); + + /** @brief Construct from a null-terminated C-style UTF-32 string + ** @param utf32String UTF-32 string to assign + **/ + String( const StringBaseType* utf32String ); + + /** @brief Construct from an UTF-32 string + ** @param utf32String UTF-32 string to assign + **/ + String( const StringType& utf32String ); + + + /** @brief Copy constructor + ** @param str Instance to copy + **/ + String( const String& str ); + + /** @brief Implicit cast operator to std::string (ANSI string) + ** The current global locale is used for conversion. If you + ** want to explicitely specify a locale, see ToAnsiString. + ** Characters that do not fit in the target encoding are + ** discarded from the returned string. + ** This operator is defined for convenience, and is equivalent + ** to calling ToAnsiString(). + ** @return Converted ANSI string + ** @see ToAnsiString, operator String + **/ + operator std::string() const; + + /** @brief Implicit cast operator to String (wide string) + ** Characters that do not fit in the target encoding are + ** discarded from the returned string. + ** This operator is defined for convenience, and is equivalent + ** to calling ToWideString(). + ** @return Converted wide string + ** @see ToWideString, operator std::string + **/ + operator std::wstring() const; + + /** @brief Convert the unicode string to an ANSI string + ** The current global locale is used for conversion. If you + ** want to explicitely specify a locale, see the other overload + ** of ToAnsiString. + ** Characters that do not fit in the target encoding are + ** discarded from the returned string. + ** @return Converted ANSI string + ** @see ToWideString, operator std::string + **/ + std::string ToAnsiString() const; + + /** @brief Convert the unicode string to an ANSI string + ** The UTF-32 string is converted to an ANSI string in + ** the encoding defined by \a locale. If you want to use + ** the current global locale, see the other overload + ** of ToAnsiString. + ** Characters that do not fit in the target encoding are + ** discarded from the returned string. + ** @param locale Locale to use for conversion + ** @return Converted ANSI string + ** @see ToWideString, operator std::string + **/ + std::string ToAnsiString(const std::locale& locale) const; + + /** @brief Convert the unicode string to a wide string + ** Characters that do not fit in the target encoding are + ** discarded from the returned string. + ** @return Converted wide string + ** @see ToAnsiString, operator String + **/ + String ToWideString() const; + + std::string ToUtf8() const; + + /** @brief Overload of assignment operator + ** @param right Instance to assign + ** @return Reference to self + **/ + String& operator =(const String& right); + + /** @brief Overload of += operator to append an UTF-32 string + ** @param right String to append + ** @return Reference to self + **/ + String& operator +=(const String& right); + + + /** @brief Overload of [] operator to access a character by its position + ** This function provides read-only access to characters. + ** Note: this function doesn't throw if \a index is out of range. + ** @param index Index of the character to get + ** @return Character at position \a index + **/ + StringBaseType operator [](std::size_t index) const; + + /** @brief Overload of [] operator to access a character by its position + ** This function provides read and write access to characters. + ** Note: this function doesn't throw if \a index is out of range. + ** @param index Index of the character to get + ** @return Reference to the character at position \a index + **/ + + StringBaseType& operator [](std::size_t index); + + /** @brief Get character in string + ** Performs a range check, throwing an exception of type out_of_range in case that pos is not an actual position in the string. + ** @return The character at position pos in the string. + */ + StringBaseType at( std::size_t index ) const; + + /** @brief clear the string + ** This function removes all the characters from the string. + ** @see empty, erase + **/ + void clear(); + + /** @brief Get the size of the string + ** @return Number of characters in the string + ** @see empty + **/ + std::size_t size() const; + + /** @see size() */ + std::size_t length() const; + + /** @brief Check whether the string is empty or not + ** @return True if the string is empty (i.e. contains no character) + ** @see clear, size + **/ + bool empty() const; + + /** @brief Erase one or more characters from the string + ** This function removes a sequence of \a count characters + ** starting from \a position. + ** @param position Position of the first character to erase + ** @param count Number of characters to erase + **/ + void erase(std::size_t position, std::size_t count = 1); + + + /** @brief Insert one or more characters into the string + ** This function inserts the characters of \a str + ** into the string, starting from \a position. + ** @param position Position of insertion + ** @param str Characters to insert + **/ + String& insert(std::size_t position, const String& str); + + String& insert( std::size_t pos1, const String& str, std::size_t pos2, std::size_t n ); + + String& insert ( std::size_t pos1, const char* s, std::size_t n ); + + String& insert ( std::size_t pos1, const char* s ); + + String& insert ( std::size_t pos1, size_t n, char c ); + + Iterator insert ( Iterator p, char c ); + + void insert ( Iterator p, std::size_t n, char c ); + + template + void insert ( Iterator p, InputIterator first, InputIterator last ) + { + mString.insert( p, first, last ); + } + + /** @brief Find a sequence of one or more characters in the string + ** This function searches for the characters of \a str + ** into the string, starting from \a start. + ** @param str Characters to find + ** @param start Where to begin searching + ** @return Position of \a str in the string, or String::InvalidPos if not found + **/ + std::size_t find( const String& str, std::size_t start = 0 ) const; + + std::size_t find ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t find ( const char* s, std::size_t pos = 0 ) const; + + std::size_t find ( char c, std::size_t pos = 0 ) const; + + /** @brief Get a pointer to the C-style array of characters + ** This functions provides a read-only access to a + ** null-terminated C-style representation of the string. + ** The returned pointer is temporary and is meant only for + ** immediate use, thus it is not recommended to store it. + ** @return Read-only pointer to the array of characters + **/ + const StringBaseType* c_str() const; + + /** @brief Get string data + ** Notice that no terminating null character is appended (see member c_str for such a functionality). + ** The returned array points to an internal location which should not be modified directly in the program. + ** Its contents are guaranteed to remain unchanged only until the next call to a non-constant member function of the string object. + ** @return Pointer to an internal array containing the same content as the string. + **/ + const StringBaseType* data() const; + + /** @brief Return an iterator to the beginning of the string + ** @return Read-write iterator to the beginning of the string characters + ** @see end + **/ + Iterator begin(); + + /** @brief Return an iterator to the beginning of the string + ** @return Read-only iterator to the beginning of the string characters + ** @see end + **/ + ConstIterator begin() const; + + /** @brief Return an iterator to the beginning of the string + ** The end iterator refers to 1 position past the last character; + ** thus it represents an invalid character and should never be + ** accessed. + ** @return Read-write iterator to the end of the string characters + ** @see begin + **/ + Iterator end(); + + /** @brief Return an iterator to the beginning of the string + ** The end iterator refers to 1 position past the last character; + ** thus it represents an invalid character and should never be + ** accessed. + ** @return Read-only iterator to the end of the string characters + ** @see begin + **/ + ConstIterator end() const; + + /** @brief Return an reverse iterator to the beginning of the string + ** @return Read-write reverse iterator to the beginning of the string characters + ** @see end + **/ + ReverseIterator rbegin(); + + /** @brief Return an reverse iterator to the beginning of the string + ** @return Read-only reverse iterator to the beginning of the string characters + ** @see end + **/ + ConstReverseIterator rbegin() const; + + /** @brief Return an reverse iterator to the beginning of the string + ** The end reverse iterator refers to 1 position past the last character; + ** thus it represents an invalid character and should never be + ** accessed. + ** @return Read-write reverse iterator to the end of the string characters + ** @see begin + **/ + ReverseIterator rend(); + + + /** @brief Return an reverse iterator to the beginning of the string + ** The end reverse iterator refers to 1 position past the last character; + ** thus it represents an invalid character and should never be + ** accessed. + ** @return Read-only reverse iterator to the end of the string characters + ** @see begin + **/ + ConstReverseIterator rend() const; + + /** @brief Resize String */ + void resize ( std::size_t n, StringBaseType c ); + + /** @brief Resize String */ + void resize ( std::size_t n ); + + /** @return Maximum size of string */ + std::size_t max_size() const; + + /** @brief Request a change in capacity */ + void reserve ( size_t res_arg=0 ); + + /** @return Size of allocated storage */ + std::size_t capacity() const; + + /** @brief Append character to string */ + void push_back( StringBaseType c ); + + /** @brief Swap contents with another string */ + void swap ( String& str ); + + String& assign ( const String& str ); + + String& assign ( const String& str, std::size_t pos, std::size_t n ); + + String& assign ( const char* s, std::size_t n ); + + String& assign ( const char* s ); + + String& assign ( std::size_t n, char c ); + + template + String& assign ( InputIterator first, InputIterator last ) + { + mString.assign( first, last ); + return *this; + } + + String& append ( const String& str ); + + String& append ( const String& str, std::size_t pos, std::size_t n ); + + String& append ( const char* s, std::size_t n ); + + String& append ( const char* s ); + + String& append ( std::size_t n, char c ); + + String& append ( std::size_t n, StringBaseType c ); + + template + String& append ( InputIterator first, InputIterator last ) + { + mString.append( first, last ); + return *this; + } + + String& replace ( std::size_t pos1, std::size_t n1, const String& str ); + + String& replace ( Iterator i1, Iterator i2, const String& str ); + + String& replace ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ); + + String& replace ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2 ); + + String& replace ( Iterator i1, Iterator i2, const char* s, std::size_t n2 ); + + String& replace ( std::size_t pos1, std::size_t n1, const char* s ); + + String& replace ( Iterator i1, Iterator i2, const char* s ); + + String& replace ( std::size_t pos1, std::size_t n1, std::size_t n2, char c ); + + String& replace ( Iterator i1, Iterator i2, std::size_t n2, char c ); + + template + String& replace ( Iterator i1, Iterator i2, InputIterator j1, InputIterator j2 ) + { + mString.replace( i1, i2, j1, j2 ); + return *this; + } + + std::size_t rfind ( const String& str, std::size_t pos = StringType::npos ) const; + + std::size_t rfind ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t rfind ( const char* s, std::size_t pos = StringType::npos ) const; + + std::size_t rfind ( char c, std::size_t pos = StringType::npos ) const; + + String substr ( std::size_t pos = 0, std::size_t n = StringType::npos ) const; + + std::size_t copy ( StringBaseType* s, std::size_t n, std::size_t pos = 0 ) const; + + int compare ( const String& str ) const; + + int compare ( const char* s ) const; + + int compare ( std::size_t pos1, std::size_t n1, const String& str ) const; + + int compare ( std::size_t pos1, std::size_t n1, const char* s) const; + + int compare ( std::size_t pos1, std::size_t n1, const String& str, std::size_t pos2, std::size_t n2 ) const; + + int compare ( std::size_t pos1, std::size_t n1, const char* s, std::size_t n2) const; + + std::size_t find_first_of ( const String& str, std::size_t pos = 0 ) const; + + std::size_t find_first_of ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t find_first_of ( const char* s, std::size_t pos = 0 ) const; + + std::size_t find_first_of ( StringBaseType c, std::size_t pos = 0 ) const; + + std::size_t find_last_of ( const String& str, std::size_t pos = StringType::npos ) const; + + std::size_t find_last_of ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t find_last_of ( const char* s, std::size_t pos = StringType::npos ) const; + + std::size_t find_last_of ( StringBaseType c, std::size_t pos = StringType::npos ) const; + + std::size_t find_first_not_of ( const String& str, std::size_t pos = 0 ) const; + + std::size_t find_first_not_of ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t find_first_not_of ( const char* s, std::size_t pos = 0 ) const; + + std::size_t find_first_not_of ( StringBaseType c, std::size_t pos = 0 ) const; + + std::size_t find_last_not_of ( const String& str, std::size_t pos = StringType::npos ) const; + + std::size_t find_last_not_of ( const char* s, std::size_t pos, std::size_t n ) const; + + std::size_t find_last_not_of ( const char* s, std::size_t pos = StringType::npos ) const; + + std::size_t find_last_not_of ( StringBaseType c, std::size_t pos = StringType::npos ) const; +private : + friend EE_API bool operator ==(const String& left, const String& right); + friend EE_API bool operator <(const String& left, const String& right); + + StringType mString; ///< Internal string of UTF-32 characters +}; + +/** @relates String +** @brief Overload of == operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if both strings are equal +**/ +EE_API bool operator ==(const String& left, const String& right); + +/** @relates String +** @brief Overload of != operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if both strings are different +**/ +EE_API bool operator !=(const String& left, const String& right); + +/** @relates String +** @brief Overload of < operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if \a left is alphabetically lesser than \a right +**/ +EE_API bool operator <(const String& left, const String& right); + +/** @relates String +** @brief Overload of > operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if \a left is alphabetically greater than \a right +**/ +EE_API bool operator >(const String& left, const String& right); + +/** @relates String +** @brief Overload of <= operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if \a left is alphabetically lesser or equal than \a right +**/ +EE_API bool operator <=(const String& left, const String& right); + +/** @relates String +** @brief Overload of >= operator to compare two UTF-32 strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return True if \a left is alphabetically greater or equal than \a right +**/ +EE_API bool operator >=(const String& left, const String& right); + +/** @relates String +** @brief Overload of binary + operator to concatenate two strings +** @param left Left operand (a string) +** @param right Right operand (a string) +** @return Concatenated string +**/ +EE_API String operator +( const String& left, const String& right ); + +} + +#endif + +/** @class EE::String +** @ingroup system +** EE::String is a utility string class defined mainly for +** convenience. It is a Unicode string (implemented using +** UTF-32), thus it can store any character in the world +** (european, chinese, arabic, hebrew, etc.). +** It automatically handles conversions from/to ANSI and +** wide strings, so that you can work with standard string +** classes and still be compatible with functions taking a +** EE::String. +** @code +** EE::String s; +** std::string s1 = s; // automatically converted to ANSI string +** String s2 = s; // automatically converted to wide string +** s = "hello"; // automatically converted from ANSI string +** s = L"hello"; // automatically converted from wide string +** s += 'a'; // automatically converted from ANSI string +** s += L'a'; // automatically converted from wide string +** @endcode +** Conversions involving ANSI strings use the default user locale. However +** it is possible to use a custom locale if necessary: +** @code +** std::locale locale; +** EE::String s; +** ... +** std::string s1 = s.ToAnsiString(locale); +** s = EE::String("hello", locale); +** @endcode +** +** EE::String defines the most important functions of the +** standard std::string class: removing, random access, iterating, +** appending, comparing, etc. However it is a simple class +** provided for convenience, and you may have to consider using +** a more optimized class if your program requires complex string +** handling. The automatic conversion functions will then take +** care of converting your string to EE::String whenever EE +** requires it. +** +** Please note that EE also defines a low-level, generic +** interface for Unicode handling, see the EE::Utf classes. +** +** All credits to Laurent Gomila, i just modified a little bit the implementation. +**/ diff --git a/src/ee.h b/src/ee.h index 405910a69..c7e3305bf 100755 --- a/src/ee.h +++ b/src/ee.h @@ -22,7 +22,6 @@ **/ /** - @TODO Remove std::wstring dependency ( wchar_t ), and create an eeString class to manage strings without wchar_t platform restrictions ( Android only supports wchar_t in 2.3 ). @TODO Check for endianness problems, and make EEPP endianness agnostic. @TODO Add backend for SDL 1.3 ( support for Android ). And may be SFML backend ( just for fun ). @TODO Support for Android and iOS. diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp index b9f299101..1f5d28a38 100755 --- a/src/graphics/cconsole.cpp +++ b/src/graphics/cconsole.cpp @@ -100,15 +100,11 @@ void cConsole::Create( cFont* Font, const bool& MakeDefaultCommands, const eeUin CmdGetLog(); } -void cConsole::AddCommand( const std::wstring& Command, ConsoleCallback CB ) { +void cConsole::AddCommand( const String& Command, ConsoleCallback CB ) { if ( !(mCallbacks.count( Command ) > 0) ) mCallbacks[Command] = CB; } -void cConsole::AddCommand( const std::string& Command, ConsoleCallback CB ) { - AddCommand ( toWStr( Command ), CB ); -} - void cConsole::Draw() { if ( mEnabled && NULL != mFont ) { Fade(); @@ -157,22 +153,22 @@ void cConsole::Draw() { CurY = mTempY + mY + mCurHeight - mFontSize; mFont->Color( eeColorA ( mFontLineColor.R(), mFontLineColor.G(), mFontLineColor.B(), static_cast(mA) ) ); - mFont->SetText( L"> " + mTBuf.Buffer() ); + mFont->SetText( "> " + mTBuf.Buffer() ); mFont->Draw( mFontSize, CurY ); mFont->Color( eeColorA ( mFontLineColor.R(), mFontLineColor.G(), mFontLineColor.B(), static_cast(mCurAlpha) ) ); if ( (eeUint)mTBuf.CurPos() == mTBuf.Buffer().size() ) { - mFont->Draw( L"_", mFontSize + mFont->GetTextWidth() , CurY ); + mFont->Draw( "_", mFontSize + mFont->GetTextWidth() , CurY ); } else { - mFont->SetText( L"> " + mTBuf.Buffer().substr( 0, mTBuf.CurPos() ) ); - mFont->Draw( L"_", mFontSize + mFont->GetTextWidth() , CurY ); + mFont->SetText( "> " + mTBuf.Buffer().substr( 0, mTBuf.CurPos() ) ); + mFont->Draw( "_", mFontSize + mFont->GetTextWidth() , CurY ); } } } if ( mShowFps ) { mFont->Color( eeColorA () ); - mFont->SetText( L"FPS: " + toWStr( mWindow->FPS() ) ); + mFont->SetText( "FPS: " + toStr( mWindow->FPS() ) ); mFont->Draw( mWindow->GetWidth() - mFont->GetTextWidth() - 15, 6 ); } } @@ -197,42 +193,38 @@ void cConsole::FadeOut() { } void cConsole::ProcessLine() { - std::wstring wstr = mTBuf.Buffer();; - std::vector < std::wstring > params = SplitString( wstr, ' ' ); + String str = mTBuf.Buffer();; + std::vector < String > params = SplitString( str, ' ' ); - mLastCommands.push_back( wstr ); + mLastCommands.push_back( str ); mLastLogPos = (eeInt)mLastCommands.size(); if ( mLastCommands.size() > 20 ) mLastCommands.pop_front(); - if ( wstr.size() > 0 ) { - PushText( L"> " + params[0] ); + if ( str.size() > 0 ) { + PushText( "> " + params[0] ); if ( mCallbacks.find( params[0] ) != mCallbacks.end() ) { mCallbacks[ params[0] ]( params ); } else { - PushText( L"Unknown Command: '" + params[0] + L"'" ); + PushText( "Unknown Command: '" + params[0] + "'" ); } } mTBuf.Clear(); } -void cConsole::PrivPushText( const std::wstring& str ) { +void cConsole::PrivPushText( const String& str ) { mCmdLog.push_back( str ); if ( mCmdLog.size() >= mMaxLogLines ) mCmdLog.pop_front(); } -void cConsole::PushText( const std::wstring& str ) { +void cConsole::PushText( const String& str ) { PrivPushText( str ); } -void cConsole::PushText( const std::string& str ) { - PrivPushText( toWStr( str ) ); -} - void cConsole::PushText( const char * format, ... ) { int n, size = 256; std::string tstr( size, '\0' ); @@ -322,9 +314,9 @@ void cConsole::Fade() { if ( mA < 0.0f ) mA = 0.0f; } -void cConsole::PrintCommandsStartingWith( const std::wstring& start ) { - std::list cmds; - std::map < std::wstring, ConsoleCallback >::iterator it; +void cConsole::PrintCommandsStartingWith( const String& start ) { + std::list cmds; + std::map < String, ConsoleCallback >::iterator it; for ( it = mCallbacks.begin(); it != mCallbacks.end(); it++ ) { if ( -1 != StrStartsWith( start, it->first ) ) { @@ -333,9 +325,9 @@ void cConsole::PrintCommandsStartingWith( const std::wstring& start ) { } if ( cmds.size() > 1 ) { - PushText( L"> " + mTBuf.Buffer() ); + PushText( "> " + mTBuf.Buffer() ); - std::list::iterator ite; + std::list::iterator ite; for ( ite = cmds.begin(); ite != cmds.end(); ite++ ) PushText( (*ite) ); @@ -384,7 +376,7 @@ void cConsole::PrivInputCallback( InputEvent * Event ) { if ( KeyCode == KEY_UP || KeyCode == KEY_DOWN ) { if ( mLastLogPos == static_cast( mLastCommands.size() ) ) { - mTBuf.Buffer( L"" ); + mTBuf.Buffer( "" ); } else { mTBuf.Buffer( mLastCommands[mLastLogPos] ); mTBuf.CursorToEnd(); @@ -426,22 +418,22 @@ void cConsole::PrivInputCallback( InputEvent * Event ) { } void cConsole::CreateDefaultCommands() { - AddCommand( L"clear", cb::Make1( this, &cConsole::CmdClear) ); - AddCommand( L"quit", cb::Make1( this, &cConsole::CmdQuit) ); - AddCommand( L"maximize", cb::Make1( this, &cConsole::CmdMaximize) ); - AddCommand( L"minimize", cb::Make1( this, &cConsole::CmdMinimize) ); - AddCommand( L"cmdlist", cb::Make1( this, &cConsole::CmdCmdList) ); - AddCommand( L"help", cb::Make1( this, &cConsole::CmdCmdList) ); - AddCommand( L"showcursor", cb::Make1( this, &cConsole::CmdShowCursor) ); - AddCommand( L"setframelimit", cb::Make1( this, &cConsole::CmdFrameLimit) ); - AddCommand( L"getlog", cb::Make1( this, &cConsole::CmdGetLog) ); - AddCommand( L"setgamma", cb::Make1( this, &cConsole::CmdSetGamma) ); - AddCommand( L"setvolume", cb::Make1( this, &cConsole::CmdSetVolume) ); - AddCommand( L"getgpuextensions", cb::Make1( this, &cConsole::CmdGetGpuExtensions) ); - AddCommand( L"dir", cb::Make1( this, &cConsole::CmdDir) ); - AddCommand( L"ls", cb::Make1( this, &cConsole::CmdDir) ); - AddCommand( L"showfps", cb::Make1( this, &cConsole::CmdShowFps) ); - AddCommand( L"gettexturememory", cb::Make1( this, &cConsole::CmdGetTextureMemory) ); + AddCommand( "clear", cb::Make1( this, &cConsole::CmdClear) ); + AddCommand( "quit", cb::Make1( this, &cConsole::CmdQuit) ); + AddCommand( "maximize", cb::Make1( this, &cConsole::CmdMaximize) ); + AddCommand( "minimize", cb::Make1( this, &cConsole::CmdMinimize) ); + AddCommand( "cmdlist", cb::Make1( this, &cConsole::CmdCmdList) ); + AddCommand( "help", cb::Make1( this, &cConsole::CmdCmdList) ); + AddCommand( "showcursor", cb::Make1( this, &cConsole::CmdShowCursor) ); + AddCommand( "setframelimit", cb::Make1( this, &cConsole::CmdFrameLimit) ); + AddCommand( "getlog", cb::Make1( this, &cConsole::CmdGetLog) ); + AddCommand( "setgamma", cb::Make1( this, &cConsole::CmdSetGamma) ); + AddCommand( "setvolume", cb::Make1( this, &cConsole::CmdSetVolume) ); + AddCommand( "getgpuextensions", cb::Make1( this, &cConsole::CmdGetGpuExtensions) ); + AddCommand( "dir", cb::Make1( this, &cConsole::CmdDir) ); + AddCommand( "ls", cb::Make1( this, &cConsole::CmdDir) ); + AddCommand( "showfps", cb::Make1( this, &cConsole::CmdShowFps) ); + AddCommand( "gettexturememory", cb::Make1( this, &cConsole::CmdGetTextureMemory) ); } void cConsole::CmdClear () { @@ -453,158 +445,158 @@ void cConsole::CmdClear () { } for (Uint16 i = 0; i < CutLines; i++ ) - PushText( L"" ); + PushText( "" ); } -void cConsole::CmdClear ( const std::vector < std::wstring >& params ) { +void cConsole::CmdClear ( const std::vector < String >& params ) { CmdClear(); } -void cConsole::CmdMaximize ( const std::vector < std::wstring >& params ) { +void cConsole::CmdMaximize ( const std::vector < String >& params ) { mExpand = true; mY = mHeight; - PushText( L"Console Maximized" ); + PushText( "Console Maximized" ); } -void cConsole::CmdMinimize ( const std::vector < std::wstring >& params ) { +void cConsole::CmdMinimize ( const std::vector < String >& params ) { mExpand = false; mY = mHeightMin; - PushText( L"Console Minimized" ); + PushText( "Console Minimized" ); } -void cConsole::CmdQuit ( const std::vector < std::wstring >& params ) { +void cConsole::CmdQuit ( const std::vector < String >& params ) { mWindow->Close(); } -void cConsole::CmdGetTextureMemory ( const std::vector < std::wstring >& params ) { - PushText( L"Total texture memory used: " + SizeToWString( cTextureFactory::instance()->MemorySize() ) ); +void cConsole::CmdGetTextureMemory ( const std::vector < String >& params ) { + PushText( "Total texture memory used: " + SizeToString( cTextureFactory::instance()->MemorySize() ) ); } -void cConsole::CmdCmdList ( const std::vector < std::wstring >& params ) { - std::map < std::wstring, ConsoleCallback >::iterator itr; +void cConsole::CmdCmdList ( const std::vector < String >& params ) { + std::map < String, ConsoleCallback >::iterator itr; for (itr = mCallbacks.begin(); itr != mCallbacks.end(); itr++) { PushText( itr->first ); } } -void cConsole::CmdShowCursor ( const std::vector < std::wstring >& params ) { +void cConsole::CmdShowCursor ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { Int32 tInt = 0; - bool Res = fromWString( tInt, params[1] ); + bool Res = fromString( tInt, params[1] ); if ( Res && ( tInt == 0 || tInt == 1 ) ) { mWindow->GetCursorManager()->Visible( 0 != tInt ); - PushText( L"showcursor " + toWStr(tInt) ); + PushText( "showcursor " + toStr( tInt ) ); } else - PushText( L"Valid parameters are 0 or 1." ); + PushText( "Valid parameters are 0 or 1." ); } catch (...) { - PushText( L"Invalid Parameter. Expected int value from '" + params[1] + L"'." ); + PushText( "Invalid Parameter. Expected int value from '" + params[1] + "'." ); } } } -void cConsole::CmdFrameLimit ( const std::vector < std::wstring >& params ) { +void cConsole::CmdFrameLimit ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { Int32 tInt = 0; - bool Res = fromWString( tInt, params[1] ); + bool Res = fromString( tInt, params[1] ); if ( Res && ( tInt >= 0 && tInt <= 10000 ) ) { mWindow->FrameRateLimit( tInt ); - PushText( L"setframelimit " + toWStr(tInt) ); + PushText( "setframelimit " + toStr( tInt ) ); } else - PushText( L"Valid parameters are between 0 and 10000 (0 = no limit)." ); + PushText( "Valid parameters are between 0 and 10000 (0 = no limit)." ); } catch (...) { - PushText( L"Invalid Parameter. Expected int value from '" + params[1] + L"'." ); + PushText( "Invalid Parameter. Expected int value from '" + params[1] + "'." ); } } } void cConsole::CmdGetLog() { - std::vector < std::wstring > tvec = SplitString( toWStr( cLog::instance()->Buffer() ) ); + std::vector < String > tvec = SplitString( String( toStr( cLog::instance()->Buffer() ) ) ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) PushText( tvec[i] ); } } -void cConsole::CmdGetLog( const std::vector < std::wstring >& params ) { +void cConsole::CmdGetLog( const std::vector < String >& params ) { CmdGetLog(); } void cConsole::CmdGetGpuExtensions() { char *Exts = GLi->GetExtensions(); - std::vector < std::wstring > tvec = SplitString( toWStr( std::string( Exts ) ), ' ' ); + std::vector < String > tvec = SplitString( String( toStr( std::string( Exts ) ) ), ' ' ); if ( tvec.size() > 0 ) { for ( eeUint i = 0; i < tvec.size(); i++ ) PushText( tvec[i] ); } } -void cConsole::CmdGetGpuExtensions( const std::vector < std::wstring >& params ) { +void cConsole::CmdGetGpuExtensions( const std::vector < String >& params ) { CmdGetGpuExtensions(); } -void cConsole::CmdSetGamma( const std::vector < std::wstring >& params ) { +void cConsole::CmdSetGamma( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { eeFloat tFloat = 0.f; - bool Res = fromWString( tFloat, params[1] ); + bool Res = fromString( tFloat, params[1] ); if ( Res && ( tFloat > 0.1f && tFloat <= 10.0f ) ) { mWindow->SetGamma( tFloat, tFloat, tFloat ); - PushText( L"setgamma " + toWStr(tFloat) ); + PushText( "setgamma " + toStr( tFloat ) ); } else - PushText( L"Valid parameters are between 0.1 and 10." ); + PushText( "Valid parameters are between 0.1 and 10." ); } catch (...) { - PushText( L"Invalid Parameter. Expected float value." ); + PushText( "Invalid Parameter. Expected float value." ); } } } -void cConsole::CmdSetVolume( const std::vector < std::wstring >& params ) { +void cConsole::CmdSetVolume( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { eeFloat tFloat = 0.f; - bool Res = fromWString( tFloat, params[1] ); + bool Res = fromString( tFloat, params[1] ); if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) { EE::Audio::cAudioListener::instance()->GlobalVolume( tFloat ); - PushText( L"setvolume " + toWStr(tFloat) ); + PushText( "setvolume " + toStr( tFloat ) ); } else - PushText( L"Valid parameters are between 0 and 100." ); + PushText( "Valid parameters are between 0 and 100." ); } catch (...) { - PushText( L"Invalid Parameter. Expected eeFloat value." ); + PushText( "Invalid Parameter. Expected eeFloat value." ); } } } -void cConsole::CmdDir( const std::vector < std::wstring >& params ) { +void cConsole::CmdDir( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { #if EE_PLATFORM == EE_PLATFORM_WIN - std::wstring Slash( L"/\\" ); + String Slash( "/\\" ); #else - std::wstring Slash( L"/" ); + String Slash( "/" ); #endif - std::wstring myPath = params[1]; - std::wstring myOrder; + String myPath = params[1]; + String myOrder; if ( params.size() > 2 ) { for ( eeUint i = 2; i < params.size(); i++ ) { if ( i + 1 == params.size() ) { - if ( params[i] == L"ff" ) + if ( params[i] == "ff" ) myOrder = params[i]; else - myPath += L" " + params[i]; + myPath += " " + params[i]; } else { - myPath += L" " + params[i]; + myPath += " " + params[i]; } } } @@ -612,14 +604,14 @@ void cConsole::CmdDir( const std::vector < std::wstring >& params ) { if ( IsDirectory( myPath ) ) { eeUint i; - std::vector mFiles = FilesGetInPath( myPath ); + std::vector mFiles = FilesGetInPath( myPath ); std::sort( mFiles.begin(), mFiles.end() ); - PushText( L"Directory: " + myPath ); + PushText( "Directory: " + myPath ); - if ( myOrder == L"ff" ) { - std::vector mFolders; - std::vector mFile; + if ( myOrder == "ff" ) { + std::vector mFolders; + std::vector mFile; for ( i = 0; i < mFiles.size(); i++ ) { if ( IsDirectory( myPath + Slash + mFiles[i] ) ) { @@ -630,47 +622,47 @@ void cConsole::CmdDir( const std::vector < std::wstring >& params ) { } if ( mFolders.size() ) - PushText( L"Folders: " ); + PushText( "Folders: " ); for ( i = 0; i < mFolders.size(); i++ ) - PushText( L" " + mFolders[i] ); + PushText( " " + mFolders[i] ); if ( mFolders.size() ) - PushText( L"Files: " ); + PushText( "Files: " ); for ( i = 0; i < mFile.size(); i++ ) - PushText( L" " + mFile[i] ); + PushText( " " + mFile[i] ); } else { for ( i = 0; i < mFiles.size(); i++ ) - PushText( L" " + mFiles[i] ); + PushText( " " + mFiles[i] ); } } else { - if ( myPath == L"help" ) - PushText( L"You can use a third parameter to show folders first, the parameter is ff." ); + if ( myPath == "help" ) + PushText( "You can use a third parameter to show folders first, the parameter is ff." ); else - PushText( L"Path is not a directory." ); + PushText( "Path is not a directory." ); } } catch (...) { - PushText( L"Invalid Parameter." ); + PushText( "Invalid Parameter." ); } } } -void cConsole::CmdShowFps( const std::vector < std::wstring >& params ) { +void cConsole::CmdShowFps( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { Int32 tInt = 0; - bool Res = fromWString( tInt, params[1] ); + bool Res = fromString( tInt, params[1] ); if ( Res && ( tInt == 0 || tInt == 1 ) ) { mShowFps = 0 != tInt; - PushText( L"showfps " + toWStr(tInt) ); + PushText( "showfps " + toStr( tInt ) ); } else - PushText( L"Valid parameters are 0 or 1." ); + PushText( "Valid parameters are 0 or 1." ); } catch (...) { - PushText( L"Invalid Parameter. Expected int value from '" + params[1] + L"'." ); + PushText( "Invalid Parameter. Expected int value from '" + params[1] + "'." ); } } } diff --git a/src/graphics/cconsole.hpp b/src/graphics/cconsole.hpp index 9352a7ae8..d396d67e9 100755 --- a/src/graphics/cconsole.hpp +++ b/src/graphics/cconsole.hpp @@ -13,8 +13,8 @@ namespace EE { namespace Graphics { class EE_API cConsole{ public: - //! The Console Callback return a vector of parameters ( wstring ) - typedef cb::Callback1& > ConsoleCallback; + //! The Console Callback return a vector of parameters ( String ) + typedef cb::Callback1& > ConsoleCallback; cConsole( cWindow * window = NULL ); @@ -93,10 +93,7 @@ class EE_API cConsole{ void Create( cFont* Font, const bool& MakeDefaultCommands = true, const eeUint& MaxLogLines = 1024, const Uint32& TextureId = 0 ); /** Add Text to Console */ - void PushText( const std::wstring& str ); - - /** Add Text to Console */ - void PushText( const std::string& str ); + void PushText( const String& str ); /** Add formated Text to console */ void PushText( const char* format, ... ); @@ -105,13 +102,7 @@ class EE_API cConsole{ * @param Command The Command Name ( raise the event ) * @param CB The Callback for the Command */ - void AddCommand( const std::wstring& Command, ConsoleCallback CB ); - - /** Adds a new Command - * @param Command The Command Name ( raise the event ) - * @param CB The Callback for the Command - */ - void AddCommand( const std::string& Command, ConsoleCallback CB ); + void AddCommand( const String& Command, ConsoleCallback CB ); /** Draw the Console ( allways call it, visible or not ) */ void Draw(); @@ -128,9 +119,9 @@ class EE_API cConsole{ /** Activate/Deactive fps rendering */ void ShowFps( const bool& Show ); protected: - std::map < std::wstring, ConsoleCallback > mCallbacks; - std::deque < std::wstring > mCmdLog; - std::deque < std::wstring > mLastCommands; + std::map < String, ConsoleCallback > mCallbacks; + std::deque < String > mCmdLog; + std::deque < String > mLastCommands; cWindow * mWindow; @@ -186,46 +177,46 @@ class EE_API cConsole{ void Fade(); /** Internal Callback for default command ( clear ) */ - void CmdClear ( const std::vector < std::wstring >& params ); + void CmdClear ( const std::vector < String >& params ); /** Internal Callback for default command ( maximize ) */ - void CmdMaximize ( const std::vector < std::wstring >& params ); + void CmdMaximize ( const std::vector < String >& params ); /** Internal Callback for default command ( minimize ) */ - void CmdMinimize ( const std::vector < std::wstring >& params ); + void CmdMinimize ( const std::vector < String >& params ); /** Internal Callback for default command ( quit ) */ - void CmdQuit ( const std::vector < std::wstring >& params ); + void CmdQuit ( const std::vector < String >& params ); /** Internal Callback for default command ( cmdlist ) */ - void CmdCmdList ( const std::vector < std::wstring >& params ); + void CmdCmdList ( const std::vector < String >& params ); /** Internal Callback for default command ( showcursor ) */ - void CmdShowCursor ( const std::vector < std::wstring >& params ); + void CmdShowCursor ( const std::vector < String >& params ); /** Internal Callback for default command ( setframelimit ) */ - void CmdFrameLimit ( const std::vector < std::wstring >& params ); + void CmdFrameLimit ( const std::vector < String >& params ); /** Internal Callback for default command ( getlog ) */ - void CmdGetLog ( const std::vector < std::wstring >& params ); + void CmdGetLog ( const std::vector < String >& params ); /** Internal Callback for default command ( setgamma ) */ - void CmdSetGamma( const std::vector < std::wstring >& params ); + void CmdSetGamma( const std::vector < String >& params ); /** Internal Callback for default command ( setvolume ) */ - void CmdSetVolume( const std::vector < std::wstring >& params ); + void CmdSetVolume( const std::vector < String >& params ); /** Internal Callback for default command ( getgpuextensions ) */ - void CmdGetGpuExtensions( const std::vector < std::wstring >& params ); + void CmdGetGpuExtensions( const std::vector < String >& params ); /** Internal Callback for default command ( dir and ls ) */ - void CmdDir( const std::vector < std::wstring >& params ); + void CmdDir( const std::vector < String >& params ); /** Internal Callback for default command ( showfps ) */ - void CmdShowFps( const std::vector < std::wstring >& params ); + void CmdShowFps( const std::vector < String >& params ); /** Internal Callback for default command ( gettexturememory ) */ - void CmdGetTextureMemory ( const std::vector < std::wstring >& params ); + void CmdGetTextureMemory ( const std::vector < String >& params ); /** The Default Commands Callbacks for the Console ( don't call it ) */ void PrivInputCallback( InputEvent * Event ); @@ -242,9 +233,9 @@ class EE_API cConsole{ /** Internal Callback to Process the new line ( when return pressed ) */ void ProcessLine(); - void PrivPushText( const std::wstring& str ); + void PrivPushText( const String& str ); - void PrintCommandsStartingWith( const std::wstring& start ); + void PrintCommandsStartingWith( const String& start ); void PrivVideoResize(); }; diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp index d5fe6d9a1..8cb183c5f 100644 --- a/src/graphics/cfont.cpp +++ b/src/graphics/cfont.cpp @@ -23,7 +23,7 @@ cFont::~cFont() { mGlyphs.clear(); } -void cFont::SetText( const std::wstring& Text ) { +void cFont::SetText( const String& Text ) { if ( mText.size() != Text.size() ) { Int32 size = Text.size() * EE_QUAD_VERTEX; @@ -37,10 +37,6 @@ void cFont::SetText( const std::wstring& Text ) { CacheWidth(); } -void cFont::SetText( const std::string& Text) { - SetText ( stringTowstring(Text) ); -} - const eeColorA& cFont::Color() const { return mColor; } @@ -76,7 +72,7 @@ eeInt cFont::GetNumLines() { return mNumLines; } -eeFloat cFont::GetTextWidth( const std::wstring& Text ) { +eeFloat cFont::GetTextWidth( const String& Text ) { SetText( Text ); return mCachedWidth; } @@ -93,7 +89,7 @@ Uint32 cFont::GetFontHeight() const { return mHeight; } -std::wstring cFont::GetText() { +String cFont::GetText() { return mText; } @@ -113,15 +109,11 @@ const std::vector& cFont::GetLinesWidth() const { return mLinesWidth; } -void cFont::Draw( const std::string& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_PRE_BLEND_FUNC& Effect ) { - Draw( stringTowstring(Text), X, Y, Flags, Scale, Angle, Effect ); -} - void cFont::Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_PRE_BLEND_FUNC& Effect) { SubDraw( mText, X, Y, Flags, Scale, Angle, true, Effect ); } -void cFont::Draw( const std::wstring& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_PRE_BLEND_FUNC& Effect ) { +void cFont::Draw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_PRE_BLEND_FUNC& Effect ) { SubDraw( Text, X, Y, Flags, Scale, Angle, false, Effect ); } @@ -312,7 +304,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } } -void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ) { +void cFont::SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ) { if ( !Text.size() ) return; @@ -482,7 +474,7 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& GLi->PopMatrix(); } -void cFont::CacheWidth( const std::wstring& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ) { +void cFont::CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ) { LinesWidth.clear(); eeFloat Width = 0, MaxWidth = 0; @@ -588,7 +580,7 @@ void cFont::ShrinkText( std::string& Str, const Uint32& MaxWidth ) { } } -void cFont::ShrinkText( std::wstring& Str, const Uint32& MaxWidth ) { +void cFont::ShrinkText( String& Str, const Uint32& MaxWidth ) { if ( !Str.size() ) return; @@ -596,11 +588,11 @@ void cFont::ShrinkText( std::wstring& Str, const Uint32& MaxWidth ) { eeFloat tWordWidth = 0.f; eeFloat tMaxWidth = (eeFloat) MaxWidth; Int32 tPrev = -1; - wchar_t * tStringLoop = &Str[0]; - wchar_t * tLastSpace = NULL; + String::StringBaseType * tStringLoop = &Str[0]; + String::StringBaseType * tLastSpace = NULL; while ( *tStringLoop ) { - if ( (Uint32)( *tStringLoop ) < mGlyphs.size() ) { + if ( (String::StringBaseType)( *tStringLoop ) < mGlyphs.size() ) { eeGlyph * pChar = &mGlyphs[ ( *tStringLoop ) ]; eeFloat fCharWidth = (eeFloat)pChar->Advance; diff --git a/src/graphics/cfont.hpp b/src/graphics/cfont.hpp index af3cffd6a..fbf14caf8 100755 --- a/src/graphics/cfont.hpp +++ b/src/graphics/cfont.hpp @@ -22,14 +22,13 @@ class EE_API cFont { * @param Text The Text * @param SupportNewLine If active will search for "\n" and back to a new line. */ - void SetText( const std::wstring& Text ); - void SetText( const std::string& Text ); + void SetText( const String& Text ); /** @return The width of the string rendered */ eeFloat GetTextWidth() const; /** @return Assign a new text and then returns his width */ - eeFloat GetTextWidth( const std::wstring& Text ); + eeFloat GetTextWidth( const String& Text ); /** @return The current text height */ eeFloat GetTextHeight(); @@ -56,7 +55,7 @@ class EE_API cFont { Uint32 GetFontHeight() const; /** @return The current text */ - std::wstring GetText(); + String GetText(); /** Set if the font will cache de text width and the number of lines ( default: true ). */ void CacheData( bool Cache ); @@ -67,7 +66,7 @@ class EE_API cFont { /** @return The last text rendered or setted lines width */ const std::vector& GetLinesWidth() const; - /** Draw a wstring on the screen + /** Draw a String on the screen * @param Text The text to draw * @param X The start x position * @param Y The start y position @@ -76,7 +75,7 @@ class EE_API cFont { * @param Angle The angle of the string rendered * @param Effect Set the Blend Mode ( default ALPHA_NORMAL ) */ - void Draw( const std::wstring& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags = FONT_DRAW_LEFT, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, const EE_PRE_BLEND_FUNC& Effect = ALPHA_NORMAL ); + void Draw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags = FONT_DRAW_LEFT, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, const EE_PRE_BLEND_FUNC& Effect = ALPHA_NORMAL ); /** Draw the string seted on the screen * @param X The start x position @@ -88,17 +87,6 @@ class EE_API cFont { */ void Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags = FONT_DRAW_LEFT, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, const EE_PRE_BLEND_FUNC& Effect = ALPHA_NORMAL ); - /** Draw a string on the screen - * @param Text The text to draw - * @param X The start x position - * @param Y The start y position - * @param Flags Set some flags to the rendering ( for text align ) - * @param Scale The string rendered scale - * @param Angle The angle of the string rendered - * @param Effect Set the Blend Mode ( default ALPHA_NORMAL ) - */ - void Draw( const std::string& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags = FONT_DRAW_LEFT, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, const EE_PRE_BLEND_FUNC& Effect = ALPHA_NORMAL ); - /** Draw a string on the screen from a cached text * @param TextCache The cached text * @param X The start x position @@ -110,11 +98,11 @@ class EE_API cFont { */ void Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, const Uint32& Flags = FONT_DRAW_LEFT, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, const EE_PRE_BLEND_FUNC& Effect = ALPHA_NORMAL ); - /** Shrink the wstring to a max width + /** Shrink the String to a max width * @param Str The string to shrink * @param MaxWidth The Max Width posible */ - void ShrinkText( std::wstring& Str, const Uint32& MaxWidth ); + void ShrinkText( String& Str, const Uint32& MaxWidth ); /** Shrink the string to a max width * @param Str The string to shrink @@ -123,7 +111,7 @@ class EE_API cFont { void ShrinkText( std::string& Str, const Uint32& MaxWidth ); /** Cache the with of the current text */ - void CacheWidth( const std::wstring& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ); + void CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ); /** @return The font texture id */ const Uint32& GetTexId() const; @@ -140,7 +128,7 @@ class EE_API cFont { std::string mFontName; Uint32 mFontHash; - std::wstring mText; + String mText; bool mCacheData; eeColorA mColor; eeColorA mShadowColor; @@ -160,7 +148,7 @@ class EE_API cFont { void CacheWidth(); void CacheNumLines(); - void SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ); + void SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_PRE_BLEND_FUNC& Effect ); }; }} diff --git a/src/graphics/ctextcache.cpp b/src/graphics/ctextcache.cpp index cba36bb1b..1bdb6980a 100644 --- a/src/graphics/ctextcache.cpp +++ b/src/graphics/ctextcache.cpp @@ -14,7 +14,7 @@ cTextCache::cTextCache() : { } -cTextCache::cTextCache( cFont * font, const std::wstring& text, eeColorA FontColor, eeColorA FontShadowColor ) : +cTextCache::cTextCache( cFont * font, const String& text, eeColorA FontColor, eeColorA FontShadowColor ) : mText( text ), mFont( font ), mCachedWidth(0.f), @@ -29,7 +29,7 @@ cTextCache::cTextCache( cFont * font, const std::wstring& text, eeColorA FontCol cTextCache::~cTextCache() { } -void cTextCache::Create( cFont * font, const std::wstring& text, eeColorA FontColor, eeColorA FontShadowColor ) { +void cTextCache::Create( cFont * font, const String& text, eeColorA FontColor, eeColorA FontShadowColor ) { mFont = font; mText = text; UpdateCoords(); @@ -47,7 +47,7 @@ void cTextCache::Font( cFont * font ) { Cache(); } -std::wstring& cTextCache::Text() { +String& cTextCache::Text() { return mText; } @@ -58,7 +58,7 @@ void cTextCache::UpdateCoords() { mColors.resize( size, mFontColor ); } -void cTextCache::Text( const std::wstring& text ) { +void cTextCache::Text( const String& text ) { bool needUpdate = false; if ( mText.size() != text.size() ) @@ -100,10 +100,6 @@ std::vector& cTextCache::Colors() { return mColors; } -void cTextCache::Text( const std::string& text ) { - Text( stringTowstring( text ) ); -} - void cTextCache::Cache() { if ( NULL != mFont && mText.size() ) { mFont->CacheWidth( mText, mLinesWidth, mCachedWidth, mNumLines ); diff --git a/src/graphics/ctextcache.hpp b/src/graphics/ctextcache.hpp index f32eb3a87..15cebc609 100644 --- a/src/graphics/ctextcache.hpp +++ b/src/graphics/ctextcache.hpp @@ -12,23 +12,21 @@ class cFont; /** @brief Cached text for a fast font rendering. */ class EE_API cTextCache { public: - cTextCache( cFont * font, const std::wstring& text = L"", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); + cTextCache( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); cTextCache(); ~cTextCache(); - void Create( cFont * font, const std::wstring& text = L"", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); + void Create( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(0xFFFFFFFF), eeColorA FontShadowColor = eeColorA(0xFF000000) ); cFont * Font() const; void Font( cFont * font ); - std::wstring& Text(); + String& Text(); - void Text( const std::wstring& text ); - - void Text( const std::string& text ); + void Text( const String& text ); eeFloat GetTextWidth(); @@ -60,7 +58,7 @@ class EE_API cTextCache { protected: friend class cFont; - std::wstring mText; + String mText; cFont * mFont; std::vector mLinesWidth; eeFloat mCachedWidth; diff --git a/src/helper/chipmunk/cpBBTree.c b/src/helper/chipmunk/cpBBTree.c index 41007c946..8adde8a2e 100644 --- a/src/helper/chipmunk/cpBBTree.c +++ b/src/helper/chipmunk/cpBBTree.c @@ -11,14 +11,14 @@ typedef struct Pair Pair; struct cpBBTree { cpSpatialIndex spatialIndex; cpBBTreeVelocityFunc velocityFunc; - + cpHashSet *leaves; Node *root; - + Node *pooledNodes; Pair *pooledPairs; cpArray *allocatedBuffers; - + cpTimestamp stamp; }; @@ -26,11 +26,11 @@ struct Node { void *obj; cpBB bb; Node *parent; - + union { // Internal nodes struct { Node *a, *b; }; - + // Leaves struct { cpTimestamp stamp; @@ -59,13 +59,13 @@ static inline cpBB GetBB(cpBBTree *tree, void *obj) { cpBB bb = tree->spatialIndex.bbfunc(obj); - + cpBBTreeVelocityFunc velocityFunc = tree->velocityFunc; if(velocityFunc){ cpFloat coef = 0.1f; cpFloat x = (bb.r - bb.l)*coef; cpFloat y = (bb.t - bb.b)*coef; - + cpVect v = cpvmult(velocityFunc(obj), 0.1f); return cpBBNew(bb.l + cpfmin(-x, v.x), bb.b + cpfmin(-y, v.y), bb.r + cpfmax(x, v.x), bb.t + cpfmax(y, v.y)); } else { @@ -115,7 +115,7 @@ static Pair * PairFromPool(cpBBTree *tree) { Pair *pair = tree->pooledPairs; - + if(pair){ tree->pooledPairs = pair->a.next; return pair; @@ -123,10 +123,10 @@ PairFromPool(cpBBTree *tree) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(Pair); cpAssert(count, "Buffer size is too small."); - + Pair *buffer = (Pair *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(tree->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; ia.leaf == thread.leaf) next->a.prev = prev; else next->b.prev = prev; } - + if(prev){ if(prev->a.leaf == thread.leaf) prev->a.next = next; else prev->b.next = next; } else { @@ -155,7 +155,7 @@ PairsClear(Node *leaf, cpBBTree *tree) { Pair *pair = leaf->pairs; leaf->pairs = NULL; - + while(pair){ if(pair->a.leaf == leaf){ Pair *next = pair->a.next; @@ -177,14 +177,14 @@ PairInsert(Node *a, Node *b, cpBBTree *tree) Pair *nextA = a->pairs, *nextB = b->pairs; Pair *pair = PairFromPool(tree); Pair temp = {{NULL, a, nextA},{NULL, b, nextB}}; - + a->pairs = b->pairs = pair; *pair = temp; - + if(nextA){ if(nextA->a.leaf == a) nextA->a.prev = pair; else nextA->b.prev = pair; } - + if(nextB){ if(nextB->a.leaf == b) nextB->a.prev = pair; else nextB->b.prev = pair; } @@ -204,7 +204,7 @@ static Node * NodeFromPool(cpBBTree *tree) { Node *node = tree->pooledNodes; - + if(node){ tree->pooledNodes = node->parent; return node; @@ -212,10 +212,10 @@ NodeFromPool(cpBBTree *tree) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(Node); cpAssert(count, "Buffer size is too small."); - + Node *buffer = (Node *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(tree->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; iobj = NULL; node->bb = cpBBmerge(a->bb, b->bb); node->parent = NULL; - + NodeSetA(node, a); NodeSetB(node, b); - + return node; } @@ -268,7 +268,7 @@ NodeReplaceChild(Node *parent, Node *child, Node *value, cpBBTree *tree) { cpAssert(!NodeIsLeaf(parent), "Cannot replace child of a leaf."); cpAssert(child == parent->a || child == parent->b, "Node is not a child of parent."); - + if(parent->a == child){ NodeRecycle(tree, parent->a); NodeSetA(parent, value); @@ -276,7 +276,7 @@ NodeReplaceChild(Node *parent, Node *child, Node *value, cpBBTree *tree) NodeRecycle(tree, parent->b); NodeSetB(parent, value); } - + for(Node *node=parent; node; node = node->parent){ node->bb = cpBBmerge(node->a->bb, node->b->bb); } @@ -294,16 +294,16 @@ SubtreeInsert(Node *subtree, Node *leaf, cpBBTree *tree) } else { cpFloat cost_a = cpBBArea(subtree->b->bb) + cpBBMergedArea(subtree->a->bb, leaf->bb); cpFloat cost_b = cpBBArea(subtree->a->bb) + cpBBMergedArea(subtree->b->bb, leaf->bb); - + // cpFloat cost_a = cpBBProximity(subtree->a->bb, leaf->bb); // cpFloat cost_b = cpBBProximity(subtree->b->bb, leaf->bb); - + if(cost_b < cost_a){ NodeSetB(subtree, SubtreeInsert(subtree->b, leaf, tree)); } else { NodeSetA(subtree, SubtreeInsert(subtree->a, leaf, tree)); } - + subtree->bb = cpBBmerge(subtree->bb, leaf->bb); return subtree; } @@ -400,7 +400,7 @@ MarkLeaf(Node *leaf, MarkContext *context) if(leaf->stamp == GetStamp(tree)){ Node *staticRoot = context->staticRoot; if(staticRoot) MarkLeafQuery(staticRoot, leaf, cpFalse, context); - + for(Node *node = leaf; node->parent; node = node->parent){ if(node == node->parent->a){ MarkLeafQuery(node->parent->b, leaf, cpTrue, context); @@ -440,11 +440,11 @@ LeafNew(cpBBTree *tree, void *obj, cpBB bb) Node *node = NodeFromPool(tree); node->obj = obj; node->bb = GetBB(tree, obj); - + node->parent = NULL; node->stamp = 0; node->pairs = NULL; - + return node; } @@ -453,19 +453,19 @@ LeafUpdate(Node *leaf, cpBBTree *tree) { Node *root = tree->root; cpBB bb = tree->spatialIndex.bbfunc(leaf->obj); - + if(!cpBBcontainsBB(leaf->bb, bb)){ leaf->bb = GetBB(tree, leaf->obj); - + root = SubtreeRemove(root, leaf, tree); tree->root = SubtreeInsert(root, leaf, tree); - + PairsClear(leaf, tree); leaf->stamp = GetStamp(tree); - + return cpTrue; } - + return cpFalse; } @@ -513,17 +513,17 @@ cpSpatialIndex * cpBBTreeInit(cpBBTree *tree, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex) { cpSpatialIndexInit((cpSpatialIndex *)tree, &klass, bbfunc, staticIndex); - + tree->velocityFunc = NULL; - + tree->leaves = cpHashSetNew(0, (cpHashSetEqlFunc)leafSetEql, NULL); tree->root = NULL; - + tree->pooledNodes = NULL; tree->allocatedBuffers = cpArrayNew(0); - + tree->stamp = 0; - + return (cpSpatialIndex *)tree; } @@ -534,7 +534,7 @@ cpBBTreeSetVelocityFunc(cpSpatialIndex *index, cpBBTreeVelocityFunc func) cpAssertWarn(cpFalse, "Ignoring cpBBTreeSetVelocityFunc() call to non-tree spatial index."); return; } - + ((cpBBTree *)index)->velocityFunc = func; } @@ -548,7 +548,7 @@ static void cpBBTreeDestroy(cpBBTree *tree) { cpHashSetFree(tree->leaves); - + cpArrayFreeEach(tree->allocatedBuffers, cpfree); cpArrayFree(tree->allocatedBuffers); } @@ -559,10 +559,10 @@ static void cpBBTreeInsert(cpBBTree *tree, void *obj, cpHashValue hashid) { Node *leaf = cpHashSetInsert(tree->leaves, hashid, obj, tree, (cpHashSetTransFunc)leafSetTrans); - + Node *root = tree->root; tree->root = SubtreeInsert(root, leaf, tree); - + leaf->stamp = GetStamp(tree); LeafAddPairs(leaf, tree); IncrementStamp(tree); @@ -572,7 +572,7 @@ static void cpBBTreeRemove(cpBBTree *tree, void *obj, cpHashValue hashid) { Node *leaf = cpHashSetRemove(tree->leaves, hashid, obj); - + tree->root = SubtreeRemove(tree->root, leaf, tree); PairsClear(leaf, tree); NodeRecycle(tree, leaf); @@ -590,17 +590,17 @@ static void cpBBTreeReindexQuery(cpBBTree *tree, cpSpatialIndexQueryCallback func, void *data) { if(!tree->root) return; - + // LeafUpdate() may modify tree->root. Don't cache it. cpHashSetEach(tree->leaves, (cpHashSetIterFunc)LeafUpdate, tree); - + cpSpatialIndex *staticIndex = tree->spatialIndex.staticIndex; Node *staticRoot = (staticIndex && staticIndex->klass == &klass ? ((cpBBTree *)staticIndex)->root : NULL); - + MarkContext context = {tree, staticRoot, func, data}; MarkSubtree(tree->root, &context); if(staticIndex && !staticRoot) cpSpatialIndexCollideStatic((cpSpatialIndex *)tree, staticIndex, func, data); - + IncrementStamp(tree); } @@ -666,18 +666,18 @@ cpBBTreeEach(cpBBTree *tree, cpSpatialIndexIterator func, void *data) static cpSpatialIndexClass klass = { (cpSpatialIndexDestroyFunc)cpBBTreeDestroy, - + (cpSpatialIndexCountFunc)cpBBTreeCount, (cpSpatialIndexEachFunc)cpBBTreeEach, - + (cpSpatialIndexContainsFunc)cpBBTreeContains, (cpSpatialIndexInsertFunc)cpBBTreeInsert, (cpSpatialIndexRemoveFunc)cpBBTreeRemove, - + (cpSpatialIndexReindexFunc)cpBBTreeReindex, (cpSpatialIndexReindexObjectFunc)cpBBTreeReindexObject, (cpSpatialIndexReindexQueryFunc)cpBBTreeReindexQuery, - + (cpSpatialIndexPointQueryFunc)cpBBTreePointQuery, (cpSpatialIndexSegmentQueryFunc)cpBBTreeSegmentQuery, (cpSpatialIndexQueryFunc)cpBBTreeQuery, @@ -704,14 +704,14 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) } else if(count == 2) { return NodeNew(tree, nodes[0], nodes[1]); } - + // Find the AABB for these nodes cpBB bb = nodes[0]->bb; for(int i=1; ibb); - + // Split it on it's longest axis cpBool splitWidth = (bb.r - bb.l > bb.t - bb.b); - + // Sort the bounds and use the median as the splitting point cpFloat bounds[count*2]; if(splitWidth){ @@ -725,14 +725,14 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) bounds[2*i + 1] = nodes[i]->bb.t; } } - + qsort(bounds, count*2, sizeof(cpFloat), (int (*)(const void *, const void *))cpfcompare); cpFloat split = (bounds[count - 1] + bounds[count])*0.5f; // use the medain as the split - + // Generate the child BBs cpBB a = bb, b = bb; if(splitWidth) a.r = b.l = split; else a.t = b.b = split; - + // Partition the nodes int right = count; for(int left=0; left < right;){ @@ -746,13 +746,13 @@ partitionNodes(cpBBTree *tree, Node **nodes, int count) left++; } } - + if(right == count){ Node *node = NULL; for(int i=0; iopath; -// +// // while(!NodeIsLeaf(node)){ // node = (path&(1<a : node->b); // bit = (bit + 1)&(sizeof(unsigned int)*8 - 1); // } -// +// // root = subtreeRemove(root, node, tree); // tree->root = subtreeInsert(root, node, tree); // } @@ -786,17 +786,17 @@ cpBBTreeOptimize(cpSpatialIndex *index) cpAssertWarn(cpFalse, "Ignoring cpBBTreeOptimize() call to non-tree spatial index."); return; } - + cpBBTree *tree = (cpBBTree *)index; Node *root = tree->root; if(!root) return; - + int count = cpBBTreeCount(tree); Node *nodes[count]; Node **cursor = nodes; - + cpHashSetEach(tree->leaves, (cpHashSetIterFunc)fillNodeArray, &cursor); - + SubtreeRecycle(tree, root); tree->root = partitionNodes(tree, nodes, count); } @@ -807,7 +807,6 @@ cpBBTreeOptimize(cpSpatialIndex *index) #ifdef CP_BBTREE_DEBUG_DRAW #include #include -#include static void NodeRender(Node *node, int depth) @@ -816,22 +815,22 @@ NodeRender(Node *node, int depth) NodeRender(node->a, depth + 1); NodeRender(node->b, depth + 1); } - + cpBB bb = node->bb; - -// GLfloat v = depth/2.0f; + +// GLfloat v = depth/2.0f; // glColor3f(1.0f - v, v, 0.0f); glLineWidth(cpfmax(5.0f - depth, 1.0f)); glBegin(GL_LINES); { glVertex2f(bb.l, bb.b); glVertex2f(bb.l, bb.t); - + glVertex2f(bb.l, bb.t); glVertex2f(bb.r, bb.t); - + glVertex2f(bb.r, bb.t); glVertex2f(bb.r, bb.b); - + glVertex2f(bb.r, bb.b); glVertex2f(bb.l, bb.b); }; glEnd(); @@ -843,7 +842,7 @@ cpBBTreeRenderDebug(cpSpatialIndex *index){ cpAssertWarn(cpFalse, "Ignoring cpBBTreeRenderDebug() call to non-tree spatial index."); return; } - + cpBBTree *tree = (cpBBTree *)index; if(tree->root) NodeRender(tree->root, 0); } diff --git a/src/helper/chipmunk/cpSpaceHash.c b/src/helper/chipmunk/cpSpaceHash.c index b6c1abb64..1792bc95e 100644 --- a/src/helper/chipmunk/cpSpaceHash.c +++ b/src/helper/chipmunk/cpSpaceHash.c @@ -1,15 +1,15 @@ /* Copyright (c) 2007 Scott Lembcke - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -30,17 +30,17 @@ typedef struct cpHandle cpHandle; struct cpSpaceHash { cpSpatialIndex spatialIndex; - + int numcells; cpFloat celldim; - + cpSpaceHashBin **table; cpHashSet *handleSet; - + cpSpaceHashBin *pooledBins; cpArray *pooledHandles; cpArray *allocatedBuffers; - + cpTimestamp stamp; }; @@ -59,7 +59,7 @@ cpHandleInit(cpHandle *hand, void *obj) hand->obj = obj; hand->retain = 0; hand->stamp = 0; - + return hand; } @@ -81,16 +81,16 @@ handleSetTrans(void *obj, cpSpaceHash *hash) // handle pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(cpHandle); cpAssert(count, "Buffer size is too small."); - + cpHandle *buffer = (cpHandle *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(hash->allocatedBuffers, buffer); - + for(int i=0; ipooledHandles, buffer + i); } - + cpHandle *hand = cpHandleInit((cpHandle *)cpArrayPop(hash->pooledHandles), obj); cpHandleRetain(hand); - + return hand; } @@ -114,13 +114,13 @@ clearTableCell(cpSpaceHash *hash, int idx) cpSpaceHashBin *bin = hash->table[idx]; while(bin){ cpSpaceHashBin *next = bin->next; - + cpHandleRelease(bin->handle, hash->pooledHandles); recycleBin(hash, bin); - + bin = next; } - + hash->table[idx] = NULL; } @@ -135,7 +135,7 @@ static inline cpSpaceHashBin * getEmptyBin(cpSpaceHash *hash) { cpSpaceHashBin *bin = hash->pooledBins; - + if(bin){ hash->pooledBins = bin->next; return bin; @@ -143,10 +143,10 @@ getEmptyBin(cpSpaceHash *hash) // Pool is exhausted, make more int count = CP_BUFFER_BYTES/sizeof(cpSpaceHashBin); cpAssert(count, "Buffer size is too small."); - + cpSpaceHashBin *buffer = (cpSpaceHashBin *)cpmalloc(CP_BUFFER_BYTES); cpArrayPush(hash->allocatedBuffers, buffer); - + // push all but the first one, return the first instead for(int i=1; itable); - + hash->numcells = numcells; hash->table = (cpSpaceHashBin **)cpcalloc(numcells, sizeof(cpSpaceHashBin *)); } @@ -177,18 +177,18 @@ cpSpatialIndex * cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int numcells, cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex) { cpSpatialIndexInit((cpSpatialIndex *)hash, &klass, bbfunc, staticIndex); - + cpSpaceHashAllocTable(hash, next_prime(numcells)); hash->celldim = celldim; - + hash->handleSet = cpHashSetNew(0, (cpHashSetEqlFunc)handleSetEql, NULL); hash->pooledHandles = cpArrayNew(0); - + hash->pooledBins = NULL; hash->allocatedBuffers = cpArrayNew(0); - + hash->stamp = 1; - + return (cpSpatialIndex *)hash; } @@ -202,13 +202,13 @@ static void cpSpaceHashDestroy(cpSpaceHash *hash) { clearTable(hash); - + cpHashSetFree(hash->handleSet); - + cpArrayFreeEach(hash->allocatedBuffers, cpfree); cpArrayFree(hash->allocatedBuffers); cpArrayFree(hash->pooledHandles); - + cpfree(hash->table); } @@ -221,7 +221,7 @@ containsHandle(cpSpaceHashBin *bin, cpHandle *hand) if(bin->handle == hand) return cpTrue; bin = bin->next; } - + return cpFalse; } @@ -250,13 +250,13 @@ hashHandle(cpSpaceHash *hash, cpHandle *hand, cpBB bb) int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + int n = hash->numcells; for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int idx = hash_func(i,j,n); cpSpaceHashBin *bin = hash->table[idx]; - + // Don't add an object twice to the same cell. if(containsHandle(bin, hand)) continue; @@ -283,11 +283,11 @@ static void cpSpaceHashRehashObject(cpSpaceHash *hash, void *obj, cpHashValue hashid) { cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, hashid, obj); - + if(hand){ hand->obj = NULL; cpHandleRelease(hand, hash->pooledHandles); - + cpSpaceHashInsert(hash, obj, hashid); } } @@ -309,7 +309,7 @@ static void cpSpaceHashRemove(cpSpaceHash *hash, void *obj, cpHashValue hashid) { cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, hashid, obj); - + if(hand){ hand->obj = NULL; cpHandleRelease(hand, hash->pooledHandles); @@ -337,17 +337,17 @@ remove_orphaned_handles(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr) while(bin){ cpHandle *hand = bin->handle; cpSpaceHashBin *next = bin->next; - + if(!hand->obj){ // orphaned handle, unlink and recycle the bin (*bin_ptr) = bin->next; recycleBin(hash, bin); - + cpHandleRelease(hand, hash->pooledHandles); } else { bin_ptr = &bin->next; } - + bin = next; } } @@ -361,7 +361,7 @@ query_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIn for(cpSpaceHashBin *bin = *bin_ptr; bin; bin = bin->next){ cpHandle *hand = bin->handle; void *other = hand->obj; - + if(hand->stamp == hash->stamp || obj == other){ continue; } else if(other){ @@ -381,7 +381,7 @@ cpSpaceHashPointQuery(cpSpaceHash *hash, cpVect point, cpSpatialIndexQueryCallba { cpFloat dim = hash->celldim; int idx = hash_func(floor_int(point.x/dim), floor_int(point.y/dim), hash->numcells); // Fix by ShiftZ - + query_helper(hash, &hash->table[idx], &point, func, data); hash->stamp++; } @@ -395,17 +395,17 @@ cpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpatialIndexQueryCallb int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + int n = hash->numcells; cpSpaceHashBin **table = hash->table; - + // Iterate over the cells and query them. for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ query_helper(hash, &table[hash_func(i,j,n)], obj, func, data); } } - + hash->stamp++; } @@ -434,26 +434,26 @@ queryRehash_helper(cpHandle *hand, queryRehashContext *context) int r = floor_int(bb.r/dim); int b = floor_int(bb.b/dim); int t = floor_int(bb.t/dim); - + cpSpaceHashBin **table = hash->table; for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int idx = hash_func(i,j,n); cpSpaceHashBin *bin = table[idx]; - + if(containsHandle(bin, hand)) continue; - + cpHandleRetain(hand); // this MUST be done first in case the object is removed in func() query_helper(hash, &bin, obj, func, data); - + cpSpaceHashBin *newBin = getEmptyBin(hash); newBin->handle = hand; newBin->next = bin; table[idx] = newBin; } } - + // Increment the stamp for each object hashed. hash->stamp++; } @@ -462,10 +462,10 @@ static void cpSpaceHashReindexQuery(cpSpaceHash *hash, cpSpatialIndexQueryCallback func, void *data) { clearTable(hash); - + queryRehashContext context = {hash, func, data}; cpHashSetEach(hash->handleSet, (cpHashSetIterFunc)queryRehash_helper, &context); - + cpSpatialIndexCollideStatic((cpSpatialIndex *)hash, hash->spatialIndex.staticIndex, func, data); } @@ -473,12 +473,12 @@ static inline cpFloat segmentQuery_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpatialIndexSegmentQueryCallback func, void *data) { cpFloat t = 1.0f; - + restart: for(cpSpaceHashBin *bin = *bin_ptr; bin; bin = bin->next){ cpHandle *hand = bin->handle; void *other = hand->obj; - + // Skip over certain conditions if(hand->stamp == hash->stamp){ continue; @@ -492,7 +492,7 @@ segmentQuery_helper(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSp goto restart; // GCC not smart enough/able to tail call an inlined function. } } - + return t; } @@ -502,7 +502,7 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa { a = cpvmult(a, 1.0f/hash->celldim); b = cpvmult(b, 1.0f/hash->celldim); - + int cell_x = floor_int(a.x), cell_y = floor_int(a.y); cpFloat t = 0; @@ -525,15 +525,15 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa y_inc = -1; temp_v = (a.y - cpffloor(a.y)); } - + // Division by zero is *very* slow on ARM cpFloat dx = cpfabs(b.x - a.x), dy = cpfabs(b.y - a.y); cpFloat dt_dx = (dx ? 1.0f/dx : INFINITY), dt_dy = (dy ? 1.0f/dy : INFINITY); - + // fix NANs in horizontal directions cpFloat next_h = (temp_h ? temp_h*dt_dx : dt_dx); cpFloat next_v = (temp_v ? temp_v*dt_dy : dt_dy); - + int n = hash->numcells; cpSpaceHashBin **table = hash->table; @@ -551,7 +551,7 @@ cpSpaceHashSegmentQuery(cpSpaceHash *hash, void *obj, cpVect a, cpVect b, cpFloa next_h += dt_dx; } } - + hash->stamp++; } @@ -564,9 +564,9 @@ cpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells) cpAssertWarn(cpFalse, "Ignoring cpSpaceHashResize() call to non-cpSpaceHash spatial index."); return; } - + clearTable(hash); - + hash->celldim = celldim; cpSpaceHashAllocTable(hash, next_prime(numcells)); } @@ -585,18 +585,18 @@ cpSpaceHashContains(cpSpaceHash *hash, void *obj, cpHashValue hashid) static cpSpatialIndexClass klass = { (cpSpatialIndexDestroyFunc)cpSpaceHashDestroy, - + (cpSpatialIndexCountFunc)cpSpaceHashCount, (cpSpatialIndexEachFunc)cpSpaceHashEach, (cpSpatialIndexContainsFunc)cpSpaceHashContains, - + (cpSpatialIndexInsertFunc)cpSpaceHashInsert, (cpSpatialIndexRemoveFunc)cpSpaceHashRemove, - + (cpSpatialIndexReindexFunc)cpSpaceHashRehash, (cpSpatialIndexReindexObjectFunc)cpSpaceHashRehashObject, (cpSpatialIndexReindexQueryFunc)cpSpaceHashReindexQuery, - + (cpSpatialIndexPointQueryFunc)cpSpaceHashPointQuery, (cpSpatialIndexSegmentQueryFunc)cpSpaceHashSegmentQuery, (cpSpatialIndexQueryFunc)cpSpaceHashQuery, @@ -608,7 +608,6 @@ static cpSpatialIndexClass klass = { #ifdef CP_BBTREE_DEBUG_DRAW #include #include -#include void cpSpaceHashRenderDebug(cpSpatialIndex *index) @@ -617,26 +616,26 @@ cpSpaceHashRenderDebug(cpSpatialIndex *index) cpAssertWarn(cpFalse, "Ignoring cpSpaceHashRenderDebug() call to non-spatial hash spatial index."); return; } - + cpSpaceHash *hash = (cpSpaceHash *)index; cpBB bb = cpBBNew(-320, -240, 320, 240); - + cpFloat dim = hash->celldim; int n = hash->numcells; - + int l = (int)floor(bb.l/dim); int r = (int)floor(bb.r/dim); int b = (int)floor(bb.b/dim); int t = (int)floor(bb.t/dim); - + for(int i=l; i<=r; i++){ for(int j=b; j<=t; j++){ int cell_count = 0; - + int index = hash_func(i,j,n); for(cpSpaceHashBin *bin = hash->table[index]; bin; bin = bin->next) cell_count++; - + GLfloat v = 1.0f - (GLfloat)cell_count/10.0f; glColor3f(v,v,v); glRectf(i*dim, j*dim, (i + 1)*dim, (j + 1)*dim); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index ab9b6b210..7a8be0767 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -141,6 +141,10 @@ void cEETest::Init() { } void cEETest::CreateAquaTextureAtlas() { + #ifndef EE_DEBUG + return; + #endif + //cUIThemeManager::instance()->Add( cUITheme::LoadFromPath( MyPath + "data/aqua/", "aqua", "aqua" ) ); std::string tgpath( MyPath + "data/aquatg/aqua" ); @@ -191,9 +195,9 @@ void cEETest::OnFontLoaded( cResourceLoader * ObjLoaded ) { CreateUI(); - mEEText.Create( TTFB, L"Entropia Engine++\nCTRL + Number to change Demo Screen" ); - mFBOText.Create( TTFB, L"This is a VBO\nInside of a FBO" ); - mInfoText.Create( FF, L"", eeColorA(255,255,255,150) ); + mEEText.Create( TTFB, "Entropia Engine++\nCTRL + Number to change Demo Screen" ); + mFBOText.Create( TTFB, "This is a VBO\nInside of a FBO" ); + mInfoText.Create( FF, "", eeColorA(255,255,255,150) ); } void cEETest::CreateShaders() { @@ -273,7 +277,7 @@ void cEETest::CreateUI() { cUITextBox * Text = eeNew( cUITextBox, ( TextParams ) ); Text->Visible( true ); Text->Enabled( false ); - Text->Text( L"Turn around\nJust Turn Around\nAround!" ); + Text->Text( "Turn around\nJust Turn Around\nAround!" ); cUITextInput::CreateParams InputParams; InputParams.Parent( C ); @@ -293,28 +297,28 @@ void cEETest::CreateUI() { cUIPushButton * Button = eeNew( cUIPushButton, ( ButtonParams ) ); Button->Visible( true ); Button->Enabled( true ); - Button->Text( L"Click Me" ); + Button->Text( "Click Me" ); Button->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::ButtonClick ) ); - Button->TooltipText( L"Click and see what happens..." ); + Button->TooltipText( "Click and see what happens..." ); TextParams.PosSet( 130, 20 ); TextParams.Size = eeSize( 80, 22 ); TextParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; cUICheckBox * Checkbox = eeNew( cUICheckBox, ( TextParams ) ); Checkbox->Visible( true ); - Checkbox->Text( L"Check Me" ); + Checkbox->Text( "Check Me" ); Checkbox->Enabled( true ); TextParams.PosSet( 130, 40 ); cUIRadioButton * RadioButton = eeNew( cUIRadioButton, ( TextParams ) ); RadioButton->Visible( true ); - RadioButton->Text( L"Check Me" ); + RadioButton->Text( "Check Me" ); RadioButton->Enabled( true ); TextParams.PosSet( 130, 60 ); RadioButton = eeNew( cUIRadioButton, ( TextParams ) ); RadioButton->Visible( true ); - RadioButton->Text( L"Check Me 2" ); + RadioButton->Text( "Check Me 2" ); RadioButton->Enabled( true ); cUISlider::CreateParams SliderParams; @@ -385,12 +389,12 @@ void cEETest::CreateUI() { Int32 wsize = 100; if ( wsize ) { - std::vector wstr(wsize); + std::vector str(wsize); for ( Int32 i = 1; i <= wsize; i++ ) - wstr[i-1] = L"Test ListBox " + toWStr(i) + L" testing it right now!"; + str[i-1] = "Test ListBox " + toStr(i) + " testing it right now!"; - mListBox->AddListBoxItems( wstr ); + mListBox->AddListBoxItems( str ); } cUIDropDownList::CreateParams DDLParams; @@ -402,11 +406,11 @@ void cEETest::CreateUI() { mDropDownList->Visible( true ); mDropDownList->Enabled( true ); - std::vector combostrs; - combostrs.push_back( L"Plane" ); - combostrs.push_back( L"Car" ); - combostrs.push_back( L"Bus" ); - combostrs.push_back( L"Train" ); + std::vector combostrs; + combostrs.push_back( "Plane" ); + combostrs.push_back( "Car" ); + combostrs.push_back( "Bus" ); + combostrs.push_back( "Train" ); mDropDownList->ListBox()->AddListBoxItems( combostrs ); mDropDownList->ListBox()->SetSelected( 0 ); @@ -433,41 +437,41 @@ void cEETest::CreateUI() { MenuParams.FontSelectedColor = eeColorA( 255, 255, 255, 255 ); MenuParams.MinRightMargin = 8; Menu = eeNew( cUIPopUpMenu, ( MenuParams ) ); - Menu->Add( L"New", cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); - Menu->Add( L"Open..." ); + Menu->Add( "New", cGlobalShapeGroup::instance()->GetByName( "aqua_button_ok" ) ); + Menu->Add( "Open..." ); Menu->AddSeparator(); - Menu->Add( L"Show Screen 1" ); - Menu->Add( L"Show Screen 2" ); - Menu->Add( L"Show Screen 3" ); - Menu->Add( L"Show Screen 4" ); - Menu->Add( L"Show Screen 5" ); - Menu->Add( L"Show Screen 6" ); + Menu->Add( "Show Screen 1" ); + Menu->Add( "Show Screen 2" ); + Menu->Add( "Show Screen 3" ); + Menu->Add( "Show Screen 4" ); + Menu->Add( "Show Screen 5" ); + Menu->Add( "Show Screen 6" ); Menu->AddSeparator(); - Menu->AddCheckBox( L"Show Window" ); - Menu->Add( L"Show Window 2" ); - Menu->AddCheckBox( L"Multi Viewport" ); + Menu->AddCheckBox( "Show Window" ); + Menu->Add( "Show Window 2" ); + Menu->AddCheckBox( "Multi Viewport" ); cUIPopUpMenu * Menu3 = eeNew( cUIPopUpMenu, ( MenuParams ) ); - Menu3->Add( L"Hello World 1" ); - Menu3->Add( L"Hello World 2" ); - Menu3->Add( L"Hello World 3" ); - Menu3->Add( L"Hello World 4" ); + Menu3->Add( "Hello World 1" ); + Menu3->Add( "Hello World 2" ); + Menu3->Add( "Hello World 3" ); + Menu3->Add( "Hello World 4" ); cUIPopUpMenu * Menu2 = eeNew( cUIPopUpMenu, ( MenuParams ) ); - Menu2->Add( L"Test 1" ); - Menu2->Add( L"Test 2" ); - Menu2->Add( L"Test 3" ); - Menu2->Add( L"Test 4" ); - Menu2->AddSubMenu( L"Hello World", NULL, Menu3 ); + Menu2->Add( "Test 1" ); + Menu2->Add( "Test 2" ); + Menu2->Add( "Test 3" ); + Menu2->Add( "Test 4" ); + Menu2->AddSubMenu( "Hello World", NULL, Menu3 ); Menu->AddSeparator(); - Menu->AddSubMenu( L"Sub-Menu", NULL, Menu2 ) ; + Menu->AddSubMenu( "Sub-Menu", NULL, Menu2 ) ; Menu->AddSeparator(); - Menu->Add( L"Quit" ); + Menu->Add( "Quit" ); Menu->AddEventListener( cUIEvent::EventOnItemClicked, cb::Make1( this, &cEETest::ItemClick ) ); - Menu->GetItem( L"Quit" )->AddEventListener( cUIEvent::EventMouseUp, cb::Make1( this, &cEETest::QuitClick ) ); + Menu->GetItem( "Quit" )->AddEventListener( cUIEvent::EventMouseUp, cb::Make1( this, &cEETest::QuitClick ) ); cUIManager::instance()->MainControl()->AddEventListener( cUIEvent::EventMouseClick, cb::Make1( this, &cEETest::MainClick ) ); cUITextEdit::CreateParams TEParams; @@ -508,7 +512,7 @@ void cEETest::CreateUI() { cUITextInput * TxtInput = eeNew( cUITextInput, ( TxtInputParams ) ); cUIGfx * TxtGfx = eeNew( cUIGfx, ( TxtGfxParams ) ); - TxtBox->Text( L"Test " + toWStr( i+1 ) ); + TxtBox->Text( "Test " + toStr( i+1 ) ); Cell->Cell( 0, TxtBox ); Cell->Cell( 1, TxtGfx ); @@ -521,7 +525,7 @@ void cEETest::CreateUI() { mGenGrid->CollumnWidth( 1, 24 ); mGenGrid->CollumnWidth( 2, 100 ); /* - //reinterpret_cast ( Menu->GetItem( L"Show Window" ) )->Active( true ); + //reinterpret_cast ( Menu->GetItem( "Show Window" ) )->Active( true ); C->Visible( true ); C->Enabled( true ); C->StartScaleAnim( 0.f, 1.f, 500.f, SINEOUT ); @@ -550,7 +554,7 @@ void cEETest::CreateDecoratedWindow() { mUIWindow = eeNew( cUIWindow, ( WinParams ) ); mUIWindow->AddEventListener( cUIEvent::EventOnWindowCloseClick, cb::Make1( this, &cEETest::CloseClick ) ); - mUIWindow->Title( L"Test Window" ); + mUIWindow->Title( "Test Window" ); mUIWindow->ToBack(); } @@ -562,21 +566,21 @@ void cEETest::ItemClick( const cUIEvent * Event ) { if ( !Event->Ctrl()->IsType( UI_TYPE_MENUITEM ) ) return; - const std::wstring& txt = reinterpret_cast ( Event->Ctrl() )->Text(); + const String& txt = reinterpret_cast ( Event->Ctrl() )->Text(); - if ( L"Show Screen 1" == txt ) { + if ( "Show Screen 1" == txt ) { SetScreen( 0 ); - } else if ( L"Show Screen 2" == txt ) { + } else if ( "Show Screen 2" == txt ) { SetScreen( 1 ); - } else if ( L"Show Screen 3" == txt ) { + } else if ( "Show Screen 3" == txt ) { SetScreen( 2 ); - } else if ( L"Show Screen 4" == txt ) { + } else if ( "Show Screen 4" == txt ) { SetScreen( 3 ); - } else if ( L"Show Screen 5" == txt ) { + } else if ( "Show Screen 5" == txt ) { SetScreen( 4 ); - } else if ( L"Show Screen 6" == txt ) { + } else if ( "Show Screen 6" == txt ) { SetScreen( 5 ); - } else if ( L"Show Window" == txt ) { + } else if ( "Show Window" == txt ) { cUIMenuCheckBox * Chk = reinterpret_cast ( Event->Ctrl() ); C->Visible( true ); @@ -591,19 +595,19 @@ void cEETest::ItemClick( const cUIEvent * Event ) { C->StartAlphaAnim( C->Alpha(), 0.f, 500.f ); C->StartRotation( 0, 360, 500.f, SINEIN ); } - } else if ( L"Show Window 2" == txt ) { + } else if ( "Show Window 2" == txt ) { if ( NULL == mUIWindow ) { CreateDecoratedWindow(); } mUIWindow->Show(); - } else if ( L"Multi Viewport" == txt ) { + } else if ( "Multi Viewport" == txt ) { MultiViewportMode = !MultiViewportMode; } } void cEETest::OnValueChange( const cUIEvent * Event ) { - mTextBoxValue->Text( L"Scroll Value:\n" + toWStr( mScrollBar->Value() ) ); + mTextBoxValue->Text( "Scroll Value:\n" + toStr( mScrollBar->Value() ) ); mProgressBar->Progress( mScrollBar->Value() * 100.f ); } @@ -643,7 +647,7 @@ void cEETest::ButtonClick( const cUIEvent * Event ) { Gfx->StartMovement( eeVector2i( eeRandi( 0, mWindow->GetWidth() ), -64 ), eeVector2i( eeRandi( 0, mWindow->GetWidth() ), mWindow->GetHeight() + 64 ), 2500 ); Gfx->CloseFadeOut( 3500 ); - mListBox->AddListBoxItem( L"Test ListBox " + toWStr( mListBox->Count() + 1 ) + L" testing it right now!" ); + mListBox->AddListBoxItem( "Test ListBox " + toStr( mListBox->Count() + 1 ) + " testing it right now!" ); } } @@ -657,20 +661,20 @@ void cEETest::SetScreen( Uint32 num ) { Screen = num; } -void cEETest::CmdSetPartsNum ( const std::vector < std::wstring >& params ) { +void cEETest::CmdSetPartsNum ( const std::vector < String >& params ) { if ( params.size() >= 2 ) { try { Int32 tInt = 0; - bool Res = fromWString( tInt, params[1] ); + bool Res = fromString( tInt, params[1] ); if ( Res && ( tInt >= 0 && tInt <= 100000 ) ) { PS[2].Create(WormHole, tInt, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 32, true); - Con.PushText( L"Wormhole Particles Number Changed to: " + toWStr(tInt) ); + Con.PushText( "Wormhole Particles Number Changed to: " + toStr(tInt) ); } else - Con.PushText( L"Valid parameters are between 0 and 100000 (0 = no limit)." ); + Con.PushText( "Valid parameters are between 0 and 100000 (0 = no limit)." ); } catch (...) { - Con.PushText( L"Invalid Parameter. Expected int value from '" + params[1] + L"'." ); + Con.PushText( "Invalid Parameter. Expected int value from '" + params[1] + "'." ); } } } @@ -732,7 +736,7 @@ void cEETest::LoadTextures() { PS[1].Create(Heal, 250, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 16, true); PS[2].Create(WormHole, PartsNum, TN[5], mWindow->GetWidth() * 0.5f, mWindow->GetHeight() * 0.5f, 32, true); - Con.AddCommand( L"setparticlesnum", cb::Make1( this, &cEETest::CmdSetPartsNum ) ); + Con.AddCommand( "setparticlesnum", cb::Make1( this, &cEETest::CmdSetPartsNum ) ); PS[3].Create(Fire, 350, TN[5], -50.f, -50.f, 32, true); PS[4].Create(Fire, 350, TN[5], -50.f, -50.f, 32, true); @@ -1135,13 +1139,13 @@ void cEETest::Render() { Uint32 NLPos = 0; Uint32 LineNum = InBuf.GetCurPosLinePos( NLPos ); if ( InBuf.CurPos() == (eeInt)InBuf.Buffer().size() && !LineNum ) { - FF2->Draw( L"_", 6.f + FF2->GetTextWidth(), 180.f ); + FF2->Draw( "_", 6.f + FF2->GetTextWidth(), 180.f ); } else { FF2->SetText( InBuf.Buffer().substr( NLPos, InBuf.CurPos() - NLPos ) ); - FF2->Draw( L"_", 6.f + FF2->GetTextWidth(), 180.f + (eeFloat)LineNum * (eeFloat)FF2->GetFontSize() ); + FF2->Draw( "_", 6.f + FF2->GetTextWidth(), 180.f + (eeFloat)LineNum * (eeFloat)FF2->GetFontSize() ); } - FF2->SetText( L"FPS: " + toWStr( mWindow->FPS() ) ); + FF2->SetText( "FPS: " + toStr( mWindow->FPS() ) ); FF2->Draw( mWindow->GetWidth() - FF2->GetTextWidth() - 15, 0 ); FF2->SetText( InBuf.Buffer() ); diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp index 8ac9905d3..0addd0ddf 100644 --- a/src/test/eetest.hpp +++ b/src/test/eetest.hpp @@ -79,7 +79,7 @@ class cEETest : private cThread { void ParticlesThread(); void Particles(); void LoadTextures(); - void CmdSetPartsNum ( const std::vector < std::wstring >& params ); + void CmdSetPartsNum ( const std::vector < String >& params ); std::vector > PS; @@ -181,7 +181,7 @@ class cEETest : private cThread { eeInt mWidth; eeInt mHeight; - std::wstring mBuda; + String mBuda; cResourceLoader mResLoad; void OnTextureLoaded( cResourceLoader * ObjLoaded ); diff --git a/src/ui/cuicomplexcontrol.cpp b/src/ui/cuicomplexcontrol.cpp index dfbc96fc1..df0947455 100644 --- a/src/ui/cuicomplexcontrol.cpp +++ b/src/ui/cuicomplexcontrol.cpp @@ -76,7 +76,7 @@ void cUIComplexControl::CreateTooltip() { mTooltip = eeNew( cUITooltip, ( Params, this ) ); } -void cUIComplexControl::TooltipText( const std::wstring& Text ) { +void cUIComplexControl::TooltipText( const String& Text ) { if ( NULL == mTooltip ) { // If the tooltip wasn't created it will avoid to create a new one if the string is "" if ( Text.size() ) { CreateTooltip(); @@ -88,15 +88,11 @@ void cUIComplexControl::TooltipText( const std::wstring& Text ) { } } -void cUIComplexControl::TooltipText( const std::string& Text ) { - TooltipText( stringTowstring( Text ) ); -} - -std::wstring cUIComplexControl::TooltipText() { +String cUIComplexControl::TooltipText() { if ( NULL != mTooltip ) return mTooltip->Text(); - return std::wstring(); + return String(); } void cUIComplexControl::TooltipRemove() { diff --git a/src/ui/cuicomplexcontrol.hpp b/src/ui/cuicomplexcontrol.hpp index e7d37775d..51543c7d2 100644 --- a/src/ui/cuicomplexcontrol.hpp +++ b/src/ui/cuicomplexcontrol.hpp @@ -17,7 +17,7 @@ class EE_API cUIComplexControl : public cUIControlAnim { inline ~CreateParams() {} - std::wstring TooltipText; + String TooltipText; }; cUIComplexControl( const cUIComplexControl::CreateParams& Params ); @@ -30,11 +30,9 @@ class EE_API cUIComplexControl : public cUIControlAnim { void TooltipRemove(); - void TooltipText( const std::wstring& Text ); + void TooltipText( const String& Text ); - void TooltipText( const std::string& Text ); - - std::wstring TooltipText(); + String TooltipText(); protected: cUITooltip * mTooltip; diff --git a/src/ui/cuilistbox.cpp b/src/ui/cuilistbox.cpp index 532ee7b85..8468680ff 100644 --- a/src/ui/cuilistbox.cpp +++ b/src/ui/cuilistbox.cpp @@ -103,7 +103,7 @@ cUIScrollBar * cUIListBox::HorizontalScrollBar() const { return mHScrollBar; } -void cUIListBox::AddListBoxItems( std::vector Texts ) { +void cUIListBox::AddListBoxItems( std::vector Texts ) { mItems.reserve( mItems.size() + Texts.size() ); mTexts.reserve( mTexts.size() + Texts.size() ); @@ -137,10 +137,10 @@ Uint32 cUIListBox::AddListBoxItem( cUIListBoxItem * Item ) { } Uint32 cUIListBox::AddListBoxItem( const std::string& Text ) { - return AddListBoxItem( stringTowstring( Text ) ); + return AddListBoxItem( String( Text ) ); } -Uint32 cUIListBox::AddListBoxItem( const std::wstring& Text ) { +Uint32 cUIListBox::AddListBoxItem( const String& Text ) { mTexts.push_back( Text ); mItems.push_back( NULL ); @@ -159,7 +159,7 @@ Uint32 cUIListBox::AddListBoxItem( const std::wstring& Text ) { return (Uint32)(mItems.size() - 1); } -cUIListBoxItem * cUIListBox::CreateListBoxItem( const std::wstring& Name ) { +cUIListBoxItem * cUIListBox::CreateListBoxItem( const String& Name ) { cUITextBox::CreateParams TextParams; TextParams.Parent( mContainer ); TextParams.Flags = UI_VALIGN_CENTER | UI_HALIGN_LEFT; @@ -171,7 +171,7 @@ cUIListBoxItem * cUIListBox::CreateListBoxItem( const std::wstring& Name ) { return tItem; } -Uint32 cUIListBox::RemoveListBoxItem( const std::wstring& Text ) { +Uint32 cUIListBox::RemoveListBoxItem( const String& Text ) { return RemoveListBoxItem( GetListBoxItemIndex( Text ) ); } @@ -228,7 +228,7 @@ Uint32 cUIListBox::RemoveListBoxItem( Uint32 ItemIndex ) { return ItemIndex; } -Uint32 cUIListBox::GetListBoxItemIndex( const std::wstring& Name ) { +Uint32 cUIListBox::GetListBoxItemIndex( const String& Name ) { Uint32 size = (Uint32)mItems.size(); for ( Uint32 i = 0; i < size; i++ ) { @@ -601,8 +601,8 @@ Uint32 cUIListBox::GetItemSelectedIndex() const { return 0xFFFFFFFF; } -std::wstring cUIListBox::GetItemSelectedText() const { - std::wstring tstr; +String cUIListBox::GetItemSelectedText() const { + String tstr; if ( mSelected.size() ) return mTexts[ mSelected.front() ]; diff --git a/src/ui/cuilistbox.hpp b/src/ui/cuilistbox.hpp index 6eb379716..8e35e1c1e 100644 --- a/src/ui/cuilistbox.hpp +++ b/src/ui/cuilistbox.hpp @@ -54,15 +54,15 @@ class EE_API cUIListBox : public cUIComplexControl { virtual ~cUIListBox(); - void AddListBoxItems( std::vector Texts ); + void AddListBoxItems( std::vector Texts ); Uint32 AddListBoxItem( const std::string& Text ); - Uint32 AddListBoxItem( const std::wstring& Text ); + Uint32 AddListBoxItem( const String& Text ); Uint32 AddListBoxItem( cUIListBoxItem * Item ); - Uint32 RemoveListBoxItem( const std::wstring& Text ); + Uint32 RemoveListBoxItem( const String& Text ); Uint32 RemoveListBoxItem( cUIListBoxItem * Item ); @@ -84,7 +84,7 @@ class EE_API cUIListBox : public cUIComplexControl { cUIListBoxItem * GetItemSelected(); - std::wstring GetItemSelectedText() const; + String GetItemSelectedText() const; Uint32 GetItemSelectedIndex() const; @@ -167,7 +167,7 @@ class EE_API cUIListBox : public cUIComplexControl { std::list mSelected; std::vector mItems; - std::vector mTexts; + std::vector mTexts; void UpdateScroll( bool FromScrollChange = false ); @@ -181,7 +181,7 @@ class EE_API cUIListBox : public cUIComplexControl { void UpdateListBoxItemsSize(); - Uint32 GetListBoxItemIndex( const std::wstring& Name ); + Uint32 GetListBoxItemIndex( const String& Name ); Uint32 GetListBoxItemIndex( cUIListBoxItem * Item ); @@ -199,7 +199,7 @@ class EE_API cUIListBox : public cUIComplexControl { void FindMaxWidth(); - cUIListBoxItem * CreateListBoxItem( const std::wstring& Name ); + cUIListBoxItem * CreateListBoxItem( const String& Name ); void CreateItemIndex( const Uint32& i ); diff --git a/src/ui/cuimenu.cpp b/src/ui/cuimenu.cpp index bbf7828fe..2fdc40934 100644 --- a/src/ui/cuimenu.cpp +++ b/src/ui/cuimenu.cpp @@ -44,7 +44,7 @@ void cUIMenu::DoAfterSetTheme() { OnSizeChange(); } -cUIMenuItem * cUIMenu::CreateMenuItem( const std::wstring& Text, cShape * Icon ) { +cUIMenuItem * cUIMenu::CreateMenuItem( const String& Text, cShape * Icon ) { cUIMenuItem::CreateParams Params; Params.Parent( this ); Params.Font = mFont; @@ -66,11 +66,11 @@ cUIMenuItem * cUIMenu::CreateMenuItem( const std::wstring& Text, cShape * Icon ) return tCtrl; } -Uint32 cUIMenu::Add( const std::wstring& Text, cShape * Icon ) { +Uint32 cUIMenu::Add( const String& Text, cShape * Icon ) { return Add( CreateMenuItem( Text, Icon ) ); } -cUIMenuCheckBox * cUIMenu::CreateMenuCheckBox( const std::wstring& Text ) { +cUIMenuCheckBox * cUIMenu::CreateMenuCheckBox( const String& Text ) { cUIMenuCheckBox::CreateParams Params; Params.Parent( this ); Params.Font = mFont; @@ -89,11 +89,11 @@ cUIMenuCheckBox * cUIMenu::CreateMenuCheckBox( const std::wstring& Text ) { return tCtrl; } -Uint32 cUIMenu::AddCheckBox( const std::wstring& Text ) { +Uint32 cUIMenu::AddCheckBox( const String& Text ) { return Add( CreateMenuCheckBox( Text ) ); } -cUIMenuSubMenu * cUIMenu::CreateSubMenu( const std::wstring& Text, cShape * Icon, cUIMenu * SubMenu ) { +cUIMenuSubMenu * cUIMenu::CreateSubMenu( const String& Text, cShape * Icon, cUIMenu * SubMenu ) { cUIMenuSubMenu::CreateParams Params; Params.Parent( this ); Params.Font = mFont; @@ -116,7 +116,7 @@ cUIMenuSubMenu * cUIMenu::CreateSubMenu( const std::wstring& Text, cShape * Icon return tCtrl; } -Uint32 cUIMenu::AddSubMenu( const std::wstring& Text, cShape * Icon, cUIMenu * SubMenu ) { +Uint32 cUIMenu::AddSubMenu( const String& Text, cShape * Icon, cUIMenu * SubMenu ) { return Add( CreateSubMenu( Text, Icon, SubMenu ) ); } @@ -219,7 +219,7 @@ cUIControl * cUIMenu::GetItem( const Uint32& Index ) { return mItems[ Index ]; } -cUIControl * cUIMenu::GetItem( const std::wstring& Text ) { +cUIControl * cUIMenu::GetItem( const String& Text ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( mItems[i]->IsType( UI_TYPE_MENUITEM ) ) { cUIMenuItem * tMenuItem = reinterpret_cast( mItems[i] ); @@ -277,7 +277,7 @@ void cUIMenu::RemoveAll() { ResizeMe(); } -void cUIMenu::Insert( const std::wstring& Text, cShape * Icon, const Uint32& Index ) { +void cUIMenu::Insert( const String& Text, cShape * Icon, const Uint32& Index ) { Insert( CreateMenuItem( Text, Icon ), Index ); } diff --git a/src/ui/cuimenu.hpp b/src/ui/cuimenu.hpp index 90c0ad71e..ad23d99d6 100644 --- a/src/ui/cuimenu.hpp +++ b/src/ui/cuimenu.hpp @@ -60,19 +60,19 @@ class EE_API cUIMenu : public cUIComplexControl { ~cUIMenu(); - Uint32 Add( const std::wstring& Text, cShape * Icon = NULL ); + Uint32 Add( const String& Text, cShape * Icon = NULL ); Uint32 Add( cUIControl * Control ); Uint32 AddSeparator(); - Uint32 AddCheckBox( const std::wstring& Text ); + Uint32 AddCheckBox( const String& Text ); - Uint32 AddSubMenu( const std::wstring& Text, cShape * Icon = NULL, cUIMenu * SubMenu = NULL ); + Uint32 AddSubMenu( const String& Text, cShape * Icon = NULL, cUIMenu * SubMenu = NULL ); cUIControl * GetItem( const Uint32& Index ); - cUIControl * GetItem( const std::wstring& Text ); + cUIControl * GetItem( const String& Text ); Uint32 GetItemIndex( cUIControl * Item ); @@ -84,7 +84,7 @@ class EE_API cUIMenu : public cUIComplexControl { void RemoveAll(); - void Insert( const std::wstring& Text, cShape * Icon, const Uint32& Index ); + void Insert( const String& Text, cShape * Icon, const Uint32& Index ); void Insert( cUIControl * Control, const Uint32& Index ); @@ -133,11 +133,11 @@ class EE_API cUIMenu : public cUIComplexControl { void ResizeMe(); - cUIMenuItem * CreateMenuItem( const std::wstring& Text, cShape * Icon ); + cUIMenuItem * CreateMenuItem( const String& Text, cShape * Icon ); - cUIMenuCheckBox * CreateMenuCheckBox( const std::wstring& Text ); + cUIMenuCheckBox * CreateMenuCheckBox( const String& Text ); - cUIMenuSubMenu * CreateSubMenu( const std::wstring& Text, cShape * Icon, cUIMenu * SubMenu ); + cUIMenuSubMenu * CreateSubMenu( const String& Text, cShape * Icon, cUIMenu * SubMenu ); void DoAfterSetTheme(); diff --git a/src/ui/cuiprogressbar.cpp b/src/ui/cuiprogressbar.cpp index c454493d6..756a354f9 100644 --- a/src/ui/cuiprogressbar.cpp +++ b/src/ui/cuiprogressbar.cpp @@ -156,7 +156,7 @@ const bool& cUIProgressBar::DisplayPercent() const { void cUIProgressBar::UpdateTextBox() { mTextBox->Visible( mDisplayPercent ); mTextBox->Size( mSize ); - mTextBox->Text( toWStr( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + L"%" ); + mTextBox->Text( toStr( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); } cUITextBox * cUIProgressBar::TextBox() const { diff --git a/src/ui/cuipushbutton.cpp b/src/ui/cuipushbutton.cpp index 3484ccf00..b48fdd56d 100644 --- a/src/ui/cuipushbutton.cpp +++ b/src/ui/cuipushbutton.cpp @@ -131,17 +131,12 @@ cUIGfx * cUIPushButton::Icon() const { return mIcon; } -void cUIPushButton::Text( const std::wstring& text ) { +void cUIPushButton::Text( const String& text ) { mTextBox->Text( text ); OnSizeChange(); } -void cUIPushButton::Text( const std::string& text ) { - mTextBox->Text( text ); - OnSizeChange(); -} - -const std::wstring& cUIPushButton::Text() { +const String& cUIPushButton::Text() { return mTextBox->Text(); } diff --git a/src/ui/cuipushbutton.hpp b/src/ui/cuipushbutton.hpp index cae710970..fa4b91e7c 100644 --- a/src/ui/cuipushbutton.hpp +++ b/src/ui/cuipushbutton.hpp @@ -62,11 +62,9 @@ class EE_API cUIPushButton : public cUIComplexControl { cUIGfx * Icon() const; - void Text( const std::wstring& text ); + void Text( const String& text ); - void Text( const std::string& text ); - - const std::wstring& Text(); + const String& Text(); void Padding( const eeRecti& padding ); diff --git a/src/ui/cuispinbox.cpp b/src/ui/cuispinbox.cpp index c7d0e044e..5a41da5b9 100644 --- a/src/ui/cuispinbox.cpp +++ b/src/ui/cuispinbox.cpp @@ -129,7 +129,7 @@ Uint32 cUISpinBox::OnMessage( const cUIMessage * Msg ) { void cUISpinBox::AddValue( const eeFloat& value ) { if ( !mInput->Text().size() ) - mInput->Text( L"0" ); + mInput->Text( "0" ); Value( mValue + value ); } @@ -141,9 +141,9 @@ void cUISpinBox::InternalValue( const eeFloat& Val, const bool& Force ) { eeFloat fValN = (eeFloat)iValN; if ( fValN == Val ) { - mInput->Text( toWStr( iValN ) ); + mInput->Text( toStr( iValN ) ); } else { - mInput->Text( toWStr( Val ) ); + mInput->Text( toStr( Val ) ); } mValue = Val; @@ -195,12 +195,12 @@ void cUISpinBox::Update() { eeFloat Val = mValue; if ( '.' == mInput->Text()[ mInput->Text().size() - 1 ] ) { - Uint32 pos = (Uint32)mInput->Text().find_first_of( L"." ); + Uint32 pos = (Uint32)mInput->Text().find_first_of( "." ); if ( pos != mInput->Text().size() - 1 ) mInput->Text( mInput->Text().substr( 0, mInput->Text().size() - 1 ) ); } else { - bool Res = fromWString( Val, mInput->Text() ); + bool Res = fromString( Val, mInput->Text() ); if ( Res ) Value( Val ); diff --git a/src/ui/cuitextbox.cpp b/src/ui/cuitextbox.cpp index 4d18cb071..09e00dd74 100644 --- a/src/ui/cuitextbox.cpp +++ b/src/ui/cuitextbox.cpp @@ -68,15 +68,11 @@ void cUITextBox::Font( cFont * font ) { } } -const std::wstring& cUITextBox::Text() { +const String& cUITextBox::Text() { return mTextCache->Text(); } -void cUITextBox::Text( const std::string& text ) { - Text( stringTowstring( text ) ); -} - -void cUITextBox::Text( const std::wstring& text ) { +void cUITextBox::Text( const String& text ) { mTextCache->Text( text ); AutoShrink(); AutoSize(); diff --git a/src/ui/cuitextbox.hpp b/src/ui/cuitextbox.hpp index f396c7200..252218406 100644 --- a/src/ui/cuitextbox.hpp +++ b/src/ui/cuitextbox.hpp @@ -46,11 +46,9 @@ class EE_API cUITextBox : public cUIComplexControl { void Font( cFont * font ); - virtual const std::wstring& Text(); + virtual const String& Text(); - virtual void Text( const std::wstring& text ); - - virtual void Text( const std::string& text ); + virtual void Text( const String& text ); const eeColorA& Color() const; diff --git a/src/ui/cuitextedit.cpp b/src/ui/cuitextedit.cpp index 4b0c95456..62b121398 100644 --- a/src/ui/cuitextedit.cpp +++ b/src/ui/cuitextedit.cpp @@ -220,11 +220,11 @@ cUIScrollBar * cUITextEdit::VScrollBar() const { return mVScrollBar; } -const std::wstring& cUITextEdit::Text() const { +const String& cUITextEdit::Text() const { return mTextInput->Text(); } -void cUITextEdit::Text( const std::wstring& Txt ) { +void cUITextEdit::Text( const String& Txt ) { mTextInput->Text( Txt ); OnInputSizeChange(); @@ -232,10 +232,6 @@ void cUITextEdit::Text( const std::wstring& Txt ) { OnSizeChange(); } -void cUITextEdit::Text( const std::string& Txt ) { - Text( stringTowstring( Txt ) ); -} - void cUITextEdit::OnInputSizeChange( const cUIEvent * Event ) { eeInt Width = mSize.Width() - mPadding.Left - mPadding.Right; eeInt Height = mSize.Height() - mPadding.Top - mPadding.Bottom; diff --git a/src/ui/cuitextedit.hpp b/src/ui/cuitextedit.hpp index fc8df0a84..4b8c33611 100644 --- a/src/ui/cuitextedit.hpp +++ b/src/ui/cuitextedit.hpp @@ -31,11 +31,9 @@ class EE_API cUITextEdit : public cUIControlAnim { virtual void SetTheme( cUITheme * Theme ); - const std::wstring& Text() const; + const String& Text() const; - void Text( const std::wstring& Txt ); - - void Text( const std::string& Txt ); + void Text( const String& Txt ); cUITextInput * TextInput() const; @@ -55,7 +53,7 @@ class EE_API cUITextEdit : public cUIControlAnim { UI_SCROLLBAR_MODE mHScrollBarMode; UI_SCROLLBAR_MODE mVScrollBarMode; eeRecti mPadding; - std::wstring mText; + String mText; bool mSkipValueChange; virtual void OnSizeChange(); diff --git a/src/ui/cuitextinput.cpp b/src/ui/cuitextinput.cpp index 43673b9ea..f6ffe8c3c 100644 --- a/src/ui/cuitextinput.cpp +++ b/src/ui/cuitextinput.cpp @@ -176,7 +176,7 @@ const bool& cUITextInput::AllowEditing() const { return mAllowEditing; } -void cUITextInput::Text( const std::wstring& text ) { +void cUITextInput::Text( const String& text ) { cUITextBox::Text( text ); mTextBuffer.Buffer( text ); @@ -184,14 +184,10 @@ void cUITextInput::Text( const std::wstring& text ) { mTextBuffer.CursorToEnd(); } -const std::wstring& cUITextInput::Text() { +const String& cUITextInput::Text() { return cUITextBox::Text(); } -void cUITextInput::Text( const std::string& text ) { - Text( stringTowstring( text ) ); -} - void cUITextInput::ShrinkText( const Uint32& MaxWidth ) { mTextCache->Text( mTextBuffer.Buffer() ); diff --git a/src/ui/cuitextinput.hpp b/src/ui/cuitextinput.hpp index 6981addf6..7ef0cf877 100644 --- a/src/ui/cuitextinput.hpp +++ b/src/ui/cuitextinput.hpp @@ -42,11 +42,9 @@ class EE_API cUITextInput : public cUITextBox { const bool& AllowEditing() const; - virtual const std::wstring& Text(); + virtual const String& Text(); - virtual void Text( const std::wstring& text ); - - virtual void Text( const std::string& text ); + virtual void Text( const String& text ); virtual void ShrinkText( const Uint32& MaxWidth ); protected: diff --git a/src/ui/cuitooltip.cpp b/src/ui/cuitooltip.cpp index cf59a2c01..1862aa419 100644 --- a/src/ui/cuitooltip.cpp +++ b/src/ui/cuitooltip.cpp @@ -107,15 +107,11 @@ void cUITooltip::Font( cFont * font ) { } } -const std::wstring& cUITooltip::Text() { +const String& cUITooltip::Text() { return mTextCache->Text(); } -void cUITooltip::Text( const std::string& text ) { - Text( stringTowstring( text ) ); -} - -void cUITooltip::Text( const std::wstring& text ) { +void cUITooltip::Text( const String& text ) { mTextCache->Text( text ); AutoPadding(); AutoSize(); diff --git a/src/ui/cuitooltip.hpp b/src/ui/cuitooltip.hpp index a7ba926cd..f2399210e 100644 --- a/src/ui/cuitooltip.hpp +++ b/src/ui/cuitooltip.hpp @@ -52,11 +52,9 @@ class EE_API cUITooltip : public cUIControlAnim { void Font( cFont * font ); - virtual const std::wstring& Text(); + virtual const String& Text(); - virtual void Text( const std::wstring& text ); - - virtual void Text( const std::string& text ); + virtual void Text( const String& text ); const eeColorA& Color() const; diff --git a/src/ui/cuiwindow.cpp b/src/ui/cuiwindow.cpp index 957bf018c..f8616e9cd 100644 --- a/src/ui/cuiwindow.cpp +++ b/src/ui/cuiwindow.cpp @@ -593,7 +593,7 @@ const Uint8& cUIWindow::BaseAlpha() const { return mBaseAlpha; } -void cUIWindow::Title( const std::wstring& Text ) { +void cUIWindow::Title( const String& Text ) { if ( NULL == mTitle ) { cUITextBox::CreateParams Params; Params.Parent( this ); @@ -620,11 +620,11 @@ void cUIWindow::FixTitleSize() { } } -std::wstring cUIWindow::Title() const { +String cUIWindow::Title() const { if ( NULL != mTitle ) return mTitle->Text(); - return std::wstring(); + return String(); } cUITextBox * cUIWindow::TitleTextBox() const { diff --git a/src/ui/cuiwindow.hpp b/src/ui/cuiwindow.hpp index e35e067fb..fbdc729a4 100644 --- a/src/ui/cuiwindow.hpp +++ b/src/ui/cuiwindow.hpp @@ -77,9 +77,9 @@ class cUIWindow : public cUIComplexControl { const Uint8& BaseAlpha() const; - void Title( const std::wstring& Text ); + void Title( const String& Text ); - std::wstring Title() const; + String Title() const; cUITextBox * TitleTextBox() const; protected: diff --git a/src/utils/string.cpp b/src/utils/string.cpp index 73e73489a..b11952bba 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -17,18 +17,6 @@ bool isLetter( const eeInt& mValue ) { return ( ( (mValue >= 65 && mValue <= 90) || (mValue >= 97 && mValue <= 122) || (mValue >= 192 && mValue <= 255) ) && (mValue != 215) && (mValue != 247) ); } -std::wstring stringTowstring(const std::string& s) { - std::wstring temp( s.length(), ' ' ); - std::copy(s.begin(), s.end(), temp.begin()); - return temp; -} - -std::string wstringTostring( const std::wstring& s ) { - std::string temp( s.length(), ' ' ); - std::copy(s.begin(), s.end(), temp.begin()); - return temp; -} - std::string intToStr( Int32 n ) { char buf[10]; @@ -68,19 +56,15 @@ std::string GetDateTimeStr() { #endif } -std::vector < std::wstring > SplitString ( const std::wstring& str, const Uint32& splitchar ) { - std::vector < std::wstring > tmp; - std::wstring tmpstr; +std::vector < String > SplitString ( const String& str, const Uint32& splitchar ) { + std::vector < String > tmp; + String tmpstr; for ( eeUint i = 0; i < str.size(); i++ ) { - #if EE_PLATFORM == EE_PLATFORM_WIN if ( str[i] == splitchar ) { - #else - if ( str[i] == (Int32)splitchar ) { - #endif if ( tmpstr.size() ) { tmp.push_back(tmpstr); - tmpstr = L""; + tmpstr = ""; } } else { tmpstr += str[i]; @@ -179,20 +163,13 @@ std::vector stringToUint8( const std::string& str ) { return std::vector( str.begin(), str.end() ); } -std::vector wstringToUint8( const std::wstring& str ) { - return std::vector( str.begin(), str.end() ); -} - std::string Uint8Tostring( const std::vector v ) { return std::string( v.begin(), v.end() ); } -std::wstring Uint8Towstring( const std::vector v ) { - return std::wstring( v.begin(), v.end() ); -} +void InsertChar( String& str, const eeUint& pos, const Uint32& tchar ) { + String tStr( str.length() ); -void InsertChar( std::wstring& str, const eeUint& pos, const Uint32& tchar ) { - std::wstring tStr( str.length() + 1, ' '); for ( eeUint i = 0; i < tStr.size(); i++ ) { if ( i < pos ) { tStr[i] = str[i]; @@ -284,7 +261,7 @@ Int32 StrStartsWith( const std::string& Start, const std::string Str ) { return Pos; } -Int32 StrStartsWith( const std::wstring& Start, const std::wstring Str ) { +Int32 StrStartsWith( const String& Start, const String Str ) { Int32 Pos = -1; if ( Str.size() >= Start.size() ) { diff --git a/src/utils/string.hpp b/src/utils/string.hpp index 3ddba0dc2..cc5dd1f0e 100755 --- a/src/utils/string.hpp +++ b/src/utils/string.hpp @@ -14,12 +14,6 @@ bool EE_API isNumber( const eeInt& mValue, bool AllowDot = false ); /** @return If the value passed is a letter */ bool EE_API isLetter( const eeInt& mValue ); -/** Converts from std::string to std::wstring */ -std::wstring EE_API stringTowstring(const std::string& s); - -/** Converts from std::wstring to std::string */ -std::string EE_API wstringTostring(const std::wstring& s); - /** Converts an integer value to std::string. It's faster than toStr. */ std::string EE_API intToStr(Int32 n); @@ -37,14 +31,6 @@ std::string toStr(const T& i) { return ss.str(); } -/** Converts from any basic type to std::wstring */ -template -std::wstring toWStr(const T& i) { - std::string str; - str = toStr(i); - return stringTowstring(str); -} - /** Converts from a string to type */ template bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { @@ -52,15 +38,15 @@ bool fromString(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) return !(iss >> f >> t).fail(); } -/** Converts from a wstring to type */ +/** Converts from a String to type */ template -bool fromWString(T& t, const std::wstring& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { - std::istringstream iss( wstringTostring( s ) ); +bool fromString(T& t, const String& s, std::ios_base& (*f)(std::ios_base&) = std::dec ) { + std::istringstream iss( s.ToUtf8() ); return !(iss >> f >> t).fail(); } -/** Split a wstring and hold it on a vector */ -std::vector < std::wstring > EE_API SplitString ( const std::wstring& str, const Uint32& splitchar = '\n' ); +/** Split a String and hold it on a vector */ +std::vector < String > EE_API SplitString ( const String& str, const Uint32& splitchar = '\n' ); /** Split a string and hold it on a vector */ std::vector < std::string > EE_API SplitString ( const std::string& str, const Int8& splitchar = '\n' ); @@ -92,17 +78,11 @@ void EE_API toLower( std::string & str ); /** Convert the string to an std::vector */ std::vector EE_API stringToUint8( const std::string& str ); -/** Convert the wstring to an std::vector */ -std::vector EE_API wstringToUint8( const std::wstring& str ); - /** Convert the std::vector to an string */ std::string EE_API Uint8Tostring( const std::vector v ); -/** Convert the std::vector to an wstring */ -std::wstring EE_API Uint8Towstring( const std::vector v ); - -/** Insert a char into wstr on pos (added this function to avoid a bug on wstring) */ -void EE_API InsertChar( std::wstring& str, const eeUint& pos, const Uint32& tchar ); +/** Insert a char into String on pos (added this function to avoid a bug on String) */ +void EE_API InsertChar( String& str, const eeUint& pos, const Uint32& tchar ); /** @return A storage path for config files for every platform */ std::string EE_API StoragePath( std::string appname ); @@ -121,7 +101,7 @@ void EE_API StrCopy( char * Dst, const char * Src, eeUint DstSize ); */ Int32 EE_API StrStartsWith( const std::string& Start, const std::string Str ); -Int32 EE_API StrStartsWith( const std::wstring& Start, const std::wstring Str ); +Int32 EE_API StrStartsWith( const String& Start, const String Str ); /** Replaces a substring by another string inside a string */ void EE_API ReplaceSubStr(std::string &target, const std::string& that, const std::string& with ); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 3c3b5c61c..71541c57e 100755 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -159,7 +159,7 @@ std::string AppPath() { GetModuleFileName(0, &dllName[0], _MAX_PATH); - std::string dllstrName( wstringTostring( dllName ) ); + std::string dllstrName( String( dllName ).ToUtf8() ); #ifdef EE_COMPILER_MSVC _splitpath_s( dllstrName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, szExt, _MAX_DIR ); @@ -191,59 +191,59 @@ std::string AppPath() { #endif } -std::vector FilesGetInPath( const std::wstring& path ) { - std::vector files; +std::vector FilesGetInPath( const String& path ) { + std::vector files; #ifdef EE_COMPILER_MSVC #ifdef UNICODE - std::wstring mPath( path ); + String mPath( path ); if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += L"*"; + mPath += "*"; } else { - mPath += L"\\*"; + mPath += "\\*"; } WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( mPath.c_str(), &findFileData ); + HANDLE hFind = FindFirstFile( mPath.ToWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { - std::wstring tmpstr( findFileData.cFileName ); + String tmpstr( findFileData.cFileName ); - if ( tmpstr != L"." && tmpstr != L".." ) + if ( tmpstr != "." && tmpstr != ".." ) files.push_back( tmpstr ); while( FindNextFile( hFind, &findFileData ) ) { - tmpstr = std::wstring( findFileData.cFileName ); + tmpstr = String( findFileData.cFileName ); - if ( tmpstr != L"." && tmpstr != L".." ) + if ( tmpstr != "." && tmpstr != ".." ) files.push_back( tmpstr ); } FindClose( hFind ); } #else - std::wstring mPath( path ); + String mPath( path ); if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += L"*"; + mPath += "*"; } else { - mPath += L"\\*"; + mPath += "\\*"; } WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.c_str(), &findFileData ); + HANDLE hFind = FindFirstFile( (LPCTSTR) mPath.ToAnsiString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { - std::wstring tmpstr( stringTowstring( findFileData.cFileName ) ); + String tmpstr( String::FromUtf8( findFileData.cFileName ) ); - if ( tmpstr != L"." && tmpstr != L".." ) + if ( tmpstr != "." && tmpstr != ".." ) files.push_back( tmpstr ); while( FindNextFile( hFind, &findFileData ) ) { - tmpstr = std::wstring( stringTowstring( findFileData.cFileName ) ); + tmpstr = String::FromUtf8( findFileData.cFileName ); - if ( tmpstr != L"." && tmpstr != L".." ) + if ( tmpstr != "." && tmpstr != ".." ) files.push_back( tmpstr ); } @@ -256,14 +256,14 @@ std::vector FilesGetInPath( const std::wstring& path ) { DIR *dp; struct dirent *dirp; - if( ( dp = opendir( wstringTostring( path.c_str() ).c_str() ) ) == NULL) + if( ( dp = opendir( path.ToUtf8().c_str() ) ) == NULL) return files; while ( ( dirp = readdir(dp) ) != NULL) { if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) { char * p = &dirp->d_name[0]; - std::wstring tmp; + String tmp; while ( *p ) { unsigned char y = *p; @@ -287,28 +287,28 @@ std::vector FilesGetInPath( const std::string& path ) { #ifdef EE_COMPILER_MSVC #ifdef UNICODE - std::wstring mPath( stringTowstring( path ) ); + String mPath( String::FromUtf8( path ) ); if ( mPath[ mPath.size() - 1 ] == '/' || mPath[ mPath.size() - 1 ] == '\\' ) { - mPath += L"*"; + mPath += "*"; } else { - mPath += L"\\*"; + mPath += "\\*"; } WIN32_FIND_DATA findFileData; - HANDLE hFind = FindFirstFile( mPath.c_str(), &findFileData ); + HANDLE hFind = FindFirstFile( mPath.ToWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { - std::wstring tmpstr( findFileData.cFileName ); + String tmpstr( findFileData.cFileName ); - if ( tmpstr != L"." && tmpstr != L".." ) - files.push_back( wstringTostring( tmpstr ) ); + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( tmpstr.ToUtf8() ); while( FindNextFile(hFind, &findFileData ) ) { - tmpstr = std::wstring( findFileData.cFileName ); + tmpstr = String( findFileData.cFileName ); - if ( tmpstr != L"." && tmpstr != L".." ) - files.push_back( std::string( wstringTostring( findFileData.cFileName ) ) ); + if ( tmpstr != "." && tmpstr != ".." ) + files.push_back( String( findFileData.cFileName ).ToUtf8() ); } FindClose( hFind ); @@ -392,8 +392,8 @@ eeDouble GetSystemTime() { #endif } -bool IsDirectory( const std::wstring& path ) { - return IsDirectory( wstringTostring( path ) ); +bool IsDirectory( const String& path ) { + return IsDirectory( path.ToUtf8() ); } bool IsDirectory( const std::string& path ) { @@ -426,7 +426,7 @@ std::string GetWindowsPath() { #ifdef UNICODE wchar_t Buffer[1024]; GetWindowsDirectory( Buffer, 1024 ); - return wstringTostring( std::wstring( Buffer ) ); + return String( Buffer ).ToUtf8(); #else char Buffer[1024]; GetWindowsDirectory( Buffer, 1024 ); @@ -437,10 +437,6 @@ std::string GetWindowsPath() { #endif } -Uint32 MakeHash( const std::wstring& str ) { - return MakeHash( reinterpret_cast( &str[0] ) ); -} - Uint32 MakeHash( const std::string& str ) { return MakeHash( reinterpret_cast( &str[0] ) ); } @@ -651,28 +647,6 @@ std::string SizeToString( const Uint32& MemSize ) { return std::string( toStr( mem ) + size ); } -std::wstring SizeToWString( const Uint32& MemSize ) { - std::wstring size = L" bytes"; - eeDouble mem = static_cast( MemSize ); - Uint8 c = 0; - - while ( mem > 1024 ) { - c++; - mem = mem / 1024; - } - - switch (c) { - case 0: size = L" bytes"; break; - case 1: size = L" KB"; break; - case 2: size = L" MB"; break; - case 3: size = L" GB"; break; - case 4: size = L" TB"; break; - default: size = L" WTF"; - } - - return std::wstring( toWStr( mem ) + size ); -} - void Write32BitKey( Uint32 * Key, Uint32 Pos, Uint32 BitWrite ) { if ( BitWrite ) ( * Key ) |= ( 1 << Pos ); diff --git a/src/utils/utils.hpp b/src/utils/utils.hpp index 7ab6e30ba..99df0607e 100755 --- a/src/utils/utils.hpp +++ b/src/utils/utils.hpp @@ -20,7 +20,7 @@ namespace EE { namespace Utils { std::vector EE_API FilesGetInPath( const std::string& path ); /** @return The files and sub directories contained by a directory */ - std::vector EE_API FilesGetInPath( const std::wstring& path ); + std::vector EE_API FilesGetInPath( const String& path ); /** @return The size of a file */ Uint32 EE_API FileSize( const std::string& Filepath ); @@ -32,7 +32,7 @@ namespace EE { namespace Utils { bool EE_API IsDirectory( const std::string& path ); /** @return If directory exists, and is a directory */ - bool EE_API IsDirectory( const std::wstring& path ); + bool EE_API IsDirectory( const String& path ); /** Creates a new directory */ bool EE_API MakeDir( const std::string& path, const Uint16& mode = 0770 ); @@ -40,9 +40,6 @@ namespace EE { namespace Utils { /** @return The default windows directory */ std::string EE_API GetWindowsPath(); - /** @return wstring hash */ - Uint32 EE_API MakeHash( const std::wstring& str ); - /** @return string hash */ Uint32 EE_API MakeHash( const std::string& str ); @@ -107,11 +104,6 @@ namespace EE { namespace Utils { */ std::string EE_API SizeToString( const Uint32& MemSize ); - /** Convert a size represented in bytes, to a wstring converted in byes/kb/mb/tb. - * @example 10485760 -> "10.0 MB" - */ - std::wstring EE_API SizeToWString( const Uint32& MemSize ); - /** Write a bit into the Key in the position defined. * @param Key The Key to write * @param Pos The Position of the bit diff --git a/src/window/backend/SDL/cclipboardsdl.cpp b/src/window/backend/SDL/cclipboardsdl.cpp index 1c023a39e..7dd1463f1 100644 --- a/src/window/backend/SDL/cclipboardsdl.cpp +++ b/src/window/backend/SDL/cclipboardsdl.cpp @@ -5,12 +5,13 @@ namespace EE { namespace Window { namespace Backend { namespace SDL { -static void * CurrentHandler = NULL; - #define T(A, B, C, D) (int)((A<<24)|(B<<16)|(C<<8)|(D<<0)) #define FORMAT_PREFIX "EE_scrap_0x" #if defined( EE_X11_PLATFORM ) + +static void * CurrentHandler = NULL; + static int clipboard_filter( const SDL_Event *event ) { /* Post all non-window manager specific events */ if ( event->type != SDL_SYSWMEVENT ) { @@ -93,7 +94,7 @@ void cClipboardSDL::Init() { void cClipboardSDL::SetText( const std::string& Text ) { } -void cClipboardSDL::SetText( const std::wstring& Text ) { +void cClipboardSDL::SetText( const String& Text ) { } int cClipboardSDL::clipboard_convert_scrap( int type, char *dst, char *src, int srclen ) { @@ -282,8 +283,8 @@ std::string cClipboardSDL::GetText() { return tStr; } -std::wstring cClipboardSDL::GetTextWStr() { - std::wstring tStr; +String cClipboardSDL::GetWideText() { + String tStr; #if defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_WIN char * scrap = NULL; @@ -308,7 +309,7 @@ std::wstring cClipboardSDL::GetTextWStr() { eeSAFE_DELETE_ARRAY( scrap ); #else - #warning cClipboardSDL::GetClipboardTextWStr() not implemented on this platform. + #warning cClipboardSDL::GetWideText() not implemented on this platform. #endif return tStr; diff --git a/src/window/backend/SDL/cclipboardsdl.hpp b/src/window/backend/SDL/cclipboardsdl.hpp index c1fd3ecbd..23cac5fe6 100644 --- a/src/window/backend/SDL/cclipboardsdl.hpp +++ b/src/window/backend/SDL/cclipboardsdl.hpp @@ -18,11 +18,11 @@ class EE_API cClipboardSDL : public cClipboard { std::string GetText(); - std::wstring GetTextWStr(); - + String GetWideText(); + void SetText( const std::string& Text ); - void SetText( const std::wstring& Text ); + void SetText( const String& Text ); protected: friend class cWindowSDL; diff --git a/src/window/backend/allegro5/cclipboardal.cpp b/src/window/backend/allegro5/cclipboardal.cpp index f4c03fa90..74f96f08c 100644 --- a/src/window/backend/allegro5/cclipboardal.cpp +++ b/src/window/backend/allegro5/cclipboardal.cpp @@ -19,15 +19,15 @@ void cClipboardAl::Init() { void cClipboardAl::SetText( const std::string& Text ) { } -void cClipboardAl::SetText( const std::wstring& Text ) { +void cClipboardAl::SetText( const String& Text ) { } std::string cClipboardAl::GetText() { return std::string(); } -std::wstring cClipboardAl::GetTextWStr() { - return std::wstring(); +String cClipboardAl::GetWideText() { + return String(); } }}}} diff --git a/src/window/backend/allegro5/cclipboardal.hpp b/src/window/backend/allegro5/cclipboardal.hpp index 798d39d71..817e079ec 100644 --- a/src/window/backend/allegro5/cclipboardal.hpp +++ b/src/window/backend/allegro5/cclipboardal.hpp @@ -16,11 +16,11 @@ class EE_API cClipboardAl : public cClipboard { std::string GetText(); - std::wstring GetTextWStr(); - + String GetWideText(); + void SetText( const std::string& Text ); - void SetText( const std::wstring& Text ); + void SetText( const String& Text ); protected: friend class cWindowAl; diff --git a/src/window/backend/null/cclipboardnull.cpp b/src/window/backend/null/cclipboardnull.cpp index 5ac56613a..7f4e838f7 100644 --- a/src/window/backend/null/cclipboardnull.cpp +++ b/src/window/backend/null/cclipboardnull.cpp @@ -17,15 +17,15 @@ void cClipboardNull::Init() { void cClipboardNull::SetText( const std::string& Text ) { } -void cClipboardNull::SetText( const std::wstring& Text ) { +void cClipboardNull::SetText( const String& Text ) { } std::string cClipboardNull::GetText() { return std::string(); } -std::wstring cClipboardNull::GetTextWStr() { - return std::wstring(); +String cClipboardNull::GetWideText() { + return String(); } }}}} diff --git a/src/window/backend/null/cclipboardnull.hpp b/src/window/backend/null/cclipboardnull.hpp index 445c2bf05..4c2e2c31f 100644 --- a/src/window/backend/null/cclipboardnull.hpp +++ b/src/window/backend/null/cclipboardnull.hpp @@ -12,11 +12,11 @@ class EE_API cClipboardNull : public cClipboard { std::string GetText(); - std::wstring GetTextWStr(); - + String GetWideText(); + void SetText( const std::string& Text ); - void SetText( const std::wstring& Text ); + void SetText( const String& Text ); protected: friend class cWindowNull; diff --git a/src/window/cclipboard.hpp b/src/window/cclipboard.hpp index c4f2387cb..5339289cb 100644 --- a/src/window/cclipboard.hpp +++ b/src/window/cclipboard.hpp @@ -12,14 +12,14 @@ class cClipboard { /** @return The Clipboard Text if available */ virtual std::string GetText() = 0; - /** @return The Clipboard Text if available ( as std::wstring ) */ - virtual std::wstring GetTextWStr() = 0; - + /** @return The Clipboard Text if available ( as String ) */ + virtual String GetWideText() = 0; + /** Set the current clipboard text */ virtual void SetText( const std::string& Text ) = 0; /** Set the current clipboard text */ - virtual void SetText( const std::wstring& Text ) = 0; + virtual void SetText( const String& Text ) = 0; cWindow * GetWindow() const; protected: diff --git a/src/window/cinputtextbuffer.cpp b/src/window/cinputtextbuffer.cpp index b81ed7d54..9c25bc9b5 100755 --- a/src/window/cinputtextbuffer.cpp +++ b/src/window/cinputtextbuffer.cpp @@ -88,7 +88,7 @@ void cInputTextBuffer::Update( InputEvent* Event ) { ( ( Event->key.keysym.mod & KEYMOD_CTRL ) && Event->key.keysym.sym == KEY_V ) ) ) { - std::wstring txt = mWindow->GetClipboard()->GetTextWStr(); + String txt = mWindow->GetClipboard()->GetWideText(); if ( !SupportNewLine() ) { Uint32 pos = txt.find_first_of( '\n' ); @@ -182,7 +182,7 @@ void cInputTextBuffer::Update( InputEvent* Event ) { ChangedSinceLastUpdate( true ); if ( AutoPrompt() ) { - mText += c; + mText.append( 1, static_cast ( c ) ); mPromptPos = (eeInt)mText.size(); } else { InsertChar( mText, mPromptPos, c ); @@ -256,7 +256,7 @@ void cInputTextBuffer::Update( InputEvent* Event ) { mEnterCall(); } else if ( CanAdd() && isCharacter(c) && !Input->MetaPressed() && !Input->AltPressed() && !Input->ControlPressed() ) { if ( !( AllowOnlyNumbers() && !isNumber( c, AllowDotsInNumbers() ) ) ) { - mText += c; + mText.append( 1, static_cast ( c ) ); } } } @@ -350,7 +350,7 @@ void cInputTextBuffer::SetReturnCallback( EnterCallback EC ) { mEnterCall = EC; } -void cInputTextBuffer::Buffer( const std::wstring& str ) { +void cInputTextBuffer::Buffer( const String& str ) { if ( mText != str ) { mText = str; ChangedSinceLastUpdate( true ); @@ -402,7 +402,7 @@ const Uint32& cInputTextBuffer::MaxLenght() const { return mMaxLenght; } -std::wstring cInputTextBuffer::Buffer() const { +String cInputTextBuffer::Buffer() const { return mText; } diff --git a/src/window/cinputtextbuffer.hpp b/src/window/cinputtextbuffer.hpp index 18a0a9d49..a2e87b088 100755 --- a/src/window/cinputtextbuffer.hpp +++ b/src/window/cinputtextbuffer.hpp @@ -29,10 +29,10 @@ class EE_API cInputTextBuffer { ~cInputTextBuffer(); /** @return The current buffer */ - std::wstring Buffer() const; + String Buffer() const; /** Set a new current buffer */ - void Buffer( const std::wstring& str ); + void Buffer( const String& str ); /** @return If input buffer is active */ bool Active() const; @@ -110,7 +110,7 @@ class EE_API cInputTextBuffer { void CursorToEnd(); protected: cWindow * mWindow; - std::wstring mText; + String mText; Uint32 mFlags; Uint32 mCallback; eeInt mPromptPos;