From a39afd4efe8f2e2eb20daa0d310e08671e4a6ffc Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 9 Apr 2023 19:53:33 +0200 Subject: [PATCH] CTextLogger: Manage keyboard and mouse inputs Manage them under 1 member variable. --- r5dev/thirdparty/imgui/misc/imgui_logger.cpp | 12 +++++------- r5dev/thirdparty/imgui/misc/imgui_logger.h | 13 ++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/r5dev/thirdparty/imgui/misc/imgui_logger.cpp b/r5dev/thirdparty/imgui/misc/imgui_logger.cpp index f4dde545..a12e7578 100644 --- a/r5dev/thirdparty/imgui/misc/imgui_logger.cpp +++ b/r5dev/thirdparty/imgui/misc/imgui_logger.cpp @@ -27,8 +27,7 @@ CTextLogger::CTextLogger() , m_bScrollToBottom(true) , m_bScrollToCursor(false) , m_bScrolledToMax(false) - , m_bHandleKeyboardInputs(true) - , m_bHandleMouseInputs(true) + , m_bHandleUserInputs(true) , m_bWithinLoggingRect(false) , m_bShowWhiteSpaces(false) , m_bLinesOffsetForward(false) @@ -769,14 +768,13 @@ void CTextLogger::Render() bool bHoveredScrollbar = hoveredID && (hoveredID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_X) || hoveredID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_Y)); bool bActiveScrollbar = activeID && (activeID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_X) || activeID == ImGui::GetWindowScrollbarID(pWindow, ImGuiAxis_Y)); - if (m_bHandleKeyboardInputs) + if (m_bHandleUserInputs) { HandleKeyboardInputs(bHoveredScrollbar, bActiveScrollbar); ImGui::PushAllowKeyboardFocus(true); - } - if (m_bHandleMouseInputs) HandleMouseInputs(bHoveredScrollbar, bActiveScrollbar); + } /* Compute mCharAdvance regarding to scaled font size (Ctrl + mouse wheel)*/ const float fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr).x; @@ -937,7 +935,7 @@ void CTextLogger::Render() ImGui::Dummy(ImVec2((longest + 2), m_Lines.size() * m_CharAdvance.y)); - m_bScrolledToMax = ImGui::GetScrollY() >= ImGui::GetScrollMaxY(); + SetScrolledToMax(ImGui::GetScrollY() >= ImGui::GetScrollMaxY()); if (m_bScrollToBottom || (m_bAutoScroll && m_bScrolledToMax && !m_bScrollToCursor)) { @@ -946,7 +944,7 @@ void CTextLogger::Render() } m_bScrollToCursor = false; - if (m_bHandleKeyboardInputs) + if (m_bHandleUserInputs) ImGui::PopAllowKeyboardFocus(); ImGui::PopStyleVar(); diff --git a/r5dev/thirdparty/imgui/misc/imgui_logger.h b/r5dev/thirdparty/imgui/misc/imgui_logger.h index b8f7f471..6b7783db 100644 --- a/r5dev/thirdparty/imgui/misc/imgui_logger.h +++ b/r5dev/thirdparty/imgui/misc/imgui_logger.h @@ -134,15 +134,15 @@ public: void MoveCursor(int aLines, bool aForward = true); void SetCursorPosition(const Coordinates& aPosition); - inline void SetHandleMouseInputs (bool aValue){ m_bHandleMouseInputs = aValue;} - inline bool IsHandleMouseInputsEnabled() const { return m_bHandleKeyboardInputs; } - - inline void SetHandleKeyboardInputs (bool aValue){ m_bHandleKeyboardInputs = aValue;} - inline bool IsHandleKeyboardInputsEnabled() const { return m_bHandleKeyboardInputs; } + inline void SetHandleUserInputs (bool aValue){ m_bHandleUserInputs = aValue;} + inline bool IsHandleUserInputs() const { return m_bHandleUserInputs; } inline void SetShowWhitespaces(bool aValue) { m_bShowWhiteSpaces = aValue; } inline bool IsShowingWhitespaces() const { return m_bShowWhiteSpaces; } + inline void SetScrolledToMax(bool aValue) { m_bScrolledToMax = aValue; } + inline bool IsScrolledToMax() const { return m_bScrolledToMax; } + void SetTabSize(int aValue); inline int GetTabSize() const { return m_nTabSize; } @@ -210,8 +210,7 @@ public: bool m_bScrollToCursor; bool m_bScrolledToMax; private: - bool m_bHandleKeyboardInputs; - bool m_bHandleMouseInputs; + bool m_bHandleUserInputs; bool m_bWithinLoggingRect; bool m_bShowWhiteSpaces; bool m_bLinesOffsetForward;