Index: source/ps/CConsole.h =================================================================== --- source/ps/CConsole.h +++ source/ps/CConsole.h @@ -70,16 +70,16 @@ void Render(); - void InsertChar(const int szChar, const wchar_t cooked); + void InsertChar(const int szChar, const char cooked); void InsertMessage(const std::string& message); - void SetBuffer(const wchar_t* szMessage); + void SetBuffer(const char* szMessage); void UseHistoryFile(const VfsPath& filename, int historysize); // Only returns a pointer to the buffer; copy out of here if you want to keep it. - const wchar_t* GetBuffer(); + const char* GetBuffer(); void FlushBuffer(); bool IsActive() { return m_bVisible; } @@ -103,12 +103,12 @@ // allows implementing other animations than sliding, e.g. fading in/out. float m_fVisibleFrac; - std::deque m_deqMsgHistory; // protected by m_Mutex - std::deque m_deqBufHistory; + std::deque m_deqMsgHistory; // protected by m_Mutex + std::deque m_deqBufHistory; int m_iMsgHistPos; - wchar_t* m_szBuffer; + char* m_szBuffer; int m_iBufferPos; int m_iBufferLength; @@ -131,7 +131,7 @@ bool IsFull() { return (m_iBufferLength == CONSOLE_BUFFER_SIZE); } bool IsEmpty() { return (m_iBufferLength == 0); } - void ProcessBuffer(const wchar_t* szLine); + void ProcessBuffer(const char* szLine); void LoadHistory(); void SaveHistory(); Index: source/ps/CConsole.cpp =================================================================== --- source/ps/CConsole.cpp +++ source/ps/CConsole.cpp @@ -55,7 +55,7 @@ m_fVisibleFrac = 0.0f; - m_szBuffer = new wchar_t[CONSOLE_BUFFER_SIZE]; + m_szBuffer = new char[CONSOLE_BUFFER_SIZE]; FlushBuffer(); m_iMsgHistPos = 1; @@ -122,7 +122,7 @@ void CConsole::FlushBuffer() { // Clear the buffer and set the cursor and length to 0 - memset(m_szBuffer, '\0', sizeof(wchar_t) * CONSOLE_BUFFER_SIZE); + memset(m_szBuffer, '\0', sizeof(char) * CONSOLE_BUFFER_SIZE); m_iBufferPos = m_iBufferLength = 0; } @@ -236,7 +236,7 @@ { int i = 1; - std::deque::iterator Iter; //History iterator + std::deque::iterator Iter; //History iterator std::lock_guard lock(m_Mutex); // needed for safe access to m_deqMsgHistory @@ -315,7 +315,7 @@ //Inserts a character into the buffer. -void CConsole::InsertChar(const int szChar, const wchar_t cooked) +void CConsole::InsertChar(const int szChar, const char cooked) { static int iHistoryPos = -1; @@ -480,8 +480,8 @@ // (TODO: this text-wrapping is rubbish since we now use variable-width fonts) //Insert newlines to wraparound text where needed - std::wstring wrapAround = wstring_from_utf8(message.c_str()); - std::wstring newline(L"\n"); + std::string wrapAround = message; + std::string newline("\n"); size_t oldNewline=0; size_t distance; @@ -516,21 +516,21 @@ } } -const wchar_t* CConsole::GetBuffer() +const char* CConsole::GetBuffer() { m_szBuffer[m_iBufferLength] = 0; return( m_szBuffer ); } -void CConsole::SetBuffer(const wchar_t* szMessage) +void CConsole::SetBuffer(const char* szMessage) { int oldBufferPos = m_iBufferPos; // remember since FlushBuffer will set it to 0 FlushBuffer(); - wcsncpy(m_szBuffer, szMessage, CONSOLE_BUFFER_SIZE); + strncpy(m_szBuffer, szMessage, CONSOLE_BUFFER_SIZE); m_szBuffer[CONSOLE_BUFFER_SIZE-1] = 0; - m_iBufferLength = static_cast(wcslen(m_szBuffer)); + m_iBufferLength = static_cast(strlen(m_szBuffer)); m_iBufferPos = std::min(oldBufferPos, m_iBufferLength); } @@ -542,12 +542,12 @@ LoadHistory(); } -void CConsole::ProcessBuffer(const wchar_t* szLine) +void CConsole::ProcessBuffer(const char* szLine) { - if (!szLine || wcslen(szLine) <= 0) + if (!szLine || strlen(szLine) <= 0) return; - ENSURE(wcslen(szLine) < CONSOLE_BUFFER_SIZE); + ENSURE(strlen(szLine) < CONSOLE_BUFFER_SIZE); m_deqBufHistory.push_front(szLine); SaveHistory(); // Do this each line for the moment; if a script causes @@ -576,14 +576,12 @@ if (g_VFS->LoadFile(m_sHistoryFile, buf, buflen) < 0) return; - CStr bytes ((char*)buf.get(), buflen); - - CStrW str (bytes.FromUTF8()); + CStr str ((char*)buf.get(), buflen); size_t pos = 0; - while (pos != CStrW::npos) + while (pos != CStr::npos) { pos = str.find('\n'); - if (pos != CStrW::npos) + if (pos != CStr::npos) { if (pos > 0) m_deqBufHistory.push_front(str.Left(str[pos-1] == '\r' ? pos - 1 : pos)); @@ -598,12 +596,12 @@ { WriteBuffer buffer; const int linesToSkip = (int)m_deqBufHistory.size() - m_MaxHistoryLines; - std::deque::reverse_iterator it = m_deqBufHistory.rbegin(); + std::deque::reverse_iterator it = m_deqBufHistory.rbegin(); if(linesToSkip > 0) std::advance(it, linesToSkip); for (; it != m_deqBufHistory.rend(); ++it) { - CStr8 line = CStrW(*it).ToUTF8(); + CStr8 line = *it; buffer.Append(line.data(), line.length()); static const char newline = '\n'; buffer.Append(&newline, 1); @@ -646,8 +644,7 @@ } else if (g_Console->IsActive() && hotkey == "copy") { - std::string text = utf8_from_wstring(g_Console->GetBuffer()); - SDL_SetClipboardText(text.c_str()); + SDL_SetClipboardText(g_Console->GetBuffer()); return IN_HANDLED; } else if (g_Console->IsActive() && hotkey == "paste") @@ -656,10 +653,10 @@ if (!utf8_text) return IN_HANDLED; - std::wstring text = wstring_from_utf8(utf8_text); + std::string text(utf8_text); SDL_free(utf8_text); - for (wchar_t c : text) + for (char c : text) g_Console->InsertChar(0, c); return IN_HANDLED; @@ -669,14 +666,11 @@ if (!g_Console->IsActive()) return IN_PASS; - // In SDL2, we no longer get Unicode wchars via SDL_Keysym - // we use text input events instead and they provide UTF-8 chars if (ev->ev.type == SDL_TEXTINPUT && !HotkeyIsPressed("console.toggle")) { - // TODO: this could be more efficient with an interface to insert UTF-8 strings directly - std::wstring wstr = wstring_from_utf8(ev->ev.text.text); - for (size_t i = 0; i < wstr.length(); ++i) - g_Console->InsertChar(0, wstr[i]); + CStr str(ev->ev.text.text); + for (size_t i = 0; i < str.length(); ++i) + g_Console->InsertChar(0, str[i]); return IN_HANDLED; } // TODO: text editing events for IME support