From bddde13b06ed8794333bc68cd3c386209ae8fe92 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 29 Feb 2024 02:16:05 +0100 Subject: [PATCH] ImGui: use Dear ImGui API for the cursor render blinker --- r5dev/thirdparty/imgui/misc/imgui_logger.cpp | 18 ++++++++++++------ r5dev/thirdparty/imgui/misc/imgui_logger.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/r5dev/thirdparty/imgui/misc/imgui_logger.cpp b/r5dev/thirdparty/imgui/misc/imgui_logger.cpp index 0212c68f..a0f3cf47 100644 --- a/r5dev/thirdparty/imgui/misc/imgui_logger.cpp +++ b/r5dev/thirdparty/imgui/misc/imgui_logger.cpp @@ -36,7 +36,7 @@ CTextLogger::CTextLogger() , m_flLineSpacing(1.0f) , m_SelectionMode(SelectionMode::Normal) , m_flLastClick(-1.0) - , m_nStartTime(std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count()) + , m_nStartTime(-1.0f) { m_Lines.push_back(Line()); } @@ -864,10 +864,16 @@ void CTextLogger::Render() // Render the cursor if (m_State.m_CursorPosition.m_nLine == lineNo && ImGui::IsWindowFocused()) { - const ImS64 timeEnd = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - const ImU64 elapsed = timeEnd - m_nStartTime; + // Initialize the cursor start render time, this is done here + // as Dear ImGui typically isn't initialized during the + // construction of this class + if (m_nStartTime == -1.0) + m_nStartTime = ImGui::GetTime(); - if (elapsed > 400) + const double currTime = ImGui::GetTime(); + const double elapsed = currTime - m_nStartTime; + + if (elapsed > 0.4) { const float width = 1.0f; const float cx = TextDistanceToLineStart(m_State.m_CursorPosition); @@ -877,8 +883,8 @@ void CTextLogger::Render() drawList->AddRectFilled(cstart, cend, 0xffe0e0e0); - if (elapsed > 800) - m_nStartTime = timeEnd; + if (elapsed > 0.8) + m_nStartTime = currTime; } } diff --git a/r5dev/thirdparty/imgui/misc/imgui_logger.h b/r5dev/thirdparty/imgui/misc/imgui_logger.h index f46b4d9e..5465842d 100644 --- a/r5dev/thirdparty/imgui/misc/imgui_logger.h +++ b/r5dev/thirdparty/imgui/misc/imgui_logger.h @@ -241,7 +241,7 @@ private: float m_flLineSpacing; SelectionMode m_SelectionMode; double m_flLastClick; - uint64_t m_nStartTime; + double m_nStartTime; Coordinates m_InteractiveStart; Coordinates m_InteractiveEnd;