Changeset View
Changeset View
Standalone View
Standalone View
source/ps/CConsole.cpp
/* Copyright (C) 2016 Wildfire Games. | /* Copyright (C) 2019 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 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | |||||
void CConsole::DrawHistory(CTextRenderer& textRenderer) | void CConsole::DrawHistory(CTextRenderer& textRenderer) | ||||
{ | { | ||||
int i = 1; | int i = 1; | ||||
std::deque<std::wstring>::iterator Iter; //History iterator | std::deque<std::wstring>::iterator Iter; //History iterator | ||||
CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory | std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | ||||
textRenderer.Color(1.0f, 1.0f, 1.0f); | textRenderer.Color(1.0f, 1.0f, 1.0f); | ||||
for (Iter = m_deqMsgHistory.begin(); | for (Iter = m_deqMsgHistory.begin(); | ||||
Iter != m_deqMsgHistory.end() | Iter != m_deqMsgHistory.end() | ||||
&& (((i - m_iMsgHistPos + 1) * m_iFontHeight) < m_fHeight); | && (((i - m_iMsgHistPos + 1) * m_iFontHeight) < m_fHeight); | ||||
++Iter) | ++Iter) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | else | ||||
} | } | ||||
} | } | ||||
return; | return; | ||||
case SDLK_HOME: | case SDLK_HOME: | ||||
if (g_keys[SDLK_RCTRL] || g_keys[SDLK_LCTRL]) | if (g_keys[SDLK_RCTRL] || g_keys[SDLK_LCTRL]) | ||||
{ | { | ||||
CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory | std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | ||||
int linesShown = (int)m_fHeight/m_iFontHeight - 4; | int linesShown = (int)m_fHeight/m_iFontHeight - 4; | ||||
m_iMsgHistPos = clamp((int)m_deqMsgHistory.size() - linesShown, 1, (int)m_deqMsgHistory.size()); | m_iMsgHistPos = clamp((int)m_deqMsgHistory.size() - linesShown, 1, (int)m_deqMsgHistory.size()); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
m_iBufferPos = 0; | m_iBufferPos = 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (m_deqBufHistory.size()) | ||||
} | } | ||||
} | } | ||||
return; | return; | ||||
// END: Buffer History Lookup | // END: Buffer History Lookup | ||||
// BEGIN: Message History Lookup | // BEGIN: Message History Lookup | ||||
case SDLK_PAGEUP: | case SDLK_PAGEUP: | ||||
{ | { | ||||
CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory | std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | ||||
if (m_iMsgHistPos != (int)m_deqMsgHistory.size()) m_iMsgHistPos++; | if (m_iMsgHistPos != (int)m_deqMsgHistory.size()) m_iMsgHistPos++; | ||||
return; | return; | ||||
} | } | ||||
case SDLK_PAGEDOWN: | case SDLK_PAGEDOWN: | ||||
if (m_iMsgHistPos != 1) m_iMsgHistPos--; | if (m_iMsgHistPos != 1) m_iMsgHistPos--; | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | while ( oldNewline+m_charsPerPage < wrapAround.length() ) | ||||
else | else | ||||
oldNewline += distance+1; | oldNewline += distance+1; | ||||
} | } | ||||
} | } | ||||
// Split into lines and add each one individually | // Split into lines and add each one individually | ||||
oldNewline = 0; | oldNewline = 0; | ||||
{ | { | ||||
CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory | std::lock_guard<std::mutex> lock(m_Mutex); // needed for safe access to m_deqMsgHistory | ||||
while ( (distance = wrapAround.find(newline, oldNewline)) != wrapAround.npos) | while ( (distance = wrapAround.find(newline, oldNewline)) != wrapAround.npos) | ||||
{ | { | ||||
distance -= oldNewline; | distance -= oldNewline; | ||||
m_deqMsgHistory.push_front(wrapAround.substr(oldNewline, distance)); | m_deqMsgHistory.push_front(wrapAround.substr(oldNewline, distance)); | ||||
oldNewline += distance+1; | oldNewline += distance+1; | ||||
} | } | ||||
m_deqMsgHistory.push_front(wrapAround.substr(oldNewline)); | m_deqMsgHistory.push_front(wrapAround.substr(oldNewline)); | ||||
▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator