From 41f801365ae2c746b4825e251b6b6af41ebbb273 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 19 Sep 2022 20:21:18 +0200 Subject: [PATCH] CConsole: fixed color bug when missing newline * Fixed bug where the in-game console could not color the line when no newline was found. * Changed behavior to only newline when: '\n' has been found, or the context has changed (using a print without newline will continue to print on the same line in the console). * Pass ImVec4 parameter in 'CTextLogger::InsertTextAt' by reference. --- r5dev/thirdparty/imgui/include/imgui_logger.h | 3 +- r5dev/thirdparty/imgui/src/imgui_logger.cpp | 49 +++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/r5dev/thirdparty/imgui/include/imgui_logger.h b/r5dev/thirdparty/imgui/include/imgui_logger.h index 824b7f83..7b6bfea5 100644 --- a/r5dev/thirdparty/imgui/include/imgui_logger.h +++ b/r5dev/thirdparty/imgui/include/imgui_logger.h @@ -185,7 +185,8 @@ private: Coordinates SanitizeCoordinates(const Coordinates& aValue) const; void Advance(Coordinates& aCoordinates) const; void DeleteRange(const Coordinates& aStart, const Coordinates& aEnd); - int InsertTextAt(Coordinates& aWhere, const char* aValue, ImVec4 aColor); + int InsertTextAt(Coordinates& aWhere, const char* aValue, const ImVec4& aColor); + void MarkNewline(Coordinates& aWhere, const ImVec4& aColor, int aIndex); Coordinates ScreenPosToCoordinates(const ImVec2& aPosition) const; Coordinates FindWordStart(const Coordinates& aFrom) const; Coordinates FindWordEnd(const Coordinates& aFrom) const; diff --git a/r5dev/thirdparty/imgui/src/imgui_logger.cpp b/r5dev/thirdparty/imgui/src/imgui_logger.cpp index 4265db97..87ea7102 100644 --- a/r5dev/thirdparty/imgui/src/imgui_logger.cpp +++ b/r5dev/thirdparty/imgui/src/imgui_logger.cpp @@ -196,7 +196,24 @@ void CTextLogger::DeleteRange(const Coordinates & aStart, const Coordinates & aE } } -int CTextLogger::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aValue, ImVec4 aColor) +void CTextLogger::MarkNewline(Coordinates& /* inout */ aWhere, const ImVec4& aColor, int aIndex) +{ + if (aIndex < static_cast(m_Lines[aWhere.m_nLine].size())) + { + Line& newLine = InsertLine(aWhere.m_nLine + 1); + Line& line = m_Lines[aWhere.m_nLine]; + newLine.insert(newLine.begin(), line.begin() + aIndex, line.end()); + line.erase(line.begin() + aIndex, line.end()); + } + else + { + Line& newLine = InsertLine(aWhere.m_nLine + 1); + Line& line = m_Lines[aWhere.m_nLine]; + line.insert(line.begin() + aIndex, Glyph('\n', aColor)); + } +} + +int CTextLogger::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aValue, const ImVec4& aColor) { int cindex = GetCharacterIndex(aWhere); int totalLines = 0; @@ -212,19 +229,7 @@ int CTextLogger::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aVal } else if (*aValue == '\n') { - if (cindex < static_cast(m_Lines[aWhere.m_nLine].size())) - { - Line& newLine = InsertLine(aWhere.m_nLine + 1); - Line& line = m_Lines[aWhere.m_nLine]; - newLine.insert(newLine.begin(), line.begin() + cindex, line.end()); - line.erase(line.begin() + cindex, line.end()); - } - else - { - Line& newLine = InsertLine(aWhere.m_nLine + 1); - Line& line = m_Lines[aWhere.m_nLine]; - line.insert(line.begin() + cindex, Glyph(*aValue, aColor)); - } + MarkNewline(aWhere, aColor, cindex); ++aWhere.m_nLine; aWhere.m_nColumn = 0; cindex = 0; @@ -234,12 +239,28 @@ int CTextLogger::InsertTextAt(Coordinates& /* inout */ aWhere, const char * aVal else { Line& line = m_Lines[aWhere.m_nLine]; + if (!line.empty() && ImGui::ColorConvertFloat4ToU32(aColor) != ImGui::ColorConvertFloat4ToU32(line[0].m_Color)) + { + MarkNewline(aWhere, line[0].m_Color, cindex); + ++aWhere.m_nLine; + aWhere.m_nColumn = 0; + cindex = 0; + ++totalLines; + continue; + } + int d = UTF8CharLength(*aValue); while (d-- > 0 && *aValue != '\0') line.insert(line.begin() + cindex++, Glyph(*aValue++, aColor)); ++aWhere.m_nColumn; } } + if (!*aValue) + { + Line& line = m_Lines[aWhere.m_nLine]; + if (!line.empty()) + line.insert(line.begin() + cindex, Glyph(' ', aColor)); + } return totalLines; }