Changeset View
Changeset View
Standalone View
Standalone View
source/ps/CConsole.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 16 Lines | |||||
#include "graphics/FontMetrics.h" | #include "graphics/FontMetrics.h" | ||||
#include "graphics/ShaderManager.h" | #include "graphics/ShaderManager.h" | ||||
#include "graphics/TextRenderer.h" | #include "graphics/TextRenderer.h" | ||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "gui/GUIMatrix.h" | #include "gui/GUIMatrix.h" | ||||
#include "lib/ogl.h" | #include "lib/ogl.h" | ||||
#include "lib/sysdep/clipboard.h" | |||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "network/NetClient.h" | #include "network/NetClient.h" | ||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
▲ Show 20 Lines • Show All 483 Lines • ▼ Show 20 Lines | |||||
void CConsole::SetBuffer(const wchar_t* szMessage) | void CConsole::SetBuffer(const wchar_t* szMessage) | ||||
{ | { | ||||
int oldBufferPos = m_iBufferPos; // remember since FlushBuffer will set it to 0 | int oldBufferPos = m_iBufferPos; // remember since FlushBuffer will set it to 0 | ||||
FlushBuffer(); | FlushBuffer(); | ||||
wcsncpy(m_szBuffer, szMessage, CONSOLE_BUFFER_SIZE); | wcsncpy(m_szBuffer, szMessage, CONSOLE_BUFFER_SIZE); | ||||
m_szBuffer[CONSOLE_BUFFER_SIZE-1] = 0; | m_szBuffer[CONSOLE_BUFFER_SIZE-1] = 0; | ||||
m_iBufferLength = (int)wcslen(m_szBuffer); | m_iBufferLength = static_cast<int>(wcslen(m_szBuffer)); | ||||
m_iBufferPos = std::min(oldBufferPos, m_iBufferLength); | m_iBufferPos = std::min(oldBufferPos, m_iBufferLength); | ||||
} | } | ||||
void CConsole::UseHistoryFile(const VfsPath& filename, int max_history_lines) | void CConsole::UseHistoryFile(const VfsPath& filename, int max_history_lines) | ||||
{ | { | ||||
m_MaxHistoryLines = max_history_lines; | m_MaxHistoryLines = max_history_lines; | ||||
m_sHistoryFile = filename; | m_sHistoryFile = filename; | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if ((int)ev->ev.type == SDL_HOTKEYDOWN) | ||||
if (hotkey == "console.toggle") | if (hotkey == "console.toggle") | ||||
{ | { | ||||
g_Console->ToggleVisible(); | g_Console->ToggleVisible(); | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
else if (g_Console->IsActive() && hotkey == "copy") | else if (g_Console->IsActive() && hotkey == "copy") | ||||
{ | { | ||||
sys_clipboard_set(g_Console->GetBuffer()); | std::string text = utf8_from_wstring(g_Console->GetBuffer()); | ||||
SDL_SetClipboardText(text.c_str()); | |||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
else if (g_Console->IsActive() && hotkey == "paste") | else if (g_Console->IsActive() && hotkey == "paste") | ||||
{ | { | ||||
wchar_t* text = sys_clipboard_get(); | char* utf8_text = SDL_GetClipboardText(); | ||||
if (text) | if (!utf8_text) | ||||
{ | return IN_HANDLED; | ||||
for (wchar_t* c = text; *c; c++) | |||||
g_Console->InsertChar(0, *c); | std::wstring text = wstring_from_utf8(utf8_text); | ||||
SDL_free(utf8_text); | |||||
for (wchar_t c : text) | |||||
g_Console->InsertChar(0, c); | |||||
sys_clipboard_free(text); | |||||
} | |||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
} | } | ||||
if (!g_Console->IsActive()) | if (!g_Console->IsActive()) | ||||
return IN_PASS; | return IN_PASS; | ||||
// In SDL2, we no longer get Unicode wchars via SDL_Keysym | // In SDL2, we no longer get Unicode wchars via SDL_Keysym | ||||
Show All 27 Lines |
Wildfire Games · Phabricator