From 71ca599869ae499bcd4e03d6cc46100249ed6ba5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 9 Jul 2019 19:19:35 +0200 Subject: [PATCH] SDK/Console: Fix history lines handling --- SDK/src/NDK/Console.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/SDK/src/NDK/Console.cpp b/SDK/src/NDK/Console.cpp index 964bb6b9c..abd333bd3 100644 --- a/SDK/src/NDK/Console.cpp +++ b/SDK/src/NDK/Console.cpp @@ -38,7 +38,8 @@ namespace Ndk BaseWidget(parent), m_historyPosition(0), m_defaultFont(Nz::Font::GetDefault()), - m_characterSize(24) + m_characterSize(24), + m_maxHistoryLines(200) { // History m_history = Add(); @@ -107,6 +108,9 @@ namespace Ndk */ void Console::AddLine(const Nz::String& text, const Nz::Color& color) { + if (m_historyLines.size() >= m_maxHistoryLines) + m_historyLines.erase(m_historyLines.begin()); + m_historyLines.emplace_back(Line{ color, text }); m_history->AppendText(text + '\n'); m_history->Resize(m_history->GetPreferredSize()); @@ -183,10 +187,12 @@ namespace Ndk /*! * \brief Performs this action when an input is added to the console */ - void Console::ExecuteInput(const TextAreaWidget* textArea, bool* /*ignoreDefaultAction*/) + void Console::ExecuteInput(const TextAreaWidget* textArea, bool* ignoreDefaultAction) { NazaraAssert(textArea == m_input, "Unexpected signal from an other text area"); + *ignoreDefaultAction = true; + Nz::String input = m_input->GetText(); Nz::String inputCmd = input.SubString(s_inputPrefixSize); m_input->SetText(s_inputPrefix); @@ -212,11 +218,8 @@ namespace Ndk unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight; float historyHeight = size.y - lineHeight; - m_maxHistoryLines = static_cast(std::ceil(historyHeight / lineHeight)); - float diff = historyHeight - m_maxHistoryLines * lineHeight; - - m_historyArea->SetPosition(origin.x, origin.y + diff); - m_historyArea->Resize({ size.x, historyHeight - diff - 4.f }); + m_historyArea->SetPosition(origin.x, origin.y); + m_historyArea->Resize({ size.x, historyHeight - 4.f }); m_input->Resize({size.x, size.y - historyHeight}); m_input->SetPosition(origin.x, origin.y + historyHeight);